Author Topic: Understanding Translations  (Read 1245 times)

Offline stownshend

  • byte
  • *
  • Posts: 25
    • View Profile
Understanding Translations
« on: October 04, 2011, 10:26:25 am »
Hi all,

I load, rotate, and translate a bunch of objects in my onSurfaceChanged() method (will change this to onSurfaceCreated()) and I'm trying to understand the effect that translations made in one place have on subsequent calls to translate().

For example, in the following code, will object2's initial position be impacted by the translation of object1?

(note the loadOBJModel method is a custom one I wrote as a shortcut to the model/texture loading process)

Code: [Select]
object1 = new Object3D(loadOBJModel(MODEL_1, TEXTURE_NAME_1));


object2 = new Object3D(loadOBJModel(MODEL_2, TEXTURE_NAME_2));


Furthermore, when I am using rotations and translations, is there an order I should be doing these?

This feels like graphics programming 101. I've written Open GL / GLU / GLUT code in C++ before and not been so confused because I could use GL_START and GL_END tags to start and stop each transformation (I think that's what they were called).

IF the answer to the above questions are yes, translate() is impacted by the previously translated position... What is an easy way to translate an Object3D to a particular point in world space?

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Understanding Translations
« Reply #1 on: October 04, 2011, 12:55:49 pm »
Your code will position each object individually in world space. object2's initial position will not be impacted by the translation of object1.

Translate basically moves the object in the world. The translation is not reset at every frame, so each translation is based on the previous translation point.

So if you want to move forward the object in world space at every frame, you would call translate(0f, 0f, 0.1f);

If you want to keep track of the position of the object yourself in world space at every frame, you could do this:

Code: [Select]
    // move my object forward incrementally
    myPosZ += 0.1f;

    // Reset the object's position back to it's origin (0,0,0)

    // Set position of object

In my opinion, it's easier to keep tabs on the location of the object by simply retrieving it's translation using Object1.getTranslation()
« Last Edit: October 04, 2011, 12:57:29 pm by K24A3 »