MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / Animate

Method Animate

engine/Poseidon/World/Scene/ObjectClasses.cpp:512–641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510namespace Poseidon
511{
512void ForestPlain::Animate(int level)
513{
514 Shape* shape = _shape->Level(level);
515 if (!shape)
516 {
517 return;
518 }
519
520 PoseidonAssert(GLandscape);
521 // save original position
522 shape->SaveOriginalPos();
523
524 if (_singleMatrixT1 || _singleMatrixT2)
525 {
526 // matrix included in object matrix
527 }
528 else
529 {
530 float xC = Position().X();
531 float zC = Position().Z();
532 // fine rectangles are not used - use rough instead
533 // calculate surface level on given coordinates
534 float xRel = xC * InvLandGrid;
535 float zRel = zC * InvLandGrid;
536 int x = toIntFloor(xRel);
537 int z = toIntFloor(zRel);
538 float xf = x;
539 float zf = z;
540
541 int subdivLog = TerrainRangeLog - LandRangeLog;
542 int subdiv = 1 << subdivLog;
543
544 int xs = x * subdiv;
545 int zs = z * subdiv;
546
547 Landscape* land = GLandscape;
548 float y00 = land->GetHeight(zs, xs);
549 float y01 = land->GetHeight(zs, xs + subdiv);
550 float y10 = land->GetHeight(zs + subdiv, xs);
551 float y11 = land->GetHeight(zs + subdiv, xs + subdiv);
552
553 float d1000 = y10 - y00;
554 float d0100 = y01 - y00;
555
556 float d1011 = y10 - y11;
557 float d0111 = y01 - y11;
558
559 shape->InvalidateNormals();
560
561 Matrix4Val toWorld = Transform();
562 Matrix4Val fromWorld = GetInvTransform();
563
564 // convert plane equations to model space
565 // change object shape to reflect surface
566 // most forest objects are not rotated, only offseted - this can be easily optimized
567 bool rotated = Direction() * VForward < 0.99;
568 float yOffset = -_shape->BoundingCenter().Y();
569 if (!rotated)

Callers

nothing calls this directly

Calls 15

TransformFunction · 0.85
DirectionClass · 0.85
LevelMethod · 0.80
SaveOriginalPosMethod · 0.80
BoundingCenterMethod · 0.80
OrigPosMethod · 0.80
MinMaxOrigCornerMethod · 0.80
SetMinMaxMethod · 0.80
CheckMinMaxFunction · 0.50
XMethod · 0.45
ZMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected