child --> parent

Started by eye1, July 31, 2006, 06:02:00 PM

Previous topic - Next topic

eye1

Hello

I'm using this code to retrieve current position of Object in world

  private SimpleVector getParentTrans(Object3D model)
  {
     Object3D[] parents = model.getParents();
     SimpleVector sv=new SimpleVector();
     for (int i = 0; i < parents.length; i++) {
        if (parents[i] != null) {
           sv.add(parents[i].getTranslation());
           sv.add(getParentTrans(parents[i]));
        }
     }
     return sv;
  }

  public SimpleVector getCurrPosition()
  {
     SimpleVector sv = model.getOrigin();
     sv.add(model.getTranslation());
     SimpleVector par = getParentTrans(model);
     System.out.println("PAR: "+par);
     sv.add(par);
     return sv;
  }


it looks like it works fine!!!


But when I unlink child from parent it look like it is not removed from array which is returned by method Object3D.getParents(). Is that a bug, or i made a mistake??

Regards

EgonOlsen

A little bit both. It's described that way (albeit not very cleary, i have to admit) in the docs but it makes no sense, does it? So i've uploaded a version that should only return the actually used parents here: http://www.jpct.net/download/beta/jpct.jar

Hope this helps.

eye1

I found a workaround, and now i translate objects seperatlly.
Thanks 4 help!

eye1

Quote from: "eye1"Hello

I'm using this code to retrieve current position of Object in world

  private SimpleVector getParentTrans(Object3D model)
  {
     Object3D[] parents = model.getParents();
     SimpleVector sv=new SimpleVector();
     for (int i = 0; i < parents.length; i++) {
        if (parents[i] != null) {
           sv.add(parents[i].getTranslation());
           sv.add(getParentTrans(parents[i]));
        }
     }
     return sv;
  }

  public SimpleVector getCurrPosition()
  {
     SimpleVector sv = model.getOrigin();
     sv.add(model.getTranslation());
     SimpleVector par = getParentTrans(model);
     System.out.println("PAR: "+par);
     sv.add(par);
     return sv;
  }


it looks like it works fine!!!


But when I unlink child from parent it look like it is not removed from array which is returned by method Object3D.getParents(). Is that a bug, or i made a mistake??

Regards

Hello again.

Should above code work also when objects are rotated?

I'm thinking of going back to my previus child-->parent translations.

eye1

I'm pretty shure it doesn't

Is it possible to get an absolute position of child object in world.

EgonOlsen

No, a simple getTranslation() gives you the translation of the object itself only. You may either use Object3D.getWorldTransformation() to get the combined translations/rotations applied to a child or use Object3D.getTransformedCenter() to get the position of the child's center in world space. Depending on how you've defined your center, this may be what you need.

eye1


eye1

Hy

I'm having problem!

I move two objects with method translate()

Here is my prompt output, just to be shure objects get same direction vector
RBG: (-3.0,0.0,0.0)
CONT: (-3.0,0.0,0.0)
TABLE: (0.0,3.0,0.0)
CONT: (0.0,3.0,0.0)

But objects move just the oposite way. And it doesen't matter if i rotate the other object also. (RBG & TABLE are childs in hierarchy)

I have no clue what colud it be
:(


Sorry, 4 all those questions :oops:

EgonOlsen

Hmm, i don't really understand the problem here!? What is CONT and what do you mean by "opposite way"? Opposite to what? Maybe you can provide me with a test case that demonstrates your problem!?

eye1

I'm doing some research on the problem 4 now.

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

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:


SimpleVector trsl=new SimpleVector(1,2,0);
trsl.matMul(p1.getWorldTransformation());
p2.translate(trsl);

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:


p2.translate(p1.getXAxis()); // Example for the X-axis


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

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


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:


  Part2.translate(1,0,0)
  O1.translate(1,0,0


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.