Author Topic: child --> parent  (Read 7493 times)

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« on: July 31, 2006, 06:02:00 pm »
Hello

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

Code: [Select]
  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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
child --> parent
« Reply #1 on: July 31, 2006, 09:07:36 pm »
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.

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« Reply #2 on: August 01, 2006, 01:03:53 am »
I found a workaround, and now i translate objects seperatlly.
Thanks 4 help!

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
Re: child --> parent
« Reply #3 on: August 02, 2006, 10:57:34 pm »
Quote from: "eye1"
Hello

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

Code: [Select]
  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.

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« Reply #4 on: August 02, 2006, 11:56:36 pm »
I'm pretty shure it doesn't

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
child --> parent
« Reply #5 on: August 03, 2006, 12:15:24 am »
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.

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« Reply #6 on: August 03, 2006, 01:00:35 am »
Thanks!

I'll try that.

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« Reply #7 on: August 03, 2006, 02:42:35 am »
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:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
child --> parent
« Reply #8 on: August 03, 2006, 09:09:14 am »
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!?

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« Reply #9 on: August 03, 2006, 01:56:49 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
child --> parent
« Reply #10 on: August 03, 2006, 05:10:25 pm »
:?: 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: [Select]

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:

Code: [Select]

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


Hope this helps.

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
child --> parent
« Reply #11 on: August 10, 2006, 01:56:22 pm »
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: [Select]

      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:

Code: [Select]

   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.
____________________________________________________________

Offline tinhtinhcd

  • byte
  • *
  • Posts: 16
    • View Profile
Re: child --> parent
« Reply #12 on: May 17, 2017, 12:52:03 pm »
after 11 years, I'm here and got the same problem.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: child --> parent
« Reply #13 on: May 17, 2017, 01:00:31 pm »
...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.