Sign in to follow this  

3D Spatial drawing and coordinates

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

Hi. This is not a specific gaming question. But, here I go. I have to draw a lot of spheres all around the scene. Each one of then, its on a different plane. For that, I'm using glPushMatrix() and glPopMatrix(), in one way that when I do one glRotate, the whole system will be safe. Doing this, I lost the origin referencial, so, every time I do one glRotate(), I have a new origin. If I wasn't clear enough, what I'm drawing its a sort of molecule. So, my problem is, I need to know where I am drawing these spheres, I mean, to get their coordinates(x,y,z). I'm looking for some way that I can get this coordinates even after all that transformations, or some other way to draw it using an absolute coordinate system. Here is a piece of code about how it is being done. glPushMatrix(); glRotated(-angle/2,0,0,1); // rotate to the new direction glPushMatrix(); // save the actual matrix glRotated(-90,1,0,0); // this piece its for drawing the tube glCallList(tube1); glPopMatrix(); // load the previous matrix glTranslated(0.0,bond,0.0); // move to the end of the tube glutSolidSphere(radius-0.02,50,50); // draw the sphere glPopMatrix(); // load the previous matrix // and so on So is it.

Share this post


Link to post
Share on other sites
I have this problem too. I use trigonometry for converting the local position to global. With translate/rotate/translate pattern, this works well and is simple to implement.
I know that there are vectors and that I uoght to use them, but I don't have time for optimizing the code.
If your transformations are complex (some rotations, scales) and hard to trace, the global position may by calculated by multiplying the local position by final transformation matrix. Though I'm not sure about that, it's only thought.

Share this post


Link to post
Share on other sites
You can get the current status of the modelview matrix, and from that get the vector that will represent the new origin of the scene when things are rendered. Some example code:


float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX,matrix);


The value x,y,z values
matrix[12],matrix[13],matrix[14]
will be the position of the origin after a matrix has been set up. In the code you provided, if you put this right before you start popping matrices these values will represent the center of the object.

Share this post


Link to post
Share on other sites

This topic is 3491 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.

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