Beispiel #1
0
NxActor* CreateCar(const NxVec3& pos)
{
	// Create body
	NxBodyDesc bodyDesc;
	NxBoxShapeDesc boxDesc;
	NxCapsuleShapeDesc capsuleDesc[4];
	NxActorDesc actorDesc;

	bodyDesc.mass = carMass;

	const NxReal height = 0.3;
	const NxReal width = 2;
	const NxReal length = 4;

	boxDesc.dimensions.set(length*0.65, height*0.85, width*0.65);
	actorDesc.shapes.pushBack(&boxDesc);

	capsuleDesc[0].radius = 0.1;
	capsuleDesc[0].height = 1;
	capsuleDesc[0].flags = NX_SWEPT_SHAPE;
	capsuleDesc[0].localPose.M.setColumn(1, NxVec3(0,-1, 0));
	capsuleDesc[0].localPose.M.setColumn(2, NxVec3(0, 0,-1));	//rotate 180 degrees around x axis to cast downward!
	capsuleDesc[0].localPose.t.set(length*0.5, -height, width*0.5);
	capsuleDesc[0].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[0].userData = &(wheelUserDatas[0]);
	actorDesc.shapes.pushBack(&capsuleDesc[0]);
	wheelUserDatas[0].frontWheel = true;

	capsuleDesc[1].radius = capsuleDesc[0].radius;
	capsuleDesc[1].height = capsuleDesc[0].height;
	capsuleDesc[1].flags = capsuleDesc[0].flags;
	capsuleDesc[1].localPose.M = capsuleDesc[0].localPose.M;	
	capsuleDesc[1].localPose.t.set(length*0.5, -height, -width*0.5);
	capsuleDesc[1].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[1].userData = &(wheelUserDatas[1]);
	actorDesc.shapes.pushBack(&capsuleDesc[1]);
	wheelUserDatas[1].frontWheel = true;

	capsuleDesc[2].radius = capsuleDesc[0].radius;
	capsuleDesc[2].height = capsuleDesc[0].height;
	capsuleDesc[2].flags = capsuleDesc[0].flags;
	capsuleDesc[2].localPose.M = capsuleDesc[0].localPose.M;
	capsuleDesc[2].localPose.t.set(-length*0.5, -height, -width*0.5);
	capsuleDesc[2].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[2].userData = &(wheelUserDatas[2]);
	actorDesc.shapes.pushBack(&capsuleDesc[2]);
	wheelUserDatas[2].frontWheel = false;

	capsuleDesc[3].radius = capsuleDesc[0].radius;
	capsuleDesc[3].height = capsuleDesc[0].height;
	capsuleDesc[3].flags = capsuleDesc[0].flags;
	capsuleDesc[3].localPose.M = capsuleDesc[0].localPose.M;
	capsuleDesc[3].localPose.t.set(-length*0.5, -height, width*0.5);
	capsuleDesc[3].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[3].userData = &(wheelUserDatas[3]);
	actorDesc.shapes.pushBack(&capsuleDesc[3]);
	wheelUserDatas[3].frontWheel = false;

	actorDesc.body			= &bodyDesc;
	actorDesc.globalPose.t  = pos;
	NxActor* a = gScene->createActor(actorDesc);

	//a->userData = &carData;		//so we can recoginze it in the contact stream

	sPhysObject* pPhys = new sPhysObject;
	pPhys->iID = 5;
	a->userData = (void*)pPhys;

	a->wakeUp(1e10);			//don't go to sleep.

	return a;
}
Beispiel #2
0
NxActor* CreateCar(const NxVec3& pos)
{
	// Create body
	NxBodyDesc bodyDesc;
	NxBoxShapeDesc boxDesc;
	NxCapsuleShapeDesc capsuleDesc[4];
	NxActorDesc actorDesc;

	bodyDesc.mass = carMass;

	const NxReal height = 0.3;
	const NxReal width = 2;
	const NxReal length = 4;

	//boxDesc.dimensions.set(length*0.65, height*0.85, width*0.65);
	//actorDesc.shapes.pushBack(&boxDesc);

	{
		sObject* pObject = dbGetObject ( 5 );
	
		float fXPos	 = pObject->position.vecPosition.x;
		float fYPos	 = pObject->position.vecPosition.y;
		float fZPos	 = pObject->position.vecPosition.z;
		float fXSize = ( pObject->collision.vecMax.x - pObject->collision.vecMin.x ) * pObject->position.vecScale.x;
		float fYSize = ( pObject->collision.vecMax.y - pObject->collision.vecMin.y ) * pObject->position.vecScale.y;
		float fZSize = ( pObject->collision.vecMax.z - pObject->collision.vecMin.z ) * pObject->position.vecScale.z;

		boxDesc.dimensions.set ( fXSize / 2, fYSize / 2, fZSize / 2 );
		boxDesc.localPose.t = NxVec3 ( pObject->collision.vecCentre.x, pObject->collision.vecCentre.y, pObject->collision.vecCentre.z  );
		//boxDesc.localPose.
		actorDesc.shapes.pushBack ( &boxDesc );
	}

	capsuleDesc[0].radius = 0.1;
	capsuleDesc[0].height = 1;
	capsuleDesc[0].flags = NX_SWEPT_SHAPE;
	capsuleDesc[0].localPose.M.setColumn(1, NxVec3(0,-1, 0));
	capsuleDesc[0].localPose.M.setColumn(2, NxVec3(0, 0,-1));	//rotate 180 degrees around x axis to cast downward!
	capsuleDesc[0].localPose.t.set(length*0.5, -height, width*0.5);
	capsuleDesc[0].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[0].userData = &(wheelUserDatas[0]);
	actorDesc.shapes.pushBack(&capsuleDesc[0]);
	wheelUserDatas[0].frontWheel = true;

	capsuleDesc[1].radius = capsuleDesc[0].radius;
	capsuleDesc[1].height = capsuleDesc[0].height;
	capsuleDesc[1].flags = capsuleDesc[0].flags;
	capsuleDesc[1].localPose.M = capsuleDesc[0].localPose.M;	
	capsuleDesc[1].localPose.t.set(length*0.5, -height, -width*0.5);
	capsuleDesc[1].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[1].userData = &(wheelUserDatas[1]);
	actorDesc.shapes.pushBack(&capsuleDesc[1]);
	wheelUserDatas[1].frontWheel = true;

	capsuleDesc[2].radius = capsuleDesc[0].radius;
	capsuleDesc[2].height = capsuleDesc[0].height;
	capsuleDesc[2].flags = capsuleDesc[0].flags;
	capsuleDesc[2].localPose.M = capsuleDesc[0].localPose.M;
	capsuleDesc[2].localPose.t.set(-length*0.5, -height, -width*0.5);
	capsuleDesc[2].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[2].userData = &(wheelUserDatas[2]);
	actorDesc.shapes.pushBack(&capsuleDesc[2]);
	wheelUserDatas[2].frontWheel = false;

	capsuleDesc[3].radius = capsuleDesc[0].radius;
	capsuleDesc[3].height = capsuleDesc[0].height;
	capsuleDesc[3].flags = capsuleDesc[0].flags;
	capsuleDesc[3].localPose.M = capsuleDesc[0].localPose.M;
	capsuleDesc[3].localPose.t.set(-length*0.5, -height, width*0.5);
	capsuleDesc[3].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[3].userData = &(wheelUserDatas[3]);
	actorDesc.shapes.pushBack(&capsuleDesc[3]);
	wheelUserDatas[3].frontWheel = false;

	actorDesc.body			= &bodyDesc;
	actorDesc.globalPose.t  = pos;
	NxActor* a = gScene->createActor(actorDesc);

	//a->userData = &carData;		//so we can recoginze it in the contact stream

sPhysObject* pPhys = new sPhysObject;
pPhys->iID = 5;
a->userData = (void*)pPhys;

	//actorDesc.globalPose.t = NxVec3 ( fXPos, fYPos, fZPos );
NxMat33 mat;
mat.rotY ( D3DXToRadian ( 90 ) );
a->setGlobalOrientation ( mat );

	a->wakeUp(1e10);			//don't go to sleep.

	return a;
}