Beispiel #1
0
	void PhysicsMgr::start()
	{
		createEmptyDynamicsWorld();

		///create a few basic rigid bodies
		btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.)));

		m_collisionShapes.push_back(groundShape);

		btTransform groundTransform;
		groundTransform.setIdentity();
		groundTransform.setOrigin(btVector3(0, -50, 0));
		{
			btScalar mass(0.);
			createRigidBodyInternal(mass, groundTransform, groundShape, btVector4(0, 0, 1, 1));
		}
		{
			//create a few dynamic rigidbodies
			// Re-using the same collision is better for memory usage and performance

			btBoxShape* colShape = createBoxShape(btVector3(.1, .1, .1));


			//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
			m_collisionShapes.push_back(colShape);

			/// Create Dynamic Objects
			btTransform startTransform;
			startTransform.setIdentity();

			btScalar	mass(1.f);

			//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)
				colShape->calculateLocalInertia(mass, localInertia);

			//int index = 0;
			//for (int k = 0; k < ARRAY_SIZE_Y; k++)
			//{
			//	for (int i = 0; i < ARRAY_SIZE_X; i++)
			//	{
			//		for (int j = 0; j < ARRAY_SIZE_Z; j++)
			//		{
			//			startTransform.setOrigin(btVector3(
			//				btScalar(0.2*i),
			//				btScalar(2 + .2*k),
			//				btScalar(0.2*j)));


			//			auto body = createRigidBody(mass, startTransform, colShape, btVector4(1, 0, 0, 1));
			//			body->setUserIndex(index);
			//			index++;
			//		}
			//	}
			//}
		}
	}
static void ob_j2(const CMpara* par,
		  const Gaussian* G1, const Gaussian* G2, 
		  const GaussianAux* X, complex double* j2)
{
  double* Xcm = par->Xcm;
  double* Vcm = par->Vcm;
  complex double l2, s2, ls;
  complex double beta;
  complex double rho2cm = 0.0, pi2cm = 0.0, rhopicm = 0.0;
  complex double rhoxpicm[3];
  int i;
  
  for (i=0; i<3; i++)
    rho2cm += csqr(X->rho[i]-Xcm[i]);
  for (i=0; i<3; i++)
    pi2cm += csqr(X->pi[i]-mass(G1->xi)*Vcm[i]);
  for (i=0; i<3; i++)
    rhopicm += (X->rho[i]-Xcm[i])*(X->pi[i]-mass(G1->xi)*Vcm[i]);
  for (i=0; i<3; i++)
    rhoxpicm[i] = 
      (X->rho[(i+1)%3]-Xcm[(i+1)%3])*(X->pi[(i+2)%3]-mass(G1->xi)*Vcm[(i+2)%3]) -
      (X->rho[(i+2)%3]-Xcm[(i+2)%3])*(X->pi[(i+1)%3]-mass(G1->xi)*Vcm[(i+1)%3]);

  beta = I*X->lambda*(conj(G1->a)-G2->a);

  l2 = (2*X->lambda*rho2cm + 2*X->alpha*pi2cm - 2*beta*rhopicm +
	 rho2cm* pi2cm - csqr(rhopicm))* X->Q;
  s2 = 0.75*X->Q;
  ls = 0.5*cvec3mult(rhoxpicm, X->sig)* X->T* X->R;
  
  *j2 += l2 + s2 + 2*ls;
}
static void tb_j2(const CMpara* par,
		  const Gaussian* G1, const Gaussian* G2, 
		  const Gaussian* G3, const Gaussian* G4, 
		  const GaussianAux* X13, const GaussianAux* X24, 
		  complex double* j2)
{	
  double* Xcm = par->Xcm;
  double* Vcm = par->Vcm;
  complex double l2, s2, ls;
  complex double rhoxpicm13[3], rhoxpicm24[3];
  int i;

  for (i=0; i<3; i++)
    rhoxpicm13[i] = 
      (X13->rho[(i+1)%3]-Xcm[(i+1)%3])*(X13->pi[(i+2)%3]-mass(G1->xi)*Vcm[(i+2)%3]) -
      (X13->rho[(i+2)%3]-Xcm[(i+2)%3])*(X13->pi[(i+1)%3]-mass(G1->xi)*Vcm[(i+1)%3]);
  for (i=0; i<3; i++)
    rhoxpicm24[i] = 
      (X24->rho[(i+1)%3]-Xcm[(i+1)%3])*(X24->pi[(i+2)%3]-mass(G2->xi)*Vcm[(i+2)%3]) -
      (X24->rho[(i+2)%3]-Xcm[(i+2)%3])*(X24->pi[(i+1)%3]-mass(G2->xi)*Vcm[(i+1)%3]);

  l2 = cvec3mult(rhoxpicm13, rhoxpicm24)* X13->Q* X24->Q;
  s2 = 0.25*cvec3mult(X13->sig, X24->sig)* X13->T* X24->T* X13->R* X24->R;
  ls = 0.25*(cvec3mult(rhoxpicm13, X24->sig)*X13->S+
	     cvec3mult(X13->sig, rhoxpicm24)*X24->S)*
       X13->T* X24->T* X13->R* X24->R;

  *j2 += 2*(l2 + s2 + 2*ls);
}
Beispiel #4
0
  void createBulletObject(Shape shape)
  {
    switch (shape) {
      case ConvexHull : {
        btConvexHullShape* bcs = new btConvexHullShape();
        for (size_t i=0; i<data.size(); i++) {
          glm::vec3& v = data[i].vertex;
          bcs->addPoint( glmvec3_to_btVector3(v) );
        }
        btScalar mass(ball_mass);
        btVector3 localInertia(0,0,0);
        //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
        // position and motion
        btTransform ballTransform;
        ballTransform.setIdentity();
        ballTransform.setOrigin(btVector3(0,ball_initial_height,0));
        btDefaultMotionState* bulletMotionState = new btDefaultMotionState(btTransform(ballTransform));
        // ball rigidbody info
        btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,bulletMotionState,bcs,localInertia);
        // tweak rigidbody info
        rbInfo.m_restitution = grestitution;
        rbInfo.m_friction = gfriction;
        // add ball to the world
        rigidbody = new btRigidBody(rbInfo);
        if(!rigidbody) std::cout << "bulletBallBody pointer null" << std::endl; 
        dynamicsWorld->addRigidBody(rigidbody);
        break;
      }
      case TriangleMesh : { 
        // Shape
        btBvhTriangleMeshShape* boardShape = new btBvhTriangleMeshShape( &bt_triangles, true );

        btScalar mass(board_mass);
        btVector3 localInertia(0,0,0);

        // transform : default position
        btTransform boardTransform;
        boardTransform.setIdentity();
        boardTransform.setOrigin(btVector3(0,0,0));
        btDefaultMotionState* bulletMotionState = new btDefaultMotionState(btTransform(boardTransform));
        btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,bulletMotionState,boardShape,localInertia);

        // tweak rigidbody properties
        rbInfo.m_restitution = grestitution;
        rbInfo.m_friction = gfriction;
        // add to the world
        rigidbody = new btRigidBody(rbInfo);
        if(!rigidbody) std::cout << "bulletBoardBody pointer null" << std::endl; 
        rigidbody->setActivationState(DISABLE_DEACTIVATION);
        dynamicsWorld->addRigidBody(rigidbody);
        break; 
      }
      case None : {
        break;
      }
    } // end switch
    
    

  }
Beispiel #5
0
void MultipleBoxesExample::initPhysics()
{
	m_guiHelper->setUpAxis(1);

	createEmptyDynamicsWorld();
	
	m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);

	if (m_dynamicsWorld->getDebugDrawer())
		m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);

	///create a few basic rigid bodies
	btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
	m_collisionShapes.push_back(groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,-50,0)); 
	{
		btScalar mass(0.);
		createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1));
	}


	{
		//create a few dynamic rigidbodies
		// Re-using the same collision is better for memory usage and performance
        btBoxShape* colShape = createBoxShape(btVector3(1,1,1));
		 
		m_collisionShapes.push_back(colShape);

		/// Create Dynamic Objects
		btTransform startTransform;
		startTransform.setIdentity();

		btScalar	mass(1.f);

		//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)
			colShape->calculateLocalInertia(mass,localInertia);

		
		for(int i=0;i<TOTAL_BOXES;++i) {
			startTransform.setOrigin(btVector3(
									 btScalar(0),
									 btScalar(20+i*2),
									 btScalar(0)));
			createRigidBody(mass,startTransform,colShape);		 
		}
	}

	m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
}
Beispiel #6
0
double kinetic(int i,int j,
	       double new_u[MAXSIZE][MAXSIZE], double new_w[MAXSIZE][MAXSIZE])
{
  double average_mass = 0.25 * ((mass(i,j)) + (mass(i,j+1)) + 
				(mass(i+1,j+1)) + (mass(i+1,j)));
  double v_square = new_u[i][j]*new_u[i][j] + new_w[i][j]*new_w[i][j];
  
  double kinetic = 0.5 * average_mass * v_square;
  return kinetic;
}
void gcmob_j2(const CMpara* par,
	      const Gaussian* G1, const Gaussian* G2,
	      const GaussianAux* X,
	      gradCM* dCMj2)
{
  double* Xcm = par->Xcm;
  double* Vcm = par->Vcm;
  complex double beta;
  complex double rhocm[3], picm[3];
  complex double rhocm2, picm2, rhopicm;
  complex double rhoxpicm[3];
  gradCM dl2m, drhocm2, dpicm2, drhopicm;
  gradCM dlsm;
  int i;

  beta = I*X->lambda*(conj(G1->a)-G2->a);

  for (i=0; i<3; i++)
    rhocm[i] = X->rho[i]-Xcm[i];
  rhocm2 = cvec3mult(rhocm, rhocm);
  for (i=0; i<3; i++)
    picm[i] = X->pi[i]-mass(G1->xi)*Vcm[i];
  picm2 = cvec3mult(picm, picm);
  rhopicm = cvec3mult(rhocm, picm);
  cvec3cross(rhocm, picm, rhoxpicm);

  for (i=0; i<3; i++)
    drhocm2.X[i] = -2*rhocm[i];
  for (i=0; i<3; i++)
    dpicm2.V[i] = -2*mass(G1->xi)*picm[i];
  for (i=0; i<3; i++)
    drhopicm.X[i] = -picm[i];
  for (i=0; i<3; i++)
    drhopicm.V[i] = -mass(G1->xi)*rhocm[i];

  for (i=0; i<3; i++)
    dl2m.X[i] = 2*X->lambda*drhocm2.X[i] - 2*beta*drhopicm.X[i] +
      drhocm2.X[i]*picm2 - 2*rhopicm*drhopicm.X[i];
  for (i=0; i<3; i++)
    dl2m.V[i] = 2*X->alpha*dpicm2.V[i] - 2*beta*drhopicm.V[i] +
      rhocm2*dpicm2.V[i] - 2*rhopicm*drhopicm.V[i];

  for (i=0; i<3; i++)
    dlsm.X[i] = -0.5*(picm[(i+1)%3]*X->sig[(i+2)%3] - 
		      picm[(i+2)%3]*X->sig[(i+1)%3]);
  for (i=0; i<3; i++)
    dlsm.V[i] = 0.5*mass(G1->xi)*(rhocm[(i+1)%3]*X->sig[(i+2)%3] - 
				  rhocm[(i+2)%3]*X->sig[(i+1)%3]);

  for (i=0; i<3; i++)
    dCMj2->X[i] += X->T* (dl2m.X[i]* X->S*X->R + 2*dlsm.X[i]* X->R);
  for (i=0; i<3; i++)
    dCMj2->V[i] += X->T* (dl2m.V[i]* X->S*X->R + 2*dlsm.V[i]* X->R);
} 
void NormalModeMeanSquareFluctuationCalculator::calculate_hessian_matrix(
        const Protein& protein,
        const ForceConstantSelector & kk_selector,
        const std::shared_ptr<ProteinSegment> &protein_segment) {
    LOGD << "calculating hessian matrix";
        Eigen::VectorXd ave = protein_segment->displacement_vector();

    for (size_t ires=0; ires < this->residue_count; ++ires) {
        for (size_t jres=0; jres < ires; ++jres) {
            Eigen::Vector3d dr = ave.segment<3>(3 * ires) - ave.segment<3>(3 * jres);

            double range1_2 = dr.squaredNorm();

            double kk = kk_selector.select_force_constant(
                    protein.get_secondary_structure_type_of_atom_pair(ires + 1, jres + 1),
                    ires - jres, range1_2);

            // calnmodemfs.f:72
            for (size_t ixyz = 0; ixyz < 3; ixyz++) {
                for (size_t jxyz = 0; jxyz < 3; jxyz++) {
                    size_t i = 3 * ires + ixyz;
                    size_t j = 3 * ires + jxyz;

                    this->hessian_matrix(i, j) += kk * dr(ixyz) * dr(jxyz) / range1_2;
                    i = 3 * ires + ixyz;
                    j = 3 * jres + jxyz;
                    this->hessian_matrix(i, j) -= kk * dr(ixyz) * dr(jxyz) / range1_2;
                    i = 3 * jres + ixyz;
                    j = 3 * ires + jxyz;
                    this->hessian_matrix(i, j) -= kk * dr(ixyz) * dr(jxyz) / range1_2;
                    i = 3 * jres + ixyz;
                    j = 3 * jres + jxyz;
                    this->hessian_matrix(i, j) += kk * dr(ixyz) * dr(jxyz) / range1_2;
                }
            }
        }
    }

    // mass weighted
    // calmodemsfss.f:200
    for (size_t ires = 0; ires < this->residue_count; ++ires) {
        for (size_t ixyz = 0; ixyz < 3; ++ixyz) {
            size_t i = 3 * ires+ixyz;
            for (size_t jres = 0; jres < this->residue_count; ++jres) {
                for (size_t jxyz = 0; jxyz < 3; ++jxyz) {
                    size_t j = 3 * jres + jxyz;
                    this->hessian_matrix(i,j) /= sqrt(mass(ires) * mass(jres));
                }
            }
        }
    }
}
void GravityOrb::init()
{
	name("Earth");
	position(Vector3());	// position(Vector3());
	velocity(Vector3());	// velocity(Vector3());
	mass(60.0f);			// mass(6e24);
	Vector3 temp = velocity();
	momentum(temp.scalarMult(mass()));	// momentum(Vector3());
	width(12.8f);			// width(12.8e6/100);
	kfriction(0.0f);
	sFriction(0.0f);
	r(0.0f);
	g(0.0f);
	b(1.0f);
}
Beispiel #10
0
void PhysicsWorld::addGroundPlane(const ngl::Vec3 &_pos, const ngl::Vec3 &_size)
{
	m_groundShape = new btStaticPlaneShape(btVector3(0,1,0),_pos.m_y);
//	m_collisionShapes.push_back(m_groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	{
			btScalar mass(0.);


			btVector3 localInertia(0,0,0);

			//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
			btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
			btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,m_groundShape,localInertia);

			btRigidBody* body = new btRigidBody(rbInfo);
			body->setFriction(1.);
			body->setRollingFriction(2.);
			//add the body to the dynamics world
			m_dynamicsWorld->addRigidBody(body);
			Body b;
			b.name="groundPlane";
			b.body=body;
			m_bodies.push_back(b);

		}

}
Beispiel #11
0
void BasicRobot::Register (PhysicsBullet* p)
{
    height = 0.02 * p->scalingFactor;
    radius = 0.035 * p->scalingFactor;

    //create a few dynamic rigidbodies
    // Re-using the same collision is better for memory usage and performance    
    shape = new btCylinderShapeZ(btVector3(radius, radius, height / 2.0));
    p->m_collisionShapes.push_back(shape);
    
    btScalar mass(0.1);    
    btVector3 localInertia(0.0, 0.0, 0.0);
    shape->calculateLocalInertia(mass,localInertia);    
 
    btTransform startTransform;
    startTransform.setIdentity();
		
    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
    rbInfo.m_friction = 0.05;    
    rbInfo.m_linearDamping = 0.05;
    rbInfo.m_angularDamping = 0.05;
    body = new btRigidBody(rbInfo);    
    body->setGravity(btVector3 (0, 0, -9.81  * p->scalingFactor));
    body->setUserPointer((void*)(this));
    
    p->m_dynamicsWorld->addRigidBody(body, collisionType, collisionFilter);

    AddDevices(p);
}
Beispiel #12
0
void PhysicsWorld::addSphere(std::string _shapeName,const ngl::Vec3 &_pos,ngl::Real _mass,const ngl::Vec3 &_inertia)
{
//create a dynamic rigidbody

btCollisionShape* colShape = CollisionShape::instance()->getShape(_shapeName);

/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();

btScalar	mass(_mass);


btVector3 localInertia(_inertia.m_x,_inertia.m_y,_inertia.m_z);
colShape->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(btVector3(_pos.m_x,_pos.m_y,_pos.m_z));

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
body->setFriction(1.0);
body->setRollingFriction(1.0);

m_dynamicsWorld->addRigidBody(body);
Body b;
b.name=_shapeName;
b.body=body;
m_bodies.push_back(b);

}
Beispiel #13
0
void PhysicsWorld::addCone(std::string _shapeName,const ngl::Vec3 &_pos)
{
	//create a dynamic rigidbody

	btCollisionShape* colShape = CollisionShape::instance()->getShape(_shapeName);


	/// Create Dynamic Objects
	btTransform startTransform;
	startTransform.setIdentity();

	btScalar	mass(2.f);


	btVector3 localInertia(0,0,0);
	colShape->calculateLocalInertia(mass,localInertia);
	startTransform.setOrigin(btVector3(_pos.m_x,_pos.m_y,_pos.m_z));

	//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
	btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);

	btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
	rbInfo.m_restitution = 0.2f;
	rbInfo.m_friction = 100.5f;
	rbInfo.m_additionalAngularDampingFactor=4.0;
	rbInfo.m_additionalDamping=true;
	btRigidBody* body = new btRigidBody(rbInfo);
	m_dynamicsWorld->addRigidBody(body);
	Body b;
	b.name=_shapeName;
	b.body=body;
	m_bodies.push_back(b);

}
Beispiel #14
0
int main() { 
  typedef funct::Product<funct::Parameter, funct::BreitWigner>::type FitFunction;
  typedef fit::HistoChiSquare<FitFunction> ChiSquared;
  try {
    funct::Parameter yield("Yield", 1000);
    funct::Parameter mass("Mass", 91.2);
    funct::Parameter gamma("Gamma", 2.50);
    funct::BreitWigner bw(mass, gamma);
    
    FitFunction f = yield * bw;
    TF1 startFun = root::tf1("startFun", f, 0, 200, yield, mass, gamma);
    TH1D histo("histo", "Z mass (GeV/c)", 200, 0, 200);
    histo.FillRandom("startFun", yield);
    ChiSquared chi2(f, &histo, 80, 120);
    fit::RootMinuit<ChiSquared> minuit(chi2, true);
    minuit.addParameter(yield, 100, 0, 10000);
    minuit.addParameter(mass, 2, 70, 120);
    minuit.addParameter(gamma, 1, 0, 5);
    minuit.minimize();
    minuit.migrad();
  } catch(std::exception & err){
    std::cerr << "Exception caught:\n" << err.what() << std::endl;
    return 1;
  }
  
  return 0;
}
Beispiel #15
0
void VTKWriter::initializeOutput(int numParticles) {

	vtkFile = new VTKFile_t("UnstructuredGrid");

	// per point, we add type, position, velocity and force
	PointData pointData;
	DataArray_t mass(type::Float32, "mass", 1);
	DataArray_t velocity(type::Float32, "velocity", 3);
	DataArray_t forces(type::Float32, "force", 3);
	DataArray_t type(type::Int32, "type", 1);
	pointData.DataArray().push_back(mass);
	pointData.DataArray().push_back(velocity);
    pointData.DataArray().push_back(forces);
    pointData.DataArray().push_back(type);

	CellData cellData; // we don't have cell data => leave it empty

	// 3 coordinates
	Points points;
	DataArray_t pointCoordinates(type::Float32, "points", 3);
	points.DataArray().push_back(pointCoordinates);

	Cells cells; // we don't have cells, => leave it empty
	// for some reasons, we have to add a dummy entry for paraview
	DataArray_t cells_data(type::Float32, "types", 0);
	cells.DataArray().push_back(cells_data);

	PieceUnstructuredGrid_t piece(pointData, cellData, points, cells, numParticles, 0);
	UnstructuredGrid_t unstructuredGrid(piece);
	vtkFile->UnstructuredGrid(unstructuredGrid);
}
Beispiel #16
0
Character::Character(Ogre::String _name, Ogre::SceneManager* _sceneMgr, Ogre::Real _height, std::string _objName) : GameObject(_name)
{
  height = _height;
  speed = 0.02f;
  mesh = _objName;
  obj = _objName;
  finished = false;
  deathTimer = 0;
  givenExp = false;
  level = 1;
  experience = 0;
  healthChange = 0;
  gold = 0;
  changes = 255;

  if (_sceneMgr)
    addToGraph(_sceneMgr);

  // set up Bullet properties
  btTransform* transform = new btTransform(btMatrix3x3::getIdentity());
  MotionState *motionState = new MotionState(node, *transform);

  btCollisionShape *shape = new btBoxShape(btVector3(height/2, height/2, height/2));
  //btCollisionShape *shape = GenerateShape(obj, 1.f);

  btScalar mass(1.f);
  btVector3 localInertia(0,0,0);
  btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, shape, localInertia);
  body = new btRigidBody(rbInfo);
  body->setLinearFactor(btVector3(1.f,0.f,1.f));
  body->forceActivationState(DISABLE_DEACTIVATION);
  body->setRestitution(1.f);
  body->setFriction(0.f);
  body->setUserPointer((void *)this);
}
Beispiel #17
0
void	BasicDemo::createGround(int cubeShapeId)
{
	{
		float color[]={0.3,0.3,1,1};
		float halfExtents[]={50,50,50,1};
		btTransform groundTransform;
		groundTransform.setIdentity();
		groundTransform.setOrigin(btVector3(0,-50,0));
		m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),color,halfExtents);
		btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(halfExtents[0]),btScalar(halfExtents[1]),btScalar(halfExtents[2])));
		//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
		{
			btScalar mass(0.);
			//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)
				groundShape->calculateLocalInertia(mass,localInertia);
			//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
			btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
			btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
			btRigidBody* body = new btRigidBody(rbInfo);
			//add the body to the dynamics world
			m_dynamicsWorld->addRigidBody(body);
		}
	}
}
Beispiel #18
0
void   XC::Twenty_Node_Brick::formInertiaTerms( int tangFlag ) const
{
        static double xsj ;  // determinant jacaobian matrix
        int i, j, k, m;
        double Nrho;

        //zero mass
        mass.Zero( ) ;

        //compute basis vectors and local nodal coordinates
        computeBasis( ) ;
        //gauss loop to compute and save shape functions
        for( i = 0; i < nintu; i++ ) {
                // compute Jacobian and global shape functions
                Jacobian3d(i, xsj, 0);
                //volume element to also be saved
                dvolu[i] = wu[i] * xsj ;
        } // end for i

        // Compute consistent mass matrix
        for(i = 0; i < nenu; i++) {
                for(j = 0; j < nenu; j++) {
                        for(m = 0; m < nintu; m++) {
                                Nrho = dvolu[m]*mixtureRho(m)*shgu[3][i][m]*shgu[3][j][m];
                                for( k = 0; k < 3; k++) {
                                        mass(i*3+k,j*3+k) += Nrho;
                                }
                        }
                }
        }

}
btRigidBody* CarHandlingDemo::createChassisRigidBodyFromShape(btCollisionShape* chassisShape)
{
    //Visualisation for the rigid body
    irr::scene::ISceneNode *node = smgr->addCubeSceneNode(1.0f);
    node->setMaterialFlag(irr::video::EMF_LIGHTING, 1);
    node->setMaterialTexture(0, driver->getTexture("assets/cube.png"));


    btTransform chassisTransform;
    chassisTransform.setIdentity();
    chassisTransform.setOrigin(btVector3(0, 1, 0));

    {
	//chassis mass 
	btScalar mass(1200);

	//since it is dynamic, we calculate its local inertia
	btVector3 localInertia(0, 0, 0);
	chassisShape->calculateLocalInertia(mass, localInertia);

	//using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects
	btDefaultMotionState* groundMotionState = new btDefaultMotionState(chassisTransform);
	btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, groundMotionState, chassisShape, localInertia);

    // Store a pointer to the irrlicht node so we can update it later
    btRigidBody *rigidBody =  new btRigidBody(rbInfo);

    rigidBody->setUserPointer((void *)(node));
    worldObjs.push_back(rigidBody);


	return rigidBody;
    }
}
Beispiel #20
0
void Entity::InitializePhysics() {
	btTransform transform(btQuaternion(0, 0, 0, 1), btVector3(mPosition.x, mPosition.y, 0));
	transform.setIdentity();
	//btTransform transform;
	transform.setIdentity();
	btScalar mass(1.f);
	btVector3 local_inertia(0, 0, 0);

	if(mUID.substr(0,5) == "empty") {
		mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(15*mScale, 1*mScale, 1)));
	} else if(mImageFile == "evil1") {
		mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(0.5*mScale, 0.22*mScale, 1)));
	} else if(mImageFile == "evil2") {
		mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(0.5*mScale, 0.05*mScale, 1)));
	} else {
		mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(1.2*mScale, 1.2*mScale, 1)));
	}

	mCollisionShape->calculateLocalInertia(mass, local_inertia);
	transform.setOrigin(btVector3(mPosition.x, mPosition.y, 0));
	transform.setRotation(btQuaternion(0, 0, PI - mRotation));

	mMotionState = boost::shared_ptr<btDefaultMotionState>(new btDefaultMotionState(transform));
	btRigidBody::btRigidBodyConstructionInfo rb_info(mass, mMotionState.get(), mCollisionShape.get(), local_inertia);
	mBody = boost::shared_ptr<btRigidBody>(new btRigidBody(rb_info));
	mBody->setDamping(0.2f, 0.2f);
	//mBody->setActivationState(DISABLE_DEACTIVATION);
	mBody->setLinearFactor(btVector3(1,1,0));
	mBody->setAngularFactor(btVector3(0,0,1));
	//mBody->setAngularFactor(btVector3(0,0,1));
	mBody->setUserPointer(this);
}
	void EigenSolver::getEigenValVectors(int dofs, const SparseMatrix &M, const SparseMatrix &K, Scalar *EigValues, Scalar *EigVectors) const{
		ARluSymMatrix<Scalar> mass(M.numColumns, M.pcol[M.numColumns], M.value, M.rows, M.pcol);
		ARluSymMatrix<Scalar> stiffness(K.numColumns, K.pcol[K.numColumns], K.value, K.rows, K.pcol);
		ARluSymGenEig<Scalar> slover(dofs, stiffness, mass);
		slover.SetShiftInvertMode(0.0);
		slover.EigenValVectors(EigVectors, EigValues);
	}
Vector2D SphSystemData2::gradientAt(
    size_t i,
    const ConstArrayAccessor1<double>& values) const {
    Vector2D sum;
    auto p = positions();
    auto d = densities();
    const auto& neighbors = neighborLists()[i];
    Vector2D origin = p[i];
    SphSpikyKernel2 kernel(_kernelRadius);
    const double m = mass();

    for (size_t j : neighbors) {
        Vector2D neighborPosition = p[j];
        double dist = origin.distanceTo(neighborPosition);
        if (dist > 0.0) {
            Vector2D dir = (neighborPosition - origin) / dist;
            sum
                += d[i] * m
                * (values[i] / square(d[i]) + values[j] / square(d[j]))
                * kernel.gradient(dist, dir);
        }
    }

    return sum;
}
btRigidBody *PhysicsWorld::addSphere(const ngl::Vec3 &_pos, float _radius, ngl::Real _mass)
{
    //create a dynamic rigidbody

    //btCollisionShape* colShape = CollisionShape::instance()->getShape(_shapeName);
    btCollisionShape* colShape = new btSphereShape(btScalar(_radius));

    /// Create Dynamic Objects
    btTransform startTransform;
    startTransform.setIdentity();

    btScalar	mass(_mass);

    startTransform.setOrigin(btVector3(_pos.m_x,_pos.m_y,_pos.m_z));
    btVector3 localInertia(0.0f,0.0f,0.0f);
    colShape->calculateLocalInertia(mass,localInertia);

    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
    rbInfo.m_restitution = 0.5f;
    rbInfo.m_friction = 0.1f;
    rbInfo.m_rollingFriction=0.1f;
    rbInfo.m_additionalAngularDampingFactor=0.1;
    rbInfo.m_additionalDamping=true;

    btRigidBody* body = new btRigidBody(rbInfo);
    //body->applyCentralImpulse(btVector3(_dir.m_x, _dir.m_y, _dir.m_z));
    body->setLinearVelocity(btVector3(0.0f,0.0f,0.0f));
    m_dynamicsWorld->addRigidBody(body);

    return body;
}
Beispiel #24
0
BoxChunk::BoxChunk(Ogre::SceneManager* _sceneMgr, Character* _character) : GameObject(nextName)
{
  height = _character->getHeight()*0.2f;
  speed = _character->getHeight()*0.03f; // ((float)(rand() % 5))/10.f; 
  direction = Ogre::Vector3(rand() % 3 - 1, 2.f, rand() % 3 -1);
  direction.normalise();

  if (_sceneMgr) {
    sceneMgr = _sceneMgr;
    addToGraph(sceneMgr);
    //node->translate(Ogre::Vector3(0, height/2.f, 0));
  }

  // set up Bullet properties
  btTransform* transform = new btTransform(btMatrix3x3::getIdentity());
  MotionState *motionState = new MotionState(node, *transform);

  btCollisionShape *shape = new btBoxShape(btVector3(height/2, height/2, height/2));

  btScalar mass(1.f);
  btVector3 localInertia(0,0,0);
  btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, shape, localInertia);
  body = new btRigidBody(rbInfo);
  body->setLinearFactor(btVector3(1.f,0.f,1.f));
  body->forceActivationState(DISABLE_DEACTIVATION);
  body->setRestitution(1.f);
  body->setFriction(0.f);
  body->setUserPointer((void *)this);
  body->translate(btVector3(0, height/2.f, 0));

  translate(_character->getPosition());
  std::stringstream ss;
  ss << "bc" << nextNum++;
  nextName = ss.str();
}
btRigidBody *PhysicsWorld::addBox(const ngl::Vec3 &_pos, float _width, float _height, float _depth, ngl::Real _mass)
{

    //btCollisionShape* colShape = CollisionShape::instance()->getShape(_shapeName);
    btCollisionShape* colShape = new btBoxShape(btVector3(_width/2.0,_height/2.0,_depth/2.0));

    /// Create Dynamic Objects
    btTransform startTransform;
    startTransform.setIdentity();

    btScalar	mass(1.0f);


    btVector3 localInertia(0,0,0);
    colShape->calculateLocalInertia(mass,localInertia);
    startTransform.setOrigin(btVector3(_pos.m_x,_pos.m_y,_pos.m_z));
    //startTransform.setRotation(btQuaternion(btVector3(_axis.m_x,_axis.m_y,_axis.m_z),ngl::radians(_angle)));
    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);

    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
    rbInfo.m_restitution = 0.5f;
    rbInfo.m_friction = 0.1f;
    rbInfo.m_rollingFriction=0.1f;
    rbInfo.m_additionalAngularDampingFactor=0.1;
    rbInfo.m_additionalDamping=true;

    btRigidBody* body = new btRigidBody(rbInfo);

    body->setActivationState(DISABLE_DEACTIVATION);
    m_dynamicsWorld->addRigidBody(body);

    return body;
}
Beispiel #26
0
void BulletCHOP::addPlane(btVector3 pos, btVector3 rot){

	btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
	//btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),0);
	
	collisionShapes.push_back(groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	//groundTransform.setOrigin(pos);
	groundTransform.setOrigin(btVector3(0,-50,0));


	btScalar mass(0.);

	//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)
		groundShape->calculateLocalInertia(mass,localInertia);

	//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
	btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
	btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
	btRigidBody* body = new btRigidBody(rbInfo);

	//add the body to the dynamics world
	dynamicsWorld->addRigidBody(body);
	

}
Beispiel #27
0
void XC::Twenty_Node_Brick::formDampingTerms( int tangFlag ) const
  {
    //static double xsj ;  // determinant jacaobian matrix
        int i, j;
        //double volume = 0.;
        //zero damp
        damp.Zero( ) ;

        if(rayFactors.getBetaK() != 0.0)
          damp.addMatrix(1.0, this->getTangentStiff(), rayFactors.getBetaK());
        if(rayFactors.getBetaK0() != 0.0)
          damp.addMatrix(1.0, this->getInitialStiff(), rayFactors.getBetaK0());
        if(rayFactors.getBetaKc() != 0.0)
          damp.addMatrix(1.0, Kc, rayFactors.getBetaKc());

        if(rayFactors.getAlphaM() != 0.0)
          {
            this->getMass();
            for( i = 0; i < 60; i++)
              for( j = 0; j < 60; j++)
                damp(i,j) += mass(i,j) * rayFactors.getAlphaM();
          }

        return; /////////

}
Beispiel #28
0
void shatter(Breakable* b)
{
	world->removeRigidBody(b->rigidBody);
	for(int z=-3; z<+3; z++)
	for(int y=-1; y<+1; y++)
	for(int x=-2; x<+2; x++)
	{
		btCollisionShape* colShape = new btBoxShape(btVector3(.5f,.5f,.5f));
		btTransform startTransform;
		startTransform.setIdentity();
		btScalar mass(1.f);
		btVector3 localInertia(0,0,0);
		colShape->calculateLocalInertia(mass, localInertia);
		startTransform.setOrigin(btVector3(x+.5f, y+.5f, z+.5f));
		startTransform = b->rigidBody->getWorldTransform() * startTransform;
		btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);
		
		//Vector avgVel = (b->velocity + cast(b->rigidBody->getLinearVelocity())) / 2;
		
		body->setLinearVelocity(cast(b->velocity));//It is important to set velocity before impact
		//body->setLinearVelocity(cast(avgVel));
		body->setUserPointer(b->rigidBody->getUserPointer());
		world->addRigidBody(body);
	}
	b->rigidBody = NULL;
}
Beispiel #29
0
void Graph::sg_CCC()
{
  if(dbg) Rprintf("Class Cover Catch: ");

  double m=MAX_DOUBLE, mm = -MAX_DOUBLE;
  std::vector<double> mass(pp->size());
  int i,j;
  int type0=1; // target type set to 1. Re-arrange in R to change.

  for(i=0; i<pp->size();i++)
  {
    mass.at(i)=mm;
    if(par[i]==type0)
    {
      mass.at(i) = m;
      for(j=0;j<pp->size();j++)
        if( (j!=i) & (par[j]!=type0) )
        {
          mass.at(i) = fmin(mass.at(i), pp->getDist(&i, &j));
        }
    }
  }
  for(i=0;i<pp->size();i++) //TODO: optimize this
    if(par[i]==type0)
      for(j=0;j<pp->size();j++)
        if(i!=j)
          if(par[j]==type0)
            if(pp->getDist(&i, &j)< mass.at(i))
              addNew(i,j+1);

  if(dbg) Rprintf(" Ok.");
}
Beispiel #30
0
// Estimate position of baseline.
// The baseline position is measured in quarter pixels.
// Using fractional pixels makes a big improvement.
static int
compute_baseline(GBitmap *bits)
{
   int h = bits->rows();
   int w = bits->columns();
   GTArray<int> mass(h);
   int i, j, m;
   int tm = 0;
   for (i=0; i<h; i++)
     {
       unsigned char *row = (*bits)[i];
       for (j=0; j<w; j++)
         if (row[j])
           break;
       for (m = w-j; m>0; m--)
         if (row[j+m-1])
           break;
       mass[i] = m;
       tm += m;
     }
   m = 0;
   i = 0;
   while (m * 6 < tm * 4)
     {
       m += mass[i/4];
       i += 1;
     }
   return i;
}