From: Matthias Braun Date: Thu, 5 May 2005 13:28:54 +0000 (+0000) Subject: renamed Rectangle to Rect because of §%$ X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1aa0de39a5f87bda1e74d0992848ad5142a850bc;p=supertux.git renamed Rectangle to Rect because of §%$ SVN-Revision: 2405 --- diff --git a/src/collision.cpp b/src/collision.cpp index aa0631a04..cce522d5d 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -28,14 +28,14 @@ #include #include "math/vector.h" #include "math/aatriangle.h" -#include "math/rectangle.h" +#include "math/rect.h" #include "collision_hit.h" static const float DELTA = .0001; bool -Collision::rectangle_rectangle(CollisionHit& hit, const Rectangle& r1, - const Vector& movement, const Rectangle& r2) +Collision::rectangle_rectangle(CollisionHit& hit, const Rect& r1, + const Vector& movement, const Rect& r2) { if(r1.p2.x < r2.p1.x || r1.p1.x > r2.p2.x) return false; @@ -98,10 +98,10 @@ static void makePlane(const Vector& p1, const Vector& p2, Vector& n, float& c) } bool -Collision::rectangle_aatriangle(CollisionHit& hit, const Rectangle& rect, +Collision::rectangle_aatriangle(CollisionHit& hit, const Rect& rect, const Vector& movement, const AATriangle& triangle) { - if(!rectangle_rectangle(hit, rect, movement, (const Rectangle&) triangle)) + if(!rectangle_rectangle(hit, rect, movement, (const Rect&) triangle)) return false; Vector normal; diff --git a/src/collision.h b/src/collision.h index 2c65c488f..d4f58825a 100644 --- a/src/collision.h +++ b/src/collision.h @@ -22,7 +22,7 @@ #define __COLLISION_H__ class Vector; -class Rectangle; +class Rect; class AATriangle; class CollisionHit; @@ -32,13 +32,13 @@ public: /** does collision detection between 2 rectangles. Returns true in case of * collision and fills in the hit structure then. */ - static bool rectangle_rectangle(CollisionHit& hit, const Rectangle& r1, - const Vector& movement, const Rectangle& r2); + static bool rectangle_rectangle(CollisionHit& hit, const Rect& r1, + const Vector& movement, const Rect& r2); /** does collision detection between a rectangle and an axis aligned triangle * Returns true in case of a collision and fills in the hit structure then. */ - static bool rectangle_aatriangle(CollisionHit& hit, const Rectangle& rect, + static bool rectangle_aatriangle(CollisionHit& hit, const Rect& rect, const Vector& movement, const AATriangle& triangle); }; diff --git a/src/collision_grid.cpp b/src/collision_grid.cpp index 660ea8784..6ed8e4cc3 100644 --- a/src/collision_grid.cpp +++ b/src/collision_grid.cpp @@ -69,7 +69,7 @@ CollisionGrid::add_object(MovingObject* object) objects.push_back(wrapper); wrapper->id = objects.size()-1; - const Rectangle& bbox = object->bbox; + const Rect& bbox = object->bbox; for(float y = bbox.p1.y; y < bbox.p2.y; y += cell_height) { for(float x = bbox.p1.x; x < bbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); @@ -107,7 +107,7 @@ CollisionGrid::remove_object(MovingObject* object) } #endif - const Rectangle& bbox = wrapper->dest; + const Rect& bbox = wrapper->dest; for(float y = bbox.p1.y; y < bbox.p2.y; y += cell_height) { for(float x = bbox.p1.x; x < bbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); @@ -129,7 +129,7 @@ CollisionGrid::move_object(ObjectWrapper* wrapper) { // FIXME not optimal yet... should leave the gridcells untouched that don't // need to be changed. - const Rectangle& obbox = wrapper->dest; + const Rect& obbox = wrapper->dest; for(float y = obbox.p1.y; y < obbox.p2.y; y += cell_height) { for(float x = obbox.p1.x; x < obbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); @@ -143,7 +143,7 @@ CollisionGrid::move_object(ObjectWrapper* wrapper) } } - const Rectangle& nbbox = wrapper->object->bbox; + const Rect& nbbox = wrapper->object->bbox; for(float y = nbbox.p1.y; y < nbbox.p2.y; y += cell_height) { for(float x = nbbox.p1.x; x < nbbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); @@ -204,7 +204,7 @@ CollisionGrid::collide_object(ObjectWrapper* wrapper) { iterator_timestamp++; - const Rectangle& bbox = wrapper->object->bbox; + const Rect& bbox = wrapper->object->bbox; for(float y = bbox.p1.y - cell_height; y < bbox.p2.y + cell_height; y += cell_height) { for(float x = bbox.p1.x - cell_width; x < bbox.p2.x + cell_width; x += cell_width) { int gridx = int(x / cell_width); @@ -240,9 +240,9 @@ CollisionGrid::collide_object_object(ObjectWrapper* wrapper, MovingObject* object1 = wrapper->object; MovingObject* object2 = wrapper2->object; - Rectangle dest1 = object1->get_bbox(); + Rect dest1 = object1->get_bbox(); dest1.move(object1->get_movement()); - Rectangle dest2 = object2->get_bbox(); + Rect dest2 = object2->get_bbox(); dest2.move(object2->get_movement()); Vector movement = object1->get_movement() - object2->get_movement(); diff --git a/src/collision_grid.h b/src/collision_grid.h index d206c8c1d..abb2ef168 100644 --- a/src/collision_grid.h +++ b/src/collision_grid.h @@ -46,7 +46,7 @@ private: struct ObjectWrapper { MovingObject* object; - Rectangle dest; + Rect dest; /** (pseudo) timestamp. When reading from the grid the timestamp is * changed so that you can easily avoid reading an object multiple times * when it is in several cells that you check. diff --git a/src/collision_grid_iterator.h b/src/collision_grid_iterator.h index fd3350beb..3d5666161 100644 --- a/src/collision_grid_iterator.h +++ b/src/collision_grid_iterator.h @@ -20,14 +20,14 @@ #ifndef __COLLISION_GRID_ITERATOR_H__ #define __COLLISION_GRID_ITERATOR_H__ -#include "math/rectangle.h" +#include "math/rect.h" class CollisionGrid; class CollisionGridIterator { public: - CollisionGridIterator(CollisionGrid& newgrid, const Rectangle& bbox) + CollisionGridIterator(CollisionGrid& newgrid, const Rect& bbox) : grid(newgrid) { start_x = int(bbox.p1.x / grid.cell_width) - 2; diff --git a/src/math/aatriangle.h b/src/math/aatriangle.h index 4a2d81ac2..5f8537cd9 100644 --- a/src/math/aatriangle.h +++ b/src/math/aatriangle.h @@ -1,13 +1,13 @@ #ifndef __AATRIANGLE_H__ #define __AATRIANGLE_H__ -#include "rectangle.h" +#include "rect.h" /** * An axis aligned triangle (ie. a triangle where 2 sides are parallel to the x- * and y-axis. */ -class AATriangle : public Rectangle +class AATriangle : public Rect { public: /** Directions: @@ -38,7 +38,7 @@ public: { } AATriangle(const Vector& v1, const Vector& v2, int newdir) - : Rectangle(v1, v2), dir(newdir) + : Rect(v1, v2), dir(newdir) { } diff --git a/src/math/rect.h b/src/math/rect.h new file mode 100644 index 000000000..a338054c9 --- /dev/null +++ b/src/math/rect.h @@ -0,0 +1,87 @@ +#ifndef __RECT_H__ +#define __RECT_H__ + +#include +#include "vector.h" + +/** This class represents a rectangle. + * (Implementation Note) We're using upper left and lower right point instead of + * upper left and width/height here, because that makes the collision dectection + * a little bit efficienter. + */ +class Rect +{ +public: + Rect() + { } + + Rect(const Vector& np1, const Vector& np2) + : p1(np1), p2(np2) + { + } + + Rect(float x1, float y1, float x2, float y2) + : p1(x1, y1), p2(x2, y2) + { + assert(p1.x <= p2.x && p1.y <= p2.y); + } + + float get_width() const + { return p2.x - p1.x; } + + float get_height() const + { return p2.y - p1.y; } + + Vector get_middle() const + { return Vector((p1.x+p2.x)/2, (p1.y+p2.y)/2); } + + void set_pos(const Vector& v) + { + move(v-p1); + } + + void set_height(float height) + { + p2.y = p1.y + height; + } + void set_width(float width) + { + p2.x = p1.x + width; + } + void set_size(float width, float height) + { + set_width(width); + set_height(height); + } + + void move(const Vector& v) + { + p1 += v; + p2 += v; + } + + bool inside(const Vector& v) const + { + return v.x >= p1.x && v.y >= p1.y && v.x < p2.x && v.y < p2.y; + } + bool inside(const Rect& other) const + { + if(p1.x >= other.p2.x || other.p1.x >= p2.x) + return false; + if(p1.y >= other.p2.y || other.p1.y >= p2.y) + return false; + + return true; + } + + // leave these 2 public to safe the headaches of set/get functions for such + // simple things :) + + /// upper left edge + Vector p1; + /// lower right edge + Vector p2; +}; + +#endif + diff --git a/src/math/rectangle.h b/src/math/rectangle.h deleted file mode 100644 index f6be7a5e4..000000000 --- a/src/math/rectangle.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef __RECTANGLE_H__ -#define __RECTANGLE_H__ - -#include -#include "vector.h" - -/** This class represents a rectangle. - * (Implementation Note) We're using upper left and lower right point instead of - * upper left and width/height here, because that makes the collision dectection - * a little bit efficienter. - */ -class Rectangle -{ -public: - Rectangle() - { } - - Rectangle(const Vector& np1, const Vector& np2) - : p1(np1), p2(np2) - { - } - - Rectangle(float x1, float y1, float x2, float y2) - : p1(x1, y1), p2(x2, y2) - { - assert(p1.x <= p2.x && p1.y <= p2.y); - } - - float get_width() const - { return p2.x - p1.x; } - - float get_height() const - { return p2.y - p1.y; } - - Vector get_middle() const - { return Vector((p1.x+p2.x)/2, (p1.y+p2.y)/2); } - - void set_pos(const Vector& v) - { - move(v-p1); - } - - void set_height(float height) - { - p2.y = p1.y + height; - } - void set_width(float width) - { - p2.x = p1.x + width; - } - void set_size(float width, float height) - { - set_width(width); - set_height(height); - } - - void move(const Vector& v) - { - p1 += v; - p2 += v; - } - - bool inside(const Vector& v) const - { - return v.x >= p1.x && v.y >= p1.y && v.x < p2.x && v.y < p2.y; - } - bool inside(const Rectangle& other) const - { - if(p1.x >= other.p2.x || other.p1.x >= p2.x) - return false; - if(p1.y >= other.p2.y || other.p1.y >= p2.y) - return false; - - return true; - } - - // leave these 2 public to safe the headaches of set/get functions for such - // simple things :) - - /// upper left edge - Vector p1; - /// lower right edge - Vector p2; -}; - -#endif - diff --git a/src/moving_object.h b/src/moving_object.h index cd6850ca6..973595304 100644 --- a/src/moving_object.h +++ b/src/moving_object.h @@ -22,7 +22,7 @@ #include "game_object.h" #include "collision_hit.h" #include "math/vector.h" -#include "math/rectangle.h" +#include "math/rect.h" class Sector; class CollisionGrid; @@ -48,7 +48,7 @@ public: } /** returns the bounding box of the Object */ - const Rectangle& get_bbox() const + const Rect& get_bbox() const { return bbox; } @@ -74,7 +74,7 @@ protected: /** The bounding box of the object (as used for collision detection, this * isn't necessarily the bounding box for graphics) */ - Rectangle bbox; + Rect bbox; /** The movement that will happen till next frame */ Vector movement; diff --git a/src/object/particlesystem.h b/src/object/particlesystem.h index 526fbdd55..23d9e293c 100644 --- a/src/object/particlesystem.h +++ b/src/object/particlesystem.h @@ -37,7 +37,7 @@ class DisplayManager; * layer where it should be drawn and a texture. * The coordinate system used here is a virtual one. It would be a bad idea to * populate whole levels with particles. So we're using a virtual rectangle - * here that is tiled onto the level when drawing. This rectangle has the size + * here that is tiled onto the level when drawing. This rect.has the size * (virtual_width, virtual_height). We're using modulo on the particle * coordinates, so when a particle leaves left, it'll reenter at the right * side. diff --git a/src/sector.cpp b/src/sector.cpp index 1470654e2..b7884fdee 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -46,7 +46,7 @@ #include "collision_grid_iterator.h" #include "object_factory.h" #include "collision.h" -#include "math/rectangle.h" +#include "math/rect.h" #include "math/aatriangle.h" #include "object/coin.h" #include "object/block.h" @@ -422,10 +422,10 @@ Sector::activate(const Vector& player_pos) camera->reset(player->get_pos()); } -Rectangle +Rect Sector::get_active_region() { - return Rectangle( + return Rect( camera->get_translation() - Vector(1600, 1200), camera->get_translation() + Vector(1600, 1200)); } @@ -590,7 +590,7 @@ Sector::collision_tilemap(MovingObject* object, int depth) int max_y = int(y2+1); CollisionHit temphit, hit; - Rectangle dest = object->get_bbox(); + Rect dest = object->get_bbox(); dest.move(object->movement); hit.time = -1; // represents an invalid value for(int x = starttilex; x*32 < max_x; ++x) { @@ -615,7 +615,7 @@ Sector::collision_tilemap(MovingObject* object, int depth) hit = temphit; } } else { // normal rectangular tile - Rectangle rect(x*32, y*32, (x+1)*32, (y+1)*32); + Rect rect(x*32, y*32, (x+1)*32, (y+1)*32); if(Collision::rectangle_rectangle(temphit, dest, object->movement, rect)) { if(temphit.time > hit.time) @@ -647,9 +647,9 @@ void Sector::collision_object(MovingObject* object1, MovingObject* object2) { CollisionHit hit; - Rectangle dest1 = object1->get_bbox(); + Rect dest1 = object1->get_bbox(); dest1.move(object1->get_movement()); - Rectangle dest2 = object2->get_bbox(); + Rect dest2 = object2->get_bbox(); dest2.move(object2->get_movement()); Vector movement = object1->get_movement() - object2->get_movement(); @@ -803,7 +803,7 @@ Sector::get_total_badguys() } bool -Sector::inside(const Rectangle& rect) const +Sector::inside(const Rect& rect) const { if(rect.p1.x > solids->get_width() * 32 || rect.p1.y > solids->get_height() * 32 diff --git a/src/sector.h b/src/sector.h index 2067e0916..c2a8f3c47 100644 --- a/src/sector.h +++ b/src/sector.h @@ -32,7 +32,7 @@ class Lisp; class Writer; } -class Rectangle; +class Rect; class Sprite; class GameObject; class Player; @@ -86,7 +86,7 @@ public: { return name; } /// tests if a given rectangle is inside the sector - bool inside(const Rectangle& rectangle) const; + bool inside(const Rect& rectangle) const; void play_music(MusicType musictype); MusicType get_music_type(); @@ -140,7 +140,7 @@ public: // TODO make this private again typedef std::vector SpawnPoints; SpawnPoints spawnpoints; - Rectangle get_active_region(); + Rect get_active_region(); private: void fix_old_tiles(); diff --git a/src/tile.cpp b/src/tile.cpp index 20835fbd9..7fef75255 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -105,7 +105,7 @@ Tile::parse_images(const lisp::Lisp& images_lisp) if(cur->get_type() == lisp::Lisp::TYPE_STRING) { std::string file; cur->get(file); - imagespecs.push_back(ImageSpec(file, Rectangle(0, 0, 0, 0))); + imagespecs.push_back(ImageSpec(file, Rect(0, 0, 0, 0))); } else if(cur->get_type() == lisp::Lisp::TYPE_CONS && cur->get_car()->get_type() == lisp::Lisp::TYPE_SYMBOL) { const lisp::Lisp* ptr = cur->get_cdr(); @@ -117,7 +117,7 @@ Tile::parse_images(const lisp::Lisp& images_lisp) ptr->get_car()->get(y); ptr = ptr->get_cdr(); ptr->get_car()->get(w); ptr = ptr->get_cdr(); ptr->get_car()->get(h); - imagespecs.push_back(ImageSpec(file, Rectangle(x, y, x+w, y+h))); + imagespecs.push_back(ImageSpec(file, Rect(x, y, x+w, y+h))); } else { std::cerr << "Expected string or list in images tag.\n"; continue; diff --git a/src/tile.h b/src/tile.h index a9ea335a7..cfddd0217 100644 --- a/src/tile.h +++ b/src/tile.h @@ -22,7 +22,7 @@ #include #include "video/surface.h" -#include "math/rectangle.h" +#include "math/rect.h" #include "lisp/lisp.h" /** @@ -72,12 +72,12 @@ private: unsigned int id; struct ImageSpec { - ImageSpec(const std::string& newfile, const Rectangle& newrect) + ImageSpec(const std::string& newfile, const Rect& newrect) : file(newfile), rect(newrect) { } std::string file; - Rectangle rect; + Rect rect; }; std::vector imagespecs; std::vector images; diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index 72c88f867..3b59368d4 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -42,7 +42,7 @@ SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader) message_displayed = false; } -SecretAreaTrigger::SecretAreaTrigger(const Rectangle& area) +SecretAreaTrigger::SecretAreaTrigger(const Rect& area) { bbox = area; message = "You found a secret area!"; diff --git a/src/trigger/secretarea_trigger.h b/src/trigger/secretarea_trigger.h index bbc3641af..0dba229d9 100644 --- a/src/trigger/secretarea_trigger.h +++ b/src/trigger/secretarea_trigger.h @@ -30,7 +30,7 @@ class SecretAreaTrigger : public TriggerBase, public Serializable { public: SecretAreaTrigger(const lisp::Lisp& reader); - SecretAreaTrigger(const Rectangle& area); + SecretAreaTrigger(const Rect& area); ~SecretAreaTrigger(); void write(lisp::Writer& writer); diff --git a/src/trigger/trigger_base.h b/src/trigger/trigger_base.h index 3f8fdc476..9038a55ee 100644 --- a/src/trigger/trigger_base.h +++ b/src/trigger/trigger_base.h @@ -20,7 +20,7 @@ #define SUPERTUX_TRIGGER_BASE_H #include "moving_object.h" -#include "math/rectangle.h" +#include "math/rect.h" #include "sprite/sprite.h" class Player;