stash/unstash clunky as fuck
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 13 Sep 2018 13:53:19 +0000 (16:53 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 13 Sep 2018 13:53:19 +0000 (16:53 +0300)
src/app.cc
src/avatar.cc
src/exman.cc
src/exman.h

index a116e68..07ecdec 100644 (file)
@@ -345,11 +345,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;
@@ -780,6 +777,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 +852,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 +890,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;
index 737d3a6..456f269 100644 (file)
@@ -1,4 +1,5 @@
 #include "avatar.h"
+#include "logger.h"
 
 Avatar::Avatar()
 {
@@ -30,6 +31,12 @@ const Vec3 &Avatar::get_position() const
 void Avatar::set_body_rotation(float rot)
 {
        body_rot = rot;
+
+       float theta = deg_to_rad(body_rot);
+       fwd.x = sin(theta);
+       fwd.y = 0;
+       fwd.z = -cos(theta);
+       right = Vec3(-fwd.z, 0, fwd.x);
 }
 
 float Avatar::get_body_rotation() const
@@ -79,8 +86,10 @@ void Avatar::mouselook(float horiz, float vert)
 
 Vec3 Avatar::calc_walk_dir(float fwd, float right) const
 {
-       // TODO
-       return Vec3(0, 0, 0);
+       float theta = M_PI * body_rot / 180.0f;
+       float dx = cos(theta) * right - sin(theta) * fwd;
+       float dz = sin(theta) * right + cos(theta) * fwd;
+       return Vec3(dx, 0, dz);
 }
 
 void Avatar::walk(float fwd, float right)
index 00f7e39..4fff917 100644 (file)
@@ -334,6 +334,17 @@ void ExhibitManager::stash_exhibit(Exhibit *ex)
        }
 }
 
+Exhibit *ExhibitManager::unstash_exhibit()
+{
+       if(stashed.empty()) {
+               return 0;
+       }
+
+       Exhibit *ex = stashed[0];
+       stashed.erase(stashed.begin());
+       return ex;
+}
+
 void ExhibitManager::update(float dt)
 {
        int num = items.size();
index 8b9b65a..13d9bcc 100644 (file)
@@ -36,6 +36,7 @@ public:
 class ExhibitManager {
 private:
        std::vector<Exhibit*> items, stashed;
+       int cur_stashed;
        std::vector<ExhibitSlot*> exslots;
        // TODO kdtree of slots for quick nearest queries
 
@@ -58,6 +59,7 @@ public:
        ExhibitSlot *nearest_empty_slot(const Vec3 &pos, float max_dist = 10) const;
 
        void stash_exhibit(Exhibit *ex);
+       Exhibit *unstash_exhibit();
 
        void update(float dt = 0.0f);
        void draw() const;