kinematics in SIO2
Posted: Wed Oct 13, 2010 9:20 pm
Greetings. I am using SIO2 game engine to make games for the iPhone. My current game is an accelerometer controlled rolling ball game, much like monkey ball. I am trying to implement a kinematic lift. Something that you can roll the ball onto and it will move you around the level. After much frustration I have it partially working. I have a platform that I can roll onto, and I no longer fall through it (immediately or slowly!). I can move the platform laterally and the bounding box stays where it is supposed to, and I don't fall through anywhere I shouldn't, or bounce up and down while I'm on top. This means that I can actually use this in my game now (hooray!), albeit to a limited extent. When I move the platform vertically the ball can't keep up, even at slow speeds. It will move up with the platform for a short period, then begin to fall through and go shooting off into space. I should mention that I am self taught and pretty noob at that, so I don't exactly know what all of this code is doing, or understand the mathematics behind it. Here is the code I am using to make my platform (named Cube) a kinematic object:
Declared variables:
Done in loading section:
I am using a convex hull with an armature to move the platform. I was just using an IPO before, and the debug drawer showed the bounds working correctly without this function. But now the bounds don't move with the object without this function:
And then this is what I call every cycle in my rendering section:
I am hoping that I can use my lift to move the ball vertically, without the ball clipping and reacting badly. Can anyone see what might be wrong with my code here? I was also hoping I could get the platform to carry my ball around. Right now the platform just slides out from underneath and you have to move to keep up with it.
Thanks,
~KeithK
Declared variables:
Code: Select all
btVector3 objectLoc;
btMatrix3x3 objectSubMatrix;
SIO2transform * _SIO2transform = NULL;
Code: Select all
cube = sio2ResourceGetObject( sio2->_SIO2resource, "object/Cube");
if( cube )
{
_SIO2transform = cube->_SIO2transform;
cube->_SIO2objectphysic->_btRigidBody->setMassProps( btScalar( 0.0f), btVector3( 0.0f, 0.0f, 0.0f ) );
cube->_SIO2objectphysic->mass = 0.0f;
cube->_SIO2objectphysic->_btRigidBody->setCollisionFlags( cube->_SIO2objectphysic->_btRigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
cube->_SIO2objectphysic->_btRigidBody->forceActivationState(DISABLE_DEACTIVATION);
sio2ObjectInitAnimationAttributes( cube );
sio2ObjectSetAction( cube, get_action( sio2->_SIO2resource, "3_03.sio2", "action/cubeTurn" ), 0.5f, 25.0f );
cube->_SIO2objectanimation->_SIO2objectactionCallback = update_convex_hull;
//sio2ObjectPlay( cube, cube->_SIO2objectanimation->loop );
}
Code: Select all
void update_convex_hull( void *_ptr )
{
SIO2object *_SIO2object = ( SIO2object * )_ptr;
unsigned int i = 0,
n_vert = sio2ObjectGetNumVert( _SIO2object );
btVector3 *pts = _SIO2object->_SIO2objectphysic->_btConvexHullShape->getUnscaledPoints();
while( i != n_vert )
{
memcpy( &pts[ i ], &_SIO2object->buf[ i * 12 ], 12 );
++i;
}
_SIO2object->_SIO2objectphysic->_btConvexHullShape->recalcLocalAabb();
}
Code: Select all
cube = sio2ResourceGetObject( sio2->_SIO2resource, "object/Cube");
if( cube )
{
objectSubMatrix.setFromOpenGLSubMatrix( cube->_SIO2transform->mat );
cube->_SIO2objectphysic->_btRigidBody->getWorldTransform().setBasis( objectSubMatrix );
cube->_SIO2objectphysic->_btRigidBody->getWorldTransform().setOrigin( btVector3( _SIO2transform->mat[ 12 ],
_SIO2transform->mat[ 13 ],
_SIO2transform->mat[ 14 ] ) );
}
Thanks,
~KeithK