Small Character Issues

dbrock

28-01-2008 19:08:49

Hey guys, I'm having 2 main issues at the moment.

1) Rotation
Problem: My character is rotating in-game, but according to the physx debugger, he isn't really rotating at all, which will cause future problems when it comes to hit boxes and ray casting to actually shoot people.

Screenshot:

// m_Character is an NxOgre::Character*
m_Character->createNode();
m_CharacterNode = m_Character->getNode()->createChildSceneNode();
m_CharacterNode->attachObject( m_CharacterEntity ); // Attach entity
m_CharacterNode->setPosition( 0,( -0.5f * size.y ),0 ); // Offset node so his feet touch the ground

// My rotation code
m_Character->getNode()->yaw( -Ogre::Radian( Ogre::Degree( x * 0.07f ).valueRadians() ) );
m_Character->setDirection( m_Character->getNode()->getWorldOrientation() );

2) Position
Problem: When my character goes into Ragdoll simlulation mode, the physx actors take over the ogre bones, and updates them. The problem is, they get updated way off screen, but in the physx debugger, they are in the proper location.

Screenshot:


m_Ragdoll = new Ragdoll( filename, m_CharacterNode, m_Name + ".ragdoll", m_PHYSScene );

// Inside the ragdoll class - Updates ogre bones acording to physx actors
void Ragdoll::updateBones()
{
Ogre::Quaternion PhysxRotation, OgreGlobalQuat, NodeRotationInverse = m_CharacterNode->getOrientation().Inverse();
for( int i=0; i<15; i++ )
{
PhysxRotation = m_BoneBoneActorBind[i].BoneActor->getGlobalOrientation()* m_BoneBoneActorBind[i].BoneActorGlobalBindOrientationInverse;
Ogre::Quaternion ParentInverse = NodeRotationInverse;
if ( m_BoneBoneActorBind[i].bone->getParent() )
ParentInverse = m_BoneBoneActorBind[i].bone->getParent()->_getDerivedOrientation().Inverse() * NodeRotationInverse;
else
// This is probably affecting why my character is way off screen
m_CharacterNode->setPosition( m_BoneBoneActorBind[i].BoneActor->getGlobalPosition() - m_CharacterNode->getOrientation() * m_BoneBoneActorBind[i].bone->getPosition() );

OgreGlobalQuat = PhysxRotation * m_BoneBoneActorBind[i].BoneGlobalBindOrientation;

m_BoneBoneActorBind[i].bone->setOrientation( ParentInverse * OgreGlobalQuat );

}

Ogre::Vector3 newPos = m_PositionControllingBone->BoneActor->getGlobalPosition() - m_CharacterNode->getOrientation() * m_PositionControllingBone->bone->getPosition() - m_PositionControllingBone->BAoffset;

// This is probably affecting why my character is way off screen
m_CharacterNode->setPosition( newPos );
}


The ragdoll is setup using Ebol's method: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=5289

betajaen

28-01-2008 19:17:33

1. No the character doesn't really rotate. So I keep a copy of the rotation in the mDirection variable, once it's changed usually the scene node is rotated as well. To move the character I just multiply the movement vector (Vector3(1,0,0) for forward) by the Quaternion for a proper direction.

In short use mDirection.


2. That isn't my code, so Ebol is probably the best man for it. But are you adding the global pose of the character to the ragdoll scenenode?

dbrock

28-01-2008 20:15:07

1) Is there any example code that technique?

2) The character node is a child node of the NxOgre::Character's node (which we offset in the beginning by (-0.5* size.y) so his feet would touch. So I'm just adding the pose of the child, rather then the global.