Ejemplo n.º 1
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setActivationState(unsigned _state)
{
    m_activationState = _state;
    if (m_activationState)
        NewtonWorldUnfreezeBody(dynamic_cast<PhysicsZone*>(m_pZone.get())->getZonePtr(), m_pActor);
    else
        NewtonWorldFreezeBody(dynamic_cast<PhysicsZone*>(m_pZone.get())->getZonePtr(), m_pActor);
}
Ejemplo n.º 2
0
// create a rope of boxes
void AddRope (NewtonWorld* nWorld)
{
	int i;
	dFloat mass;
	dFloat Ixx;
	dFloat Iyy;
	dFloat Izz;
	NewtonBody* link0;
	NewtonBody* link1;
	NewtonCustomJoint* joint;
	
	NewtonCollision* collision;
	RenderPrimitive* visualObject;


	dVector size (2.0f, 0.25f, 0.25f);

	// calculate a acurate momenet of inertia
	mass = 2.0f;
	Ixx = 0.7f * mass * (size.m_y * size.m_y + size.m_z * size.m_z) / 12.0f;
	Iyy = 0.7f * mass * (size.m_x * size.m_x + size.m_z * size.m_z) / 12.0f;
	Izz = 0.7f * mass * (size.m_x * size.m_x + size.m_y * size.m_y) / 12.0f;


	// create 100 tack of 10 boxes each
	//dMatrix location (GetIdentityMatrix());
	dMatrix location (dgRollMatrix(3.1426f * 0.5f));
	location.m_posit.m_y = 11.5f; 
	location.m_posit.m_z = -5.0f; 

	// create a collision primitive to be shared by all links
	collision = NewtonCreateCapsule (nWorld, size.m_y, size.m_x, NULL);
	link0 = NULL;

	// create a lon vertical rope with limits
	for (i = 0; i < 7; i ++) {
		// create the a graphic character (use a visualObject as our body
		visualObject = new CapsulePrimitive (location, size.m_y, size.m_x);

		//create the rigid body
		link1 = NewtonCreateBody (nWorld, collision);


		// add some damping to each link
		NewtonBodySetLinearDamping (link1, 0.2f);
		dVector angularDamp (0.2f, 0.2f, 0.2f);
		NewtonBodySetAngularDamping (link1, &angularDamp.m_x);

		// Set Material Id for this object
		NewtonBodySetMaterialGroupID (link1, woodID);

		// save the pointer to the graphic object with the body.
		NewtonBodySetUserData (link1, visualObject);

		// set a destrutor for this rigid body
		NewtonBodySetDestructorCallback (link1, PhysicsBodyDestructor);

		// set the tranform call back function
		NewtonBodySetTransformCallback (link1, PhysicsSetTransform);

		// set the force and torque call back funtion
		NewtonBodySetForceAndTorqueCallback (link1,PhysicsApplyGravityForce);

		// set the mass matrix
		NewtonBodySetMassMatrix (link1, mass, Ixx, Iyy, Izz);

		// set the matrix for tboth the rigid nody and the graphic body
		NewtonBodySetMatrix (link1, &location[0][0]);
		PhysicsSetTransform (link1, &location[0][0]);

		dVector pivot (location.m_posit);
		pivot.m_y += (size.m_x - size.m_y) * 0.5f;

		dFloat coneAngle = 2.0 * 3.1416f / 180.0f;
		dFloat twistAngle = 2.0 * 3.1416f / 180.0f;
		dVector pin (location.m_front.Scale (-1.0f));

		joint = new CustomConeLimitedBallAndSocket(twistAngle, coneAngle, pin, pivot, link1, link0);

		link0 = link1;
		location.m_posit.m_y -= (size.m_x - size.m_y);
	}


	// vrete a short horizontal rope with limits
	location = GetIdentityMatrix();
	location.m_posit.m_y = 2.5f; 
	location.m_posit.m_z = -7.0f; 
	link0 = NULL;
	for (i = 0; i < 3; i ++) {
		// create the a graphic character (use a visualObject as our body
		visualObject = new CapsulePrimitive (location, size.m_y, size.m_x);

		//create the rigid body
		link1 = NewtonCreateBody (nWorld, collision);

		// add some damping to each link
		NewtonBodySetLinearDamping (link1, 0.2f);
		dVector angularDamp (0.2f, 0.2f, 0.2f);
		NewtonBodySetAngularDamping (link1, &angularDamp.m_x);

		// Set Material Id for this object
		NewtonBodySetMaterialGroupID (link1, woodID);

		// save the pointer to the graphic object with the body.
		NewtonBodySetUserData (link1, visualObject);

		// make sure it is active
		NewtonWorldUnfreezeBody (nWorld, link1);
		//NewtonBodySetAutoFreeze (link1, 0);

		// set a destrutor for this rigid body
		NewtonBodySetDestructorCallback (link1, PhysicsBodyDestructor);

		// set the tranform call back function
		NewtonBodySetTransformCallback (link1, PhysicsSetTransform);

		// set the force and torque call back funtion
		NewtonBodySetForceAndTorqueCallback (link1,PhysicsApplyGravityForce);

		// set the mass matrix
		NewtonBodySetMassMatrix (link1, mass, Ixx, Iyy, Izz);

		// set the matrix for tboth the rigid nody and the graphic body
		NewtonBodySetMatrix (link1, &location[0][0]);
		PhysicsSetTransform (link1, &location[0][0]);

		dVector pivot (location.m_posit);
		pivot.m_x += (size.m_x - size.m_y) * 0.5f;

		dFloat coneAngle = 10.0 * 3.1416f / 180.0f;
		dFloat twistAngle = 10.0 * 3.1416f / 180.0f;
		dVector pin (location.m_front.Scale (-1.0f));
		joint = new CustomConeLimitedBallAndSocket(twistAngle, coneAngle, pin, pivot, link1, link0);

		link0 = link1;
		location.m_posit.m_x -= (size.m_x - size.m_y);
	}

	// release the collision geometry when not need it
	NewtonReleaseCollision (nWorld, collision);
}