jPCT - a 3d engine for Java > Bugs

child --> parent

<< < (3/3)

EgonOlsen:
:?: Where is the rest of your last post gone? Didn't you like it? That's too bad because it made me understand your problem now. In the (now deleted) example, you were expecting part2 (as a child of part1) to translate in world space even after part1 has been rotated. This isn't the case. So is this a bug? No, it isn't. part2 translates in part1's space (...well, that's not totally correct..."it translates relative to part1's axis" describes it better). This may not be very intuitive, but it has to be that way. Imagine a swapped order, i.e. if you do the translation of part2 first and then (after a while) you rotate part1. If part2 wouldn't translate relative to part1's axis but to world space, the result would be wrong.
The remaining question is: What can you do to avoid this? There are two (and a half) solutions i can think of ATM:

a) translate part1 instead...maybe that's not a solution for you, because it doesn't work for your application.

b) transform your translation vector from world space into part1's space. I.e. do something like this:


--- Code: ---
SimpleVector trsl=new SimpleVector(1,2,0);
trsl.matMul(p1.getWorldTransformation());
p2.translate(trsl);
--- End code ---

this, of course, has to be done after applying the rotation to part1.

There are some shortcuts if you want to translate along X,Y,Z only. In that case, this should work too:


--- Code: ---
p2.translate(p1.getXAxis()); // Example for the X-axis
--- End code ---


Hope this helps.

eye1:
Hi Egon.

Tnx 4 your help, I wasn't working for a week on that. So I apologise for late respond.

Here is original post


__________________________________________________________
If i have two 3d objects (actually 4, I'll get to that latter)

First one O1, is just one simple object.

While second one is actually 3 simple objects (Part1, Part2, Part3) which are linked by parent to child connection, like this

--- Code: ---
      Part1.setOrigin(origin);
      Part2.setOrigin(origin);
      Part3.setOrigin(origin);
      Part1.addChild(Part2);
      Part2.addChild(Part3);
      world.addObject(Part1);
      world.addObject(Part2);
      world.addObject(Part3);

--- End code ---


So I have three level parent to child connection deepth here. I Hope i'm not doing something wrong here.

Than, when I rotate Part1 for 180 degrees, all 3 parts (1,2,3) are rotateted , that is correct. Than I rotate an O1 object also by 180 degrees.

And than when i try to move those objects, my expectations are that if I move them like this:


--- Code: ---
   Part2.translate(1,0,0)
   O1.translate(1,0,0

--- End code ---


They should move in same direction. But they don't. O1 is moved by absolute (world) axis. While Part(s) are moved by they own axis. In that specific case, they move just the opposite way <--->.


Best regards and by the way I really love your engine, it helped me so much this far.
____________________________________________________________

tinhtinhcd:
after 11 years, I'm here and got the same problem.

EgonOlsen:
...and the answer is still valid: http://www.jpct.net/forum2/index.php/topic,608.msg3143.html#msg3143

The thread got a little mixed up, but that's the actual answer to the problem.

Navigation

[0] Message Index

[*] Previous page

Go to full version