Sign in to follow this  

Creating imposters

This topic is 4333 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 understand how to resize the frustum so that my object, which I want to make an imposter texture of, completely fills up the viewport and is WITHIN the viewport. I'm using this article as a reference, A Real-Time Procedural Universe, Part Three: Matters of Scale http://www.gamasutra.com/features/20020712/oneil_03.htm But I cannot seem to get it to work right. I calculate the size of my frustum using the code below
                        glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
		
			float m_fDistance = sqrt(camera.position().x*camera.position().x + camera.position().y*camera.position().y +
									camera.position().z*camera.position().z);
			float m_fBoundingRadius = 2.0f;
			float m_fBoundingRadius = 2.0f;
			float fAltitude = m_fDistance - m_fBoundingRadius;								// Height above the surface of the bounding radius
			float fHorizon = sqrt(fAltitude*fAltitude + 2.0f*fAltitude*m_fBoundingRadius);	// Distance to horizon (use pythagorean theorem to get the equation)
			float fCos = fHorizon / m_fDistance;											// Cosine of angle between ray to center of sphere and ray to horizon (part of a right triangle)
			float fTemp = fAltitude / fCos;													// Horizon distance cut off at the near clipping plane
			float fBound = sqrt(fTemp*fTemp - fAltitude*fAltitude);							// Distance from center to sides at the near clipping plane (boundaries of the projection frustum) (part of another right triangle)
			float fTemp2 = m_fDistance / fCos;
			float m_fBillboardRadius = sqrt(fTemp2*fTemp2 - m_fDistance*m_fDistance);	// Distance from center to sides at the center of the object (size of the billboard)
			glFrustum(-fBound, fBound, -fBound, fBound, m_fDistance-m_fBoundingRadius, m_fDistance+m_fBoundingRadius);

			glMatrixMode(GL_MODELVIEW);


This code works perfectly is the camera is staring straight at the object. But if the camera is looking diagonally at the object, then when I set the frustum, part of the object is above and below the viewing area. In the author's code he sets up some sort of viewing matrix to set the projection correctly, I just can't seem to understand what he's doing and how it works. Here's his code:
        CMatrix mModel, mView;
	mModel.ModelMatrix(*this, vView);
	GetImpostorViewMatrix(mView, vView);
	m_vUp = CVector(mView.f12, mView.f22, mView.f32);

        glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadMatrixf(mView);
	glPushMatrix();
	glMultMatrixf(mModel);

Is there an easier way to setup imposter rendering?

Share this post


Link to post
Share on other sites
Hey thanks alot for that piece of code. But once you build your view, world and projection matrices, how are you applying them? This is what I tried, but the object does not appear anywhere on the screen.


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLoadMatrixf(projMatrix.m);

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(viewMatrix.m);
glMultMatrixf(worldMatrix.m);




Here's my full code based off of yours

glLoadIdentity();

float Radius = 2.0f;
float d = vectorMag(camera.position() - Vector3(0, 0, 0));
float fov = asin(Radius / d);
float l = d * tan(fov);

Matrix4 viewMatrix;
viewMatrix.setupLookAtMatrix(camera.position(), Vector3(0, 0, 0), Vector3(0, 1, 0));

Matrix4 translateMatrix;
translateMatrix.setupTranslation(-camera.position());

viewMatrix = translateMatrix * transpose(viewMatrix);

Matrix4 projMatrix;
projMatrix.setupProjectionMatrix(60, 1, 0, 100);

Matrix4 worldMatrix;
worldMatrix.identity();

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLoadMatrixf(projMatrix.m);
glMatrixMode(GL_MODELVIEW);

glLoadMatrixf(viewMatrix.m);
glMultMatrixf(worldMatrix.m);




To clarify some things, my object is centered at the origin and its radius is 2.0.

Share this post


Link to post
Share on other sites
I can't say exactly, as my code is based on a generic renderer, and setup as with DirectX matrices. A few notes though:

Your projection matrix doesn't look good. You're not using the field-of-view angle at all, and your ZNear is 0, which isn't valid even in OpenGL. It should actually be:

projMatrix.setupProjectionMatrix(fov, 1, 0.1, 100);


Today, i checked again in my engine that the calculations are correct, by placing a sphere at (0, 0, 0) with a given radius (tried many values), and guarantee that the calculated parameters (field of view, camera position, camera orientation) are correct. I can't say if your functions to build a LookAt matrix, or to concatenate matrixes, is equivalent though. For what i know, you could very well use post-concatenation as opposed to pre-concatenation, or vice-versa. Or your matrixes could be row major instead of being column major. Many things can go wrong, so i'd suggest that you review your code and try many combinations (for example, transpose some of the matrices and see what happens).. can't add much. Of course i can post my matrix code, but as it's specific to my engine and probably not compatible with yours, i'm not sure if that'd be helpful..

Y.

Share this post


Link to post
Share on other sites

This topic is 4333 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