aNt,
I am currently experiancing the exact same problem as you - and it is driving me nuts. I spent countless hours last night trying to get it to work but to no avail. This morning I tried with a simple cube and still no cigar.
This is code that I ported from j3d and was working fine in j3d. I thought I understood this concept. Back when I was using gl4java I encountered and solved (easily) the same problem. And I have a few books on j3d/opengl to assist. I have compiled and run my code so many times that my processor has almost melted.
Seriously though, here is the problem.
Take a small cube, at the position 10, 10, 0. (ie. 10 to the right, and 10 up).
| [_]
|
|
_______________
|
|
|
Now I want to rotate that cube in place.
| \_\
|
|
_______________
|
|
|
How I did it with straight OpenGL calls and j3d was this:
Move the cube to (0,0,0) > rotate it > move back to (10,10,0).
Rotating without that move caused it to rotate (or orbit) around the (0,0,0) “pivot point” which is correct but not wanted in my case.
not wanted:
| [_]
| [_]
|
_______________
| [_]
| [_]
| etc...
Now no matter what I tried last night and this morning I can not get any object in Xith3D to change it’s “point of rotation”.
move to origin > rotate > move back simply has the same effect as
rotate
move to some place > rotate just moves the whole bloody thing to a different area.
So no matter what I wanted the “Reference point/pivot point/point of rotation” to be for the rotation - I always go the same (see “not wanted” ASCII diagram). It seemed like moving the object moved it’s origin as well and thus I just couldn’t rotate it around an arbitrary reference.
Now, sure - I could simply load the object in relitive to (0,0,0) but this is a work around and I have spent too many hours trying the other way that I must as least know how to do it correctly (and then I won’t mind about applying any work arounds).
This was tested using a Single TransformGroup so no funny stuff is happening with TransformGroup children.
here is a handy method that recursivly prints the contects of a group.
public static void printGroup (Group g, String offset) {
System.out.println(offset + (g.getClass().getName()));
for (int i = 0; i < g.numChildren(); i++) {
Class c = g.getChild(i).getClass();
if (c.getName().lastIndexOf("Group") != -1)
printGroup((Group) g.getChild(i), offset + " ");
else
System.out.println(offset + " " + c.getName() + " group");
}
}
This is my very simple cube, so as you can see no funny stuff:
com.xith3d.scenegraph.TransformGroup
com.xith3d.scenegraph.BranchGroup
com.xith3d.scenegraph.Shape3D
I am using Xith3d from CVS and keeping up to date which I am hoping fixes more problems than it introduces however it is a double edged sword.
What am I doing wrong? I thought I understood the transform concept and have managed to do this exact thing fine in OpenGL and j3d. But I am running out of ideas for this one.
I can easily do my work around and I know that will work - but I refuse to believe that it isn’t possbile this way.
Please tell me what you think.
Cheers,
Will.
[edit: formatting, correcting]
[edit: aNt, I wish I had read your posts before hitting the same brick wall myself and trying a similar cube test - it would have saved me some time but at least now there are two case studies :D]