Explorar el Código

Racing sample:
- Updated car model.
- Tweaked car physics.
- Updated fly through camera.

GamePlay:
- Changed PhysicsVehicleWheel to ignore bullet wheel transform and instead use car body transform offset. This is a temporary change until we fix some transform related issues in PhysicsVehicleWheel.

Steve Grenier hace 13 años
padre
commit
e388bba2d5
Se han modificado 2 ficheros con 10 adiciones y 1 borrados
  1. 9 1
      gameplay/src/PhysicsVehicleWheel.cpp
  2. 1 0
      gameplay/src/PhysicsVehicleWheel.h

+ 9 - 1
gameplay/src/PhysicsVehicleWheel.cpp

@@ -14,6 +14,8 @@ PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, const PhysicsCollisionShape
     _rigidBody = new PhysicsRigidBody(node, shape, parameters);
 
     findAncestorAndBind();
+
+    _initialOffset = node->getTranslation();
 }
 
 PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, PhysicsRigidBody* rigidBody)
@@ -22,6 +24,8 @@ PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, PhysicsRigidBody* rigidBody
     _rigidBody = rigidBody;
 
     findAncestorAndBind();
+
+    _initialOffset = node->getTranslation();
 }
 
 PhysicsVehicleWheel* PhysicsVehicleWheel::create(Node* node, Properties* properties)
@@ -183,7 +187,11 @@ void PhysicsVehicleWheel::transform(Node* node) const
     const btQuaternion& rot = trans.getRotation();
     const btVector3& pos = trans.getOrigin();
     node->setRotation(rot.x(), rot.y(), rot.z(), rot.w());
-    node->setTranslation(pos.x(), pos.y(), pos.z());
+
+    // Ignore X and Z translation for wheel
+    Vector3 wheelPos = _initialOffset;
+    _host->_node->getMatrix().transformPoint(&wheelPos);
+    node->setTranslation(wheelPos.x, wheelPos.y, wheelPos.z);
 }
 
 bool PhysicsVehicleWheel::isFront() const

+ 1 - 0
gameplay/src/PhysicsVehicleWheel.h

@@ -329,6 +329,7 @@ private:
     PhysicsRigidBody* _rigidBody;
     PhysicsVehicle* _host;
     unsigned int _indexInHost;
+    Vector3 _initialOffset;
 };
 
 }