Jump to content
  • Advertisement
Sign in to follow this  
starfleetrp

Displaying 3D object in Ortho

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

I have been trying to do this, however it seems that If I try to draw any object with a Z axis, it just wont display. (Ive been using cubes for testing) I want to do this so I can load 3D models into my Ortho Scene, and have them rotate. I am using this code to make it ortho, however i'm not even sure if its the right way to go about it.
void glEnable2D()
{
	int vPort[4];

   glGetIntegerv(GL_VIEWPORT, vPort);

   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();

   glOrtho(0, vPort[2], 0, vPort[3], -.001, 1000);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
}

void glDisable2D()
{
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();   
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix();	
}

Share this post


Link to post
Share on other sites
Advertisement
The problem is (possibly) your glOrtho call. The last two parameters specify the smallest and largest z value that are rendered. Try using glOrtho(0, vPort[2], 0 vPort[3], -1000, 1000) and see if that works.

Share this post


Link to post
Share on other sites
I am now also wondering if there is a way to rotate a quad on the y axis (so it appears to become shorter/like a gun barel at 45 degrees would look like from the air.) since the Z axis sets its direction.


Also, is there a way to make it so you see a 3D model as if from a birds eye view, but not right on top. So you might see 3/4 of its top and maybe 1/4 of its side thats facing the monitor (front back, side etc). Would this be just as simple as roating the object? However I dont think this will work because once you set its direction, wont it be all messed up? I am not sure if this is exactly clear, however if its not I will try and clarify the best that I can.

Share this post


Link to post
Share on other sites
Quote:
Original post by starfleetrp
I am now also wondering if there is a way to rotate a quad on the y axis (so it appears to become shorter/like a gun barel at 45 degrees would look like from the air.) since the Z axis sets its direction.
glRotate*

The y-axis is the vector (0,1,0).
Quote:
Original post by starfleetrp
Also, is there a way to make it so you see a 3D model as if from a birds eye view, but not right on top. So you might see 3/4 of its top and maybe 1/4 of its side thats facing the monitor (front back, side etc). Would this be just as simple as roating the object? However I dont think this will work because once you set its direction, wont it be all messed up? I am not sure if this is exactly clear, however if its not I will try and clarify the best that I can.
Just position the "camera" so that it looks at the object from above and to the side (one way to do that is with gluLookAt). If you're just looking at one object than you could get the same effect by just rotating that object.

How would setting its direction mess it up?

Share this post


Link to post
Share on other sites
When I try to set the Quad with a Y axis of even (1 as angle) it just disappears, I have no idea why. Sorry that I wasnt clearer, I skipped a scentence.

Hmm, the camera, I thought I tried that and it didnt work... Ill try it again! Thanks for your help. So id move it back(z) maybe 10.0f and up(y) 40.0f as an example?

Share this post


Link to post
Share on other sites
I think your dissapearance issue has to do with the fact that your pivotal point for rotation is not the center of the quad.

Consider if your quad's center coordinates are 1,1,1

If you now rotate it by 1 degree the center of the quad will move.

The way to remedy this is to use gltranslate, try the following code

glPushMatrix(); // save the matrix
glTranslatef(x,y,z);
glScalef(sizex,sizey,sizez);
glBegin(GL_QUADS);
glVertex3f(-1,-1,0);
glVertex3f(1,-1,0);
glVertex3f(1,1,0);
glVertex3f(-1,1,0);
glEnd();
glPopMatrix();//Restore the matrix

Share this post


Link to post
Share on other sites
Ah, that would be the problem, however since I have an image on the quad, whos center point of rotation should be at one end not the middle, how would I be able to fix this so it will still rotate?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!