[Bf-blender-cvs] [270eb336455] vr_scene_inspection: Fix various space transform issues

Julian Eisel noreply at git.blender.org
Wed Dec 11 18:56:50 CET 2019


Commit: 270eb336455e0aa950e3e052a8bdb6a42e97923b
Author: Julian Eisel
Date:   Wed Dec 11 18:54:35 2019 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB270eb336455e0aa950e3e052a8bdb6a42e97923b

Fix various space transform issues

===================================================================

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/windowmanager/intern/wm_xr.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index ec6ec027810..22281f85aa4 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -158,6 +158,7 @@ void BKE_object_obdata_size_init(struct Object *ob, const float scale);
 void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]);
 void BKE_object_rot_to_mat3(const struct Object *ob, float mat[3][3], bool use_drot);
 void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat);
+void BKE_object_rot_to_quat(struct Object *ob, float r_quat[4]);
 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
 void BKE_object_apply_mat4(struct Object *ob,
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 08890965ece..db5828493a3 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2101,6 +2101,28 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
   }
 }
 
+void BKE_object_rot_to_quat(Object *ob, float r_quat[4])
+{
+  float quat[4], dquat[4];
+
+  switch (ob->rotmode) {
+    case ROT_MODE_QUAT:
+      copy_v4_v4(quat, ob->quat);
+      copy_v4_v4(dquat, ob->dquat);
+      break;
+    case ROT_MODE_AXISANGLE:
+      axis_angle_to_quat(quat, ob->rotAxis, ob->rotAngle);
+      axis_angle_to_quat(dquat, ob->drotAxis, ob->drotAngle);
+      break;
+    default: /* euler */
+      eulO_to_quat(quat, ob->rot, ob->rotmode);
+      eulO_to_quat(dquat, ob->drot, ob->rotmode);
+      break;
+  }
+
+  mul_qt_qtqt(r_quat, dquat, quat);
+}
+
 void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
 {
 
@@ -2645,7 +2667,8 @@ void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *o
 }
 
 /**
- * Applies the global transformation \a mat to the \a ob using a relative parent space if supplied.
+ * Applies the global transformation \a mat to the \a ob using a relative parent space if
+ * supplied.
  *
  * \param mat: the global transformation mat that the object should be set object to.
  * \param parent: the parent space in which this object will be set relative to
@@ -3148,7 +3171,8 @@ typedef struct ObTfmBack {
   float obmat[4][4];
   /** inverse result of parent, so that object doesn't 'stick' to parent. */
   float parentinv[4][4];
-  /** inverse result of constraints. doesn't include effect of parent or object local transform. */
+  /** inverse result of constraints. doesn't include effect of parent or object local transform.
+   */
   float constinv[4][4];
   /** inverse matrix of 'obmat' for during render, temporally: ipokeys of transform. */
   float imat[4][4];
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index 7de110eb9d0..8888863ccff 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -25,6 +25,7 @@
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
+#include "BKE_object.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
 
@@ -188,16 +189,8 @@ static bXrRuntimeSessionState *wm_xr_runtime_session_state_create(const Scene *s
 
   if (scene->camera) {
     copy_v3_v3(state->reference_pose.position, scene->camera->loc);
-    if (scene->camera->rotmode == ROT_MODE_AXISANGLE) {
-      axis_angle_to_quat(
-          state->reference_pose.orientation_quat, scene->camera->rotAxis, scene->camera->rotAngle);
-    }
-    else if (scene->camera->rotmode == ROT_MODE_QUAT) {
-      copy_v4_v4(state->reference_pose.orientation_quat, scene->camera->quat);
-    }
-    else {
-      eul_to_quat(state->reference_pose.orientation_quat, scene->camera->rot);
-    }
+    add_v3_v3(state->reference_pose.position, scene->camera->dloc);
+    BKE_object_rot_to_quat(scene->camera, state->reference_pose.orientation_quat);
   }
   else {
     copy_v3_fl(state->reference_pose.position, 0.0f);
@@ -220,15 +213,15 @@ static void wm_xr_runtime_session_state_update(bXrRuntimeSessionState *state,
                                           XR_SESSION_USE_POSITION_TRACKING) !=
                                          (settings->flag & XR_SESSION_USE_POSITION_TRACKING);
 
+  copy_v4_v4(state->final_reference_pose.orientation_quat, state->reference_pose.orientation_quat);
+
   if (position_tracking_toggled) {
     copy_v3_v3(state->final_reference_pose.position, state->reference_pose.position);
-    copy_v4_v4(state->final_reference_pose.orientation_quat,
-               state->reference_pose.orientation_quat);
 
     /* Update reference pose to the current position. */
     if ((settings->flag & XR_SESSION_USE_POSITION_TRACKING) == 0) {
       /* OpenXR/Ghost-XR returns the local pose in local space, we need it in world space. */
-      state->final_reference_pose.position[0] -= draw_view->local_pose.position[0];
+      state->final_reference_pose.position[0] += draw_view->local_pose.position[0];
       state->final_reference_pose.position[1] -= draw_view->local_pose.position[2];
       state->final_reference_pose.position[2] += draw_view->local_pose.position[1];
     }
@@ -496,8 +489,12 @@ static void wm_xr_draw_matrices_create(const GHOST_XrDrawViewInfo *draw_view,
   }
 
   float base_mat[4][4];
-  quat_to_mat4(base_mat, session_state->final_reference_pose.orientation_quat);
-  translate_m4(base_mat, UNPACK3(session_state->final_reference_pose.position));
+  invert_qt_qt_normalized(quat, session_state->final_reference_pose.orientation_quat);
+  quat_to_mat4(base_mat, quat);
+  translate_m4(base_mat,
+               -session_state->final_reference_pose.position[0],
+               -session_state->final_reference_pose.position[1],
+               -session_state->final_reference_pose.position[2]);
 
   mul_m4_m4m4(r_view_mat, eye_mat, base_mat);
 }



More information about the Bf-blender-cvs mailing list