Author Topic: How to Get Worldspace position of a Joint  (Read 28218 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
How to Get Worldspace position of a Joint
« on: June 07, 2013, 09:30:56 pm »
How can I get a SimpleVector, in worldspace, of a given Joint?

Offline Gatobot

  • byte
  • *
  • Posts: 15
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #1 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 :(

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #2 on: June 08, 2013, 12:15:39 am »
Thanks for your response, but there has to be a better way.

Offline Gatobot

  • byte
  • *
  • Posts: 15
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #3 on: June 08, 2013, 12:43:17 am »
Of course,  i hope there could be a method for that,  that should be very handy

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to Get Worldspace position of a Joint
« Reply #4 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());

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #5 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.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to Get Worldspace position of a Joint
« Reply #6 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?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #7 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.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to Get Worldspace position of a Joint
« Reply #8 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());

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #9 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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #10 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()));

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to Get Worldspace position of a Joint
« Reply #11 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?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: How to Get Worldspace position of a Joint
« Reply #12 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?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to Get Worldspace position of a Joint
« Reply #13 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.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to Get Worldspace position of a Joint
« Reply #14 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.