Rectf Class Reference

This class represents a rectangle. More...

#include <rectf.hpp>

List of all members.

Public Member Functions

 Rectf ()
 Rectf (const Vector &np1, const Vector &np2)
 Rectf (float x1, float y1, float x2, float y2)
 Rectf (const Vector &p1_, const Sizef &size)
float get_left () const
float get_right () const
float get_top () const
float get_bottom () const
float get_width () const
float get_height () const
Vector get_middle () const
void set_pos (const Vector &v)
void set_height (float height)
void set_width (float width)
void set_size (float width, float height)
Vector get_size ()
void move (const Vector &v)
bool contains (const Vector &v) const
bool contains (const Rectf &other) const
float distance (const Vector &other, AnchorPoint ap=ANCHOR_MIDDLE) const
float distance (const Rectf &other, AnchorPoint ap=ANCHOR_MIDDLE) const

Public Attributes

Vector p1
 upper left edge
Vector p2
 lower right edge


Detailed Description

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 detection a little bit more efficient.

Definition at line 32 of file rectf.hpp.


Constructor & Destructor Documentation

Rectf::Rectf (  )  [inline]

Definition at line 35 of file rectf.hpp.

00035           :
00036     p1(),
00037     p2()
00038   { }

Rectf::Rectf ( const Vector np1,
const Vector np2 
) [inline]

Definition at line 40 of file rectf.hpp.

00040                                               :
00041     p1(np1), p2(np2)
00042   {
00043   }

Rectf::Rectf ( float  x1,
float  y1,
float  x2,
float  y2 
) [inline]

Definition at line 45 of file rectf.hpp.

References p1, p2, Vector::x, and Vector::y.

00045                                                 :
00046     p1(x1, y1), p2(x2, y2)
00047   {
00048     assert(p1.x <= p2.x && p1.y <= p2.y);
00049   }

Rectf::Rectf ( const Vector p1_,
const Sizef size 
)

Definition at line 21 of file rectf.cpp.

00021                                                  :
00022   p1(p1_),
00023   p2(p1_.x + size.width, p1_.y + size.height)
00024 {
00025 }


Member Function Documentation

float Rectf::get_left (  )  const [inline]

Definition at line 53 of file rectf.hpp.

References p1, and Vector::x.

Referenced by check_collisions(), Tile::check_position_unisolid(), Sector::collision_tilemap(), GLRenderer::draw_filled_rect(), Background::draw_image(), get_anchor_pos(), get_hit_normal(), TileMap::get_tiles_overlapping(), Player::handle_input(), operator<<(), collision::rectangle_aatriangle(), collision::set_rectangle_rectangle_constraints(), and Player::try_grab().

00054   { return p1.x; }

float Rectf::get_right (  )  const [inline]

Definition at line 56 of file rectf.hpp.

References p2, and Vector::x.

Referenced by check_collisions(), Tile::check_position_unisolid(), Sector::collision_tilemap(), GLRenderer::draw_filled_rect(), Background::draw_image(), get_anchor_pos(), get_hit_normal(), TileMap::get_tiles_overlapping(), Player::handle_input(), operator<<(), collision::rectangle_aatriangle(), collision::set_rectangle_rectangle_constraints(), and Player::try_grab().

00057   { return p2.x; }

float Rectf::get_top (  )  const [inline]

Definition at line 59 of file rectf.hpp.

References p1, and Vector::y.

Referenced by check_collisions(), Tile::check_position_unisolid(), InvisibleBlock::collides(), UnstableTile::collision(), Brick::collision(), BonusBlock::collision(), Block::collision(), Sector::collision_tilemap(), GLRenderer::draw_filled_rect(), Background::draw_image(), get_anchor_pos(), get_hit_normal(), TileMap::get_tiles_overlapping(), Player::handle_input(), operator<<(), collision::rectangle_aatriangle(), and collision::set_rectangle_rectangle_constraints().

00060   { return p1.y; }

float Rectf::get_bottom (  )  const [inline]

Definition at line 62 of file rectf.hpp.

References p2, and Vector::y.

Referenced by GhostTree::active_update(), check_collisions(), Tile::check_position_unisolid(), InvisibleBlock::collides(), UnstableTile::collision(), Brick::collision(), BonusBlock::collision(), Block::collision(), Sector::collision_tilemap(), GLRenderer::draw_filled_rect(), Background::draw_image(), get_anchor_pos(), get_hit_normal(), TileMap::get_tiles_overlapping(), operator<<(), collision::rectangle_aatriangle(), collision::set_rectangle_rectangle_constraints(), Player::try_grab(), and Camera::update_scroll_normal().

00063   { return p2.y; }

float Rectf::get_width (  )  const [inline]

Definition at line 65 of file rectf.hpp.

References p1, p2, and Vector::x.

Referenced by GhostTree::active_update(), Player::adjust_height(), BicyclePlatform::BicyclePlatform(), Sector::collision_static_constrains(), Background::draw(), DrawingContext::draw_filled_rect(), Background::draw_image(), get_size(), Player::handle_input(), Dispenser::launch_badguy(), PneumaticPlatform::PneumaticPlatform(), Player::position_grabbed_object(), collision::rectangle_aatriangle(), and Block::start_bounce().

00066   { return p2.x - p1.x; }

float Rectf::get_height (  )  const [inline]

Definition at line 68 of file rectf.hpp.

References p1, p2, and Vector::y.

Referenced by GhostTree::active_update(), Player::adjust_height(), PushButton::collision(), Sector::collision_static_constrains(), Fish::collision_tile(), Background::draw(), DrawingContext::draw_filled_rect(), Background::draw_image(), get_size(), Player::handle_input(), Player::position_grabbed_object(), collision::rectangle_aatriangle(), FlipLevelTransformer::transform_block(), FlipLevelTransformer::transform_moving_object(), FlipLevelTransformer::transform_platform(), FlipLevelTransformer::transform_sector(), FlipLevelTransformer::transform_tilemap(), and Camera::update_scroll_normal().

00069   { return p2.y - p1.y; }

Vector Rectf::get_middle (  )  const [inline]

Definition at line 71 of file rectf.hpp.

References p1, p2, Vector::x, and Vector::y.

Referenced by GhostTree::active_update(), FlyingSnowBall::active_update(), Firefly::collision(), Stumpy::collision_squished(), PoisonIvy::collision_squished(), Yeti::drop_stalactite(), Explosion::explode(), get_anchor_pos(), BadGuy::is_offscreen(), MagicBlock::MagicBlock(), Candle::puff_smoke(), Block::start_bounce(), Mole::throw_rock(), Kugelblitz::try_activate(), BonusBlock::try_open(), Ispy::update(), and Camera::update_scroll_normal().

00072   { return Vector((p1.x+p2.x)/2, (p1.y+p2.y)/2); }

void Rectf::set_pos ( const Vector v  )  [inline]

Definition at line 74 of file rectf.hpp.

References move(), and p1.

Referenced by BonusBlock::BonusBlock(), Brick::Brick(), Bullet::Bullet(), Door::Door(), Flame::Flame(), InfoBlock::InfoBlock(), InvisibleBlock::InvisibleBlock(), MovingSprite::MovingSprite(), Platform::Platform(), ScriptTrigger::ScriptTrigger(), SequenceTrigger::SequenceTrigger(), MovingObject::set_pos(), and ScriptedObject::set_pos().

00075   {
00076     move(v-p1);
00077   }

void Rectf::set_height ( float  height  )  [inline]

Definition at line 79 of file rectf.hpp.

References p1, p2, and Vector::y.

Referenced by Player::adjust_height(), and set_size().

00080   {
00081     p2.y = p1.y + height;
00082   }

void Rectf::set_width ( float  width  )  [inline]

Definition at line 83 of file rectf.hpp.

References p1, p2, and Vector::x.

Referenced by set_size(), and MovingObject::set_width().

00084   {
00085     p2.x = p1.x + width;
00086   }

void Rectf::set_size ( float  width,
float  height 
) [inline]

Definition at line 87 of file rectf.hpp.

References set_height(), and set_width().

Referenced by Block::Block(), Bullet::Bullet(), Climbable::Climbable(), Totem::collision_squished(), Dispenser::Dispenser(), Door::Door(), Firefly::Firefly(), Flower::Flower(), WalkingBadguy::initialize(), Stumpy::initialize(), InvisibleWall::InvisibleWall(), Totem::jump_off(), Totem::jump_on(), MovingSprite::MovingSprite(), PushButton::PushButton(), ScriptedObject::ScriptedObject(), ScriptTrigger::ScriptTrigger(), SecretAreaTrigger::SecretAreaTrigger(), SequenceTrigger::SequenceTrigger(), MovingObject::set_size(), MrIceBlock::set_state(), Switch::Switch(), and Wind::Wind().

00088   {
00089     set_width(width);
00090     set_height(height);
00091   }

Vector Rectf::get_size (  )  [inline]

Definition at line 92 of file rectf.hpp.

References get_height(), and get_width().

Referenced by Candle::draw(), MovingSprite::set_action_centered(), and BicyclePlatform::update().

00093   {
00094     return Vector(get_width(), get_height());
00095   }

void Rectf::move ( const Vector v  )  [inline]

Definition at line 97 of file rectf.hpp.

References p1, and p2.

Referenced by Player::adjust_height(), ParticleSystem_Interactive::collision(), Sector::collision_object(), Sector::collision_static_constrains(), TileMap::get_tiles_overlapping(), ScriptedObject::move(), MovingObject::set_pos(), and set_pos().

00098   {
00099     p1 += v;
00100     p2 += v;
00101   }

bool Rectf::contains ( const Vector v  )  const [inline]

Definition at line 103 of file rectf.hpp.

References p1, p2, Vector::x, and Vector::y.

Referenced by Sector::inside(), and Player::try_grab().

00104   {
00105     return v.x >= p1.x && v.y >= p1.y && v.x < p2.x && v.y < p2.y;
00106   }

bool Rectf::contains ( const Rectf other  )  const [inline]

Definition at line 107 of file rectf.hpp.

References p1, p2, Vector::x, and Vector::y.

00108   {
00109     if(p1.x >= other.p2.x || other.p1.x >= p2.x)
00110       return false;
00111     if(p1.y >= other.p2.y || other.p1.y >= p2.y)
00112       return false;
00113 
00114     return true;
00115   }

float Rectf::distance ( const Vector other,
AnchorPoint  ap = ANCHOR_MIDDLE 
) const [inline]

Definition at line 117 of file rectf.hpp.

References get_anchor_pos().

00118   {
00119     Vector v = get_anchor_pos (*this, ap);
00120     return ((v - other).norm ());
00121   }

float Rectf::distance ( const Rectf other,
AnchorPoint  ap = ANCHOR_MIDDLE 
) const [inline]

Definition at line 123 of file rectf.hpp.

References get_anchor_pos().

00124   {
00125     Vector v1 = get_anchor_pos (*this, ap);
00126     Vector v2 = get_anchor_pos (other, ap);
00127 
00128     return ((v1 - v2).norm ());
00129   }


Member Data Documentation

Vector Rectf::p1

upper left edge

Definition at line 135 of file rectf.hpp.

Referenced by WillOWisp::active_update(), Stalactite::active_update(), SSpiky::active_update(), Plant::active_update(), AngryStone::active_update(), Player::adjust_height(), BadGuy::BadGuy(), Igel::can_see(), Climbable::Climbable(), Dispenser::collision(), BadGuy::collision(), Kugelblitz::collision_player(), MrTree::collision_squished(), Sector::collision_static_constrains(), Sector::collision_tile_attributes(), contains(), Door::Door(), Switch::draw(), Door::draw(), InfoBoxLine::draw(), Player::draw(), InfoBlock::draw(), Menu::draw(), Font::draw_chars(), DrawingContext::draw_filled_rect(), Climbable::event(), IceCrusher::found_victim(), get_height(), get_left(), get_middle(), MovingObject::get_pos(), get_top(), get_width(), Player::handle_input(), IceCrusher::IceCrusher(), Sector::inside(), collision::intersects(), Ispy::intersects_line(), Owl::is_above_player(), Climbable::may_climb(), CaptainSnowball::might_climb(), BadGuy::might_fall(), move(), MovingSprite::MovingSprite(), collision::rectangle_aatriangle(), Rectf(), ScriptTrigger::ScriptTrigger(), SecretAreaTrigger::SecretAreaTrigger(), SequenceTrigger::SequenceTrigger(), Player::set_bonus(), set_height(), set_pos(), Toad::set_state(), set_width(), Block::start_bounce(), Switch::Switch(), Kugelblitz::try_activate(), BadGuy::try_activate(), Switch::update(), Wind::update(), Player::update(), InfoBlock::update(), and Wind::Wind().

Vector Rectf::p2

lower right edge

Definition at line 137 of file rectf.hpp.

Referenced by WillOWisp::active_update(), Stalactite::active_update(), SSpiky::active_update(), Plant::active_update(), AngryStone::active_update(), Igel::can_see(), PneumaticPlatform::collision(), BicyclePlatform::collision(), Dispenser::collision(), BadGuy::collision(), Kugelblitz::collision_player(), MrTree::collision_squished(), Sector::collision_static_constrains(), Sector::collision_tile_attributes(), contains(), InfoBoxLine::draw(), Player::draw(), InfoBlock::draw(), Menu::draw(), Font::draw_chars(), Climbable::event(), IceCrusher::found_victim(), get_bottom(), get_height(), get_middle(), get_right(), get_width(), Player::handle_input(), collision::intersects(), Ispy::intersects_line(), Owl::is_above_player(), TitleScreen::make_tux_jump(), Climbable::may_climb(), CaptainSnowball::might_climb(), BadGuy::might_fall(), move(), collision::rectangle_aatriangle(), Rectf(), Player::set_bonus(), set_height(), Toad::set_state(), set_width(), Kugelblitz::try_activate(), BadGuy::try_activate(), Wind::update(), Player::update(), InfoBlock::update(), and Camera::update_scroll_normal().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:34 2014 for SuperTux by  doxygen 1.5.1