Jump to content

Get Node/Bone Position


Recommended Posts

Need to find the position of the Eye node? No problem! GetEyePoint()!

Need to find the position of any other node or bone in the player model? Errr ...


Introducing getNodePoint! (original from Tim-MGT but I updated it just now to work engineDefines).


In shapeBase.h near getEyeTransform in the "public" section add:

   virtual void getNodeTransform(const char* nodeName, MatrixF* mat);
   virtual void getNodeVector(const char* nodeName, VectorF* vec);
   void getNodePoint(const char* nodeName, Point3F* pos);

 

In shapeBase.cpp

//yorks for node transforms
void ShapeBase::getNodeTransform(const char* nodeName, MatrixF* mat)
{
	S32 node = getShape()->findNode(nodeName);
 
	MatrixF pmat;
	pmat.identity();
 
	F32 *dp = pmat;
 
	if (node != -1)
	{
		F32* sp;
		sp = mShapeInstance->mNodeTransforms[node];
		const Point3F& scale = getScale();
		dp[3] = sp[3] * scale.x;
		dp[7] = sp[7] * scale.y;
		dp[11] = sp[11] * scale.z;
	}
 
	mat->mul(getTransform(), pmat);
}
 
void ShapeBase::getNodeVector(const char* nodeName, VectorF* vec)
{
	MatrixF mat;
	getNodeTransform(nodeName, &mat);
 
	mat.getColumn(1, vec);
}
 
void ShapeBase::getNodePoint(const char* nodeName, Point3F* pos)
{
	MatrixF mat;
	getNodeTransform(nodeName, &mat);
	mat.getColumn(3, pos);
}
//yorks end

 

And then down at the bottom expose it to glorious Torquescript.

 

DefineEngineMethod(ShapeBase, getNodeTransform, MatrixF, (const char* nodeName), ,
	"@brief Get the node/bone transform.\n\n"
 
	"@param node/bone name to query\n"
	"@return the node position\n\n")
{
	MatrixF mat;
	object->getNodeTransform(nodeName, &mat);
	return mat;
}
 
DefineEngineMethod(ShapeBase, getNodeVector, VectorF, (const char* nodeName), ,
	"@brief Get the node/bone vector.\n\n"
 
	"@param node/bone name to query\n"
	"@return the node vector\n\n")
{
	VectorF vec(0, 1, 0);
	object->getNodeVector(nodeName, &vec);
 
	return vec;
}
 
DefineEngineMethod(ShapeBase, getNodePoint, Point3F, (const char* nodeName), ,
	"@brief Get the node/bone position.\n\n"
 
	"@param node/bone name to query\n"
	"@return the node position\n\n")
{
	Point3F pos(0, 0, 0);
	object->getNodePoint(nodeName, &pos);
 
	return pos;
}
Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...