geActor_SetBoneGlobalAttachment

Programming Reality Factory and Genesis3D.
Post Reply
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

geActor_SetBoneGlobalAttachment

Post by federico » Wed Oct 24, 2007 11:37 pm

geActor_SetBoneGlobalAttachment(geActor *A, const char *BoneName, geXForm3d *Attachment, geXForm3d *OffsetTransform)

set rotation of the Bone (BoneName) of the Actor (A) to a value relative to the world axis (and not relative to the parent bone). The OffsetTrasform can be set to define an offset rotation relative to parent matrix.


actor.h (prototyped also in the include\actor.h file)

Code: Select all

GENESISAPI geBoolean GENESISCC geActor_SetBoneGlobalAttachment(geActor *A, const char *BoneName, geXForm3d *Transform,geXForm3d *OffsetTransform);
actor.c

Code: Select all

GENESISAPI geBoolean GENESISCC geActor_SetBoneGlobalAttachment(geActor *A,
								const char *BoneName,
								geXForm3d *Attachment,
								geXForm3d *OffsetTransform)
{

	int BoneIndex;

	assert( geActor_IsValid(A) != GE_FALSE);
	assert( geXForm3d_IsOrthonormal(Attachment) != GE_FALSE );
	
	if (geActor_GetBoneIndex(A,BoneName,&(BoneIndex))==GE_FALSE)
		{
			geErrorLog_AddString(-1,"Named bone not found", BoneName);
			return GE_FALSE;
		}
	
	gePose_SetJointGlobalAttachment(A->Pose,BoneIndex, Attachment, OffsetTransform);

	return GE_TRUE;
}
pose.h

Code: Select all

void GENESISCC gePose_SetJointGlobalAttachment(gePose *P,int JointIndex,const geXForm3d *AttachmentTransform, const geXForm3d *OffsetTransform);
pose.c

Code: Select all

void GENESISCC gePose_SetJointGlobalAttachment(gePose *P,
	int JointIndex, 
	const geXForm3d *AttachmentTransform,
	const geXForm3d *OffsetTransform)
{
	assert( P != NULL );
	assert( AttachmentTransform != NULL );
	{
		geQuaternion LocRot, MyRot, RotRoot, RotParent, RotBase, RotInv, RotOff;
		gePose_Joint *J;
		gePose_Joint *Parent;

		J = (gePose_Joint *)gePose_JointByIndex(P, JointIndex);
		geQuaternion_FromMatrix(AttachmentTransform,&MyRot);
		geQuaternion_FromMatrix(OffsetTransform,&RotOff);

		RotRoot = J->Rotation;
		Parent = (gePose_Joint *)gePose_JointByIndex(P, J->ParentJoint);

		LocRot = Parent->LocalRotation;

		geQuaternion_Multiply(&RotRoot, &LocRot, &RotParent);
		geQuaternion_Multiply(&MyRot, &RotOff, &RotBase);
		geQuaternion_Inverse(&RotParent, &RotInv);

		geQuaternion_Multiply(&RotInv, &RotBase, &(J->LocalRotation));
		
		
		J->Touched = GE_TRUE;
		//gePose_SetAttachmentRotationFlag(J);
	}
	P->Touched = GE_TRUE;
}

Post Reply