Sign in to follow this  

Scene graphing and frustum culling...

This topic is 4745 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get frustum culling working with my scene graphing system... at the moment I'm just using the origin of the node for culling, but after i work the bugs out of this, ill go to bounding box.... Anyway.... it works great, except when there is rotation involved.... here is some code:
    void CSceneNode::update(CRenderer* pRenderer) {
		glPushMatrix();

		if(isChild())
			m_vAbsolutePos = m_vPos + getParent()->getAbsolutePosition();
		else
			m_vAbsolutePos = m_vPos;

		if(m_fXRotation >= 360.0f) m_fXRotation = 0.0f;
		if(m_fYRotation >= 360.0f) m_fYRotation = 0.0f;
		if(m_fZRotation >= 360.0f) m_fZRotation = 0.0f;

		glTranslatef(m_vPos.x, m_vPos.y, m_vPos.z);
		glRotatef(m_fXRotation, 1.0f, 0.0f, 0.0f);
		glRotatef(m_fYRotation, 0.0f, 1.0f, 0.0f);
		glRotatef(m_fZRotation, 0.0f, 0.0f, 1.0f);

		if(m_bFrustumCull) {
			if(!m_bHidden && pRenderer->getFrustum()->pointInFrustum(m_vAbsolutePos)) draw();
		}
		else {
			if(!m_bHidden) draw();
		}

		for(std::list<CSceneNode*>::iterator i = m_lChildren.begin(); i != m_lChildren.end(); i++) {
			(*i)->update(pRenderer);
		}

		glPopMatrix();
	}

Basicly, I just need to calculate the absoulute position in order to cull a node correctly, and it works fine, if there is no rotation involved.... but, I think i'm handling rotation in a crappy way... what is the best way to handle rotations in scene graphing? matrices? if so, can i calculate the absolute position of the node WITH rotation inovle? Thanks

Share this post


Link to post
Share on other sites
Hi,

Firstly, using a single point to determine if your node is outside the frustrum is a nice first approach, but you'll see nodes popping out of view on the borders of that frustrum, as the center (or whichever point you use) falls outside the frustrum but the content doesn't. (pfew! Hope you got that. [wink])

Secondly, when you're creating a scenegraph, use transformation nodes. They contain rotation, scale and translation information, which influence its child nodes. I can clarify if you want, but am guessing you know what i mean.

hth,
CipherCraft

Share this post


Link to post
Share on other sites
Yes,a ll that you have told me makes sense, and is alreay implmemented..... the reason im doing single point culling is so that I CAN see when an object leaves the frustum, just to make sure its working good

My only problem is getting the absolute position of any givin node when rotation is involved

Share this post


Link to post
Share on other sites
Well, i used to keep the current transformation matrix with my renderer. The transformation nodes would alter it to their liking and any calculations of points could be done with this for any other node. This has its drawbacks too: keeping the matrix up-to-date is effectively duplicating the HW calculations.

As to your code, i'm stumped at the moment. Thought i could help at the end of a long day but i'm not seeing straight any more i guess. (No, i do not work for EA.) Sorry. Will try again tomorrow, if someone doesn't beat me to it, that is. [wink]

btw: checking full circle like that does not account for more that one full circle, and the round off your using now might cause some jittering. Consider modulo 360 as an alternative.

cu
CipherCraft

Share this post


Link to post
Share on other sites

This topic is 4745 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this