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

Method ObjectForDrawing

engine/Poseidon/World/Scene/Scene.cpp:793–918  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

791
792#define MaxDistance2(obj) (Square(ENGINE_CONFIG.objectsZ))
793
794void Scene::ObjectForDrawing(Object* obj, int forceLOD, ClipFlags clip)
795{
796 LODShapeWithShadow* shape = obj->GetShapeOnPos(obj->Position());
797
798 // some objects may be trivially clipped
799 // get rid of them ...
800 bool invisible = false;
801 Vector3Val pos = obj->Position();
802 if (!shape)
803 {
804 return; // nothing to draw
805 }
806 float radius = obj->GetRadius();
807 // get object position in clipping coordinates
808
809 if (obj != GWorld->CameraOn())
810 {
811 if (_camera->IsClipped(pos, radius, 1))
812 {
813 // check if shadow is enabled
814 if (shape->Special() & NoShadow)
815 {
816 return;
817 }
818 // some invisible objects have visible shadows
819 // simple test - shadow possible
820 if (_camera->IsClipped(pos, radius + 50, 1))
821 {
822 return;
823 }
824
825 Vector3 objTop = obj->Position() + Vector3(0, radius, 0);
826 Vector3 shadowPos = objTop;
827
828 // estimate shadow position
829 if (!ShadowPos(objTop, shadowPos, _mainLight))
830 {
831 return;
832 }
833 if (_camera->IsClipped(shadowPos, 0.5f, 1))
834 {
835 // shadow of object top is clipped
836 // check whole shadow shape
837 // estimate shadow radius and shadow center
838 float distTopBot = shadowPos.Distance(pos) * 0.5f;
839 Vector3 shadowCenter = (shadowPos + pos) * 0.5f;
840 float shadowRadius = floatMax(distTopBot, radius);
841 if (_camera->IsClipped(shadowCenter, shadowRadius, 1))
842 {
843 return;
844 }
845 }
846 invisible = true;
847 }
848 }
849
850 // calculate distance

Callers 9

SimulateMethod · 0.80
DrawDiagsMethod · 0.80
DrawDiagsMethod · 0.80
DrawDiagsMethod · 0.80
DrawDiagsMethod · 0.80
DrawDiagsMethod · 0.80
DrawDiagsMethod · 0.80
DrawRectMethod · 0.80
DrawDiagsMethod · 0.80

Calls 15

floatMaxFunction · 0.85
InvSqrtFunction · 0.85
saturateMaxFunction · 0.85
CameraOnMethod · 0.80
IsClippedMethod · 0.80
InvLeftMethod · 0.80
InvTopMethod · 0.80
Vector3Class · 0.50
SquareFunction · 0.50
GetShapeOnPosMethod · 0.45
PositionMethod · 0.45
SpecialMethod · 0.45

Tested by

no test coverage detected