Ball on surface physics
2 posters
Ball on surface physics
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.
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.
Re: Ball on surface physics
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...
Applying an impulse would auto activate it too of course...
Francescu- Posts : 136
Join date : 2009-03-18
Re: Ball on surface physics
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...
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.
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.
Re: Ball on surface physics
Add the following code below:
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...
- Code:
btMatrix3x3 mat3;
mat3.setFromOpenGLSubMatrix( (btScalar *)box->_SIO2transform->mat );
box->_SIO2objectphysic->_btRigidBody->getWorldTransform().setBasis( mat3 );
- Code:
sio2TransformBindMatrix(box->_SIO2transform);
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
Similar topics
» Bouncing ball physics
» Physics in 1.3.1
» problem with surface
» Render unlit surface
» physics object inside another physics object
» Physics in 1.3.1
» problem with surface
» Render unlit surface
» physics object inside another physics object
Permissions in this forum:
You cannot reply to topics in this forum