How can i check if a vertex is into the frustum view?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
siberianstar
Posts: 11
Joined: Wed Jun 28, 2006 5:13 pm

How can i check if a vertex is into the frustum view?

Post by siberianstar »

The title is my question ^^
GueZt_Coders
Posts: 44
Joined: Tue Jan 17, 2006 4:04 am

Post by GueZt_Coders »

Note that a vertex is just a point. If this is really your case
try my piece of code, this one works on me, you just have
to pass a position coordinate and your active cam. Hope this
will work on your case too.

Code: Select all


	//| CHECKING POINT POSITION FROM ACTIVE CAMERA FRUSTRUM VIEW
	//|
	//|--------------------------------------------------------
	bool IsPointPosInFrustum
	( 
		core::vector3df			  pPointPos,	
		scene::ICameraSceneNode*  pActiveCam 
	)
	//|--------------------------------------------------------
	{	

		//| NEEDED LOCAL MEMVARS
		//|
		const scene::SViewFrustrum* mCamView = pActiveCam->getViewFrustrum(); 
		float mPointD  = float( pPointPos.getDistanceFrom( pPointPos ) ); 
		float mNewD    = 0; 

		//| IF OUTSIDE OF PLANE-1 RETURN FALSE
		//|
		mNewD = mCamView->planes[0].Normal.dotProduct( pPointPos )+mCamView->planes[0].D; 
		if( mNewD>mPointD ) 
		{
			return false;
		}

		//| IF OUTSIDE OF PLANE-2 RETURN FALSE
		//|
		mNewD = mCamView->planes[1].Normal.dotProduct( pPointPos )+mCamView->planes[1].D; 
		if( mNewD>mPointD ) 
		{
			return false;
		}

		//| IF OUTSIDE OF PLANE-3 RETURN FALSE
		//|
		mNewD = mCamView->planes[2].Normal.dotProduct( pPointPos )+mCamView->planes[2].D; 
		if( mNewD>mPointD ) 
		{
			return false;
		}

		//| IF OUTSIDE OF PLANE-4 RETURN FALSE
		//|
		mNewD = mCamView->planes[3].Normal.dotProduct( pPointPos )+mCamView->planes[3].D; 
		if( mNewD>mPointD ) 
		{
			return false;
		}

		//| IF OUTSIDE OF PLANE-5 RETURN FALSE
		//|
		mNewD = mCamView->planes[4].Normal.dotProduct( pPointPos )+mCamView->planes[4].D; 
		if( mNewD>mPointD ) 
		{
			return false;
		}

		//| IF OUTSIDE OF PLANE-6 RETURN FALSE
		//|
		mNewD = mCamView->planes[5].Normal.dotProduct( pPointPos )+mCamView->planes[5].D; 
		if( mNewD>mPointD ) 
		{
			return false;
		}
	

		//| POINT POSITION INSIDE CAMERA FRUSTRUM VIEW FROM HERE
		//|
		return true; 
	

	}

Just part of irrlicht related project| CLEAR CODE NOTATIONS IS LARGELY SELF CODUMENTING!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Unfortunately this guy is trying to rewrite the OpenGL driver for PSP. That means that the code in question is COpenGLDriver.cpp. Not only does he need to know if the vertex is in the frustrum, he [according to what he claims in another post] also needs to be able to clip the triangle that the vertex belongs to.

I'm going to suggest that he look at the CSoftwareDriver2 implementation for guidance. The method CSoftwareDriver2::clipToHyperPlane() and the methods that call it do exactly what he wants.

Travis
TheGameMaker
Posts: 275
Joined: Fri May 12, 2006 6:37 pm
Location: Germany

Post by TheGameMaker »

isn´t there a viewfrustrum matrix or somthing like this??(i think i heared about this...) or just multipli the position of the vert with the projektion matrix of the cam, and check if the result lays in the legal range.
but just ideas, i dunno if it works...
Post Reply