Sign in to follow this  
starfleetrp

Displaying 3D object in Ortho

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
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

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

Sign in to follow this