Compare commits

..

No commits in common. "12bbfe94849752377d46ffddfa3aa2742912420f" and "0611be13f202c92cd99099053e17b76f2fad8005" have entirely different histories.

7 changed files with 30 additions and 128 deletions

View file

@ -160,7 +160,3 @@ std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane) {
ray.position.y + ray.direction.y * amount, ray.position.y + ray.direction.y * amount,
ray.position.z + ray.direction.z * amount}; ray.position.z + ray.direction.z * amount};
} }
Vector3 operator+(const Vector3 &a, const Vector3 &b) {
return Vector3{a.x + b.x, a.y + b.y, a.z + b.z};
}

View file

@ -31,6 +31,4 @@ extern std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane);
// weirdness regarding column-major matrices. // weirdness regarding column-major matrices.
// extern Vector4 operator*(const Matrix &m, const Vector4 &v); // extern Vector4 operator*(const Matrix &m, const Vector4 &v);
extern Vector3 operator+(const Vector3 &a, const Vector3 &b);
#endif #endif

View file

@ -1,10 +0,0 @@
#ifndef JUMPARTIFACT_DOT_COM_DEMO_0_COMMON_CONSTANTS_H_
#define JUMPARTIFACT_DOT_COM_DEMO_0_COMMON_CONSTANTS_H_
constexpr unsigned int SURFACE_UNIT_WIDTH = 51;
constexpr unsigned int SURFACE_UNIT_HEIGHT = 51;
constexpr float SURFACE_X_OFFSET = (float)SURFACE_UNIT_WIDTH / 2.0F - 0.5F;
constexpr float SURFACE_Y_OFFSET = (float)SURFACE_UNIT_HEIGHT / 2.0F - 0.5F;
#endif

View file

@ -20,21 +20,7 @@ TRunnerScreen::TRunnerScreen(std::weak_ptr<ScreenStack> stack)
: Screen(stack), : Screen(stack),
surface(), surface(),
surface_bbs(), surface_bbs(),
walkers{Walker{(float)(SURFACE_UNIT_WIDTH / 4) - SURFACE_X_OFFSET, walker(),
(float)(SURFACE_UNIT_HEIGHT / 4) - SURFACE_Y_OFFSET, true},
Walker{(float)((SURFACE_UNIT_WIDTH / 4) * 3) - SURFACE_X_OFFSET,
(float)(SURFACE_UNIT_HEIGHT / 4) - SURFACE_Y_OFFSET, true},
Walker{(float)(SURFACE_UNIT_WIDTH / 4) - SURFACE_X_OFFSET,
(float)((SURFACE_UNIT_HEIGHT / 4) * 3) - SURFACE_Y_OFFSET,
true},
Walker{(float)((SURFACE_UNIT_WIDTH / 4) * 3) - SURFACE_X_OFFSET,
(float)((SURFACE_UNIT_HEIGHT / 4) * 3) - SURFACE_Y_OFFSET,
true}
},
camera{Vector3{0.0F, 1.0F, 0.5F}, Vector3{0.0F, 0.0F, 0.0F}, camera{Vector3{0.0F, 1.0F, 0.5F}, Vector3{0.0F, 0.0F, 0.0F},
Vector3{0.0F, 1.0F, 0.0F}, 80.0F, CAMERA_PERSPECTIVE}, Vector3{0.0F, 1.0F, 0.0F}, 80.0F, CAMERA_PERSPECTIVE},
flags(), flags(),
@ -255,6 +241,7 @@ bool TRunnerScreen::update(float dt) {
this->camera_target.y = this->camera_target.y =
(current.nw + current.ne + current.sw + current.se) / 4.0F; (current.nw + current.ne + current.sw + current.se) / 4.0F;
this->camera_target.z = zf; this->camera_target.z = zf;
this->walker.set_body_pos(this->camera_target);
if (idx != SURFACE_UNIT_WIDTH / 2 + if (idx != SURFACE_UNIT_WIDTH / 2 +
(SURFACE_UNIT_HEIGHT / 2) * SURFACE_UNIT_WIDTH) { (SURFACE_UNIT_HEIGHT / 2) * SURFACE_UNIT_WIDTH) {
this->camera_pos = Vector3Add( this->camera_pos = Vector3Add(
@ -286,9 +273,7 @@ bool TRunnerScreen::update(float dt) {
camera_to_targets(dt); camera_to_targets(dt);
for (auto &walker : walkers) {
walker.update(dt, surface_bbs, SURFACE_UNIT_WIDTH, SURFACE_UNIT_HEIGHT); walker.update(dt, surface_bbs, SURFACE_UNIT_WIDTH, SURFACE_UNIT_HEIGHT);
}
return false; return false;
} }
@ -330,9 +315,7 @@ bool TRunnerScreen::draw() {
// .bindPose = TEMP_cube_model.bindPose}, // .bindPose = TEMP_cube_model.bindPose},
// Vector3{0.0F, 0.0F, -4.0F}, 1.0F, WHITE); // Vector3{0.0F, 0.0F, -4.0F}, 1.0F, WHITE);
for (auto &walker : walkers) {
walker.draw(TEMP_cube_model); walker.draw(TEMP_cube_model);
}
// TODO DEBUG // TODO DEBUG
DrawLine3D(Vector3{0.0F, 3.0F, 0.0F}, mouse_hit, BLACK); DrawLine3D(Vector3{0.0F, 3.0F, 0.0F}, mouse_hit, BLACK);

View file

@ -12,12 +12,17 @@
#include <raylib.h> #include <raylib.h>
// local includes // local includes
#include "common_constants.h"
#include "walker.h" #include "walker.h"
constexpr float POS_VALUE_INC_RATE = 0.2F; constexpr float POS_VALUE_INC_RATE = 0.2F;
constexpr float CAMERA_UPDATE_RATE = 1.0F; constexpr float CAMERA_UPDATE_RATE = 1.0F;
constexpr unsigned int SURFACE_UNIT_WIDTH = 51;
constexpr unsigned int SURFACE_UNIT_HEIGHT = 51;
constexpr float SURFACE_X_OFFSET = (float)SURFACE_UNIT_WIDTH / 2.0F - 0.5F;
constexpr float SURFACE_Y_OFFSET = (float)SURFACE_UNIT_HEIGHT / 2.0F - 0.5F;
constexpr float SURFACE_HEIGHT_INTERVAL = 0.7F; constexpr float SURFACE_HEIGHT_INTERVAL = 0.7F;
class TRunnerScreen : public Screen { class TRunnerScreen : public Screen {
@ -56,7 +61,7 @@ class TRunnerScreen : public Screen {
surface; surface;
std::array<BoundingBox, SURFACE_UNIT_WIDTH * SURFACE_UNIT_HEIGHT> surface_bbs; std::array<BoundingBox, SURFACE_UNIT_WIDTH * SURFACE_UNIT_HEIGHT> surface_bbs;
std::array<Walker, 4> walkers; Walker walker;
Camera3D camera; Camera3D camera;
std::bitset<64> flags; std::bitset<64> flags;

View file

@ -10,10 +10,9 @@
#include "3d_helpers.h" #include "3d_helpers.h"
#include "ems.h" #include "ems.h"
Walker::Walker(float x, float z, bool auto_roaming, float body_height, Walker::Walker(float body_height, float body_feet_radius, float feet_radius)
float body_feet_radius, float feet_radius) : body_pos{0.0F, body_height, 0.0F},
: body_pos{x, body_height, z}, target_body_pos{0.0F, body_height, 0.0F},
target_body_pos{x, body_height, z},
leg_nw(), leg_nw(),
leg_ne(), leg_ne(),
leg_sw(), leg_sw(),
@ -32,44 +31,31 @@ Walker::Walker(float x, float z, bool auto_roaming, float body_height,
feet_radius(feet_radius), feet_radius(feet_radius),
lift_start_y(0.0F), lift_start_y(0.0F),
rotation(0.0F), rotation(0.0F),
target_rotation(0.0F), target_rotation(0.0F) {
body_idle_move_timer(0.0F),
roaming_time(5.0F),
roaming_timer(0.0F) {
flags |= auto_roaming ? 4 : 0;
roaming_time =
call_js_get_random() * ROAMING_WAIT_VARIANCE + ROAMING_WAIT_AMOUNT;
const Vector3 nw = Vector3Normalize(Vector3{-1.0F, 0.0F, -1.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 ne = Vector3Normalize(Vector3{1.0F, 0.0F, -1.0F});
const Vector3 sw = Vector3Normalize(Vector3{-1.0F, 0.0F, 1.0F}); const Vector3 sw = Vector3Normalize(Vector3{-1.0F, 0.0F, 1.0F});
const Vector3 se = Vector3Normalize(Vector3{1.0F, 0.0F, 1.0F}); const Vector3 se = Vector3Normalize(Vector3{1.0F, 0.0F, 1.0F});
const Vector3 offset{x, 0.0F, z}; leg_nw = Vector3Add(
leg_nw =
offset +
Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F, Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F,
(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV} + (call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV},
Vector3Scale(nw, body_feet_radius); Vector3Scale(nw, body_feet_radius));
target_leg_nw = leg_nw; target_leg_nw = leg_nw;
leg_ne = leg_ne = Vector3Add(
offset +
Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F, Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F,
(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV} + (call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV},
Vector3Scale(ne, body_feet_radius); Vector3Scale(ne, body_feet_radius));
target_leg_ne = leg_ne; target_leg_ne = leg_ne;
leg_sw = leg_sw = Vector3Add(
offset +
Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F, Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F,
(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV} + (call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV},
Vector3Scale(sw, body_feet_radius); Vector3Scale(sw, body_feet_radius));
target_leg_sw = leg_sw; target_leg_sw = leg_sw;
leg_se = leg_se = Vector3Add(
offset +
Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F, Vector3{(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV, 0.0F,
(call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV} + (call_js_get_random() - 0.5F) / FEET_INIT_POS_VARIANCE_DIV},
Vector3Scale(se, body_feet_radius); Vector3Scale(se, body_feet_radius));
target_leg_se = leg_se; target_leg_se = leg_se;
} }
@ -85,11 +71,7 @@ void Walker::draw(const Model &model) {
.boneCount = model.boneCount, .boneCount = model.boneCount,
.bones = model.bones, .bones = model.bones,
.bindPose = model.bindPose}, .bindPose = model.bindPose},
Vector3{body_pos.x, body_pos, 1.0F, WHITE);
body_pos.y + BODY_IDLE_MOVE_AMOUNT *
std::sin(body_idle_move_timer + PI),
body_pos.z},
1.0F, WHITE);
// draw legs // draw legs
DrawModel(Model{.transform = model.transform * rotationMatrix, DrawModel(Model{.transform = model.transform * rotationMatrix,

View file

@ -13,8 +13,6 @@
// local includes // local includes
#include "3d_helpers.h" #include "3d_helpers.h"
#include "common_constants.h"
#include "ems.h"
constexpr float FEET_RADIUS_PLACEMENT_CHECK_SCALE = 1.0F; constexpr float FEET_RADIUS_PLACEMENT_CHECK_SCALE = 1.0F;
constexpr float FEET_RADIUS_PLACEMENT_SCALE = 0.9F; constexpr float FEET_RADIUS_PLACEMENT_SCALE = 0.9F;
@ -25,15 +23,11 @@ constexpr float FEET_LIFT_SPEED = 5.5F;
constexpr float FEET_HORIZ_MOVE_SPEED = 8.0F; constexpr float FEET_HORIZ_MOVE_SPEED = 8.0F;
constexpr float FEET_INIT_POS_VARIANCE_DIV = 3.0F; constexpr float FEET_INIT_POS_VARIANCE_DIV = 3.0F;
constexpr float BODY_ROTATION_SPEED = 1.0F; constexpr float BODY_ROTATION_SPEED = 1.0F;
constexpr float BODY_IDLE_TIMER_RATE = 1.0F;
constexpr float BODY_IDLE_MOVE_AMOUNT = 0.2F;
constexpr float ROAMING_WAIT_AMOUNT = 2.0F;
constexpr float ROAMING_WAIT_VARIANCE = 7.0F;
class Walker { class Walker {
public: public:
Walker(float x, float z, bool auto_roaming, float body_height = 2.0F, Walker(float body_height = 2.0F, float body_feet_radius = 1.7F,
float body_feet_radius = 1.7F, float feet_radius = 1.5F); float feet_radius = 1.5F);
template <typename TBBS> template <typename TBBS>
void update(float dt, const TBBS &bbs, unsigned int width, void update(float dt, const TBBS &bbs, unsigned int width,
@ -62,7 +56,6 @@ class Walker {
// ???? ??00 - body stopped // ???? ??00 - body stopped
// ???? ??01 - rotating to move // ???? ??01 - rotating to move
// ???? ??10 - moving // ???? ??10 - moving
// ???? ?1?? - auto roaming
unsigned int flags; unsigned int flags;
const float body_height; const float body_height;
@ -71,37 +64,11 @@ class Walker {
float lift_start_y; float lift_start_y;
float rotation; float rotation;
float target_rotation; float target_rotation;
float body_idle_move_timer;
float roaming_time;
float roaming_timer;
}; };
template <typename TBBS> template <typename TBBS>
void Walker::update(float dt, const TBBS &bbs, unsigned int width, void Walker::update(float dt, const TBBS &bbs, unsigned int width,
unsigned int height) { unsigned int height) {
if ((flags & 4) != 0 && (flags & 3) == 0) {
roaming_timer += dt;
if (roaming_timer > roaming_time) {
roaming_timer = 0.0F;
roaming_time =
call_js_get_random() * ROAMING_WAIT_VARIANCE + ROAMING_WAIT_AMOUNT;
unsigned int idx = call_js_get_random() * (float)bbs.size();
float x = (float)(idx % width) - SURFACE_X_OFFSET;
float y = 0.0F;
float z = (float)(idx / width) - SURFACE_Y_OFFSET;
Ray downwards{.position = Vector3{x, 20.0F, z},
.direction = Vector3{0.0F, -1.0F, 0.0F}};
for (const auto &bb : bbs) {
if (GetRayCollisionBox(downwards, bb).hit) {
y = (bb.min.y + bb.max.y) / 2.0F;
}
}
set_body_pos(Vector3{x, y, z});
}
}
const auto initialized_setup_fn = [&bbs](Vector3 &leg, Vector3 &leg_target) { const auto initialized_setup_fn = [&bbs](Vector3 &leg, Vector3 &leg_target) {
Ray downwards{.position = leg, .direction = Vector3{0.0F, -1.0F, 0.0F}}; Ray downwards{.position = leg, .direction = Vector3{0.0F, -1.0F, 0.0F}};
for (const auto &bb : bbs) { for (const auto &bb : bbs) {
@ -284,25 +251,6 @@ void Walker::update(float dt, const TBBS &bbs, unsigned int width,
update_leg_fn(target_leg_sw, leg_sw, sw_flags, update_leg_fn(target_leg_sw, leg_sw, sw_flags,
((nw_flags & 7) == 1 ? 1 : 0) + ((ne_flags & 7) == 1 ? 1 : 0) + ((nw_flags & 7) == 1 ? 1 : 0) + ((ne_flags & 7) == 1 ? 1 : 0) +
((se_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 #endif