A Simple question

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
siberianstar
Posts: 11
Joined: Wed Jun 28, 2006 5:13 pm

A Simple question

Post by siberianstar »

How can i see if a triangle S3DVertex2TCoords triangle[3], is interesecting the frustum view?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

// this is a rough estimate because the frustrum box is larger than the actual view frustrum
core::aabbox3df frustrumBox = SceneManager->getActiveCamera()->getViewFrustrum()->getBoundingBox();

const core::line3df lineA(triangles[0].Pos, triangles[1].Pos);
const core::line3df lineB(triangles[1].Pos, triangles[2].Pos);
const core::line3df lineC(triangles[2].Pos, triangles[0].Pos);

return frustrumBox.intersectsWithLine(lineA) ||
       frustrumBox.intersectsWithLine(lineB) ||
       frustrumBox.intersectsWithLine(lineC);

Code: Select all

// this is even worse estimate because the triangle is fit into a box and that
// is compared against the frustrum box
core::aabbox3df frustrumBox = SceneManager->getActiveCamera()->getViewFrustrum()->getBoundingBox();

core::aabbox3df triangleBox(triangles[0].Pos);
triangleBox.addInternalPoint(triangles[1].Pos);
triangleBox.addInternalPoint(triangles[2].Pos);

return frustrumBox.intersectsWithBox(triangleBox);

Code: Select all

// this should be more accurate, but slow. probably a more efficient way
scene::SViewFrustrum* frustrum =  SceneManager->getActiveCamera()->getViewFrustrum();

const core::line3df lineA(triangles[0].Pos, triangles[1].Pos);
const core::line3df lineB(triangles[1].Pos, triangles[2].Pos);
const core::line3df lineC(triangles[2].Pos, triangles[0].Pos);

u32 p;
for (p = 0; p < scene::VF_PLANE_COUNT; ++p)
{
  if (frustrum->planes[p].getIntersectionWithLimitedLine(triangles[0].Pos, triangles[1].Pos) ||
      frustrum->planes[p].getIntersectionWithLimitedLine(triangles[1].Pos, triangles[2].Pos) ||
      frustrum->planes[p].getIntersectionWithLimitedLine(triangles[2].Pos, triangles[0].Pos))
    return true;
}

return false;
Last edited by vitek on Fri Jun 30, 2006 5:49 am, edited 1 time in total.
siberianstar
Posts: 11
Joined: Wed Jun 28, 2006 5:13 pm

Post by siberianstar »

i've to put the code on COpenGLDriver.cpp, what i've to include ? the last code you paste me didn't compile
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Dude, you don't want to be putting that code in the driver. There are better ways to do what you want.
siberianstar
Posts: 11
Joined: Wed Jun 28, 2006 5:13 pm

Post by siberianstar »

i've to tessellate the triangles that intersect the frustrum view planes on rendering time..
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

software2 driver does this, you can find the code in there.
also, why would you need to do this anyway?
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
siberianstar
Posts: 11
Joined: Wed Jun 28, 2006 5:13 pm

Post by siberianstar »

i've rewritten the csoftwaredriver2 class because there were less code to delete :P I'm using pspgl with the PSP Console to port irrlicht 1.0 on psp.

But the psp has got a stupid clipping algo and when a vertex goes too far from the screen it just culls the entire primitive. The result is here:

http://85.25.18.122/IM000345.jpg
siberianstar
Posts: 11
Joined: Wed Jun 28, 2006 5:13 pm

Post by siberianstar »

I've rewritten the csoftwaredriver2 class because there were less code to delete. I'm using PSPGL to port Irrlicht 1.0 on the PSP. But the PSP has a stupid clip algo. And when a vertex goes too far away from the screen the psp just cull the entire primitive.

Result:
http://85.25.18.122/IM000345.jpg

So i'had to tessellate the triangles that intersect the frustum view.
Post Reply