Skip to content

Commit

Permalink
0.4.1 - inverse kinematics and stairs - VERY AWESOME. Also made the s…
Browse files Browse the repository at this point in the history
…tairs actually look like stairs now (dunno how I missed that one). And fixed several memory bugs in the loader.
  • Loading branch information
penguin673 committed Nov 22, 2008
1 parent 5dd17d7 commit 20fcbfa
Show file tree
Hide file tree
Showing 28 changed files with 393 additions and 184 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS = -I./ -DSTRICT_MEM -DDEBUG -DTIXML_USE_STL -DUSE_PUGIXML -g3 -Wall
CXXFLAGS = -I./ -DSTRICT_MEM -DDEBUG -DTIXML_USE_STL -DUSE_IK -DUSE_PUGIXML -g3 -Wall
#ifeq( $() )
#endif
pugiXML_USE_STL := YES
Expand Down Expand Up @@ -26,10 +26,10 @@ UPLOAD := python googlecode_upload.py -p 'l-echo' -s


all: $(OFILES)
gcc pugixml/*.o *.o -DTIXML_USE_STL -lGL -lGLU -lglut -lpthread -g3 -Wall -o l-echo
gcc pugixml/*.o *.o -lGL -lGLU -lglut -lpthread -g3 -Wall -o l-echo

valgrind:
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --suppressions=fglrx.supp --sim-hints=lax-ioctls ./l-echo A1.xml.real 2> summary.txt
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --suppressions=fglrx.supp --sim-hints=lax-ioctls ./l-echo -t A1.xml.real 2> summary.txt
sed 's|.*/usr/lib.*|LOL|' summary.txt > summary3.txt

#lab: CXXFLAGS += -DLAB
Expand Down
113 changes: 104 additions & 9 deletions echo_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <hole.h>
#include <isect_grid.h>

#include <gen/gen.h>

//how high aboce the start grid does the character start?
#define STARTY 30

Expand Down Expand Up @@ -329,6 +331,25 @@ void echo_char::step()
}
}

vector3f* echo_char::get_direction()
{
if(grid2) //if both grids are there
{
grid_info_t* i1 = grid1->get_info(echo_ns::angle);
if(i1)
{
vector3f pos1 = i1->pos;
grid_info_t* i2 = grid2->get_info(echo_ns::angle);
if(i2)
{
vector3f pos2 = i2->pos;
return(pos2.sub_new(&pos1));
}
}
}
return(NULL);
}

void echo_char::draw(vector3f vec)
{
draw(vec.x, vec.y, vec.z);
Expand All @@ -354,18 +375,92 @@ void echo_char::draw(float x, float y, float z)
}
if(main_grid)
{
y += grid2->vert_shift(main_per);
float vshift = main_grid->vert_shift(main_per);
y += vshift;
//gfx_translatef(0, grid2->vert_shift(main_per), 0);
joints.rshoulder_swing = -20 * echo_cos(dist_traveled_cyclic);
joints.lshoulder_swing = 20 * echo_cos(dist_traveled_cyclic);
joints.rarm_bend = -10 * echo_cos(dist_traveled_cyclic) - 20;
joints.larm_bend = 10 * echo_cos(dist_traveled_cyclic) - 20;
joints.rthigh_lift = -45 * echo_cos(dist_traveled_cyclic);
joints.lthigh_lift = 45 * echo_cos(dist_traveled_cyclic);
joints.rshoulder_swing = -20 * echo_sin(dist_traveled_cyclic);
joints.lshoulder_swing = 20 * echo_sin(dist_traveled_cyclic);
joints.rarm_bend = -10 * echo_sin(dist_traveled_cyclic) - 20;
joints.larm_bend = 10 * echo_sin(dist_traveled_cyclic) - 20;
joints.rthigh_lift = 35 * echo_sin(dist_traveled_cyclic) - 15;
joints.lthigh_lift = -35 * echo_sin(dist_traveled_cyclic) - 15;

#ifdef USE_IK
vector3f* foot_vec = get_direction();

if(foot_vec != NULL)
{
vector3f* up = new vector3f(0, 1, 0);
CHKPTR(up);

float left_dir_angle = 0;
foot_vec->scalar_angle(up, &left_dir_angle);
const float left_dist_foot = (vshift + 0.825f) * echo_sin(abs(joints.lthigh_lift))
/ echo_sin(left_dir_angle);

float right_dir_angle = 0;
foot_vec->scalar_angle(up, &right_dir_angle);
float right_dist_foot = (vshift + 0.825f) * echo_sin(abs(joints.rthigh_lift))
/ echo_sin(right_dir_angle);
//ECHO_PRINT("rdf: %f\n", right_dist_foot);
float temp = joints.rleg_bend;
if(IK_angle(0.5f, 0.65f, right_dist_foot, &joints.rleg_bend) == WIN)
{
//ECHO_PRINT("joints.rleg_bend: %f\n", joints.rleg_bend);
if(joints.rleg_bend == 0 || joints.rleg_bend != joints.rleg_bend)
joints.rleg_bend = temp;
else if(joints.rleg_bend > 90)
joints.rleg_bend -= 90;
//ECHO_PRINT("joints.rleg_bend: %f\n", joints.rleg_bend);
temp = joints.lleg_bend;
if(IK_angle(0.5f, 0.65f, left_dist_foot, &joints.lleg_bend) == WIN)
{
if(joints.lleg_bend == 0 || joints.lleg_bend != joints.lleg_bend)
joints.lleg_bend = temp;
else if(joints.lleg_bend > 90)
joints.lleg_bend -= 90;
}
else
echo_error("Inverse Kinematics failed?\n");
}
else
echo_error("Inverse Kinematics failed?\n");

delete up;
delete foot_vec;
}
else
{
float temp = joints.rleg_bend;
if(IK_angle(0.5f, 0.65f, (vshift + 1.175f)
/ echo_cos(joints.rthigh_lift), &joints.rleg_bend) == WIN)
{
if(joints.rleg_bend == 0)
joints.rleg_bend = temp;
temp = joints.lleg_bend;
if(IK_angle(0.5f, 0.65f, (vshift + 1.175f)
/ echo_cos(joints.lthigh_lift), &joints.lleg_bend) == WIN)
{
if(joints.lleg_bend == 0)
joints.lleg_bend = temp;
}
else
echo_error("Inverse Kinematics failed?\n");
}
else
echo_error("Inverse Kinematics failed?\n");
}


/*
ECHO_PRINT("joints.lthigh_lift: %f\n", joints.lthigh_lift);
ECHO_PRINT("echo_cos(joints.lthigh_lift): %f\n", echo_cos(joints.lthigh_lift));
ECHO_PRINT("dist: %f\n", (vshift + 1.837f) / echo_cos(joints.lthigh_lift));
ECHO_PRINT("lleg: %f\n", joints.lleg_bend);
// */
#else
#define LEG_BEND_MAX 30

//*
if(dist_traveled > 1 && dist_traveled <= 1.5f)
joints.rleg_bend = LEG_BEND_MAX * echo_cos(dist_traveled * 180 + 180);
else if(dist_traveled > 3.0f || dist_traveled <= 1)
Expand All @@ -378,7 +473,7 @@ void echo_char::draw(float x, float y, float z)
joints.lleg_bend = LEG_BEND_MAX * echo_sin(dist_traveled * 45 - 90);
else
joints.lleg_bend = 0;
// */
#endif
}
gfx_translatef(x, y, z);
//direction he is facing.
Expand Down
2 changes: 2 additions & 0 deletions echo_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class echo_char

void toggle_run();

vector3f* get_direction();

//pause or unpause
void toggle_pause();
//is this character paused?
Expand Down
5 changes: 5 additions & 0 deletions echo_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ void genmemerr()
//*c = 'l';
}

void echo_error(const char* msg)
{
ECHO_PRINT(msg);
std::exit(1);
}
1 change: 1 addition & 0 deletions echo_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void ldwarn(const char* msg);

//GENeral MEMory ERRor
void genmemerr();
void echo_error(const char* msg);

#ifdef STRICT_MEM
#define CHKPTR(ptr) if(!(ptr)) genmemerr();
Expand Down
4 changes: 2 additions & 2 deletions echo_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void draw_character(echo_char_joints* joints)
draw_sphere_pointzero75();
if(joints != NULL)
gfx_rotatef(joints->lfoot_x, 1, 0, 0);
glTranslatef(0.01f, -0.15f, -0.075f);
glTranslatef(0.01f, -0.15f, 0.025f);
SET_ID(11);
draw_foot();
}
Expand Down Expand Up @@ -379,7 +379,7 @@ void draw_character(echo_char_joints* joints)
draw_sphere_pointzero75();
if(joints != NULL)
gfx_rotatef(joints->rfoot_x, 1, 0, 0);
glTranslatef(-0.01f, -0.15f, -0.075f);
glTranslatef(-0.01f, -0.15f, 0.025f);
SET_ID(11);
draw_foot();
}
Expand Down
15 changes: 14 additions & 1 deletion echo_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ stage* load_stage(char* file_name)
#endif
{
lderr("parse not successful!");
delete (*root);
delete root;
delete child;
delete e;
echo_xml_delete_file(*doc);
Expand All @@ -253,6 +255,8 @@ stage* load_stage(char* file_name)
{

lderr("unknown node type!");
delete (*root);
delete root;
delete child;
delete e;
echo_xml_delete_file(*doc);
Expand All @@ -269,6 +273,8 @@ stage* load_stage(char* file_name)
else
{
lderr("couldn't get node type!\n");
delete (*root);
delete root;
delete child;
delete e;
echo_xml_delete_file(*doc);
Expand All @@ -282,9 +288,10 @@ stage* load_stage(char* file_name)
return(NULL);
}
}
while(echo_xml_next_sibling(*child , child));
while(echo_xml_next_sibling(*child, child));
delete e;
}
//delete *child;
delete child;
//-------------------------------------------------------------get starting point string
char** start = new(char*);
Expand Down Expand Up @@ -364,6 +371,7 @@ stage* load_stage(char* file_name)
delete_dependencies(map);
echo_xml_delete_file(*doc);
delete doc;
delete (*root);
delete root;
//-------------------------------------------------------------hand out the polyIDs
#ifdef ECHO_NDS
Expand Down Expand Up @@ -559,6 +567,7 @@ static int add_esc(echo_xml_element* child, stage* st, DEPENDENCY_MAP* map, escg
if(g != NULL)
{
egrid->add(each_angle, g);
delete *first;
delete first;
delete e;
delete type;
Expand All @@ -573,6 +582,7 @@ static int add_esc(echo_xml_element* child, stage* st, DEPENDENCY_MAP* map, escg
}
else
lderr("no esc in angle!");
delete *first;
delete first;
}
else
Expand Down Expand Up @@ -889,6 +899,7 @@ static trigger* get_trigger(echo_xml_element* txe, stage* st, DEPENDENCY_MAP* ma
}
delete e;
}
delete *first;
delete first;
char* name = get_attribute(txe, "id", "no id for trigger");
if(name != NULL)
Expand Down Expand Up @@ -1228,6 +1239,7 @@ static grid* parse_grid(echo_xml_element* txe, stage* st, DEPENDENCY_MAP* map, e
delete e;
}
}
delete *first;
delete first;
//dep check
FUNCTOR_VEC* deps = dep_set(map, name);
Expand All @@ -1246,6 +1258,7 @@ static grid* parse_grid(echo_xml_element* txe, stage* st, DEPENDENCY_MAP* map, e
}
else
LD_PRINT("deps not found for: %s\n", name);
delete type;
return(new_grid);

}
Expand Down
Loading

0 comments on commit 20fcbfa

Please sign in to comment.