how to get the normalised_movement_vector

planB

20-09-2010 01:55:58

hi, there!

i have render the animited character to the ogre. but there are some problem with the move and turn.

how could i get the value of normalised_movement_vector in the move funtion.

my keypress is below,

bool test_character::keyPressed( const OIS::KeyEvent &evt )
{
switch(evt.key)
{
case OIS::KC_UP:
case OIS::KC_K:
mDirection.z -= 1;
break;
case OIS::KC_DOWN:
case OIS::KC_L:
mDirection.z +=1;
break;
case OIS::KC_LEFT:
case OIS::KC_I:
mRotation = 3.5f;
break;
case OIS::KC_RIGHT:
case OIS::KC_M:
mRotation = -3.5f;
break;

}

return BaseApplication::keyPressed(evt);

}


so how can i get the value to move the character ahead (not move to only two strange direction as i did now),

mcharacter->move(????);

betajaen

20-09-2010 08:27:05

How I've moved characters in the pass is usually based around this:

original_pos + ((direction * orientation) * deltaTime)

Direction is a vector i.e. 1,0,0 (you can just called direction.normalise() before using).
Orientation is the orientation of the character, as a quaternion. Usually just the yaw. You could use the Quaternion::fromAngleAxis function if you just have a radian value stored as the yaw, if you prefer working in radians or degrees.
deltatTime is just the time passed.

I don't have the OGRESDK open at the moment, but you may need to swap direction/orientation around.

planB

21-09-2010 06:07:10

tks, but i failed that.

my code is like below,
create,

void test_character::createScene(void)
{
Critter::AnimatedCharacterDescription descr;
descr.mName="char";
descr.mCallback=this;
descr.mWalkingVelocity=13;

SimpleBox shape;
shape.mSize=Vec3(2,3,8);

mcharacter = mRenderSystem->createCharactor(shape ,NxOgre::Vec3(0,0,0),NxOgre::Radian(0),"Sinbad.mesh",descr);
}

keypress and keyrelease,

bool test_character::keyPressed( const OIS::KeyEvent &evt )
{
switch(evt.key)
{
case OIS::KC_UP:
case OIS::KC_I:
mDirection.z -= 1;
if(mDirection.z<-1) mDirection.z=-1;
break;
case OIS::KC_DOWN:
case OIS::KC_K:
mDirection.z +=1;
if(mDirection.z>1) mDirection.z=1;
break;
case OIS::KC_LEFT:
case OIS::KC_J:
mRotation = 3.5f;
break;
case OIS::KC_RIGHT:
case OIS::KC_L:
mRotation = -3.5f;
break;

}

return BaseApplication::keyPressed(evt);
}


bool test_character::keyReleased( const OIS::KeyEvent &evt )
{
switch(evt.key)
{
case OIS::KC_UP:
case OIS::KC_I:
mDirection.z = 0;
break;
case OIS::KC_DOWN:
case OIS::KC_K:
mDirection.z = 0;
break;
case OIS::KC_LEFT:
case OIS::KC_J:
mRotation = 0.0f;
break;
case OIS::KC_RIGHT:
case OIS::KC_L:
mRotation = 0.0f;
break;

}

return BaseApplication::keyReleased(evt);
}

framequeued,

bool test_character::frameRenderingQueued( const Ogre::FrameEvent& evt )
{
mGoalDirection = Vector3::ZERO;
if (mDirection != Vector3::ZERO )
{
mGoalDirection=mcharacter->getSceneNode()->getOrientation()*mDirection* evt.timeSinceLastFrame;

mcharacter->move(mGoalDirection);

}

float turn = 0;
if (mRotation != 0.0f)
{
turn = mRotation *evt.timeSinceLastFrame;

mcharacter->turn( turn );
}

return BaseApplication::frameRenderingQueued(evt);

}


the result is that, the character can move only two direction, and the entity can't face the move direction.

any help will be appreciated .