]> git.seodisparate.com - jumpartifact.com_demo_0/commitdiff
Impl. walker bobbing head on idle
authorStephen Seo <seo.disparate@gmail.com>
Fri, 11 Aug 2023 03:14:48 +0000 (12:14 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 11 Aug 2023 03:14:48 +0000 (12:14 +0900)
src/walker.cc
src/walker.h

index eaa292254cdf5cdbf7363b122c0eff78d10b72bd..57bba25f9bb3823b2b8d583201d93ed248ec192e 100644 (file)
@@ -31,7 +31,8 @@ Walker::Walker(float body_height, float body_feet_radius, float feet_radius)
       feet_radius(feet_radius),
       lift_start_y(0.0F),
       rotation(0.0F),
-      target_rotation(0.0F) {
+      target_rotation(0.0F),
+      body_idle_move_timer(0.0F) {
   const Vector3 nw = Vector3Normalize(Vector3{-1.0F, 0.0F, -1.0F});
   const Vector3 ne = Vector3Normalize(Vector3{1.0F, 0.0F, -1.0F});
   const Vector3 sw = Vector3Normalize(Vector3{-1.0F, 0.0F, 1.0F});
@@ -71,7 +72,11 @@ void Walker::draw(const Model &model) {
                   .boneCount = model.boneCount,
                   .bones = model.bones,
                   .bindPose = model.bindPose},
-            body_pos, 1.0F, WHITE);
+            Vector3{body_pos.x,
+                    body_pos.y + BODY_IDLE_MOVE_AMOUNT *
+                                     std::sin(body_idle_move_timer + PI),
+                    body_pos.z},
+            1.0F, WHITE);
 
   // draw legs
   DrawModel(Model{.transform = model.transform * rotationMatrix,
index 95b77dcbed647cde35444a57ee4fbefbbca631e7..a0016c86cb96c2247ae573f9f15a8f827d7b59cf 100644 (file)
@@ -23,6 +23,8 @@ constexpr float FEET_LIFT_SPEED = 5.5F;
 constexpr float FEET_HORIZ_MOVE_SPEED = 8.0F;
 constexpr float FEET_INIT_POS_VARIANCE_DIV = 3.0F;
 constexpr float BODY_ROTATION_SPEED = 1.0F;
+constexpr float BODY_IDLE_TIMER_RATE = 1.0F;
+constexpr float BODY_IDLE_MOVE_AMOUNT = 0.2F;
 
 class Walker {
  public:
@@ -64,6 +66,7 @@ class Walker {
   float lift_start_y;
   float rotation;
   float target_rotation;
+  float body_idle_move_timer;
 };
 
 template <typename TBBS>
@@ -251,6 +254,25 @@ void Walker::update(float dt, const TBBS &bbs, unsigned int width,
   update_leg_fn(target_leg_sw, leg_sw, sw_flags,
                 ((nw_flags & 7) == 1 ? 1 : 0) + ((ne_flags & 7) == 1 ? 1 : 0) +
                     ((se_flags & 7) == 1 ? 1 : 0));
+
+  if ((flags & 3) == 0) {
+    body_idle_move_timer += dt * BODY_IDLE_TIMER_RATE;
+    if (body_idle_move_timer > PI * 2.0F) {
+      body_idle_move_timer -= PI * 2.0F;
+    }
+  } else if (!FloatEquals(body_idle_move_timer, 0.0F)) {
+    if (body_idle_move_timer < PI) {
+      body_idle_move_timer += dt * BODY_IDLE_TIMER_RATE;
+      if (body_idle_move_timer > PI) {
+        body_idle_move_timer = 0;
+      }
+    } else {
+      body_idle_move_timer += dt * BODY_IDLE_TIMER_RATE;
+      if (body_idle_move_timer > PI * 2.0F) {
+        body_idle_move_timer = 0.0F;
+      }
+    }
+  }
 }
 
 #endif