world position of a child object

Started by Marlon, January 26, 2012, 01:43:13 PM

Previous topic - Next topic

Marlon

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

Vi_O

did you try Object.getWorldTransformation() ?

Marlon

Quote from: Vi_O on January 26, 2012, 02:08:22 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

EgonOlsen

Just multiply the SimpleVector with the matrix returned from Object3D.getWorldTransformation().

Marlon

#4
Quote from: EgonOlsen on January 26, 2012, 02:40:08 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:

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.
www.forgottenelements.com
Free Action JAVA MMORPG

EgonOlsen

This should be sufficient:


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.

Marlon

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

EgonOlsen

Maybe because you are working directly on the instances? Have you tried to use the copy of the center position vector instead?

Marlon

Quote from: EgonOlsen 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?

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