Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a sphere in my 3D world located at the origin. I have models orbiting it and I need to keep track of each models' position (x, y, x coordinates) as well as update their bounding boxes for collision detection. I have calls to glRotate() and glTranslate() but I'm not sure how to keep track of this. Should I create a position matrix and apply rotations and translations to it? Any help on that would be great!

Also if there is a better way to do this I am open to anything.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Sounds like you're using very out dated OpenGL code. You should look into modern techniques, I wouldn't waste much more time learning/using the dated code you're using now.

Beyond that, there are lots of ways to organize your world and the objects you store in it. The very basic example is to just have a class that represents an object in your world:

public class DrawableObject {
   Vector3f position;
   Vector3f rotation;
   Model model;
   BoundingBox bounds;
}

Then create your objects using these classes. When you're updating the position of the orbiting objects, update the DrawableObject instance that represents them. Then when you're drawing the objects, use the position and rotation stored in the DrawableObject instance.

Basically, you don't want to send the updates to the graphics card and not have them stored anywhere on the CPU side. You want to update something locally and then use that data to update the data on the graphics card.

Eventually you could move on to something more complex like an entity component system. But for now, I'd stick with learning modern OpenGL and keeping track of the objects in your world in a more organized way.

share|improve this answer
    
Thanks, the problem is I am developing on Android which only has access to OpenGL ES 1.X and 2. Since pretty much all devices support 1.1 I am developing for that... That being said, I created a base class that my world objects now all extend. I'm trying to apply translations and rotations to them every time I make a call to the corresponding glRotate() and glTranslate() but I think I am going wrong somewhere with that. At least I'm going in the right direction so thanks for your answer. –  DiscGolfer Dec 28 '12 at 22:26
1  
Offtopic, but currently 90.8% percent of devices is ES 2.0 (developer.android.com/about/dashboards/index.html), and with the remaining 9.8 percent the GPU might not be the main barrier in running your game (ancient Android version, no CPU power to speak of, etc). Unless going the ES 1.X route saves you serious time because you are more familier with the concepts, it might pay off to switch to 2. You will have to at some point in the future anyway. –  Paul-Jan Dec 29 '12 at 16:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.