Jump to content
  • Advertisement
  • entries
    232
  • comments
    1463
  • views
    961871

Impostor bug fixed

Sign in to follow this  
Ysaneya

515 views

I finally fixed the impostor bug. The formula i used was wrong, i was not calculating the frustum field of view angle correctly. It was a bit tricky to understand why, but revising my trigonometry helped a bit. For those interesting, the code looks like this: for a viewer position located at ViewPos, the impostored object being represented as its bounding sphere Center, Radius,


float d = distance(ViewPos, Center)
float fov = asin(Radius / d)
float l = d * tan(fov)
matrix4x4 viewMatrix = buildLookAtMatrix(ViewPos, Center)
viewMatrix = buildTranslateMatrix(-ViewPos) * viewMatrix.transpose()
matrix4x4 projMatrix = buildProjectionMatrix(fov, 1, znear, zfar)
matrix4x4 worldMatrix = buildIdentityMatrix()


To render the impostor, set your camera properties to projMatrix (the argument 1.0 is the aspect ratio, it's 1.0 since the impostor texture is square), viewMatrix and worldMatrix and render your object in a texture.

To display the object as a textured quad, use this:


matrix4x4 rotMatrix = buildLookAtMatrix(ViewPos, Center)
vector3d xAxis = vector3d(l, 0, 0) * rotMatrix
vector3d yAxis = vector3d(0, l, 0) * rotMatrix
vector3d vertex0 = -xAxis - yAxis + Center;
vector3d vertex1 = xAxis - yAxis + Center;
vector3d vertex2 = xAxis + yAxis + Center;
vector3d vertex3 = -xAxis + yAxis + Center;


The quad being defined by (vertex0, vertex1, vertex2, vertex3) with tex coords (0, 0), (1, 0), (1, 1) and (0, 1) respectively.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

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
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!