Movement

Fred

05-12-2007 20:59:05

Hi,

I've a programm using Ogre and OgreODE.
There are some classes.
FrameListener,
Main,
Object,

FrameListener should be clear(Inputs)
Main is the main class which is the base of the programm. In it are created the FrameListener, Initialised the Physics and so on.
The Object class manages the objects. Create Entitys, Nodes, Bodys etc.

The movement behaves as follows:

If a button was pressed, a "movement vector" is set on Vector3(1,0,0).

In the move method of the object I wrote:

int Object::Move(float fTime)
{
m_vPosition += 1000.0f * fTime * 0.2;
m_pBody->setPosition(m_vPosition);
return 0;
}



But now there is no gravity anymore. I was told that I have to define a force:

int Object::Move(float fTime)
{
m_vPosition += 1000.0f * fTime * 0.2;
m_pBody->addForce(Ogre::Vector3(0,-100000,0));
m_pBody->setPosition(m_vPosition);
return 0;
}


The same result.
What I have to do?
What's wrong?

Thanks for reply,
Fred

rewb0rn

05-12-2007 21:10:49

As I told you before, changing the position of the body yourself will overwrite any movement that comes from ode, and you still do that in your second try. Just try



int Object::Move(float fTime)
{
m_pBody->addForce(Ogre::Vector3(0,-100*fTime,0));
return 0;
}

Fred

05-12-2007 22:11:07

Ah I know what you mean

So my method has to be:

int Object::Move(float fTime)
{
m_pBody->setForce(m_vMove * 10000.0f * fTime);
return 0;
}


But quite strange:
1. I need a very hig factor
2. If the button is released m_vMove is set to Ogre::Vector3(0,0,0), but why my object stop if I release? n*0 = 0

Edit: Oh Newton's first law:
An object at rest tends to stay at rest and an object in motion tends to stay in motion with the same speed and in the same direction unless acted upon by an unbalanced force.
But how I can implement that

rewb0rn

05-12-2007 23:32:50

what is the value of m_vMove? You told me you already use gravity, what value did you set? Is there much difference between it and the force you use?

Every body has a linear and an angular damping that make the body lose speed over time, you can adjust them by calling setLinearDamping and setAngularDamping.

If your object immediately stops after releasing your button, maybe you reset the force or speed of your body in another function?

In general I recommend to check out the simple scenes demo to get a first clue on how to use OgreOde for your purpose.

Fred

06-12-2007 13:11:05

OK Thanks. Now my code is like that and my object is moving :)

int Object::Move(float fTime)
{
m_pBody->addForce(m_vMove * 1000000.0f * fTime);
m_pBody->setLinearDamping( 100000.0f * fTime);
}


But there is the "problem" of the high values. My gravity-value is set on 9.81 and the object fall down quite fast. m_vMove is set on Vrctor3(1,0,0), if Button KC_RIGHT is pressed.