mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Replace static_cast
s with vector operations
This commit is contained in:
parent
6f5711e799
commit
447e7b3844
@ -127,51 +127,42 @@ void SensorImpl::close()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector3f SensorImpl::update()
|
Vector3f SensorImpl::update()
|
||||||
{
|
{
|
||||||
Vector3f value;
|
|
||||||
CMMotionManager* const manager = [SFAppDelegate getInstance].motionManager;
|
CMMotionManager* const manager = [SFAppDelegate getInstance].motionManager;
|
||||||
|
|
||||||
switch (m_sensor)
|
switch (m_sensor)
|
||||||
{
|
{
|
||||||
case Sensor::Type::Accelerometer:
|
case Sensor::Type::Accelerometer:
|
||||||
// Acceleration is given in G, convert to m/s^2
|
// Acceleration is given in G, convert to m/s^2
|
||||||
value.x = static_cast<float>(manager.accelerometerData.acceleration.x * 9.81);
|
return Vector3f(9.81 * Vector3(manager.accelerometerData.acceleration.x,
|
||||||
value.y = static_cast<float>(manager.accelerometerData.acceleration.y * 9.81);
|
manager.accelerometerData.acceleration.y,
|
||||||
value.z = static_cast<float>(manager.accelerometerData.acceleration.z * 9.81);
|
manager.accelerometerData.acceleration.z));
|
||||||
break;
|
|
||||||
|
|
||||||
case Sensor::Type::Gyroscope:
|
case Sensor::Type::Gyroscope:
|
||||||
// Rotation rates are given in rad/s
|
// Rotation rates are given in rad/s
|
||||||
value.x = static_cast<float>(manager.gyroData.rotationRate.x);
|
return Vector3f(
|
||||||
value.y = static_cast<float>(manager.gyroData.rotationRate.y);
|
Vector3(manager.gyroData.rotationRate.x, manager.gyroData.rotationRate.y, manager.gyroData.rotationRate.z));
|
||||||
value.z = static_cast<float>(manager.gyroData.rotationRate.z);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Sensor::Type::Magnetometer:
|
case Sensor::Type::Magnetometer:
|
||||||
// Magnetic field is given in microteslas
|
// Magnetic field is given in microteslas
|
||||||
value.x = static_cast<float>(manager.magnetometerData.magneticField.x);
|
return Vector3f(Vector3(manager.magnetometerData.magneticField.x,
|
||||||
value.y = static_cast<float>(manager.magnetometerData.magneticField.y);
|
manager.magnetometerData.magneticField.y,
|
||||||
value.z = static_cast<float>(manager.magnetometerData.magneticField.z);
|
manager.magnetometerData.magneticField.z));
|
||||||
break;
|
|
||||||
|
|
||||||
case Sensor::Type::UserAcceleration:
|
case Sensor::Type::UserAcceleration:
|
||||||
// User acceleration is given in G, convert to m/s^2
|
// User acceleration is given in G, convert to m/s^2
|
||||||
value.x = static_cast<float>(manager.deviceMotion.userAcceleration.x * 9.81);
|
return Vector3f(9.81 * Vector3(manager.deviceMotion.userAcceleration.x,
|
||||||
value.y = static_cast<float>(manager.deviceMotion.userAcceleration.y * 9.81);
|
manager.deviceMotion.userAcceleration.y,
|
||||||
value.z = static_cast<float>(manager.deviceMotion.userAcceleration.z * 9.81);
|
manager.deviceMotion.userAcceleration.z));
|
||||||
break;
|
|
||||||
|
|
||||||
case Sensor::Type::Orientation:
|
case Sensor::Type::Orientation:
|
||||||
// Absolute rotation (Euler) angles are given in radians
|
// Absolute rotation (Euler) angles are given in radians
|
||||||
value.x = static_cast<float>(manager.deviceMotion.attitude.yaw);
|
return Vector3f(Vector3<double>(manager.deviceMotion.attitude.yaw,
|
||||||
value.y = static_cast<float>(manager.deviceMotion.attitude.pitch);
|
manager.deviceMotion.attitude.pitch,
|
||||||
value.z = static_cast<float>(manager.deviceMotion.attitude.roll);
|
manager.deviceMotion.attitude.roll));
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user