src/supertux/sector.cpp File Reference

#include "supertux/sector.hpp"
#include <algorithm>
#include <math.h>
#include "audio/sound_manager.hpp"
#include "badguy/jumpy.hpp"
#include "lisp/list_iterator.hpp"
#include "math/aatriangle.hpp"
#include "object/background.hpp"
#include "object/bonus_block.hpp"
#include "object/brick.hpp"
#include "object/bullet.hpp"
#include "object/camera.hpp"
#include "object/cloud_particle_system.hpp"
#include "object/coin.hpp"
#include "object/comet_particle_system.hpp"
#include "object/display_effect.hpp"
#include "object/ghost_particle_system.hpp"
#include "object/gradient.hpp"
#include "object/invisible_block.hpp"
#include "object/particlesystem.hpp"
#include "object/particlesystem_interactive.hpp"
#include "object/player.hpp"
#include "object/portable.hpp"
#include "object/pulsing_light.hpp"
#include "object/rain_particle_system.hpp"
#include "object/smoke_cloud.hpp"
#include "object/snow_particle_system.hpp"
#include "object/text_object.hpp"
#include "object/tilemap.hpp"
#include "physfs/ifile_stream.hpp"
#include "scripting/squirrel_util.hpp"
#include "supertux/collision.hpp"
#include "supertux/constants.hpp"
#include "supertux/game_session.hpp"
#include "supertux/globals.hpp"
#include "supertux/level.hpp"
#include "supertux/object_factory.hpp"
#include "supertux/player_status.hpp"
#include "supertux/spawn_point.hpp"
#include "supertux/tile.hpp"
#include "trigger/sequence_trigger.hpp"
#include "util/file_system.hpp"

Go to the source code of this file.

Functions

void check_collisions (collision::Constraints *constraints, const Vector &obj_movement, const Rectf &obj_rect, const Rectf &other_rect, GameObject *object=NULL, MovingObject *other=NULL, const Vector &other_movement=Vector(0, 0))
 r1 is supposed to be moving, r2 a solid object
static void get_hit_normal (const Rectf &r1, const Rectf &r2, CollisionHit &hit, Vector &normal)
 fills in CollisionHit and Normal vector of 2 intersecting rectangle

Variables

const float MAX_SPEED = 16.0f


Function Documentation

void check_collisions ( collision::Constraints constraints,
const Vector obj_movement,
const Rectf obj_rect,
const Rectf other_rect,
GameObject object = NULL,
MovingObject other = NULL,
const Vector other_movement = Vector(0,0) 
)

r1 is supposed to be moving, r2 a solid object

Definition at line 888 of file sector.cpp.

References ABORT_MOVE, CollisionHit::bottom, MovingObject::collides(), collision::Constraints::constrain_bottom(), collision::Constraints::constrain_left(), collision::Constraints::constrain_right(), collision::Constraints::constrain_top(), Rectf::get_bottom(), Rectf::get_left(), Rectf::get_right(), Rectf::get_top(), collision::Constraints::ground_movement, collision::Constraints::hit, collision::intersects(), CollisionHit::left, CollisionHit::right, SHIFT_DELTA, CollisionHit::top, Vector::x, and Vector::y.

Referenced by Sector::collision_static(), and Sector::collision_tilemap().

00891 {
00892   if(!collision::intersects(obj_rect, other_rect))
00893     return;
00894 
00895   MovingObject *moving_object = dynamic_cast<MovingObject*> (object);
00896   CollisionHit dummy;
00897   if(other != NULL && !other->collides(*object, dummy))
00898     return;
00899   if(moving_object != NULL && !moving_object->collides(*other, dummy))
00900     return;
00901 
00902   // calculate intersection
00903   float itop    = obj_rect.get_bottom() - other_rect.get_top();
00904   float ibottom = other_rect.get_bottom() - obj_rect.get_top();
00905   float ileft   = obj_rect.get_right() - other_rect.get_left();
00906   float iright  = other_rect.get_right() - obj_rect.get_left();
00907 
00908   if(fabsf(obj_movement.y) > fabsf(obj_movement.x)) {
00909     if(ileft < SHIFT_DELTA) {
00910       constraints->constrain_right(other_rect.get_left(), other_movement.x);
00911       return;
00912     } else if(iright < SHIFT_DELTA) {
00913       constraints->constrain_left(other_rect.get_right(), other_movement.x);
00914       return;
00915     }
00916   } else {
00917     // shiftout bottom/top
00918     if(itop < SHIFT_DELTA) {
00919       constraints->constrain_bottom(other_rect.get_top(), other_movement.y);
00920       return;
00921     } else if(ibottom < SHIFT_DELTA) {
00922       constraints->constrain_top(other_rect.get_bottom(), other_movement.y);
00923       return;
00924     }
00925   }
00926 
00927   constraints->ground_movement += other_movement;
00928   if(other != NULL) {
00929     HitResponse response = other->collision(*object, dummy);
00930     if(response == ABORT_MOVE)
00931       return;
00932 
00933     if(other->get_movement() != Vector(0, 0)) {
00934       // TODO what todo when we collide with 2 moving objects?!?
00935       constraints->ground_movement = other->get_movement();
00936     }
00937   }
00938 
00939   float vert_penetration = std::min(itop, ibottom);
00940   float horiz_penetration = std::min(ileft, iright);
00941   if(vert_penetration < horiz_penetration) {
00942     if(itop < ibottom) {
00943       constraints->constrain_bottom(other_rect.get_top(), other_movement.y);
00944       constraints->hit.bottom = true;
00945     } else {
00946       constraints->constrain_top(other_rect.get_bottom(), other_movement.y);
00947       constraints->hit.top = true;
00948     }
00949   } else {
00950     if(ileft < iright) {
00951       constraints->constrain_right(other_rect.get_left(), other_movement.x);
00952       constraints->hit.right = true;
00953     } else {
00954       constraints->constrain_left(other_rect.get_right(), other_movement.x);
00955       constraints->hit.left = true;
00956     }
00957   }
00958 }

static void get_hit_normal ( const Rectf r1,
const Rectf r2,
CollisionHit hit,
Vector normal 
) [static]

fills in CollisionHit and Normal vector of 2 intersecting rectangle

Definition at line 1055 of file sector.cpp.

References CollisionHit::bottom, Rectf::get_bottom(), Rectf::get_left(), Rectf::get_right(), Rectf::get_top(), CollisionHit::left, CollisionHit::right, CollisionHit::top, Vector::x, and Vector::y.

Referenced by Sector::collision_object(), and Sector::handle_collisions().

01057 {
01058   float itop = r1.get_bottom() - r2.get_top();
01059   float ibottom = r2.get_bottom() - r1.get_top();
01060   float ileft = r1.get_right() - r2.get_left();
01061   float iright = r2.get_right() - r1.get_left();
01062 
01063   float vert_penetration = std::min(itop, ibottom);
01064   float horiz_penetration = std::min(ileft, iright);
01065   if(vert_penetration < horiz_penetration) {
01066     if(itop < ibottom) {
01067       hit.bottom = true;
01068       normal.y = vert_penetration;
01069     } else {
01070       hit.top = true;
01071       normal.y = -vert_penetration;
01072     }
01073   } else {
01074     if(ileft < iright) {
01075       hit.right = true;
01076       normal.x = horiz_penetration;
01077     } else {
01078       hit.left = true;
01079       normal.x = -horiz_penetration;
01080     }
01081   }
01082 }


Variable Documentation

const float MAX_SPEED = 16.0f [static]

Definition at line 1247 of file sector.cpp.

Referenced by Sector::handle_collisions().


Generated on Mon Apr 21 03:38:20 2014 for SuperTux by  doxygen 1.5.1