www.jpct.net

Bones - Skeletal and Pose Animations for jPCT/jPCT-AE => Bones => Topic started by: AGP on June 07, 2013, 09:30:56 pm

Title: How to Get Worldspace position of a Joint
Post by: AGP on June 07, 2013, 09:30:56 pm
How can I get a SimpleVector, in worldspace, of a given Joint?
Title: Re: How to Get Worldspace position of a Joint
Post by: Gatobot on June 07, 2013, 11:50:01 pm
I add the position o the joint to the transformed center of the object but its not very accurate :(
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 08, 2013, 12:15:39 am
Thanks for your response, but there has to be a better way.
Title: Re: How to Get Worldspace position of a Joint
Post by: Gatobot on June 08, 2013, 12:43:17 am
Of course,  i hope there could be a method for that,  that should be very handy
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 08, 2013, 02:38:20 pm
Object3D.getTransformedCenter() takes center of Object3D into account and that center is calculated by jPCT. instead, use Object3D.getTranslation().

if there is a rotation on Object3D that should be taken into account to.

simply applying Object3D.getWorldTransformation() matrix to bone location should work (not tested). it should take both translation and rotation into account. ie:

Code: [Select]
SimpleVector.matMul(Animated3D.getWorldTransformation());
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 09, 2013, 12:05:53 am
I see. A follow-up, then: How do you, Raft, do area-specific collision-detection. Because the way I was going about it was to add primitives to specific joints and collide them with my collision objects.
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 09, 2013, 12:36:44 am
if you mean you need info about colliding polygons, attach CollisionListener's to your "joint primitives". see CollisionListener.requiresPolygonIDs().

btw, what is the overall purpose here? why do you want to collide joint primitives instead of the mesh itself?
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 09, 2013, 08:18:27 pm
Most of the time we need to know where the collision happened on the mesh, but in my current particular case, it's a little fighting game. A Joint.getWSPosition() method would be very helpful.
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 10, 2013, 01:51:35 am
a Joint is just a part of Skeleton. It doesnt know anything about which Animated3D it's related to. furthermore more it does not even have a location in Skeleton. that data is stored in SkeletonPose class.

just use the code below for WS of a joint. (not tested but it should work)

Code: [Select]
SimpleVector location = skeletonPose.getGlobal(jointIndex).getTranslation();
location.matMul(animated3D.getWorldTransformation());
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 10, 2013, 02:19:30 am
Thanks a lot, I will use your code. But it should be noted that Joint doesn't have to know anything about its Animated3D. Knowing its location is more important.
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 10, 2013, 10:48:49 pm
Yet another follow-up: why doesn't the following work perfectly (it mostly works in that the head collision object translates with the model, but the head object is front of it)?

Code: [Select]
head = Primitives.getCube(15);
joint = skeleton.findJointByName(bipName+ " Head");
head.setTranslationMatrix(skeletonPose.getGlobal(joint.getIndex()));
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 10, 2013, 11:11:26 pm
I've just made a quick test and it works as expected. the collision object is positioned just at joint location ???

* although it's uncommon, maybe that joint is actually in front of model?
* are you translating the model itself? maybe that translation is not applied to collision object?
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 10, 2013, 11:15:04 pm
I'm translating it, but as long as they share the same matrix, shouldn't it all move in unison?

I assume Animated3D.getRoot().translate(...) is the way to move everything, including its Skeleton. Am I wrong?
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 10, 2013, 11:21:44 pm
no.

1. jPCT possibly copies matrix values at setTranslationMatrix(..) not holds a reference to it. (beeing open source really helps on these kinds of things)
2. More importantly, the joint transformations retrieved by SkeletonPose.getGlobal(..) are in object space. they have no relation to translation applied to AnimatedGroup or Animated3D.
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 10, 2013, 11:27:45 pm
I assume Animated3D.getRoot().translate(...) is the way to move everything, including its Skeleton. Am I wrong?
no, it just moves the model, AnimatedGroup and Animated3D. Skeleton does not move anywhere. indeed, Skeleton is not even something that can be moved around. it's just a definition of joint hierarchies, not a physical thing if that is the correct expression.
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 10, 2013, 11:28:41 pm
No, jPCT holds a reference to the matrix. So that means that getGlobal(...) won't work for moving objects. But as this way is both very useful and very efficient, is there any chance I can persuade you to write a getGlobalWS(...)?
Title: Re: How to Get Worldspace position of a Joint
Post by: raft on June 10, 2013, 11:35:00 pm
why not just use that code? I've tested it and it works as expected.

Code: [Select]
SimpleVector location = skeletonPose.getGlobal(jointIndex).getTranslation();
location.matMul(animated3D.getWorldTransformation());

I wont and cant write such a method because a SkeletonPose knows nothing about the Animated3D and AnimatedGroup it's attached to. Furthermore, same SkeletonPose can be attached to multiple AnimatedGroup/Animated3D's.
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 10, 2013, 11:37:02 pm
I see. Thanks.
Title: Re: How to Get Worldspace position of a Joint
Post by: Gatobot on June 11, 2013, 05:46:26 am
hey raft thanks a lot this works great!! ;D
Title: Re: How to Get Worldspace position of a Joint
Post by: AGP on June 11, 2013, 06:08:17 pm
It's just that raft's way you have to adjust the objects every iteration, and you end up with multiple matrices that effectively do the same thing. If getGlobalWS(...) were possible, it would be faster, neater, and used less RAM.