void PhysXShape::setLocalOrintation(const math::quaternion&v)
{
	NxMat33 nm;
	NxQuat q;
	q.setWXYZ(v.w,v.x,v.y,v.z);
	nm.fromQuat(q);
	m_nxShape->setLocalOrientation(nm);
}
Beispiel #2
0
void Vehicle::resetCarPos()
{

	NxVec3 vec3(mOriginalPos.x, mOriginalPos.y, mOriginalPos.z);
	NxQuat quat;
	quat.setWXYZ(mOriginalQuat.w, mOriginalQuat.x, mOriginalQuat.y, mOriginalQuat.z);

	mActor->setGlobalPose(NxMat34(quat, vec3));

	vec3.zero();
	mActor->setLinearVelocity(vec3);
	mActor->setAngularVelocity(vec3);

}
Beispiel #3
0
void Vehicle::loadScene(const std::string &fileName)
{

	//车的父节点
	mBaseCarNode			= mSceneMgr->getRootSceneNode()->createChildSceneNode(fileName + "BaseCarNode");

	//DotSceneLoader* dsl = new DotSceneLoader();//rel
	//dsl->parseDotScene(fileName + ".scene", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mSceneMgr, mBaseCarNode);

	mVehicleRenderable = new VehicleRenderable(mSceneMgr, mBaseCarNode);
	mVehicleRenderable->load(fileName + ".vrf");

	//车身节点
	mBodyNode				= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "Body"));

	//轮子节点
	mWheels[TOP_LEFT].mSceneNode	= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "LTWheel"));
	mWheels[TOP_LEFT].mName			= fileName + "LTWheel";

	mWheels[TOP_RIGHT].mSceneNode	= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "RTWheel"));
	mWheels[TOP_RIGHT].mName		= fileName + "RTWheel";

	mWheels[Bottom_LEFT].mSceneNode	= static_cast<Ogre::SceneNode*>(mBaseCarNode->getChild(fileName + "LBWheel"));
	mWheels[Bottom_LEFT].mName		= fileName + "LBWheel";

	mWheels[Bottom_RIGHT].mSceneNode  = static_cast<Ogre::SceneNode*> (mBaseCarNode->getChild(fileName + "RBWheel"));
	mWheels[Bottom_RIGHT].mName		  = fileName + "RBWheel";

	//设置整体参数
	NxBodyDesc bodyDes;
	//bodyDes.wakeUpCounter	= 1E8;
	bodyDes.mass			= 12000;//mVehicleInfo.gMass;
	//bodyDes.massLocalPose.t	= NxVec3(mVehicleInfo.gMassLocalPose.x, mVehicleInfo.gMassLocalPose.y, mVehicleInfo.gMassLocalPose.z);

	bodyDes.angularDamping	= 0.03f;
	bodyDes.linearDamping	= 0.08f;

	//写入车身的shapeDesc
	mBoundingBox		= mBodyNode->getAttachedObject(0)->getBoundingBox();
	NxBoxShapeDesc boxDes;
	NxVec3 dimen		(mBoundingBox.getHalfSize().x, mBoundingBox.getHalfSize().y, mBoundingBox.getHalfSize().z);
	NxVec3 localPos		(mBodyNode->getPosition().x, mBodyNode->getPosition().y, mBodyNode->getPosition().z);

	////车身到轮子的距离
	//NxReal d1 = NxMath::abs(mBodyNode->getPosition().y - mWheels[0].mSceneNode->getPosition().y);
	////包围盒半径之和
	//NxReal d2 = mBoundingBox.getHalfSize().y + mWheels[0].mSceneNode->getAttachedObject(0)->getBoundingBox().getHalfSize().y;
	////判断轮子是否与车身的包围盒重叠
	//if(d1 < d2)
	//{
	//	//设置为最大适合高度
	//	dimen.y = (mBoundingBox.getSize().y - (d2 - d1)) / 2.0f;
	//}
	boxDes.dimensions.set(dimen);
	boxDes.localPose.t	= localPos;

	NxActorDesc actorDesc;
	actorDesc.body			= &bodyDes;
	actorDesc.globalPose.t	= NxVec3(mOriginalPos.x, mOriginalPos.y, mOriginalPos.z);
	NxQuat quat;
	quat.setWXYZ(mOriginalQuat.w, mOriginalQuat.x, mOriginalQuat.y, mOriginalQuat.z);
	actorDesc.globalPose.M.fromQuat(quat);
	actorDesc.shapes.pushBack(&boxDes);
	mActor		= mNxScene->createActor(actorDesc);
	mActor->setCMassOffsetLocalPosition(NxVec3(0, -mBoundingBox.getSize().y, 0));
	mBodyShape  = static_cast<NxBoxShape*>(mActor->getShapes()[0]);

	//写入轮子的shapeDesc

	createWheelShapeDesc(&mWheels[TOP_LEFT], true);
	createWheelShapeDesc(&mWheels[TOP_RIGHT], true);
	createWheelShapeDesc(&mWheels[Bottom_LEFT], false);
	createWheelShapeDesc(&mWheels[Bottom_RIGHT], false);

	//mWheels[TOP_LEFT].mWheelDesc.localPose.t = NxVec3(mBoundingBox.getHalfSize().x, 2, 0);
	//mWheels[TOP_RIGHT].mWheelDesc.localPose.t = NxVec3(-mBoundingBox.getHalfSize().x, 2, 0);
	//mWheels[Bottom_LEFT].mWheelDesc.localPose.t = NxVec3(mBoundingBox.getHalfSize().x, -mBoundingBox.getHalfSize().y, 0);
	//mWheels[Bottom_RIGHT].mWheelDesc.localPose.t = NxVec3(-mBoundingBox.getHalfSize().x, -mBoundingBox.getHalfSize().y, 0);

	//创建轮子
	mWheels[TOP_LEFT].mWheel = static_cast<NxWheelShape*>(mActor->createShape(mWheels[TOP_LEFT].mWheelDesc));
	mWheels[TOP_RIGHT].mWheel = static_cast<NxWheelShape*>(mActor->createShape(mWheels[TOP_RIGHT].mWheelDesc));
	mWheels[Bottom_LEFT].mWheel	= static_cast<NxWheelShape*>(mActor->createShape(mWheels[Bottom_LEFT].mWheelDesc));
	mWheels[Bottom_RIGHT].mWheel = static_cast<NxWheelShape*>(mActor->createShape(mWheels[Bottom_RIGHT].mWheelDesc));

	NxMaterial* mat = mNxScene->getMaterialFromIndex(0);
	mat->setFrictionCombineMode(NX_CM_MULTIPLY);
	mat->setStaticFriction(300.2f);
	mat->setDynamicFriction(100.5f);
}