# Creating imposters

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

## 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);

float m_fDistance = sqrt(camera.position().x*camera.position().x + camera.position().y*camera.position().y +
camera.position().z*camera.position().z);
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)

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();
glPushMatrix();
glMultMatrixf(mModel);


Is there an easier way to setup imposter rendering?

##### Share on other sites
Don't know if that would be helpful, but i made a post in my journal some months (years?) ago:

Setting up a camera for impostors rendering

Y.

##### 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 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 on other sites
Thanks for your help. I actually got it working! I'll post a small demo with source later today.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×