Author Topic: world position of a child object  (Read 1772 times)

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
world position of a child object
« on: January 26, 2012, 01:43:13 pm »
Hi there!

I have a parent object with world position (ie. 1,0,0) and a child object with relative position to the parent object (ie. 2,0,0). This means the world position of the child object in this case would become (3,0,0), because it's relative to the parent object's space. I would like to retrieve the world position (ie. 3,0,0) of the child.
Currently the child only knows it's relative position.
How can I achieve this? What functions I have to use to calculate it?

Thanks in advance!
Marlon
www.forgottenelements.com
Free Action JAVA MMORPG

Offline Vi_O

  • byte
  • *
  • Posts: 17
    • View Profile
Re: world position of a child object
« Reply #1 on: January 26, 2012, 02:08:22 pm »
did you try Object.getWorldTransformation() ?

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: world position of a child object
« Reply #2 on: January 26, 2012, 02:24:01 pm »
did you try Object.getWorldTransformation() ?

The problem here is that I have calculated the center positions of the childs mesh of each keyframe and saved them into a ArrayList of SimpleVectors.
So what I have is the object and a SimpleVector for each keyframe (relative position in object world space).
I need to know what calculation I have to use to get a SimpleVector in world space.
www.forgottenelements.com
Free Action JAVA MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: world position of a child object
« Reply #3 on: January 26, 2012, 02:40:08 pm »
Just multiply the SimpleVector with the matrix returned from Object3D.getWorldTransformation().

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: world position of a child object
« Reply #4 on: January 26, 2012, 08:12:50 pm »
Just multiply the SimpleVector with the matrix returned from Object3D.getWorldTransformation().

Mhhh.. in my case this doesn't seem to work.

In practise I want to add Particles to an item, the character of my game is wearing in his hand. To be even more concrete I want to make a torch which is emitting fire particles.
Because the character (and so the item) is moving while attacking or walking I need to look about the center point of the items mesh at each keyframe.
So I made a list (you already gave me some helpful tipps, egon) and added those center points to it.
With getCenterPosition() I receive the actual position.
Unfortunatly this position is in object space and I need the coordinates in world space.

Here is my code:
Code: [Select]
float cx=0, cy=0, cz=0;
SimpleVector tmpVec=obj3D.getCenterPosition();
if(tmpVec!=null) {
tmpVec.matMul(obj3D.getWorldTransformation());
cx=tmpVec.x*obj3D.getScale();
cy=tmpVec.y*obj3D.getScale();
cz=tmpVec.z*obj3D.getScale();
}
particlePosition = new SimpleVector(obj3D.getTranslation().x+cx, obj3D.getTranslation().y+cy, obj3D.getTranslation().z+cz);

Although mathematic was my intensive course at shool the third dimension is always bringing confusion to my brain.  :o
It would be great if somebody could help me.
« Last Edit: January 26, 2012, 08:14:43 pm by Marlon »
www.forgottenelements.com
Free Action JAVA MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: world position of a child object
« Reply #5 on: January 26, 2012, 09:06:22 pm »
This should be sufficient:

Code: [Select]
float cx=0, cy=0, cz=0;
SimpleVector tmpVec=obj3D.getCenterPosition();
if(tmpVec!=null) {
tmpVec.matMul(obj3D.getWorldTransformation());
}
particlePosition = new SimpleVector(tmpVec);

The method returns the world transformation(!)...it should include all rotations/translations/scalings.

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: world position of a child object
« Reply #6 on: January 26, 2012, 09:13:56 pm »
I already tested this, but there are no particles.

When I use my code (except tmpVec.matMul(obj3D.getWorldTransformation()) particles are shown (always at 12 o clock).
So when I rotate the character with 180 degree, they are exactly on the wrong position ^^. Not easy...

I am going to debug this thing and write here later...
Thanks!
www.forgottenelements.com
Free Action JAVA MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: world position of a child object
« Reply #7 on: January 26, 2012, 09:16:09 pm »
Maybe because you are working directly on the instances? Have you tried to use the copy of the center position vector instead?

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: world position of a child object
« Reply #8 on: January 26, 2012, 09:23:47 pm »
Maybe because you are working directly on the instances? Have you tried to use the copy of the center position vector instead?

Arghhh.. i just found it out while debugging! Yes, now it works! Damnnn, I forgot that tempVec is an instance which is saved in the mentioned ArrayList.

The effect now looks great! I can't wait for releasing this! :)

THANKS!!!
Marlon
www.forgottenelements.com
Free Action JAVA MMORPG