Пример #1
0
void BulletDynamicsBody::AddAnchor( unsigned int index, const Integration::DynamicsBody* anchorBody, bool collisions )
{
  DEBUG_PRINTF("%s\n", __func__);
  const BulletDynamicsBody* anchorDynamicsBody( static_cast< const BulletDynamicsBody* >( anchorBody ) );

  btSoftBody* softBody( static_cast< btSoftBody* >( mBody ) );
  btRigidBody* rigidBody( static_cast< btRigidBody* >( anchorDynamicsBody->GetBody() ) );
  softBody->appendAnchor( index, rigidBody, !collisions );
}
Пример #2
0
/* Function: CallPerFrame
 * Description: All the computations are performed for the new frame to obtain the new goal position
 * Input: None
 * Output: None
 */
void CallPerFrame()
{
	pModel *temp;

	temp = phyzxModels;

	while(temp->next != NULL)
	{
		// Compute the center of mass
		CalcCM(1, temp->pObj);

		// Compute the relative positions of the model vertices  from center of mass
		//CalcRelLoc(1, temp->pObj);

		// Compute the Rotational matrix using Apq
		CalcRotMat(temp->pObj);

		if (temp->pObj->deformMode == 1)
			rigidBody(temp->pObj);  // Rigid Body Deformation
		else if (temp->pObj->deformMode == 2)
			linearDeform(temp->pObj);  // Linear Deformation

		// Compute the Goal position for the current frame
/*		if (temp->deformMode == 3)
			quadDeform(temp->pObj);  // Quadratic Deformation
		else
			CalcGoalPos(temp->pObj);*/

		// Time step using modified Euler
		/*if (boundSphereToWallCollisionDetection(temp) == 1)
			objCollide = true;
		else
			objCollide = false;*/
		ModEuler(temp->pObj, temp->mIndex, temp->pObj->deformMode);

		// Check for collision and perform the response action upon collision
		//CollisionDetectionAndResponse(temp);
		
		// Compute the center of the model with  the radius of the bounding sphere
		glmMeshGeometricParameters(temp->pObj->model, &temp->cModel.x, &temp->cModel.y, &temp->cModel.z, &temp->radius);

		// Compute the radius of the best bounding sphere around the model
		glmMeshRadius(temp->pObj->model,  temp->cModel.x, temp->cModel.y, temp->cModel.z, &temp->radius);

		SphereCollisionResponse(temp);

		temp = temp->next;
	}
}
Пример #3
0
PlayerPhysicsComponent::PlayerPhysicsComponent(GameObject &gameObject, float mass)
   : PhysicsComponent(gameObject, CollisionGroup::Characters, CollisionGroup::Everything) {
   collisionShape = UPtr<btCollisionShape>(new btCapsuleShape(PLAYER_RADIUS, PLAYER_MIDDLE_HEIGHT));

   collisionShape->setLocalScaling(toBt(gameObject.getScale()));

   motionState = UPtr<btMotionState>(new PlayerMotionState(gameObject));

   btVector3 inertia(0.0f, 0.0f, 0.0f);
   collisionShape->calculateLocalInertia(mass, inertia);
   btRigidBody::btRigidBodyConstructionInfo constructionInfo(mass, motionState.get(), collisionShape.get(), inertia);

   UPtr<btRigidBody> rigidBody(new btRigidBody(constructionInfo));
   rigidBody->setAngularFactor(0.0f); // Prevent the capsule from falling over
   rigidBody->setSleepingThresholds(0.0f, 0.0f); // Prevent the capsule from sleeping

   collisionObject = std::move(rigidBody);
}
Пример #4
0
void BulletDynamicsBody::SetKinematic( bool flag )
{
  DEBUG_PRINTF("%s( new:%d current:%d)\n", __func__, flag, mKinematic);

  if( flag != mKinematic )
  {
    mKinematic = flag;

    btRigidBody* rigidBody( static_cast< btRigidBody* >( mBody ) );

    if( flag )
    {
      rigidBody->setCollisionFlags( rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
      mBody->setActivationState(DISABLE_DEACTIVATION);
    }
    else
    {
      rigidBody->setCollisionFlags( rigidBody->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
    }
  }
}
Пример #5
0
void game::run(void)
{
  init();

  for(int i = 0; m_network->init(i==0?1:0, 8000+i); i++){}
  
  std::queue<char> inputs;
  for(int i = 0; i < 6; i++)
	inputs.push(0);
  
  
  polygon player, floor, wall1, wall2;
  std::vector<rigidBody> test;

  player.m_vertices.push_back(vec3f(-1.0f,-1.0f));
  player.m_vertices.push_back(vec3f(-1.0f, 1.0f));
  player.m_vertices.push_back(vec3f(1.0f,1.0f));
  player.m_vertices.push_back(vec3f(1.0f,-1.0f));

  floor.m_vertices.push_back(vec3f(-19.0f,-19.0f));
  floor.m_vertices.push_back(vec3f(-19.0f,-14.0f));
  floor.m_vertices.push_back(vec3f(19.0f,-14.0f));
  floor.m_vertices.push_back(vec3f(19.0f,-19.0f));

  wall1.m_vertices.push_back(vec3f(-14.0f, -19.0f));
  wall1.m_vertices.push_back(vec3f(-19.0f, -19.0f));
  wall1.m_vertices.push_back(vec3f(-19.0f, 14.0f));
  wall1.m_vertices.push_back(vec3f(-14.0f, 14.0f));

  wall2.m_vertices.push_back(vec3f(14.0f, -19.0f));
  wall2.m_vertices.push_back(vec3f(19.0f, -19.0f));
  wall2.m_vertices.push_back(vec3f(19.0f, 14.0f));
  wall2.m_vertices.push_back(vec3f(14.0f, 14.0f));


  float time = 0;
  float dt = 1.0f/30.0f;
  bool spawning = false;

  while(m_looping)
	{
	  if(m_input->update()) m_looping = false;


	  for(int i = 0; i < test.size(); i++)
	  {
		  test[i].render(m_graphics->getRenderer());
		  test[i].update(time, dt);
	  }
	  time += dt;

	  player.render(m_graphics->getRenderer());

	  if(m_input->isKeyPressed(input::e_left))
		  for(unsigned int i = 0; i < player.m_vertices.size(); i++)
			  player.m_vertices[i].i -= 0.1f;

	  if(m_input->isKeyPressed(input::e_right))
		  for(unsigned int i = 0; i < player.m_vertices.size(); i++)
			  player.m_vertices[i].i += 0.1f;

	  if(m_input->isKeyPressed(input::e_up))
		  for(unsigned int i = 0; i < player.m_vertices.size(); i++)
			  player.m_vertices[i].j += 0.1f;

	  if(m_input->isKeyPressed(input::e_down))
		  for(unsigned int i = 0; i < player.m_vertices.size(); i++)
			  player.m_vertices[i].j -= 0.1f;

	  if(m_input->isKeyPressed(input::e_respawn) && spawning == false)
	  {
		  test.push_back(rigidBody());
		  test[test.size()-1].m_vertices.push_back(vec3f(-0.75f,-0.75f));
		  test[test.size()-1].m_vertices.push_back(vec3f(-0.75f,0.75f));
		  test[test.size()-1].m_vertices.push_back(vec3f(0.75f,0.75f));
		  test[test.size()-1].m_vertices.push_back(vec3f(0.75f,-0.75f));
		  spawning = false;
	  }else if(!m_input->isKeyPressed(input::e_respawn)) spawning = false;

	  floor.render(m_graphics->getRenderer());
	  wall1.render(m_graphics->getRenderer());
	  wall2.render(m_graphics->getRenderer());
	  for(int i = 0; i < test.size(); i++)
	  {
		  test[i].collideSAT(&wall2);
		  test[i].collideSAT(&wall1);
		  test[i].collideSAT(&floor);
		  test[i].collideSAT(&player);
	  }
	  for(int i = 0; i < test.size(); i++)
	  {
		  for(int ii = 0; ii < test.size(); ii++)
		  {
			  if(i == ii) continue;
			  test[i].collideSAT(&test[ii]);
		  }
	  }
	  m_network->recievePacket();
	  m_network->update(dt);
	  m_graphics->render();
	  
	 // Sleep(30);
	}
}