瀏覽代碼

bullet: change wheel get/setSteering to use degrees

Fixes #757
Closes #784
leotada 6 年之前
父節點
當前提交
636c3d044a
共有 2 個文件被更改,包括 35 次插入2 次删除
  1. 8 2
      panda/src/bullet/bulletWheel.cxx
  2. 27 0
      tests/bullet/test_bullet_wheel.py

+ 8 - 2
panda/src/bullet/bulletWheel.cxx

@@ -218,22 +218,28 @@ get_wheel_radius() const {
 
 /**
  * Sets the steering angle.
+ *
+ * @warning
+ * As of 1.11, this method uses degrees.  Previous versions used radians.
  */
 void BulletWheel::
 set_steering(PN_stdfloat value) {
   LightMutexHolder holder(BulletWorld::get_global_lock());
 
-  _info.m_steering = (btScalar)value;
+  _info.m_steering = (btScalar)deg_2_rad(value);
 }
 
 /**
  * Returns the steering angle in degrees.
+ *
+ * @warning
+ * As of 1.11, this method uses degrees.  Previous versions used radians.
  */
 PN_stdfloat BulletWheel::
 get_steering() const {
   LightMutexHolder holder(BulletWorld::get_global_lock());
 
-  return (PN_stdfloat)_info.m_steering;
+  return rad_2_deg((PN_stdfloat)_info.m_steering);
 }
 
 /**

+ 27 - 0
tests/bullet/test_bullet_wheel.py

@@ -0,0 +1,27 @@
+import pytest
+from pytest import approx
+# Skip these tests if we can't import bullet.
+bullet = pytest.importorskip("panda3d.bullet")
+
+from panda3d.core import Vec3
+from panda3d.bullet import BulletWorld
+from panda3d.bullet import BulletBoxShape
+from panda3d.bullet import BulletRigidBodyNode
+from panda3d.bullet import BulletVehicle
+
+
+def test_get_steering():
+    world = BulletWorld()
+    # Chassis
+    shape = BulletBoxShape(Vec3(0.6, 1.4, 0.5))
+    body = BulletRigidBodyNode('Vehicle')
+    body.addShape(shape)
+    world.attach(body)
+    # Vehicle
+    vehicle = BulletVehicle(world, body)
+    world.attachVehicle(vehicle)
+    # Wheel
+    wheel = vehicle.createWheel()
+    wheel.setSteering(30.0)
+    # Returns the steering angle in degrees.
+    assert wheel.getSteering() == approx(30.0)