Ball on surface physics

View previous topic View next topic Go down

Ball on surface physics

Post  innovation on Tue Sep 29, 2009 1:07 pm

I just started using the SIO2 game engine and firstly its a really great engine. Great work by SIO2.

I'm working on a simple simulation with a ball in a box. The ball is set to a rigid body in blender with the box set as a static actor. The ball is dropped from a height and falls into the box
What i am trying to do here is, based on the accelerometer input the box is rotated and the ball rolls around based on the tilt of the box's base. When the simulation starts the ball drops from a height by gravity and hits the base of the box, but once the box starts to rotate the ball doesn't move. I am under the impression the ball's position should be updated automatically once the physics properties have been set (maybe a false impression) or do i have to call some function to update this position? Any suggestions are welcome.

Thanks.

innovation

Posts: 3
Join date: 2009-09-22
Location: Toronto

View user profile http://www.cellinnovation.ca

Back to top Go down

Re: Ball on surface physics

Post  Francescu on Tue Sep 29, 2009 5:17 pm

Physics objects auto-deactivate. you could disable sleeping for that rigidbody (but this might be too cpu intensive with lots of dynamic objects in a scene) or do a myRigidBody->activate(true)

Applying an impulse would auto activate it too of course...

Francescu

Posts: 136
Join date: 2009-03-18

View user profile

Back to top Go down

Re: Ball on surface physics

Post  innovation on Wed Sep 30, 2009 10:46 pm

Thanks for the response.

I'm probably still missing something because that didn't solve the problem. I had already tried that looking at the tutorial 6 code and that was also mentioned in a couple of posts on here. I also tried deactivating sleep completely without the intended result. Here's the code i have so far if anyone can spot what i'm missing.
Inside my templateRender() function i have...
Code:

sio2WindowEnterLandscape3D();
    { 
        SIO2object *box = (SIO2object *)sio2ResourceGet(sio2->_SIO2resource, SIO2_OBJECT, "object/Box");
        SIO2object *ball = (SIO2object *)sio2ResourceGet(sio2->_SIO2resource, SIO2_OBJECT, "object/Ball");
       
        box->_SIO2transform->rot->x = sio2->_SIO2window->accel->x * sensitivity;
        box->_SIO2transform->rot->y = sio2->_SIO2window->accel->y * sensitivity;
        ball->_SIO2objectphysic->_btRigidBody->setActivationState(ACTIVE_TAG);

//    also tried this here
//    ball->_SIO2objectphysic->_btRigidBody->activate(TRUE);

        sio2TransformBindMatrix(box->_SIO2transform);   

//    Tried this line uncommented as well 
//    sio2TransformBindMatrix(ball->_SIO2transform);

      sio2CameraRender(sio2->_SIO2camera);
      sio2ResourceRender(sio2->_SIO2resource,
                                  sio2->_SIO2window,
                                  sio2->_SIO2camera,
                                  SIO2_RENDER_SOLID_OBJECT);
    }
sio2WindowLeaveLandscape3D();

In the tutorial 6 code i see that a a linear velocity is applied on the physics object. I think that is an external force being applied and not the world interacting on its own. Is that correct?
And from the above code is there some function i should be calling on the ball physics object to make it react to the slope of the box, or should that happen automatically?
Thanks.

innovation

Posts: 3
Join date: 2009-09-22
Location: Toronto

View user profile http://www.cellinnovation.ca

Back to top Go down

Re: Ball on surface physics

Post  Francescu on Thu Oct 01, 2009 12:49 am

Add the following code below:
Code:
btMatrix3x3 mat3;
            
mat3.setFromOpenGLSubMatrix( (btScalar *)box->_SIO2transform->mat );
            
box->_SIO2objectphysic->_btRigidBody->getWorldTransform().setBasis( mat3 );
_after_

Code:
sio2TransformBindMatrix(box->_SIO2transform);
What kind of bounds did you set in blender (logic panel) for the ball - Sphere?

Also, is your box on some static triangle mesh plane?

Are you actually seeing your box rotating?

You should not have to give an impulse to the ball - physics (bullet) should take care of the physics for the ball based on the box rotating.

I do assume that you did set a mass for the ball at least >= 1

Make sure to do a 'center new' in blender for the ball and box as well as Ctrl-A then 'Scale and Rotation to obData'.

Yep, tutorial06 is applying forces not caused by the world - there is a picking contraint in tutorial062 where the force applied is influenced by dragging the object...

Francescu

Posts: 136
Join date: 2009-03-18

View user profile

Back to top Go down

View previous topic View next topic Back to top


Permissions in this forum:
You cannot reply to topics in this forum