I need some help here, because I have no idea what's going on
I don't necessarily understand how joints are implemented in ODE, and whether there is a different between ODE's coordinate systems and OGREs.
Let me explain what I'm trying to do:
Player control using ODE physics. Simple as that. Push forward button, move player forward, colliding with the static environment, and interacting with other dynamic bodies in the world. So, move forward, backwards, turn left and right, and jump. Tada! If I could get this working, the possibilities are endless. The first thing that comes to mind are first person shooters, 3rd person shooters, and platformers, but it could be (and would be) used for RPGs as well, for simple movement and world navigation.
Whoever actually gets this working will be the king of the universe!
There are a few ways it can be done, and by reading the ODE forums, they include:
1. Control a body's (player's) velocity and orientation directly. This is regarded by the ODE forums as a bad idea, because you're circumventing ODE's physics system. If you got hit by an object, you wouldn't budge, unless you put special code in there to deal with it.
2. Control a body by using forces or torque. Moving forward adds torque in that direction, etc. Use a sphere or capsule to represent the player, and float it a small distance above the ground so it doesn't collide with the ground all the time. Through a system of using joints to keep the capsule floating above the ground, this will work.
3. Create a joint similar to Plane2D that doesn't enforce the z=0 constraints of that joint. Attach the player to the joint, and the joint to the static environment. Move the joint directly by using motors. You can control the velocity of the motors, and hence control the player almost as freely as with option 1, but without the negative factors because you will still interact completely with other physical objects.
So, based on my limited knowledge of ODE, #3 sounds like the best option.
Here's a link that describes it, and has some modifications to Plane2D to enable it:
http://article.gmane.org/gmane.comp.lib.ode/8002
Unfortunately, even after making the changes to the Plane2D code, I can't get it to work.
I've modified the OgreODE example called SimpleScenes_Joints to try to get this to work. I've tried a hundred different things, but I'm really just shooting in the dark because I don't actually know what the code is doing.
The result of simply modifying the Plane2D code with the code above, and then adding this to the addForcesAndTorques function of SimpleScenes_Joints is the ball rocking back and forth once J is pressed. It just rocks back forth along what I believe is the Z axis.
Code: Select all
if( left )
{
ball_body->wake();
joint2d->setParameterX( OgreOde::Joint::Parameter_MotorVelocity, 40.0f );
joint2d->setParameterX( OgreOde::Joint::Parameter_MaximumForce, 100.0f );
joint2d->setParameterY( OgreOde::Joint::Parameter_MotorVelocity, 40.0f );
joint2d->setParameterY( OgreOde::Joint::Parameter_MaximumForce, 100.0f );
}
if( right )
{
ball_body->wake();
joint2d->setParameterX( OgreOde::Joint::Parameter_MotorVelocity, -40.0f );
joint2d->setParameterX( OgreOde::Joint::Parameter_MaximumForce, 100.0f );
joint2d->setParameterY( OgreOde::Joint::Parameter_MotorVelocity, -40.0f );
joint2d->setParameterY( OgreOde::Joint::Parameter_MaximumForce, 100.0f );
}
I actually think that the joint should limit rotation to only the Y axis, so it will only turn the ball around (as a player would rotate). Does this sound right? As far as I know, the modified Plane2D tries to limit rotation around the Z axis.
So, I tried modifying the Plane2D code to limit to the Y axis instead, but playing with these values in the plane2dGetInfo2 function:
Code: Select all
VoXYZ (&info->J1l[r0], =, 0, 0, 0);
VoXYZ (&info->J1l[r1], =, 0, 0, 0);
VoXYZ (&info->J1a[r0], =, 1, 0, 0);
VoXYZ (&info->J1a[r1], =, 0, 1, 0);
dVector3 ax1 = {
joint->node[0].body->R[0],
joint->node[0].body->R[4],
joint->node[0].body->R[8] };
dVector3 ax2 = {
joint->node[0].body->R[1],
joint->node[0].body->R[5],
joint->node[0].body->R[9] };
I tried changing the r0 and r1 values, and the ax1 and ax2 values, so far without success. It does *something*, such as stop the ball from rotating at all when J or L is pressed, and in some circumstances makes the ball fly off in a diagonal direction, but I'm getting frustrated.
Any help would be appreciated. I actually doubt anyone will reply, but it's worth trying.
Clay