Exemplo n.º 1
0
void shootBox(const btVector3& destination)
{
	float mass = 1.f;
	btTransform startTransform;
	startTransform.setIdentity();
	btVector3 camPos = getCameraPosition();
	startTransform.setOrigin(camPos);



	const btScalar BOX_DIMENSIONS = 3.0f;

	btBoxShape* box = new btBoxShape( btVector3(BOX_DIMENSIONS, 0.1f, BOX_DIMENSIONS*4/3) );
	box->initializePolyhedralFeatures();
	m_shootBoxShape = box;

	btRigidBody* body = localCreateRigidBody(mass, startTransform,m_shootBoxShape);
	body->setLinearFactor(btVector3(1,1,1));
	//body->setRestitution(1);

	btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
	linVel.normalize();
	linVel*=m_ShootBoxInitialSpeed;

	body->getWorldTransform().setOrigin(camPos);
	body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
	body->setLinearVelocity(linVel);
	body->setAngularVelocity(btVector3(0,0,0));
	body->setCcdMotionThreshold(0.5);
	body->setCcdSweptSphereRadius(0.4f);//value should be smaller (embedded) than the half extends of the box (see ::setShootBoxShape)
	LOGI("shootBox uid=%d\n", body->getBroadphaseHandle()->getUid());
	LOGI("camPos=%f,%f,%f\n",camPos.getX(),camPos.getY(),camPos.getZ());
	LOGI("destination=%f,%f,%f\n",destination.getX(),destination.getY(),destination.getZ());

}
Exemplo n.º 2
0
void Fenettre::shootBox(const btVector3& destination)
{
    if (World)
	{
        btVector3 camPos = camera->GetPosition();
        btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
		linVel.normalize();
		linVel*=1000.0f; //vitesse

        double size =1;
	    RigideBox* Box =new RigideBox(10.L,World,camPos,btVector3(size,size,size));
	    Box->SetShaderProgram(Prog[1]);
	    //Box->SetShaderProgram(Prog[randRange(0,MAXSHADER)]);
	    Box->setLinearFactor(btVector3(1,1,1));
	    Box->setOrigin(camPos);
        Box->setRotation(btQuaternion(0,0,0,1)); //angle de base
	    Box->setLinearVelocity(linVel);
	    Box->setAngularVelocity(btVector3(25,25,25)); //rotation
	    Box->setCcdMotionThreshold(size/2.0f);
	    Box->setCcdSweptSphereRadius(0.9f);

        ObjetsBt.push_back(Box);


	}
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
void GimpactConcaveDemo::shootTrimesh(const btVector3& destination)
{

	if (m_dynamicsWorld)
	{
		float mass = 4.f;
		btTransform startTransform;
		startTransform.setIdentity();
		btVector3 camPos = getCameraPosition();
		startTransform.setOrigin(camPos);
#ifdef BULLET_GIMPACT
		btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_trimeshShape2);
#else
		btRigidBody* body = this->localCreateRigidBody(mass, startTransform,createBunnyShape());
#endif
		btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
		linVel.normalize();
		linVel*=m_ShootBoxInitialSpeed*0.25;

		body->getWorldTransform().setOrigin(camPos);
		body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
		body->setLinearVelocity(linVel);
		body->setAngularVelocity(btVector3(0,0,0));
	}
}
void	DemoApplication::shootBox(const btVector3& destination)
{

	if (m_dynamicsWorld)
	{
		float mass = 1.f;
		btTransform startTransform;
		startTransform.setIdentity();
		btVector3 camPos = getCameraPosition();
		startTransform.setOrigin(camPos);

		setShootBoxShape ();

		btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);
		body->setLinearFactor(btVector3(1,1,1));
		//body->setRestitution(1);

		btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
		linVel.normalize();
		linVel*=m_ShootBoxInitialSpeed;

		body->getWorldTransform().setOrigin(camPos);
		body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
		body->setLinearVelocity(linVel);
		body->setAngularVelocity(btVector3(0,0,0));
		body->setCcdMotionThreshold(1.);
		body->setCcdSweptSphereRadius(0.2f);
		
	}
}
void	DemoApplication::shootBox(const btVector3& destination)
{

	if (m_dynamicsWorld)
	{
		float mass = 1.f*1000.;
		btTransform startTransform;
		startTransform.setIdentity();
		btVector3 camPos = getCameraPosition();
		startTransform.setOrigin(camPos);

		setShootBoxShape ();

		btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape,3,1|2);
		body->setUserPointer((void*)-1);
		
		body->setLinearFactor(btVector3(1,1,1));
		//body->setRestitution(1);

		btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
		linVel.normalize();
		linVel*=m_ShootBoxInitialSpeed;

		body->getWorldTransform().setOrigin(camPos);
		body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
		body->setLinearVelocity(linVel);
		body->setAngularVelocity(btVector3(0,0,0));
		body->setCcdMotionThreshold(0.5);
		body->setCcdSweptSphereRadius(0.4f);//value should be smaller (embedded) than the half extends of the box (see ::setShootBoxShape)
//		printf("shootBox uid=%d\n", body->getBroadphaseHandle()->getUid());
//		printf("camPos=%f,%f,%f\n",camPos.getX(),camPos.getY(),camPos.getZ());
//		printf("destination=%f,%f,%f\n",destination.getX(),destination.getY(),destination.getZ());
		
	}
}
void PhysicRigidBody::force(float x, float y, float z, float ax, float ay, float az, float force)
{
	btVector3 linVel(x, y, z);
	linVel.normalize();
	linVel*=force;

	m_pBodies->setLinearVelocity(linVel);
	m_pBodies->setAngularVelocity(btVector3(ax, ay, az));
}
Exemplo n.º 7
0
U32 PxSingleActor::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
{
   U32 retMask = Parent::packUpdate(con, mask, stream);

   /*
   if ( stream->writeFlag( mask & ForceSleepMask ) )
      stream->writeFlag( mForceSleep );
   

   stream->writeFlag( mask & SleepMask );
   */   
   if ( stream->writeFlag( mask & WarpMask ) )
   {
      stream->writeAffineTransform( getTransform() );
   }

   if ( stream->writeFlag( mask & MoveMask ) )
   {
      stream->writeAffineTransform( getTransform() );

      if ( stream->writeFlag( mActor ) )
      {
         const NxVec3& linVel = mActor->getLinearVelocity();
         stream->write( linVel.x );
         stream->write( linVel.y );
         stream->write( linVel.z );

         const NxVec3& angVel = mActor->getAngularVelocity();
         stream->write( angVel.x );
         stream->write( angVel.y );
         stream->write( angVel.z );
      }
   }

   if ( stream->writeFlag( mask & ImpulseMask ) )
   {
         NxVec3 linVel( 0, 0, 0 );
         if ( mActor )
            linVel = mActor->getLinearVelocity();

         stream->write( linVel.x );
         stream->write( linVel.y );
         stream->write( linVel.z );
   }

   // This internally uses the mask passed to it.
   if ( mLightPlugin )
      retMask |= mLightPlugin->packUpdate( this, LightMask, con, mask, stream );

   return retMask;
}
Exemplo n.º 8
0
void	shootBox(const SimdVector3& destination)
{
	int i  = numObjects-1;



	SimdVector3 linVel(destination[0]-eye[0],destination[1]-eye[1],destination[2]-eye[2]);
	linVel.normalize();
	linVel*=bulletSpeed;

	physObjects[i]->setPosition(eye[0],eye[1],eye[2]);
	physObjects[i]->setOrientation(0,0,0,1);
	physObjects[i]->SetLinearVelocity(linVel[0],linVel[1],linVel[2],false);
	physObjects[i]->SetAngularVelocity(0,0,0,false);
}
Exemplo n.º 9
0
    Twist Axis::getRotationTwist(const double dtheta) const
    {
        Twist ret;

        Eigen::Map<Eigen::Vector3d> linVel(ret.getLinearVec3().data());
        Eigen::Map<Eigen::Vector3d> angVel(ret.getAngularVec3().data());

        Eigen::Map<const Eigen::Vector3d> dir(direction.data());
        Eigen::Map<const Eigen::Vector3d> orig(origin.data());

        linVel = dtheta*(orig.cross(dir));
        angVel = dir*dtheta;

        return ret;
    }
Exemplo n.º 10
0
void	FractureDemo::shootBox(const btVector3& destination)
{

	if (m_dynamicsWorld)
	{
		btScalar mass = 1.f;
		btTransform startTransform;
		startTransform.setIdentity();
		btVector3 camPos = getCameraPosition();
		startTransform.setOrigin(camPos);

		setShootBoxShape ();

		btAssert((!m_shootBoxShape || m_shootBoxShape->getShapeType() != INVALID_SHAPE_PROXYTYPE));

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

		btVector3 localInertia(0,0,0);
		if (isDynamic)
			m_shootBoxShape->calculateLocalInertia(mass,localInertia);

		//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects

		btFractureBody* body = new btFractureBody(mass,0,m_shootBoxShape,localInertia,&mass,1,m_dynamicsWorld);

		body->setWorldTransform(startTransform);

		m_dynamicsWorld->addRigidBody(body);


		body->setLinearFactor(btVector3(1,1,1));
		//body->setRestitution(1);

		btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
		linVel.normalize();
		linVel*=m_ShootBoxInitialSpeed;

		body->getWorldTransform().setOrigin(camPos);
		body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
		body->setLinearVelocity(linVel);
		body->setAngularVelocity(btVector3(0,0,0));
		body->setCcdMotionThreshold(1.);
		body->setCcdSweptSphereRadius(0.2f);

	}
}
Exemplo n.º 11
0
void	CcdPhysicsDemo::shootBox(const btVector3& destination)
{

	if (m_dynamicsWorld)
	{
		float mass = 1.f;
		btTransform startTransform;
		startTransform.setIdentity();
		btVector3 camPos = getCameraPosition();
		startTransform.setOrigin(camPos);

		setShootBoxShape ();


		btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);
		body->setLinearFactor(btVector3(1,1,1));
		//body->setRestitution(1);

		btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
		linVel.normalize();
		linVel*=m_ShootBoxInitialSpeed;

		body->getWorldTransform().setOrigin(camPos);
		body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
		body->setLinearVelocity(linVel);
		body->setAngularVelocity(btVector3(0,0,0));
		body->setContactProcessingThreshold(1e30);

		///when using m_ccdMode, disable regular CCD
		if (m_ccdMode==USE_CCD)
		{
			body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);
			body->setCcdSweptSphereRadius(0.4f);
		}
		
	}
}
Exemplo n.º 12
0
void BulletShooter::shootBox(BulletWorld *world, 
        const btVector3 &camPos, const btVector3 &destination)
{
    btTransform startTransform;
    startTransform.setIdentity();
    //startTransform.setOrigin(camPos);

    btRigidBody* body = world->localCreateRigidBody(1.0f, startTransform, m_shootBoxShape);

    body->setLinearFactor(btVector3(1,1,1));

    body->getWorldTransform().setOrigin(camPos);
    body->getWorldTransform().setRotation(btQuaternion(0,0,0,1));
    btVector3 linVel(
            destination[0]-camPos[0],
            destination[1]-camPos[1],
            destination[2]-camPos[2]);
    linVel.normalize();
    linVel*=m_ShootBoxInitialSpeed;
    body->setLinearVelocity(linVel);
    body->setAngularVelocity(btVector3(0,0,0));
    body->setCcdMotionThreshold(0.5);
    body->setCcdSweptSphereRadius(0.9f);
}