Skip to content

Commit

Permalink
plant feet slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Barrett committed Oct 28, 2016
1 parent fdd8778 commit 1adee1e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ vec left_foot;
vec right_foot;
int left_foot_planted=0;
int right_foot_planted=0;
int left_foot_good, right_foot_good;

void render_player(vec pos, vec sz, vec ang, float bottom_z, objid player)
{
Expand Down Expand Up @@ -790,48 +791,58 @@ void render_player(vec pos, vec sz, vec ang, float bottom_z, objid player)
y_left = c * mag / 20;
z_left = s * 0.4f;
if (z_left < 0) z_left = 0;
z_left += bottom_z + 0.05;

y_right = -c * mag / 20;
z_right = -s * 0.4f;
if (z_right < 0) z_right = 0;
z_right += bottom_z + 0.05;

if (animation_state >= 0 && animation_state <= M_PI) {
if (!left_foot_planted) {
objspace_to_worldspace(&left_foot.x, player, -0.35f, y_left, 0, 0);
if (fabs(z_left - floor(z_left)) > 0.1f)
z_left = floor(z_left) + 0.05;
left_foot.x += pos.x;
left_foot.y += pos.y;
left_foot_planted = True;
left_foot.z = z_left+bottom_z+0.05;
left_foot.z = z_left;
left_foot_good = can_place_foot(left_foot, 0.3,0.3);
}

objspace_to_worldspace(&right_foot.x, player, 0.35f, y_right, 0, 0);
right_foot.x += pos.x;
right_foot.y += pos.y;
right_foot.z = z_right+bottom_z+0.05;
right_foot.z = z_right;
right_foot_planted = False;
right_foot_good = True;
} else {
if (!right_foot_planted) {
objspace_to_worldspace(&right_foot.x, player, 0.35f, y_right, 0, 0);
if (fabs(z_right - floor(z_right)) > 0.1f)
z_right = floor(z_left) + 0.05;
right_foot.x += pos.x;
right_foot.y += pos.y;
right_foot.z = z_right+bottom_z+0.05;
right_foot.z = z_right;
right_foot_planted = True;
right_foot_good = can_place_foot(right_foot, 0.3,0.3);
}
objspace_to_worldspace(&left_foot.x, player, -0.35f, y_left, 0, 0);
left_foot.x += pos.x;
left_foot.y += pos.y;
left_foot.z = z_left+bottom_z+0.05;
left_foot.z = z_left;
left_foot_planted = False;
left_foot_good = True;
}


glMaterialfv(GL_FRONT, GL_DIFFUSE , left_foot_good ? mat_diffuse : mat_red);
glPushMatrix();
glTranslatef(left_foot.x, left_foot.y, left_foot.z);
glRotatef(ang.z, 0,0,1);
stbgl_drawBox(0,0,0, 0.2f,0.4f,0.1f, 1);
glPopMatrix();

glMaterialfv(GL_FRONT, GL_DIFFUSE , mat_diffuse );
glMaterialfv(GL_FRONT, GL_DIFFUSE , right_foot_good ? mat_diffuse : mat_red);
glPushMatrix();
glTranslatef(right_foot.x, right_foot.y, right_foot.z);
glRotatef(ang.z, 0,0,1);
Expand Down
1 change: 1 addition & 0 deletions src/obbg_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extern void add_sprite(float x, float y, float z, int id);
extern void stop_manager(void);
extern Bool can_stand(path_behavior *pb, int x, int y, int z, vec3i start);
extern Bool ai_can_stand(object *o, vec3i target);
extern Bool can_place_foot(vec location, float x_rad, float y_rad);

typedef struct
{
Expand Down
29 changes: 29 additions & 0 deletions src/path.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "obbg_funcs.h"
#include <stdlib.h>
#include <math.h>

//#define OLD_PATHFIND

Expand Down Expand Up @@ -42,6 +43,34 @@ Bool can_fit(path_behavior *pb, int x, int y, int z, vec3i start)
return can_stand_raw(pb,x,y,z,start, False);
}

Bool can_place_foot(vec location, float x_rad, float y_rad)
{
int i,j;
int x0 = (int) floor(location.x - x_rad);
int x1 = (int) floor(location.x + x_rad);
int y0 = (int) floor(location.y - y_rad);
int y1 = (int) floor(location.y + y_rad);
int z = (int) floor(location.z);
int z_ground = z-1;
Bool any_ground = False;

for (j=y0; j <= y1; ++j) {
int ry = j & (MESH_CHUNK_SIZE_Y-1);
for (i=x0; i <= x1; ++i) {
int rx = i & (MESH_CHUNK_SIZE_X-1);
mesh_chunk *mc = get_physics_chunk_for_coord(i,j);
if (mc == NULL)
return False;
if (mc->pc.pathdata[ry][rx].data[z>>4] & (1 << (z&15)))
return True;
if (z_ground < 0 || (mc->pc.pathdata[ry][rx].data[z_ground>>4] & (1 << (z_ground&15)))) {
any_ground = True;
}
}
}
return any_ground;
}


#define MAX_PATH_NODES 5000
#define NUM_PQ_PRIMARY 32
Expand Down

0 comments on commit 1adee1e

Please sign in to comment.