Skip to content

Commit

Permalink
added a prefs system (UNTESTED!) and WALKING ANIMATION!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
penguin673 committed Oct 25, 2008
1 parent a28a913 commit 3f5ab91
Show file tree
Hide file tree
Showing 18 changed files with 546 additions and 88 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ CXXFLAGS = -I./ -DSTRICT_MEM -DDEBUG -DTIXML_USE_STL -g3 -Wall
#endif
TINYXML_USE_STL := YES

DEVELOPER_SDK_DIR := /opt/mac/SDKs

CFLAGS := -isysroot /opt/mac/SDKs/MacOSX10.5.sdk
CPPFILES := $(wildcard *.cpp) $(wildcard tinyxml/*.cpp) $(wildcard ext/*.cpp)

OFILES := $(CPPFILES:.cpp=.o)
Expand Down Expand Up @@ -34,8 +37,9 @@ lab: $(OFILES)
w32: $(OBJFILES)
i586-mingw32msvc-g++ *.OBJ tinyxml/*.OBJ glut32.lib -lGL -lGLU -g3 -Wall -o l-echo.exe

%.DO: CXXFLAGS += -isysroot /opt/mac/SDKs/MacOSX10.5.sdk -I/opt/mac/SDKs/MacOSX10.5.sdk/usr/include
%.DO: %.cpp
powerpc-apple-darwin8-g++ -arch i386 -arch ppc $(CXXFLAGS) -c -o $@ $<
powerpc-apple-darwin8-g++ -arch i386 -arch ppc $(CXXFLAGS) -c -o $@ $<

mac: $(DOFILES)
powerpc-apple-darwin8-g++ -arch i386 -arch ppc *.DO tinyxml/*.DO -framework OpenGL -framework GLUT -g3 -Wall -o l-echo-mac
Expand Down
32 changes: 32 additions & 0 deletions echo_char_joints.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// echo_char_joints.cpp

/*
This file is part of L-Echo.
L-Echo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
L-Echo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_char_joints.h>
#include <echo_debug.h>
#include <echo_error.h>

int reset_joints(echo_char_joints* joints)
{
if(!joints)
return(FAIL);
for(int each = 0; each < NUM_VALUES; each++)
joints->value[each] = 0;
//joints->waist_turn = 60;
return(WIN);
}
114 changes: 114 additions & 0 deletions echo_char_joints.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// echo_char_joints.h

/*
This file is part of L-Echo.
L-Echo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
L-Echo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_debug.h>

#ifndef __ECHO_CHAR_JOINTS__
#define __ECHO_CHAR_JOINTS__
#define NUM_VALUES 27 //just count them
/** This union represents the joints and possible ways of bending them (at least, based on my body)
* This is setup so that there are two ways to access a value:
* 1) joints->[joint/body part]_[axis of rotation] (front is negative z, up is positive y, right is negative x)
* (positive is clockwise)
* 2) joints->[joint/body part (may be different)]_[action]
* For example: lhand_x is the same as lwrist
**/
typedef union
{
float value[27];
struct
{
float head_x; //nodding
float head_y; //turning head
float head_z; //tilting head
float waist_y; //turning waist
float waist_z; //bowing

float lthigh_x; //lifting leg
float lthigh_y; //twisting leg (roll)
float lthigh_z; //opening legs

float lleg_x; //bending leg
float lfoot_x; //flexing foot

float rthigh_x; //lifting leg
float rthigh_y; //twisting leg (roll)
float rthigh_z; //opening legs

float rleg_x; //bending leg
float rfoot_x; //flexing foot

float lshoulder_z; //flapping arms
float lshoulder_y; //pushing out
float lshoulder_x; //swinging arms

float larm_x; //bending elbow
float larm_y; //twisting arm
float lhand_x; //wrist

float rshoulder_z; //flapping arms
float rshoulder_y; //pushing out
float rshoulder_x; //swinging arms

float rarm_x; //bending elbow
float rarm_y; //twisting arm
float rhand_x; //wrist
};
struct
{
float head_nod; //nodding
float head_turn; //turning head
float head_tilt; //tilting head
float waist_turn; //turning waist
float waist_bow; //bowing

float lthigh_lift; //lifting leg
float lthigh_twist; //twisting leg (roll)
float lthigh_open; //opening legs

float lleg_bend; //bending leg
float lfoot_bend; //flexing foot

float rthigh_lift; //lifting leg
float rthigh_twist; //twisting leg (roll)
float rthigh_open; //opening legs

float rleg_bend; //bending leg
float rfoot_bend; //flexing foot

float lshoulder_flap; //flapping arms
float lshoulder_push; //pushing out
float lshoulder_swing; //swinging arms

float larm_bend; //bending elbow
float larm_twist; //twisting arm
float lwrist; //wrist

float rshoulder_flap; //flapping arms
float rshoulder_push; //pushing out
float rshoulder_swing; //swinging arms

float rarm_bend; //bending elbow
float rarm_twist; //twisting arm
float rwrist; //wrist
};
} echo_char_joints;

int reset_joints(echo_char_joints* joints);
#endif
76 changes: 66 additions & 10 deletions echo_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <iostream>
#include <typeinfo>
#include <cmath>
#include <cfloat>

#include <echo_platform.h>
#include <echo_sys.h>
Expand All @@ -29,6 +30,7 @@
#include <echo_math.h>
#include <echo_ns.h>
#include <echo_character.h>
#include <echo_char_joints.h>

#include <launcher.h>
#include <grid.h>
Expand All @@ -55,7 +57,7 @@
#define SPEED_FALL_FROM_SKY 0.15f
#else
//various character speeds
#define SPEED_STEP 0.08f
#define SPEED_STEP 0.12f
#define SPEED_RUN 0.25f
#define SPEED_FALL 0.50f
#define SPEED_LAUNCH 0.30f
Expand Down Expand Up @@ -145,6 +147,9 @@ void echo_char::init(grid * g1)
start = grid1 = g1;
grid2 = g1 ? grid1->get_next(echo_ns::angle, grid1) : NULL;

dist_traveled = 0;
dist_traveled_cyclic = 0;

paused = 0;
grid1per = 1;
grid2per = 0;
Expand All @@ -157,6 +162,7 @@ void echo_char::init(grid * g1)
#ifdef HAS_ACCEL
is_accel = NO_FALL;
#endif
reset_joints(&joints);
change_speed();
}

Expand Down Expand Up @@ -247,9 +253,25 @@ void echo_char::step()
vector3f pos2 = i2->pos;
if(!paused)
{
dist_traveled += speed;
dist_traveled_cyclic += speed * 180;
if(dist_traveled_cyclic > 720)
{
dist_traveled -= 4;
dist_traveled_cyclic -= 720;
}
dist = pos1.dist(pos2);
grid1per -= speed / dist; //step thru it
grid2per += speed / dist;
if((dist_traveled > 0.5f && dist_traveled <= 1)
|| (dist_traveled > 2.5f && dist_traveled <= 3))
{
grid1per -= (1 + 0.75f * echo_cos(360 * dist_traveled)) * speed / dist; //step thru it
grid2per += (1 + 0.75f * echo_cos(360 * dist_traveled)) * speed / dist;
}
else
{
grid1per -= speed / dist; //step thru it
grid2per += speed / dist;
}
#ifdef HAS_ACCEL
if(is_accel == FALL_FROM_HOLE)
speed += ACCEL;
Expand All @@ -269,10 +291,6 @@ void echo_char::step()
if(i2)
{
vector3f pos2 = i2->pos;
draw(pos1.x * grid1per + pos2.x * grid2per,
pos1.y * grid1per + pos2.y * grid2per,
pos1.z * grid1per + pos2.z * grid2per);
return;
}
}
}
Expand Down Expand Up @@ -309,6 +327,43 @@ void echo_char::draw(float x, float y, float z)
//*
gfx_push_matrix();
gfx_translatef(x, y, z);
float main_per = 0;
grid* main_grid = NULL;
if(grid1 && grid1per >= 0.5f)
{
main_per = grid1per;
main_grid = grid1;
}
else if(grid2 && grid2per >= 0.5f)
{
main_per = grid2per;
main_grid = grid2;
}
if(main_grid)
{
gfx_translatef(0, grid2->vert_shift(main_per), 0);
joints.rshoulder_swing = -20 * echo_cos(dist_traveled_cyclic / 2);
joints.lshoulder_swing = 20 * echo_cos(dist_traveled_cyclic / 2);
joints.rarm_bend = -10 * echo_cos(dist_traveled_cyclic / 2) - 20;
joints.larm_bend = 10 * echo_cos(dist_traveled_cyclic / 2) - 20;
joints.rthigh_lift = -45 * echo_cos(dist_traveled_cyclic / 2);
joints.lthigh_lift = 45 * echo_cos(dist_traveled_cyclic / 2);

#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)
joints.rleg_bend = LEG_BEND_MAX * echo_sin(dist_traveled * 45);
else
joints.rleg_bend = 0;
if(dist_traveled > 3 && dist_traveled <= 3.5f)
joints.lleg_bend = LEG_BEND_MAX * echo_cos(dist_traveled * 180 + 180);
else if(dist_traveled > 1.0f && dist_traveled <= 3)
joints.lleg_bend = LEG_BEND_MAX * echo_sin(dist_traveled * 45 - 90);
else
joints.lleg_bend = 0;
}
if(grid1 && grid2)
{
grid_info_t* i1 = grid1->get_info(echo_ns::angle);
Expand All @@ -322,13 +377,14 @@ void echo_char::draw(float x, float y, float z)
#ifndef ECHO_NDS
//gfx_colorf
gfx_outline_start();
draw_character();
draw_character(&joints);
gfx_outline_mid();
draw_character();
draw_character(&joints);
gfx_outline_end();
//ECHO_PRINT("joints->rthigh_lift: %f\n", joints.rthigh_lift);
#else
gfx_set_polyID(1);
draw_character();
draw_character(&joints);
#endif
gfx_pop_matrix();
// */
Expand Down
7 changes: 6 additions & 1 deletion echo_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <echo_math.h>
#include <grid.h>
#include <echo_stage.h>
#include <echo_char_joints.h>

#ifndef __ECHO_CHARACTER__
#define __ECHO_CHARACTER__
Expand Down Expand Up @@ -52,8 +53,12 @@ class echo_char
dist is the distance between the two grids.
weight +=/-= (speed / dist) each step;
dist_traveled is used to remember the amount of distance traveled so that I can do animations accordingly
*/
float grid1per, grid2per, startper, speed, dist, act_speed;
float grid1per, grid2per, startper, speed, dist, act_speed, dist_traveled, dist_traveled_cyclic;
//the rotations of the joints
echo_char_joints joints;

public:
//default constructor
Expand Down
1 change: 1 addition & 0 deletions echo_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#else
#include <cstdio>

//#warning "lol"
#define ECHO_PRINT printf
#endif

Expand Down
3 changes: 3 additions & 0 deletions echo_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <cstdlib>
#include <iostream>

#define WIN 0
#define FAIL -1

void lderr(const char* msg);
void ldmemerr();
void lderr(const char* msg1, const char* msg2);
Expand Down
Loading

0 comments on commit 3f5ab91

Please sign in to comment.