• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# camera corners

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

helloz! i was trying to calculate the world coordinates of the 4 corners of the camera view plane, so i thought of just storing the "directional vectors" from the viewpoint to each of the 4 corners of the viewplane. firstly does this make sense to u? or am i missing something at this point? if the above is the most logical way to do it, given that near plane distance = 0.001f, fov y = 90.0f, i would perform the algorithm in order: 1)calculate the initial 4 directional vectors to each corner using near plane distance, & fov y & initial camera position & initial camera rotation (assuming no rotation for now)
float near_dist = 0.001f;
float fovy = 90.0f;
float bias = near_dist * tan(fovy/2);

//vector->topleft

m_topleft.x[0] = m_camPosition.x[0] - bias;
m_topleft.x[1] = m_camPosition.x[1] + bias;
m_topleft.x[2] = m_camPosition.x[2] - near_dist;//RHS coord system


2)whenever i update the camera look at vector, i would take the difference of the updated look at vector.
Vector3D prev_view = m_camPosition + m_camLookAt;
//calculate new lookat vector

Vector3D view_diff = prev_view - (m_camPosition + m_camLookAt);

3)update each directional vector with the difference calculated in step 2.
//for directional vector(viewpoint to topleft of viewplane)

m_topleft = m_topleft + view_diff;

somehow i tried to printing the values out, guts tell me something somewhere is not so correct...sigh thx! Edwinz

#### Share this post

##### Share on other sites
Advertisement
First off, your initial calculation is assumming an aspect ration of 1, which is usually not the case. The aspect ratio is the ratio between the width and height of the viewport, and is usually 4/3=1.25. To correct this, multiply the bias by this value when updating the [0] coordinate.

That said, the vector math you are doing to update the corners, will only work for translations; not for rotations. When you rotate the camera, each corner of the view plane will move in different directions, therefore adding the same vector to the old positions will not give the correct results. When you change the look-at vector, you are usually (if not always) rotating the camera.

If you know the transformation that was applied to the old look-at vector to arive at the new one, apply the same transformation to the corner positions. Otherwise, the simplest solution would be to just recalculate the corners from scratch.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"

We come in peace... surrender or die!

4/3 = 1.33~

#### Share this post

##### Share on other sites
You know that the corners of the near clipping plane will end up at (1,0,0), (0,1,0), (0,-1,0), (-1,0,0) after you apply the projection and view transformations. So find the inverse of (projection matrix * view matrix), and multiply those points by it to get the right points in world space.

For calculating the matrix inverse, there's an extremely... succinct solution in Circuit's reply in this thread.

[edited by - Matei on May 27, 2004 5:26:55 PM]

#### Share this post

##### Share on other sites
quote:
Original post by digitec devil
4/3 = 1.33~

err... right. oops
the 3 and 4 momentarily swapped places in my mind for a some reason when I was doing the division...

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"

We come in peace... surrender or die!

#### Share this post

##### Share on other sites
hi all,
thx so much!

i will try the inverse method, and i think i jus realize i could simply use glUnproject.

thx!
Edwinz

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 9
• 12
• 10
• 10
• 11
• Advertisement