bullet: change wheel get/setSteering to use degrees

Fixes #757
Closes #784
This commit is contained in:
leotada 2019-12-11 16:29:37 +01:00 committed by rdb
parent 8615e25a12
commit 636c3d044a
2 changed files with 35 additions and 2 deletions

View File

@ -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);
}
/**

View File

@ -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)