assman was renamed to assfile
[laserbrain_demo] / src / app.cc
index a116e68..178b7df 100644 (file)
@@ -2,6 +2,7 @@
 #include <limits.h>
 #include <assert.h>
 #include <goatvr.h>
+#include <assfile.h>
 #include "app.h"
 #include "opengl.h"
 #include "sdr.h"
@@ -63,7 +64,7 @@ static bool bnstate[8];
 static bool keystate[256];
 static bool gpad_bnstate[64];
 static Vec2 joy_move, joy_look;
-static float joy_deadzone = 0.01;
+static float joy_deadzone = 0.1;
 
 static float framerate;
 
@@ -113,6 +114,11 @@ bool app_init(int argc, char **argv)
        app_resize(opt.width, opt.height);
        app_fullscreen(opt.fullscreen);
 
+       if(opt.data_url) {
+               info_log("Adding URL asset source: %s\n", opt.data_url);
+               ass_add_url("data", opt.data_url);
+       }
+
        if(opt.vr) {
                if(goatvr_init() == -1) {
                        return false;
@@ -319,7 +325,18 @@ static void update(float dt)
                jlook_lensq -= jdeadsq;
 
                float mag = len * len;
-               avatar.body_rot += mag * joy_look.x / len * 200.0 * dt;
+
+               if(opt.min_turn > 0.0f) {
+                       static long last_turn;
+                       if(len > 0.5 && time_msec - last_turn > 350) {
+                               float sign = joy_look.x > 0.0f ? 1.0f : -1.0f;
+                               avatar.body_rot += opt.min_turn * sign;
+                               last_turn = time_msec;
+                       }
+               } else {
+                       avatar.body_rot += mag * joy_look.x / len * 200.0 * dt;
+               }
+
                avatar.head_alt += mag * joy_look.y / len * 100.0 * dt;
                if(avatar.head_alt < -90.0f) avatar.head_alt = -90.0f;
                if(avatar.head_alt > 90.0f) avatar.head_alt = 90.0f;
@@ -345,11 +362,8 @@ static void update(float dt)
                avatar.pos.y -= speed;
        }
 
-       float theta = M_PI * avatar.body_rot / 180.0f;
-       Vec3 newpos;
-       newpos.x = avatar.pos.x + cos(theta) * dir.x - sin(theta) * dir.z;
-       newpos.y = avatar.pos.y;
-       newpos.z = avatar.pos.z + sin(theta) * dir.x + cos(theta) * dir.z;
+       Vec3 walk_dir = avatar.calc_walk_dir(dir.z, dir.x);
+       Vec3 newpos = avatar.pos + walk_dir;
 
        if(noclip) {
                avatar.pos = newpos;
@@ -562,6 +576,12 @@ void app_display()
                vp_width = win_width;
                vp_height = win_height;
 
+               if(!gfbo && !fb_srgb && sdr_post_gamma) {
+                       glViewport(0, 0, win_width, win_height);
+                       slow_post(sdr_post_gamma);
+                       glUseProgram(0);
+               }
+
                if(should_swap) {
                        app_swap_buffers();
                }
@@ -780,6 +800,24 @@ void app_keyboard(int key, bool pressed)
                        exui_change_tab(1);
                        break;
 
+               case '\t':
+                       if(exsel_grab_mouse) {
+                               Exhibit *ex = exsel_grab_mouse.ex;
+                               exslot_mouse.detach_exhibit();
+                               exman->stash_exhibit(ex);
+                               exsel_grab_mouse = ExSelection::null;
+                       } else {
+                               Exhibit *ex = exman->unstash_exhibit();
+                               if(ex) {
+                                       exslot_mouse.attach_exhibit(ex, EXSLOT_ATTACH_TRANSIENT);
+                                       exsel_grab_mouse = ex;
+
+                                       Vec3 fwd = avatar.get_body_fwd();
+                                       exslot_mouse.node.set_position(avatar.pos + fwd * 100);
+                               }
+                       }
+                       break;
+
                case KEY_F5:
                case KEY_F6:
                case KEY_F7:
@@ -837,7 +875,7 @@ void app_mouse_button(int bn, bool pressed, int x, int y)
 
                                exslot_mouse.detach_exhibit();
 
-                               ExhibitSlot *slot = exman->nearest_empty_slot(pos, 100);
+                               ExhibitSlot *slot = exman->nearest_empty_slot(pos, 300);
                                if(!slot) {
                                        debug_log("no empty slot nearby\n");
                                        if(ex->prev_slot && ex->prev_slot->empty()) {
@@ -875,7 +913,7 @@ void app_mouse_button(int bn, bool pressed, int x, int y)
 static inline void mouse_look(float dx, float dy)
 {
        float scrsz = (float)win_height;
-       avatar.body_rot += dx * 512.0 / scrsz;
+       avatar.set_body_rotation(avatar.body_rot + dx * 512.0 / scrsz);
        avatar.head_alt += dy * 512.0 / scrsz;
 
        if(avatar.head_alt < -90) avatar.head_alt = -90;