| 791 | |
| 792 | #define MaxDistance2(obj) (Square(ENGINE_CONFIG.objectsZ)) |
| 793 | |
| 794 | void 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 |
no test coverage detected