* Fixed truck placement callback registration.
authorUrban Wallasch <urban.wallasch@freenet.de>
Sun, 21 Jul 2019 21:38:51 +0000 (23:38 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sun, 21 Jul 2019 21:38:51 +0000 (23:38 +0200)
telemetry.cpp
telemetry.h

index 342303eb60fb03b05c4b015fd4765791ac4fe4cd..6030b3a4d481e5110242288e07d5d2a950c6c6d6 100644 (file)
@@ -147,7 +147,7 @@ SCSAPI_VOID telemetry_frame_end(const scs_event_t UNUSED(event), const void *con
     // The data line.
 
     log_print("%" SCS_PF_U64 ";%" SCS_PF_U64 ";%" SCS_PF_U64 ";%" SCS_PF_U64, telemetry->timestamp, telemetry->raw_rendering_timestamp, telemetry->raw_simulation_timestamp, telemetry->raw_paused_simulation_timestamp);
-    if (telemetry->orientation_available) {
+    if (telemetry->placement_available) {
         log_print(";%f;%f;%f", telemetry->heading, telemetry->pitch, telemetry->roll);
     }
     else {
@@ -283,25 +283,24 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e
 
 // Handling of individual channels.
 
-SCSAPI_VOID telemetry_store_orientation(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
+SCSAPI_VOID telemetry_store_dplacement(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
     assert(context);
-    telemetry_state_t *const state = static_cast<telemetry_state_t *>(context);
+    telemetry_state_t *const tele = static_cast<telemetry_state_t *>(context);
 
     // This callback was registered with the SCS_TELEMETRY_CHANNEL_FLAG_no_value flag
     // so it is called even when the value is not available.
-
-    if (! value) {
-        state->orientation_available = false;
+    if ( !value || value->type != SCS_VALUE_TYPE_dplacement ) {
+        tele->placement_available = false;
         return;
     }
-
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_euler);
-    state->orientation_available = true;
-    state->heading = value->value_euler.heading * 360.0f;
-    state->pitch = value->value_euler.pitch * 360.0f;
-    state->roll = value->value_euler.roll * 360.0f;
+    tele->placement_available = true;
+    tele->x = value->value_dplacement.position.x;
+    tele->y = value->value_dplacement.position.y;
+    tele->z = value->value_dplacement.position.z;
+    tele->heading = value->value_dplacement.orientation.heading;
+    tele->pitch = value->value_dplacement.orientation.pitch;
+    tele->roll = value->value_dplacement.orientation.roll;
 }
 
 SCSAPI_VOID telemetry_store_float(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
@@ -418,7 +417,7 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in
     // (SCS_RESULT_unsupported_type). For purpose of this example we ignore the failues
     // so the unsupported channels will remain at theirs default value.
 
-    version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_world_placement, SCS_U32_NIL, SCS_VALUE_TYPE_euler, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_orientation, &telemetry);
+    version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_world_placement, SCS_U32_NIL, SCS_VALUE_TYPE_dplacement, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_dplacement, telemetry);
     version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_speed, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->speed);
     version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_rpm, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->rpm);
     version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_gear, SCS_U32_NIL, SCS_VALUE_TYPE_s32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_s32, &telemetry->gear);
index b9e5f70b30f9d5edf389cf259e377ecda4078592..2c09682bab8eb877161e72566db764c9632794cd 100644 (file)
@@ -9,10 +9,13 @@ struct telemetry_state_t {
     uint64_t raw_simulation_timestamp;
     uint64_t raw_paused_simulation_timestamp;
 
-    bool    orientation_available;
-    float   heading;
-    float   pitch;
-    float   roll;
+    bool    placement_available;
+    double  x;
+    double  y;
+    double  z;
+    double  heading;
+    double  pitch;
+    double  roll;
 
     float   speed;
     float   rpm;