How to Get Worldspace position of a Joint

Started by AGP, June 07, 2013, 09:30:56 PM

Previous topic - Next topic

AGP

How can I get a SimpleVector, in worldspace, of a given Joint?

Gatobot

I add the position o the joint to the transformed center of the object but its not very accurate :(

AGP

Thanks for your response, but there has to be a better way.

Gatobot

Of course,  i hope there could be a method for that,  that should be very handy

raft

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:

SimpleVector.matMul(Animated3D.getWorldTransformation());

AGP

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.

raft

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?

AGP

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.

raft

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)


SimpleVector location = skeletonPose.getGlobal(jointIndex).getTranslation();
location.matMul(animated3D.getWorldTransformation());

AGP

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.

AGP

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)?


head = Primitives.getCube(15);
joint = skeleton.findJointByName(bipName+ " Head");
head.setTranslationMatrix(skeletonPose.getGlobal(joint.getIndex()));

raft

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?

AGP

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?

raft

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.

raft

Quote from: AGP on June 10, 2013, 11:15:04 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.