# 3D Spatial drawing and coordinates

This topic is 3801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 12
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632991
• Total Posts
3009749
• ### Who's Online (See full list)

There are no registered users currently online

×