function IsTriangleInFrustum(Vektor1,Vektor2,Vektor3:TD3DVector):boolean;
begin
Result:=
((PlaneTop.a*Vektor1.x + PlaneTop.b*Vektor1.y + PlaneTop.c*Vektor1.z + PlaneTop.d > 0)or
(PlaneTop.a*Vektor2.x + PlaneTop.b*Vektor2.y + PlaneTop.c*Vektor2.z + PlaneTop.d > 0)or
(PlaneTop.a*Vektor3.x + PlaneTop.b*Vektor3.y + PlaneTop.c*Vektor3.z + PlaneTop.d > 0))
and
((PlaneRight.a*Vektor1.x + PlaneRight.b*Vektor1.y + PlaneRight.c*Vektor1.z + PlaneRight.d > 0)or
(PlaneRight.a*Vektor2.x + PlaneRight.b*Vektor2.y + PlaneRight.c*Vektor2.z + PlaneRight.d > 0)or
(PlaneRight.a*Vektor3.x + PlaneRight.b*Vektor3.y + PlaneRight.c*Vektor3.z + PlaneRight.d > 0))
and
((PlaneBottom.a*Vektor1.x + PlaneBottom.b*Vektor1.y + PlaneBottom.c*Vektor1.z + PlaneBottom.d > 0)or
(PlaneBottom.a*Vektor2.x + PlaneBottom.b*Vektor2.y + PlaneBottom.c*Vektor2.z + PlaneBottom.d > 0)or
(PlaneBottom.a*Vektor3.x + PlaneBottom.b*Vektor3.y + PlaneBottom.c*Vektor3.z + PlaneBottom.d > 0))
and
((PlaneLeft.a*Vektor1.x + PlaneLeft.b*Vektor1.y + PlaneLeft.c*Vektor1.z + PlaneLeft.d > 0)or
(PlaneLeft.a*Vektor2.x + PlaneLeft.b*Vektor2.y + PlaneLeft.c*Vektor2.z + PlaneLeft.d > 0)or
(PlaneLeft.a*Vektor3.x + PlaneLeft.b*Vektor3.y + PlaneLeft.c*Vektor3.z + PlaneLeft.d > 0))
and
((PlaneNear.a*Vektor1.x + PlaneNear.b*Vektor1.y + PlaneNear.c*Vektor1.z + PlaneNear.d > 0)or
(PlaneNear.a*Vektor2.x + PlaneNear.b*Vektor2.y + PlaneNear.c*Vektor2.z + PlaneNear.d > 0)or
(PlaneNear.a*Vektor3.x + PlaneNear.b*Vektor3.y + PlaneNear.c*Vektor3.z + PlaneNear.d > 0))
and
((PlaneFar.a*Vektor1.x + PlaneFar.b*Vektor1.y + PlaneFar.c*Vektor1.z + PlaneFar.d > 0)or
(PlaneFar.a*Vektor2.x + PlaneFar.b*Vektor2.y + PlaneFar.c*Vektor2.z + PlaneFar.d > 0)or
(PlaneFar.a*Vektor3.x + PlaneFar.b*Vektor3.y + PlaneFar.c*Vektor3.z + PlaneFar.d > 0));
end;
is triangle in the frustum?
hi
i'm tring some test about frustum
i can do these things:
-is Point in frustrum
-is Sphere in frustrum
but when i try triangle with frustum i cant get right result here is my code :
if you want to see how do i make Frustum planes i can show you but i'm shure its correct, and "triangle code" is not completely trash its working when vektors in frustrum
thanks everybody
As long as your point-in-frustum code works, try
function IsTriangleInFrustum(Vektor1,Vektor2,Vektor3:TD3DVector) : boolean;begin Result := IsPointInFrustum(Vektor1) and IsPointInFrustum(Vektor2) and IsPointInFrustum(Vektor3);end;
but your code is going to work only one ore more vertices in the frustum right?
first code is working already like yours, i want more complex calculation (maybe extra calculation for triangle's edges)
well maybe i can handle this if i can get "line-frustum" thing, is there anybody who know this stuf?
first code is working already like yours, i want more complex calculation (maybe extra calculation for triangle's edges)
well maybe i can handle this if i can get "line-frustum" thing, is there anybody who know this stuf?
What Dave has suggested can be modified to work however you want. A triangle is just 3 points. If you want to test if the whole triangle is in the frustum then check if all 3 points are inside. If you only want to check if the triangle is partly in the frustum check to see if any of the points are in the frustum. It shouldn't be much more complex than that.
Although.. you could get into a situation where all points are outside the frustum but you're looking through the middle of the triangle. That could be a little more involved.
Although.. you could get into a situation where all points are outside the frustum but you're looking through the middle of the triangle. That could be a little more involved.
Quote:Original post by ibr_ozdemirIf you want a 'perfect' triangle-frustum test, you can use the separating axis test. If you want a test that is basically accurate but may occasionally return false positives, you can use the SAT but only test the axes corresponding to the frustum plane normals. (Basically, you check to see if the triangle is entirely on the back side of any of the six frustum planes.)
first code is working already like yours, i want more complex calculation (maybe extra calculation for triangle's edges)
well maybe i can handle this if i can get "line-frustum" thing, is there anybody who know this stuf?
Note however that per-triangle frustum culling is pretty rare these days; it's more common to cull on the object/node/model level.
thanks to all of you
well i'm actualy little bit more closer to target
now my code almost returns perfect result, except this situation (folowing picture)
but i think i can handle that to (with triangle vs triangle intersection test)
well i'm not going to use this code directly in my game engine, its just for my "mesh editing" pogram (selecting triangle in frustum)
thanks
well i'm actualy little bit more closer to target
now my code almost returns perfect result, except this situation (folowing picture)
but i think i can handle that to (with triangle vs triangle intersection test)
Quote:Original post by jyk
Note however that per-triangle frustum culling is pretty rare these days; it's more common to cull on the object/node/model level.
well i'm not going to use this code directly in my game engine, its just for my "mesh editing" pogram (selecting triangle in frustum)
thanks
Quote:Original post by ibr_ozdemirThe SAT will catch that case (and other similar cases).
now my code almost returns perfect result, except this situation (folowing picture)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement