Solved

Calculate Position of an Object after Performing Tranlations (OpenGL)

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi GLScene export scene 7 1,195
Game Center error 5 635
Tetris download for windows 7 17 159
How Complex Is This Java Course ? 9 63
What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

13 Experts available now in Live!

Get 1:1 Help Now