Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calculate Position of an Object after Performing Tranlations (OpenGL)

Posted on 2008-06-15
4
Medium Priority
?
1,293 Views
Last Modified: 2013-12-21
Basically I have written a Cube class. It has a member variable that determines the location it should be drawn in. I set the coordinates then call its Draw method. This Pushes the current matrix onto the stack, moves to correct position (glTranslatef) draws the cube, then pops the matrix back off the stack.

This all works fine, but elsewhere in my code I have done other translations (a rotate) and I could like to  calculate what the co-ordinate of the cube would be after the translation.

So..:
1. Am i doing this the wrong way? Should I not be using glTranslatef and manuallycalculate the position of the cube using a custom matrix and redraw it?
2. Could I multiply the coordintes of the cube by somthing to get its new position? Is there a function for this.

I'm terribly confused! Hope i have explained things OK.
translation.gif
0
Comment
Question by:Jamsb
  • 2
  • 2
4 Comments
 
LVL 2

Author Comment

by:Jamsb
ID: 21788231
That meant to say "should I not be using a glRotatef".
0
 
LVL 20

Accepted Solution

by:
ikework earned 500 total points
ID: 21788564
hey Jamsb,

1. >> Am i doing this the wrong way? Should I not be using glTranslatef and manuallycalculate the position of the cube using a custom matrix and redraw it?

not necessarily, depends on how you work with your scene

2. >> Could I multiply the coordintes of the cube by somthing to get its new position? Is there a function for this.
yes, there is an opengl-function to retreive the current modelview-matrix (the matrix which moves the model from modelspace to worldspace, with other words the top modelview-matrix on the stack). you can get that matrix with:

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

now multiply that matrix with the points in objectspace of your model, then you have its points in worldspace


ike
0
 
LVL 2

Author Comment

by:Jamsb
ID: 21788649
ikework:

Thankyou I was wondering if that was what I was supposed to do!  
0
 
LVL 20

Expert Comment

by:ikework
ID: 21788720
you're welcome .. :)  but be aware that retreiving that matrix from the graphics card can be slow, since it has to be transfered from the graphics-card-pipeline back to mainmemory .. it could be more efficient to store all the previous transformations in a cache and get the current matrix from there. but that depends on your application

good luck :)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question