Skip to content

Commit

Permalink
started launchers, fixed a isect_grid bug (pos.y in get_next was 0, s…
Browse files Browse the repository at this point in the history
…o end_pt was nan)
  • Loading branch information
penguin673 committed May 27, 2008
1 parent 0202ac2 commit becd857
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
CXXFLAGS = -I./ -I../include -DTIXML_USE_STL -g3 -Wall
TINYXML_USE_STL := YES

CPPFILES := $(wildcard *.cpp)
CPPFILES := $(wildcard *.cpp) $(wildcard tinyxml/*.cpp)

LINFILES := $(wildcard lin/*.cpp)
OFILES := $(CPPFILES:.cpp=.o) $(LINFILES:.cpp=.o)

WINFILES := $(wildcard win/*.cpp)
OBJFILES := $(CPPFILES:.cpp=.OBJ) $(WINFILES:.cpp=.OBJ)

PKGPREFIX := ../l-echo-0.0.8_r16-
PKGPREFIX := ../l-echo-0.0.8_r23-

all: $(OFILES)
gcc tinyxml/*.o *.o lin/*.o -DTIXML_USE_STL -lGL -lGLU /usr/lib/libglut.so.3.8.0 -lpthread -g3 -Wall -o l-echo
Expand All @@ -36,6 +36,6 @@ package: all w32
zip -r $(PKGPREFIX)lin32.zip l-echo *.xml L_ECHO_README
zip -r $(PKGPREFIX)w32.zip l-echo.exe *.xml L_ECHO_README

commit: clean-all
svn commit ./ --username penguin673
count:
wc -l *.cpp *.h lin/*.cpp win/*.cpp

15 changes: 15 additions & 0 deletions echo_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <vector>
#include <map>

#include <launcher.h>
#include <stair.h>
#include <t_grid.h>
#include <escgrid.h>
Expand Down Expand Up @@ -228,6 +229,20 @@ static grid* parse_grid(TiXmlElement* txe, stage* st, DEPENDENCY_MAP* map, escgr
}
}
}
else if(!strcmp(type, "launcher"))
{
std::cout << name << " is an launcher!" << std::endl;
new_grid = new launcher(info, prev, next);
if(txe->FirstChild())
{
TiXmlElement* child = txe->FirstChild()->ToElement();
while(child)
{
add_esc(child, st, map, escroot, (escgrid*)new_grid);
child = child->NextSiblingElement();
}
}
}
else if(!strcmp(type, "stair"))
{
std::cout << name << " is a stair!" << std::endl;
Expand Down
6 changes: 6 additions & 0 deletions echo_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,9 @@ int angle_range::is_vec_in(vector3f v)
&& IN_BETWEEN(v1->z, v.z, v2->z));
}

vector3f* vector3f::rotate_about_y(float angle)
{
return(new vector3f(z * echo_sin(angle) + x * echo_cos(angle)
, y, z * echo_cos(angle) - x * echo_sin(angle)));
}

3 changes: 1 addition & 2 deletions echo_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ class vector3f
float length();
vector3f* angle_xy();
vector3f* rotate_xy(vector3f rot);
//vector3f* rotate_yx(vector3f rot);
//vector3f* neg_rotate_xy(vector3f rot);
vector3f* neg_rotate_yx(vector3f rot);
vector3f* rotate_about_y(float angle);
vector3f normalize_angle();
vector3f negate();
float dist(vector3f other);
Expand Down
3 changes: 2 additions & 1 deletion isect_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ grid* isect_grid::get_next(vector3f angle, grid* current)
float delta_y = level_y - prev_pos.y;
if((delta_y > 0 && vec.y < 0) || (delta_y < 0 && vec.y > 0))
return(grid::get_next(angle, current));
vec = vec * (delta_y / vec.y);
if(vec.y != 0)
vec = vec * (delta_y / vec.y);
vector3f end_pt = prev_pos + vec;
/*
std::cout << "end_pt: " << std::endl;
Expand Down
189 changes: 189 additions & 0 deletions launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// launcher.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 <cmath>
#include <iostream>

#include <echo_ns.h>
#include <echo_gfx.h>
#include <launcher.h>
#include <echo_math.h>
#include <grid.h>
#include <isect_grid.h>

launcher::launcher() : escgrid()
{

}

launcher::launcher(vector3f* my_escangle, grid_info_t* my_normal_info, grid_info_t* my_esc_info
, grid* my_normal_prev, grid* my_esc_prev, grid* my_normal_next, grid* my_esc_next)
{
init(my_escangle, my_normal_info, my_esc_info, my_normal_prev, my_esc_prev, my_normal_next, my_esc_next);
}

launcher::launcher(grid_info_t* my_info, grid* my_prev, grid* my_next, angle_range** my_escranges, grid** my_escs, int my_num_escs)
{
init(my_info, my_prev, my_next, my_escranges, my_escs, my_num_escs);
}

launcher::launcher(grid_info_t* my_info, grid* my_prev, grid* my_next)
{
init(my_info, my_prev, my_next);
}

void launcher::init(vector3f* my_escangle, grid_info_t* my_normal_info, grid_info_t* my_esc_info
, grid* my_normal_prev, grid* my_esc_prev, grid* my_normal_next, grid* my_esc_next)
{
escgrid::init(my_escangle, my_normal_info, my_esc_info, echo_ns::hole_grid, my_esc_prev, echo_ns::hole_grid, my_esc_next);
real_prev = my_normal_prev;
real_next = my_normal_next;
}

void launcher::init(grid_info_t* my_info, grid* my_prev, grid* my_next, angle_range** my_escranges, grid** my_escs, int my_num_escs)
{
escgrid::init(my_info, echo_ns::hole_grid, echo_ns::hole_grid, my_escranges, my_escs, my_num_escs);
real_prev = my_prev;
real_next = my_next;
}

void launcher::init(grid_info_t* my_info, grid* my_prev, grid* my_next)
{
launcher::init(my_info, my_prev, my_next, NULL, NULL, 0);
}

launcher::~launcher()
{
}

void launcher::draw(vector3f angle)
{
escgrid::draw(angle);
draw_launcher(get_info(angle)->pos);
}

void launcher::set_real_next(grid* g)
{
real_next = g;
}

void launcher::set_real_prev(grid* g)
{
real_prev = g;
}

grid* launcher::get_real_next()
{
return(real_next);
}

grid* launcher::get_real_prev()
{
return(real_prev);
}

#define VERTEX_Z 2
#define VERTEX_Y 4
#define STATIC_STEP 0.25f
#define GET_Z(y) (2 + sqrtf(4 - (y)))
#define GET_Y(z) (4 - powf((z) - 2, 2))
#define TRANS_TO_LAUNCH(vec, angle, pos) (*(vec.rotate_about_y(angle)) + pos)
#define TRANS_PTR_TO_LAUNCH(vec, angle, pos) (*(vec->rotate_about_y(angle)) + pos)

grid* launcher::get_next(vector3f angle, grid* current)
{
grid* esc = get_esc(angle);
if(esc)
return(esc->get_next(angle, current));
vector3f pos = get_info(angle)->pos;

grid* my_prev = get_real_prev();
vector3f* direction;
if(my_prev)
{
grid_info_t* info = my_prev->get_info(angle);
direction = info ? &(pos - info->pos) : new vector3f(0, 0, 1);
}
else
direction = new vector3f(0, 0, 1);

float launch_angle = TO_DEG(atan2f(direction->x, direction->z));
std::cout << "angle of launcher: " << launch_angle << std::endl;

/*
vector3f* vertex = new vector3f(0, VERTEX_Y, VERTEX_Z);
vector3f rotated_vertex = TRANS_TO_LAUNCH(vertex, launch_angle, pos);
std::cout << "translated vertex: ";
rotated_vertex.dump();
std::cout << std::endl;
// */

grid* begin = NULL;
grid* temp1 = this;
grid* temp2 = NULL;

float z = 0;
while(z <= VERTEX_Z)
{
grid_info_t* info = new(grid_info_t);
info->pos.set(0, GET_Y(z), z);
info->pos = TRANS_TO_LAUNCH(info->pos, launch_angle, pos);
/*
std::cout << "info->pos: ";
info->pos.dump();
std::cout << std::endl;
// */

temp2 = new static_grid(info, temp1, echo_ns::hole_grid, angle);
if(temp1 != this)
temp1->set_real_next(temp2);
temp1 = temp2;
if(!begin)
begin = temp1;

//std::cout << "z: " << z << std::endl;
z += STATIC_STEP;
}
return(begin);

/*
LEVEL_MAP* levels = echo_ns::current_stage->get_levels_lower_than(pos.y + VERTEX_Y);
if(levels->size() > 0)
{
LEVEL_MAP::iterator it = levels->begin(), end = (levels->end());
isect_grid* begin = NULL;
grid* temp = echo_ns::hole_grid;
while(it != end)
{
grid_info_t* info = new(grid_info_t);
info->pos.set(pos.x, it->first, pos.z);
//info->pos.dump();
//std::cout << std::endl;
begin = new isect_grid(info, NULL, temp, angle, it->second);
temp->set_real_prev(begin);
temp = begin;
it++;
}
begin->set_real_prev(this);
return(begin);
}
return(echo_ns::hole_grid);
// */
}

51 changes: 51 additions & 0 deletions launcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// launcher.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_math.h>
#include <grid.h>
#include <escgrid.h>

#ifndef __ECHO_CLASS_LAUNCHER__
#define __ECHO_CLASS_LAUNCHER__
class launcher : public escgrid
{
protected:
grid* real_prev;
grid* real_next;
public:
launcher();
launcher(grid_info_t* my_info, grid* my_prev, grid* my_next);
launcher(vector3f* my_escangle, grid_info_t* my_normal_info, grid_info_t* my_esc_info
, grid* my_normal_prev, grid* my_esc_prev, grid* my_normal_next, grid* my_esc_next);
launcher(grid_info_t* my_info, grid* my_prev, grid* my_next, angle_range** my_escranges, grid** my_escs, int my_num_escs);
void init(vector3f* my_escangle, grid_info_t* my_normal_info, grid_info_t* my_esc_info
, grid* my_normal_prev, grid* my_esc_prev, grid* my_normal_next, grid* my_esc_next);
void init(grid_info_t* my_info, grid* my_prev, grid* my_next, angle_range** my_escranges, grid** my_escs, int my_num_escs);
void init(grid_info_t* my_info, grid* my_prev, grid* my_next);

virtual ~launcher();
virtual grid* get_next(vector3f angle, grid* current);
virtual void draw(vector3f angle);
virtual grid* get_real_next();
virtual grid* get_real_prev();

virtual void set_real_next(grid* g);
virtual void set_real_prev(grid* g);
};
#endif
8 changes: 8 additions & 0 deletions launcher_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" standalone="no" ?>
<stage name="launcher demo" start="start" goals="0">
<grid id="start" x="-1" y="0" z="0" prev="launcher" next="launcher"/>
<launcher id="launcher" x="0" y ="0" z="0" prev="start" next="start"/>

<grid id="east1" x="4" y="0" z="0" prev="east2" next="east2" />
<grid id="east2" x="5" y="0" z="0" prev="east1" next="east1" />
</stage>

0 comments on commit becd857

Please sign in to comment.