Browse Source

Allow arbitrary coordinate systems for RaycastVehicle.

Nicholas Farshidmehr 7 years ago
parent
commit
cb6fe9b896

+ 6 - 8
Source/Urho3D/Physics/RaycastVehicle.cpp

@@ -67,11 +67,8 @@ struct RaycastVehicleData
         return vehicle_;
     }
 
-    void Init(Scene* scene, RigidBody* body, bool enabled)
+    void Init(Scene* scene, RigidBody* body, bool enabled, const IntVector3& coordinateSystem)
     {
-        int rightIndex = 0;
-        int upIndex = 1;
-        int forwardIndex = 2;
         auto* pPhysWorld = scene->GetComponent<PhysicsWorld>();
         btDynamicsWorld* pbtDynWorld = pPhysWorld->GetWorld();
         if (!pbtDynWorld)
@@ -95,7 +92,7 @@ struct RaycastVehicleData
             added_ = true;
         }
 
-        vehicle_->setCoordinateSystem(rightIndex, upIndex, forwardIndex);
+        vehicle_->setCoordinateSystem(coordinateSystem.x_, coordinateSystem.y_, coordinateSystem.z_);
         physWorld_ = pPhysWorld;
     }
 
@@ -132,6 +129,7 @@ RaycastVehicle::RaycastVehicle(Context* context) :
     // fixed update() for inputs and post update() to sync wheels for rendering
     SetUpdateEventMask(USE_FIXEDUPDATE | USE_FIXEDPOSTUPDATE | USE_POSTUPDATE);
     vehicleData_ = new RaycastVehicleData();
+    coordinateSystem_ = IntVector3(0, 1, 2);
     wheelNodes_.Clear();
     activate_ = false;
     inAirRPM_ = 0.0f;
@@ -190,7 +188,7 @@ void RaycastVehicle::ApplyAttributes()
     int index = 0;
     hullBody_ = node_->GetOrCreateComponent<RigidBody>();
     Scene* scene = GetScene();
-    vehicleData_->Init(scene, hullBody_, IsEnabledEffective());
+    vehicleData_->Init(scene, hullBody_, IsEnabledEffective(), coordinateSystem_);
     VariantVector& value = loadedWheelData_;
     int numObjects = value[index++].GetInt();
     int wheelIndex = 0;
@@ -264,11 +262,11 @@ void RaycastVehicle::ApplyAttributes()
     URHO3D_LOGDEBUG("loaded wheels: " + String(GetNumWheels()));
 }
 
-void RaycastVehicle::Init()
+void RaycastVehicle::Init(const IntVector3& coordinateSystem)
 {
     hullBody_ = node_->GetOrCreateComponent<RigidBody>();
     Scene* scene = GetScene();
-    vehicleData_->Init(scene, hullBody_, IsEnabledEffective());
+    vehicleData_->Init(scene, hullBody_, IsEnabledEffective(), coordinateSystem);
 }
 
 void RaycastVehicle::FixedUpdate(float timeStep)

+ 3 - 1
Source/Urho3D/Physics/RaycastVehicle.h

@@ -93,7 +93,7 @@ public:
     /// Set revolution per minute value for when wheel doesn't touch ground. If set to 0 (or not set), calculated from engine force (probably not what you want).
     void SetInAirRPM(float rpm);
     /// Init the vehicle component after creation
-    void Init();
+    void Init(const IntVector3& coordinateSystem = IntVector3(0, 1, 2));
     /// Perform fixed step pre-update.
     void FixedUpdate(float timeStep) override;
     /// Perform fixed step post-update.
@@ -168,6 +168,8 @@ private:
     WeakPtr<RigidBody> hullBody_;
     /// Opaque Bullet data hidden from public
     RaycastVehicleData* vehicleData_;
+    /// Coordinate system
+    IntVector3 coordinateSystem_;
     /// Nodes of all wheels
     Vector<Node*> wheelNodes_;
     /// All wheels original rotations. These are applied in addition to wheel rotations by btRaycastVehicle