Help to newbie......

KoMaTo3HuK
Posts: 4
Joined: Mon Oct 22, 2007 10:28 pm

Help to newbie......

Post by KoMaTo3HuK »

Well, i got a real problem and need some help here.

Situation:
I have a ball; and a floor; ball - is dynamic object; floor - kinematic;

here some initialization functions:
-----------------------------------------------------------------------

Code: Select all

 btRigidBody *body,*body1;

    createBall(){
		SimpleSceneNode *s = new SimpleSceneNode("ball");

		btTransform trans;
		trans.setIdentity();
		trans.setOrigin(btVector3(-0.8f,2.0,-6.0f));
		
		btDefaultMotionState* motionstate = new btDefaultMotionState(trans);
		
		float mass = 5.0f;
		btCollisionShape *geom = new btSphereShape (0.2f);
		geom->calculateLocalInertia(mass,btVector3(0,0,0));
		body = new btRigidBody(mass,motionstate,geom);
		
		world->addRigidBody(body);
		
		return s;
	}

        createFloor(){
		btTransform trans;
		trans.setIdentity();
		trans.setOrigin(btVector3(0.0f,-0.7f,-6.0f));
		float mass = 0.0f;

		btBoxShape *geom = new btBoxShape(btVector3(2,0.1,2));
		btDefaultMotionState *motionstate = new btDefaultMotionState(trans);
		geom->calculateLocalInertia(mass,btVector3(0,0,0));
		body1 = new btRigidBody(mass,motionstate,geom);
		world->addRigidBody(body1);

		body1->setCollisionFlags(body1->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
		body1->setActivationState(DISABLE_DEACTIVATION);

		return s;
	}
-------------------------------------------------------------------------------------

and world initialization:

-------------------------------------------------------------------------------------

Code: Select all

btDiscreteDynamicsWorld *world;
     bool SimpleEngine::initPhysycs(){
	    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
            btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConfiguration);

	    btVector3 worldAabbMin(-100,-100,-100);
  	    btVector3 worldAabbMax(100,100,100);
	    btBroadphaseInterface* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);

	    btConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
	
	    dispatcher->registerCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,new   btSphereBoxCollisionAlgorithm::CreateFunc);
	
            btSphereBoxCollisionAlgorithm::CreateFunc* boxSphereCF = new btSphereBoxCollisionAlgorithm::CreateFunc;
            boxSphereCF->m_swapped = true;
	    dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,boxSphereCF);

	    world = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver);
 	    world->setGravity(btVector3(0,-10,0));
	
	return true;
}
------------------------------------------------------------------------------------------------
floor movement function

Code: Select all

:

void rot(int dir,btRigidBody *obj){
		btDefaultMotionState *motionstate = (btDefaultMotionState *)obj->getMotionState();
		btQuaternion old = motionstate->m_graphicsWorldTrans.getRotation();

		float angle = 0.002;

		switch (dir){
			case 1: // up
				motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(1.0,0,0),angle));		
			break;

			case 2: // down
				motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(1.0,0,0),-angle));
			break;

			case 3: // left
				motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(0,0,1),angle));
			break;

			case 4: // RIGHT
				motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(0,0,1),-angle));
			break;
		}

	}
-----------------------------------------------------------------------------------------------
The task:
i need create a scene with floor and a ball; ball is falling to the floor; floor can rotate to any angle, but cant move; thats all.

So now the problem :
In some cases the ball is disappears when it contacts a floor, but sometimes it's works well.

Can somebody help me?
maybe i have wrong world configuration?
or i should use another solution?

sorry for so question but i have time a little.............

PS: sorry for my English.
KoMaTo3HuK
Posts: 4
Joined: Mon Oct 22, 2007 10:28 pm

Re: Help to newbie......

Post by KoMaTo3HuK »

Anyone can help me?

Please check the code......
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Help to newbie......

Post by Erwin Coumans »

You sphere is very small, and the floor very thin. Can you make the floor thicker, and see if that helps?

Please attach a fully working modified Bullet Demo that reproduces the problem.

Hope this helps,
Erwin

By the way: most people are too busy to analyse other's source code. Please describe the problem more concisely next time.
KoMaTo3HuK
Posts: 4
Joined: Mon Oct 22, 2007 10:28 pm

Re: Help to newbie......

Post by KoMaTo3HuK »

no, it's not work.... pity......

but thanks for try....
KoMaTo3HuK
Posts: 4
Joined: Mon Oct 22, 2007 10:28 pm

Re: Help to newbie......

Post by KoMaTo3HuK »

Ok, then please tell me way to control KINEMATIC objects, except direct coordinates controll.
I suppose that problem in rotation.