edwinnie 122 Report post Posted May 27, 2004 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 0 Share this post Link to post Share on other sites

technobot 238 Report post Posted May 27, 2004 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! 0 Share this post Link to post Share on other sites

digitec devil 206 Report post Posted May 27, 2004 4/3 = 1.33~ 0 Share this post Link to post Share on other sites

Matei 190 Report post Posted May 27, 2004 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] 0 Share this post Link to post Share on other sites

technobot 238 Report post Posted May 27, 2004 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! 0 Share this post Link to post Share on other sites

edwinnie 122 Report post Posted May 27, 2004 hi all,thx so much!i will try the inverse method, and i think i jus realize i could simply use glUnproject.thx!Edwinz 0 Share this post Link to post Share on other sites