Merge branch 'master' of goat:git/laserbrain_demo
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 16 Sep 2017 06:55:20 +0000 (09:55 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 16 Sep 2017 06:55:20 +0000 (09:55 +0300)
src/app.cc
src/avatar.h [new file with mode: 0644]
src/vrinput.cc [new file with mode: 0644]
src/vrinput.h [new file with mode: 0644]

index 24658ee..17ab2fd 100644 (file)
@@ -14,6 +14,7 @@
 #include "opt.h"
 #include "post.h"
 #include "renderer.h"
+#include "vrinput.h"
 #include "exman.h"
 #include "blob_exhibit.h"
 
@@ -45,14 +46,7 @@ static float walk_speed = 300.0f;
 static float mouse_speed = 0.5f;
 static bool show_walk_mesh, noclip = false;
 
-static bool have_headtracking, should_swap;
-static bool have_handtracking;
-
-static struct {
-       Vec3 pos;
-       Quat rot;
-       bool valid;
-} hand[2];
+static bool have_headtracking, have_handtracking, should_swap;
 
 static int prev_mx, prev_my;
 static bool bnstate[8];
@@ -119,6 +113,10 @@ bool app_init(int argc, char **argv)
 
        glClearColor(1, 1, 1, 1);
 
+       if(!init_vrhands()) {
+               return false;
+       }
+
        mscn = new MetaScene;
        if(!mscn->load(opt.scenefile ? opt.scenefile : "data/museum.scene")) {
                return false;
@@ -176,6 +174,7 @@ void app_cleanup()
        if(opt.vr) {
                goatvr_shutdown();
        }
+       destroy_vrhands();
 
        delete rend;
 
@@ -298,16 +297,9 @@ static void update(float dt)
        mouse_view_matrix.pre_rotate_y(deg_to_rad(cam_theta));
        mouse_view_matrix.pre_translate(-cam_pos.x, -cam_pos.y, -cam_pos.z);
 
+       // update hand-tracking
        if(have_handtracking) {
-               for(int i=0; i<2; i++) {
-                       if(goatvr_hand_active(i)) {
-                               goatvr_hand_position(i, &hand[i].pos.x);
-                               goatvr_hand_orientation(i, &hand[i].rot.x);
-                               hand[i].valid = true;
-                       } else {
-                               hand[i].valid = false;
-                       }
-               }
+               update_vrhands();
        }
 }
 
@@ -348,6 +340,9 @@ void app_display()
                        glLoadMatrixf(view_matrix[0]);
 
                        draw_scene();
+                       if(have_handtracking) {
+                               draw_vrhands();
+                       }
                }
                goatvr_draw_done();
 
@@ -395,6 +390,7 @@ static void draw_scene()
                blobs->draw();
        }
 
+       /*
        if(have_handtracking) {
                Mat4 head_xform = inverse(mouse_view_matrix);//goatvr_head_matrix();
                Mat4 head_dir_xform = head_xform.upper3x3();
@@ -424,6 +420,7 @@ static void draw_scene()
                glEnd();
                glPopAttrib();
        }
+       */
 
        if(show_walk_mesh && mscn->walk_mesh) {
                glPushAttrib(GL_ENABLE_BIT);
diff --git a/src/avatar.h b/src/avatar.h
new file mode 100644 (file)
index 0000000..6c3521e
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef AVATAR_H_
+#define AVATAR_H_
+
+#include <gmath/gmath.h>
+
+/* when head-tracking is available, head_tilt is ignored, and the
+ * body_rot (controlled by mouse/gamepad) is independent of head_rot.
+ *
+ * without head-tracking, head_rot is derived from body_rot and head_tilt
+ */
+class Avatar {
+public:
+       Vec3 pos;
+       float body_rot;
+       Quat head_rot;          // used when head-tracking
+       float head_tilt;        // used for mouselook
+
+       Avatar();
+       ~Avatar();
+
+       void draw() const;
+};
+
+#endif // AVATAR_H_
diff --git a/src/vrinput.cc b/src/vrinput.cc
new file mode 100644 (file)
index 0000000..e488c74
--- /dev/null
@@ -0,0 +1,41 @@
+#include <string.h>
+#include "vrinput.h"
+#include "scene.h"
+
+VRHand vrhand[2];
+
+static Scene *scn;
+
+bool init_vrhands()
+{
+       scn = new Scene;
+       if(!(scn->load("data/vrhands.obj"))) {
+               return false;
+       }
+       return true;
+}
+
+void destroy_vrhands()
+{
+       delete scn;
+       scn = 0;
+}
+
+void update_vrhands()
+{
+       for(int i=0; i<2; i++) {
+               if(!(vrhand[i].src = goatvr_get_hand_tracker(i))) {
+                       vrhand[i].valid = false;
+                       continue;
+               }
+               goatvr_source_position(vrhand[i].src, &vrhand[i].pos.x);
+               goatvr_source_orientation(vrhand[i].src, &vrhand[i].rot.x);
+               float *mat = goatvr_source_matrix(vrhand[i].src);
+               memcpy(vrhand[i].xform[0], mat, 16 * sizeof(float));
+               vrhand[i].valid = true;
+       }
+}
+
+void draw_vrhands()
+{
+}
diff --git a/src/vrinput.h b/src/vrinput.h
new file mode 100644 (file)
index 0000000..1ab89a1
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef VRINPUT_H_
+#define VRINPUT_H_
+
+#include <gmath/gmath.h>
+#include <goatvr.h>
+
+struct VRHand {
+       bool valid;
+       Vec3 pos;
+       Quat rot;
+       Mat4 xform;     /* combination of the above */
+       goatvr_source *src;
+};
+
+extern VRHand vrhand[2];
+
+bool init_vrhands();
+void destroy_vrhands();
+
+void update_vrhands();
+void draw_vrhands();
+
+#endif /* VRINPUT_H_ */