2424#include < util/tracy.h>
2525TRACY_MODULE_NAME (SceMotion);
2626
27- EXPORT (int , sceMotionGetAngleThreshold) {
27+ EXPORT (SceFloat , sceMotionGetAngleThreshold) {
2828 TRACY_FUNC (sceMotionGetAngleThreshold);
29- return UNIMPLEMENTED ( );
29+ return get_angle_threshold (emuenv. motion );
3030}
3131
3232EXPORT (int , sceMotionGetBasicOrientation, SceFVector3 *basicOrientation) {
@@ -35,26 +35,16 @@ EXPORT(int, sceMotionGetBasicOrientation, SceFVector3 *basicOrientation) {
3535 return RET_ERROR (SCE_MOTION_ERROR_NULL_PARAMETER );
3636
3737 std::lock_guard<std::mutex> guard (emuenv.motion .mutex );
38- Util::Quaternion quat = get_orientation (emuenv.motion );
39-
40- *basicOrientation = { 0 .f , 0 .f , 0 .f };
41- // get the basic orientation, only one component is not zero and will be 1 or -1
42- // TODO: this is probably wrong
43- float max_val = std::max ({ std::abs (quat.xyz .x ), std::abs (quat.xyz .y ), std::abs (quat.xyz .z ) });
44- if (max_val == std::abs (quat.xyz .x )) {
45- basicOrientation->x = quat.xyz .x > 0 .0f ? 1 .0f : -1 .0f ;
46- } else if (max_val == std::abs (quat.xyz .y )) {
47- basicOrientation->y = quat.xyz .y > 0 .0f ? 1 .0f : -1 .0f ;
48- } else {
49- basicOrientation->z = quat.xyz .z > 0 .0f ? 1 .0f : -1 .0f ;
50- }
38+ SceFVector3 accelerometer = get_acceleration (emuenv.motion );
39+
40+ *basicOrientation = get_basic_orientation (emuenv.motion );
5141
5242 return 0 ;
5343}
5444
5545EXPORT (SceBool, sceMotionGetDeadband) {
5646 TRACY_FUNC (sceMotionGetDeadband);
57- return UNIMPLEMENTED ( );
47+ return get_deadband (emuenv. motion );
5848}
5949
6050EXPORT (int , sceMotionGetDeadbandExt) {
@@ -123,6 +113,7 @@ EXPORT(int, sceMotionGetState, SceMotionState *motionState) {
123113 motionState->angularVelocity = get_gyroscope (emuenv.motion );
124114
125115 Util::Quaternion dev_quat = get_orientation (emuenv.motion );
116+ motionState->basicOrientation = get_basic_orientation (emuenv.motion );
126117
127118 static_assert (sizeof (motionState->deviceQuat ) == sizeof (dev_quat));
128119 memcpy (&motionState->deviceQuat , &dev_quat, sizeof (motionState->deviceQuat ));
@@ -168,7 +159,7 @@ EXPORT(int, sceMotionGetStateInternal) {
168159
169160EXPORT (SceBool, sceMotionGetTiltCorrection) {
170161 TRACY_FUNC (sceMotionGetTiltCorrection);
171- return UNIMPLEMENTED ( );
162+ return get_tilt_correction (emuenv. motion );
172163}
173164
174165EXPORT (int , sceMotionGetTiltCorrectionExt) {
@@ -193,7 +184,9 @@ EXPORT(int, sceMotionMagnetometerOn) {
193184
194185EXPORT (int , sceMotionReset) {
195186 TRACY_FUNC (sceMotionReset);
196- return UNIMPLEMENTED ();
187+ std::lock_guard<std::mutex> guard (emuenv.motion .mutex );
188+ emuenv.motion .motion_data .SetQuaternion ({ { 0 .0f , 0 .0f , -1 .0f }, 0 .0f });
189+ return 0 ;
197190}
198191
199192EXPORT (int , sceMotionResetExt) {
@@ -203,17 +196,22 @@ EXPORT(int, sceMotionResetExt) {
203196
204197EXPORT (int , sceMotionRotateYaw, const float radians) {
205198 TRACY_FUNC (sceMotionRotateYaw, radians);
206- return UNIMPLEMENTED ();
199+ emuenv.motion .motion_data .RotateYaw (radians);
200+ return 0 ;
207201}
208202
209- EXPORT (int , sceMotionSetAngleThreshold, const float angle) {
203+ EXPORT (int , sceMotionSetAngleThreshold, SceFloat angle) {
210204 TRACY_FUNC (sceMotionSetAngleThreshold, angle);
211- return UNIMPLEMENTED ();
205+ set_angle_threshold (emuenv.motion , angle);
206+ return 0 ;
212207}
213208
214209EXPORT (int , sceMotionSetDeadband, SceBool setValue) {
215210 TRACY_FUNC (sceMotionSetDeadband, setValue);
216- return UNIMPLEMENTED ();
211+ STUBBED (" only set value" );
212+ set_deadband (emuenv.motion , setValue);
213+
214+ return 0 ;
217215}
218216
219217EXPORT (int , sceMotionSetDeadbandExt) {
@@ -230,7 +228,9 @@ EXPORT(int, sceMotionSetGyroBiasCorrection, SceBool setValue) {
230228
231229EXPORT (int , sceMotionSetTiltCorrection, SceBool setValue) {
232230 TRACY_FUNC (sceMotionSetTiltCorrection, setValue);
233- return UNIMPLEMENTED ();
231+ STUBBED (" only set value" );
232+ set_tilt_correction (emuenv.motion , setValue);
233+ return 0 ;
234234}
235235
236236EXPORT (int , sceMotionSetTiltCorrectionExt) {
0 commit comments