Author Topic: Losing transforms on MergeObjects(...)  (Read 1085 times)

Offline tbj

  • byte
  • *
  • Posts: 2
    • View Profile
Losing transforms on MergeObjects(...)
« on: December 06, 2011, 11:06:15 pm »
Hi all,

Newbie here - sorry if this has been asked before.

I've got a class called SceneManager. This contains an ArrayList called sceneObjects which is a list of primitives (in this case, boxes) to be drawn in the scene.

Code:

Code: [Select]
Object3D scene = new Object3D(0);

for (SceneManager.SceneObject s: sceneManager.sceneObjects)
{
System.out.println("Adding object at x:" + s.x + " y: " + s.y + " z: " + s.z);
Object3D newObject = Primitives.getBox(13.0f, 1.0f);

newObject.translate(new SimpleVector(s.x, s.y, s.z));
scene = Object3D.mergeObjects(scene, newObject);

}

world.addObject(scene);

I'm trying to get all my objects merged into one so I can generate an Octree from it.

However... after merging newObject into scene, in the code above, the object seems to lose its transforms, and all my boxes end up in the same place.

If, on the other hand, I add each newObject to the World, the transforms work as expected.

Now...

- Is this what is meant to happen?
- If so, what should I do instead?

Am I right in trying to merge all my objects into one before I generate the Octree?

Should I be doing something with addChild instead?

I have read the Javadocs but I'm not too clear on this. Perhaps someone could help a newbie in distress.

Cheers :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Losing transforms on MergeObjects(...)
« Reply #1 on: December 07, 2011, 12:16:50 am »
Yes, that's what meant to happen. If you want it to behave otherwise, you have to make the transformations permanent to the mesh before merging, i.e. do something like:

Code: [Select]
Object3D newObject = Primitives.getBox(13.0f, 1.0f);

newObject.translate(new SimpleVector(s.x, s.y, s.z));
newObject.translateMesh();
scene = Object3D.mergeObjects(scene, newObject);
« Last Edit: December 07, 2011, 02:04:00 pm by EgonOlsen »

Offline tbj

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Losing transforms on MergeObjects(...)
« Reply #2 on: December 07, 2011, 01:54:57 pm »
Thanks Egon - that worked a treat.  :)

Love the engine by the way - so easy to use! Especially for someone like me who doesn't like maths and has been struggling with pure OpenGL for quite a while...