Dimensions of the opengl world space.

Started by
3 comments, last by Enigma 19 years, 6 months ago

bool MainWindow::Reshape( long width, long height )
{
   m_Width  = width;
   m_Height = height;
   std::ostringstream temp;
   temp << "{ width="  << width;
   temp << ", height=" << height << " }";
   m_Console.AddLine( temp.str() );
   if( height < 1 ) // Prevent A Divide By Zero By
      height=1;
   ::glViewport( 0, 0, (GLsizei)(width), (GLsizei)(height) );
   ::glMatrixMode( GL_PROJECTION );
   ::glLoadIdentity();                                                  // Reset The Projection Matrix
   ::gluPerspective( m_FieldOfView, (GLfloat)(width)/(GLfloat)(height), // Calculate The Aspect Ratio Of The Window
                     0.010f, 1000.0f );
   ::glMatrixMode( GL_MODELVIEW );                                      // Select The Modelview Matrix
   ::glLoadIdentity();
   return false;
}

This is my reshape function. Given that I use this to setup a perspective vied how can I determine if I draw a particular primative at a given coordinate if it will be on the screen or not? If you need anymore information I will provide it. But I need a way to calculate if an object will be on the screen if I try to renderit at a particular point. {0,0-40} is on the screen but will be {-40,0,-40} on the screen? thanks
Advertisement
I think u need frustum culling:
http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg5.htm


I need to do a calculation that will allow me to stick some numbers in a function and then find out where would the top left coordinate be in open gl coordinates.

If I give it the values I sent to gluperspective and a value for z then I should beable to calculate the dimensions and coordinates of the slice of the pyramid.
Look at the tutorial that the AP gave you a link to. It will tell you how to determine if a sphere or cube is in the frustum, and it's easy enough to make it work for polys.
____________________________________________________________Programmers Resource Central
You can find the equations you want in this thread.

Enigma

This topic is closed to new replies.

Advertisement