当前位置 : 主页 > 网络编程 > 其它编程 >

PhysX两轮载具简单实现

来源:互联网 收集:自由互联 发布时间:2023-07-02
文章目录PxVehicleNoDrive1.修改轮子个数2.修改报错3.控制台提示参数不对PVD效果想实现一个摩托车的物理载具所以先在Snippet里面改了一下Px 文章目录 PxVehicleNoDrive 1.修改轮子个数 2.修改报错
文章目录PxVehicleNoDrive1.修改轮子个数2.修改报错3.控制台提示参数不对PVD效果想实现一个摩托车的物理载具所以先在Snippet里面改了一下Px

文章目录

  • PxVehicleNoDrive
    • 1.修改轮子个数
    • 2.修改报错
    • 3.控制台提示参数不对
  • PVD效果
想实现一个摩托车的物理载具所以先在Snippet里面改了一下

PxVehicleNoDrive

看到UE4中是用PxVehicleNoDrive实现的就想在SnippetVehicleNoDrive快速改一下看下效果结果改了几行代码就基本看到效果了

1.修改轮子个数

VehicleDesc initVehicleDesc(){// 省略...// two wheelsconst PxU32 nbWheels 2;

2.修改报错

主要是默认是四个轮子的然后默认代码传多了删掉即可

void startBrakeMode(){gVehicleNoDrive->setBrakeTorque(0, 1000.0f);gVehicleNoDrive->setBrakeTorque(1, 1000.0f);//gVehicleNoDrive->setBrakeTorque(2, 1000.0f);//gVehicleNoDrive->setBrakeTorque(3, 1000.0f);}void startHandbrakeTurnLeftMode(){//gVehicleNoDrive->setBrakeTorque(2, 1000.0f);//gVehicleNoDrive->setBrakeTorque(3, 1000.0f);gVehicleNoDrive->setDriveTorque(0, 1000.0f);gVehicleNoDrive->setDriveTorque(1, 1000.0f);gVehicleNoDrive->setSteerAngle(0, 1.0f); gVehicleNoDrive->setSteerAngle(1, 1.0f); }void startHandbrakeTurnRightMode(){//gVehicleNoDrive->setBrakeTorque(2, 1000.0f);//gVehicleNoDrive->setBrakeTorque(3, 1000.0f);gVehicleNoDrive->setDriveTorque(0, 1000.0f);gVehicleNoDrive->setDriveTorque(1, 1000.0f);gVehicleNoDrive->setSteerAngle(0, -1.0f); gVehicleNoDrive->setSteerAngle(1, -1.0f); }void releaseAllControls(){gVehicleNoDrive->setDriveTorque(0, 0.0f);gVehicleNoDrive->setDriveTorque(1, 0.0f);//gVehicleNoDrive->setDriveTorque(2, 0.0f);//gVehicleNoDrive->setDriveTorque(3, 0.0f);gVehicleNoDrive->setBrakeTorque(0, 0.0f);gVehicleNoDrive->setBrakeTorque(1, 0.0f);//gVehicleNoDrive->setBrakeTorque(2, 0.0f);//gVehicleNoDrive->setBrakeTorque(3, 0.0f);gVehicleNoDrive->setSteerAngle(0, 0.0f);gVehicleNoDrive->setSteerAngle(1, 0.0f);//gVehicleNoDrive->setSteerAngle(2, 0.0f);//gVehicleNoDrive->setSteerAngle(3, 0.0f);}

3.控制台提示参数不对

..\..\PhysXVehicle\src\PxVehicleUpdate.cpp (244) : invalid parameter : PxVehicleComputeSprungMasses: sprungMassCoordinates must all be valid coordinates

断点看一下就知道问题在哪里了主要是计算便宜的时候坐标是无穷大修改下下面的代码即可

void computeWheelCenterActorOffsets(const PxF32 wheelFrontZ, const PxF32 wheelRearZ, const PxVec3 (wheelFrontZ - wheelRearZ) / (numLeftWheels - 1.0f);PX_UNUSED(numWheels);PX_UNUSED(wheelWidth);//front wheel offset from origin.wheelCentreOffsets[0] PxVec3(0.f, -(chassisDims.y / 2 wheelRadius), wheelRearZ);//rear wheel offsets from origin.wheelCentreOffsets[1] PxVec3(0.f, -(chassisDims.y / 2 wheelRadius), wheelFrontZ);}

PVD效果

two wheels

上一篇:mysql中CASE的用法
下一篇:没有了
网友评论