Solved

Calculate Position of an Object after Performing Tranlations (OpenGL)

Posted on 2008-06-15
4
1,285 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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is best Python DS to store a chess board? 1 122
Game w 3D galaxy - How should I do vertical distancing? 3 76
Game Asset Design and Performance. 7 147
bunnyEars2 challenge 6 129
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now