Solved

Calculate Position of an Object after Performing Tranlations (OpenGL)

Posted on 2008-06-15
4
1,290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

630 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