From aca8bb39c7af0085a28f2c6495028ca1b7e72f86 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Wed, 1 Apr 2009 01:30:10 +0000 Subject: [PATCH] Renaved MovingPhysics to PhysicalObject. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3338 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/Makefile.am | 4 +- src/ide/vc9/supertuxkart.vcproj | 6 ++- src/items/flyable.cpp | 4 +- src/items/flyable.hpp | 4 +- src/items/plunger.cpp | 10 ++--- src/items/plunger.hpp | 4 +- src/loader.cpp | 2 +- ...moving_physics.cpp => physical_object.cpp} | 20 ++++----- ...moving_physics.hpp => physical_object.hpp} | 25 +++++------ src/physics/physics.cpp | 14 +++---- src/tracks/track.cpp | 14 +++---- src/tracks/track.hpp | 5 ++- src/user_pointer.hpp | 42 +++++++++---------- 13 files changed, 80 insertions(+), 74 deletions(-) rename src/physics/{moving_physics.cpp => physical_object.cpp} (94%) rename src/physics/{moving_physics.hpp => physical_object.hpp} (75%) diff --git a/src/Makefile.am b/src/Makefile.am index 0e1586712..2d56146ef 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -215,8 +215,8 @@ supertuxkart_SOURCES = \ physics/btKart.hpp \ physics/btUprightConstraint.cpp \ physics/btUprightConstraint.hpp \ - physics/moving_physics.hpp \ - physics/moving_physics.cpp \ + physics/physical_object.hpp \ + physics/physical_object.cpp \ physics/physics.cpp \ physics/physics.hpp \ physics/kart_motion_state.hpp \ diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index fb7f7a096..07afdb1da 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -489,7 +489,7 @@ > + + diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index dc160872d..95d248cc7 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -245,7 +245,7 @@ bool Flyable::isOwnerImmunity(const Kart* kart_hit) const } // isOwnerImmunity // ----------------------------------------------------------------------------- -void Flyable::hit(Kart *kart_hit, MovingPhysics* moving_physics) +void Flyable::hit(Kart *kart_hit, PhysicalObject* object) { // the owner of this flyable should not be hit by his own flyable if(m_exploded || isOwnerImmunity(kart_hit)) return; @@ -284,7 +284,7 @@ void Flyable::hit(Kart *kart_hit, MovingPhysics* moving_physics) } } } - RaceManager::getTrack()->handleExplosion(pos_explosion, moving_physics); + RaceManager::getTrack()->handleExplosion(pos_explosion, object); } // hit /* EOF */ diff --git a/src/items/flyable.hpp b/src/items/flyable.hpp index af762a8db..ea32661b7 100644 --- a/src/items/flyable.hpp +++ b/src/items/flyable.hpp @@ -30,7 +30,7 @@ using namespace irr; class FlyableInfo; class Kart; -class MovingPhysics; +class PhysicalObject; class Flyable : public Moveable, public TerrainInfo { @@ -107,7 +107,7 @@ public: void updateFromServer(const FlyableInfo &f, float dt); virtual void hitTrack () {}; - virtual void hit (Kart* kart, MovingPhysics* moving_physics=NULL); + virtual void hit (Kart* kart, PhysicalObject* obj=NULL); bool hasHit () { return m_has_hit_something; } /** Indicates that something was hit and that this object must * be removed. */ diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 5be267f03..29430ed9c 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -26,7 +26,7 @@ #include "items/projectile_manager.hpp" #include "karts/player_kart.hpp" #include "modes/world.hpp" -#include "physics/moving_physics.hpp" +#include "physics/physical_object.hpp" #include "tracks/track.hpp" #include "utils/constants.hpp" @@ -150,9 +150,9 @@ void Plunger::update(float dt) * Instead it stays around (though not as a graphical or physical object) * till the rubber band expires. * \param kart Pointer to the kart hit (NULL if not a kart). - * \param mp Pointer to MovingPhysics object if hit (NULL otherwise). + * \param obj Pointer to PhysicalObject object if hit (NULL otherwise). */ -void Plunger::hit(Kart *kart, MovingPhysics *mp) +void Plunger::hit(Kart *kart, PhysicalObject *obj) { if(isOwnerImmunity(kart)) return; @@ -190,9 +190,9 @@ void Plunger::hit(Kart *kart, MovingPhysics *mp) m_rubber_band->hit(kart); return; } - else if(mp) + else if(obj) { - Vec3 pos(mp->getBody()->getWorldTransform().getOrigin()); + Vec3 pos(obj->getBody()->getWorldTransform().getOrigin()); m_rubber_band->hit(NULL, &pos); } else diff --git a/src/items/plunger.hpp b/src/items/plunger.hpp index b94a02988..350293d38 100644 --- a/src/items/plunger.hpp +++ b/src/items/plunger.hpp @@ -26,7 +26,7 @@ using namespace irr; class RubberBand; class Kart; -class MovingPhysics; +class PhysicalObject; class Plunger : public Flyable { @@ -47,7 +47,7 @@ public: void setKeepAlive(float t) {m_keep_alive = t;} virtual void update (float dt); virtual void hitTrack (); - virtual void hit (Kart *kart, MovingPhysics *mp=NULL); + virtual void hit (Kart *kart, PhysicalObject *obj=NULL); /** A plunger does not explode if it is removed. */ virtual bool needsExplosion() const {return false;} diff --git a/src/loader.cpp b/src/loader.cpp index f364a60b4..c5cb14a33 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -37,7 +37,7 @@ #include "material.hpp" #include "graphics/moving_texture.hpp" #include "io/file_manager.hpp" -#include "physics/moving_physics.hpp" +#include "physics/physical_object.hpp" Loader* loader = 0; diff --git a/src/physics/moving_physics.cpp b/src/physics/physical_object.cpp similarity index 94% rename from src/physics/moving_physics.cpp rename to src/physics/physical_object.cpp index d396ddc46..628629502 100644 --- a/src/physics/moving_physics.cpp +++ b/src/physics/physical_object.cpp @@ -1,4 +1,4 @@ -// $Id: moving_physics.cpp 839 2006-10-24 00:01:56Z hiker $ +// $Id: physical_object.cpp 839 2006-10-24 00:01:56Z hiker $ // // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2006 Joerg Henrichs @@ -17,7 +17,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "physics/moving_physics.hpp" +#include "physics/physical_object.hpp" #include #include @@ -36,7 +36,7 @@ using namespace irr; #include "utils/string_utils.hpp" // ----------------------------------------------------------------------------- -MovingPhysics::MovingPhysics(const XMLNode *xml_node) +PhysicalObject::PhysicalObject(const XMLNode *xml_node) { std::string model_name; const Track *track=RaceManager::getTrack(); @@ -91,21 +91,21 @@ MovingPhysics::MovingPhysics(const XMLNode *xml_node) if (shape=="cone" ) m_body_type = MP_CONE; else if(shape=="box" ) m_body_type = MP_BOX; else if(shape=="sphere" ) m_body_type = MP_SPHERE; -} // MovingPhysics +} // PhysicalObject // ----------------------------------------------------------------------------- -MovingPhysics::~MovingPhysics() +PhysicalObject::~PhysicalObject() { RaceManager::getWorld()->getPhysics()->removeBody(m_body); delete m_body; delete m_motion_state; delete m_shape; -} // ~MovingPhysics +} // ~PhysicalObject // ----------------------------------------------------------------------------- /** Additional initialisation after loading of the model is finished. */ -void MovingPhysics::init() +void PhysicalObject::init() { // 1. Determine size of the object // ------------------------------- @@ -151,7 +151,7 @@ void MovingPhysics::init() } // init // ----------------------------------------------------------------------------- -void MovingPhysics::update(float dt) +void PhysicalObject::update(float dt) { btTransform t; m_motion_state->getWorldTransform(t); @@ -166,7 +166,7 @@ void MovingPhysics::update(float dt) } // update // ----------------------------------------------------------------------------- -void MovingPhysics::reset() +void PhysicalObject::reset() { m_body->setCenterOfMassTransform(m_init_pos); m_body->setAngularVelocity(btVector3(0,0,0)); @@ -175,7 +175,7 @@ void MovingPhysics::reset() } // reset // ----------------------------------------------------------------------------- -void MovingPhysics::handleExplosion(const Vec3& pos, bool direct_hit) { +void PhysicalObject::handleExplosion(const Vec3& pos, bool direct_hit) { if(direct_hit) { btVector3 impulse(0.0f, 0.0f, stk_config->m_explosion_impulse_objects); m_body->applyCentralImpulse(impulse); diff --git a/src/physics/moving_physics.hpp b/src/physics/physical_object.hpp similarity index 75% rename from src/physics/moving_physics.hpp rename to src/physics/physical_object.hpp index fc0a5ec76..5ffd33f19 100644 --- a/src/physics/moving_physics.hpp +++ b/src/physics/physical_object.hpp @@ -1,4 +1,4 @@ -// $Id: moving_physics.hpp 839 2006-10-24 00:01:56Z hiker $ +// $Id: physical_object.hpp 839 2006-10-24 00:01:56Z hiker $ // // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2006 Joerg Henrichs @@ -17,8 +17,9 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_MOVING_PHYSICS_HPP -#define HEADER_MOVING_PHYSICS_HPP +#ifndef HEADER_PHYSICAL_OBJECT_HPP +#define HEADER_PHYSICAL_OBJECT_HPP + #include #include "irrlicht.h" using namespace irr; @@ -30,7 +31,7 @@ class Vec3; class scene::IAnimatedMesh; class XMLNode; -class MovingPhysics +class PhysicalObject { public: enum bodyTypes {MP_NONE, MP_CONE, MP_BOX, MP_SPHERE}; @@ -47,15 +48,15 @@ protected: scene::IMesh *m_mesh; scene::ISceneNode *m_node; public: - MovingPhysics (const XMLNode *node); - ~MovingPhysics (); - void update (float dt); - void init (); - virtual void reset (); - btRigidBody *getBody () { return m_body; } - const char *getTypeName() { return "moving physics"; } + PhysicalObject (const XMLNode *node); + ~PhysicalObject (); + void update (float dt); + void init (); + virtual void reset (); + /** Returns the rigid body of this physical object. */ + btRigidBody *getBody () { return m_body; } virtual void handleExplosion(const Vec3& pos, bool directHit); -}; // MovingPhysics +}; // PhysicalObject #endif /* EOF */ diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 3bbccf3ae..7657b7271 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -135,9 +135,9 @@ void Physics::update(float dt) { p->a->getPointerFlyable()->hitTrack(); } - else if(p->b->is(UserPointer::UP_MOVING_PHYSICS)) + else if(p->b->is(UserPointer::UP_PHYSICAL_OBJECT)) { - p->a->getPointerFlyable()->hit(NULL, p->b->getPointerMovingPhysics()); + p->a->getPointerFlyable()->hit(NULL, p->b->getPointerPhysicalObject()); } else if(p->b->is(UserPointer::UP_KART)) // projectile hit kart @@ -270,15 +270,15 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies, // ========================= else if(upA->is(UserPointer::UP_FLYABLE)) { - if(upB->is(UserPointer::UP_TRACK ) || // 3.1) projectile hits track - upB->is(UserPointer::UP_FLYABLE ) || // 3.2) projectile hits projectile - upB->is(UserPointer::UP_MOVING_PHYSICS) || // 3.3) projectile hits projectile - upB->is(UserPointer::UP_KART ) ) // 3.4) projectile hits kart + if(upB->is(UserPointer::UP_TRACK ) || // 3.1) projectile hits track + upB->is(UserPointer::UP_FLYABLE ) || // 3.2) projectile hits projectile + upB->is(UserPointer::UP_PHYSICAL_OBJECT) || // 3.3) projectile hits projectile + upB->is(UserPointer::UP_KART ) ) // 3.4) projectile hits kart { m_all_collisions.push_back(upA, upB); } } - else if(upA->is(UserPointer::UP_MOVING_PHYSICS)) + else if(upA->is(UserPointer::UP_PHYSICAL_OBJECT)) { if(upB->is(UserPointer::UP_FLYABLE)) { diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 6b40b5df9..61b428b31 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -42,7 +42,7 @@ #include "lisp/lisp.hpp" #include "lisp/parser.hpp" #include "modes/world.hpp" -#include "physics/moving_physics.hpp" +#include "physics/physical_object.hpp" #include "physics/triangle_mesh.hpp" #include "race_manager.hpp" #include "utils/ssg_help.hpp" @@ -1292,15 +1292,15 @@ void Track::update(float dt) /** Handles an explosion, i.e. it makes sure that all physical objects are * affected accordingly. * \param pos Position of the explosion. - * \param mp If the hit was a physical object, this object will be affected + * \param obj If the hit was a physical object, this object will be affected * more. Otherwise this is NULL. */ -void Track::handleExplosion(const Vec3 &pos, const MovingPhysics *mp) const +void Track::handleExplosion(const Vec3 &pos, const PhysicalObject *obj) const { - for(std::vector::const_iterator i=m_physical_objects.begin(); + for(std::vector::const_iterator i=m_physical_objects.begin(); i!=m_physical_objects.end(); i++) { - (*i)->handleExplosion(pos, mp==(*i)); + (*i)->handleExplosion(pos, obj==(*i)); } } // handleExplosion @@ -1396,7 +1396,7 @@ void Track::loadTrackModel() if(name=="track") continue; if(name=="object") { - m_physical_objects.push_back(new MovingPhysics(node)); + m_physical_objects.push_back(new PhysicalObject(node)); } else if(name=="water") { @@ -1449,7 +1449,7 @@ void Track::loadTrackModel() } // Init all physical objects - for(std::vector::const_iterator i=m_physical_objects.begin(); + for(std::vector::const_iterator i=m_physical_objects.begin(); i!=m_physical_objects.end(); i++) { (*i)->init(); diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 86ca725c1..1cbee8171 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -42,6 +42,7 @@ using namespace irr; class TriangleMesh; class MovingTexture; class XMLNode; +class PhysicalObject; class Track { @@ -79,7 +80,7 @@ private: std::vector m_animated_textures; /** List of all physical objects. */ - std::vector m_physical_objects; + std::vector m_physical_objects; /** If a sky dome is used, the number of horizontal segments * the sphere should be divided in. */ @@ -221,7 +222,7 @@ public: float getTerrainHeight(const Vec3 &pos) const; void createPhysicsModel(); void update(float dt); - void handleExplosion(const Vec3 &pos, const MovingPhysics *mp) const; + void handleExplosion(const Vec3 &pos, const PhysicalObject *mp) const; void glVtx (sgVec2 v, float x_offset, float y_offset) const { glVertex2f( diff --git a/src/user_pointer.hpp b/src/user_pointer.hpp index 7ad91365a..df4edf10c 100644 --- a/src/user_pointer.hpp +++ b/src/user_pointer.hpp @@ -17,8 +17,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_USER_POINTER_H -#define HEADER_USER_POINTER_H +#ifndef HEADER_USER_POINTER_HPP +#define HEADER_USER_POINTER_HPP /** Some bullet objects store 'user pointers'. This is a base class * that allows to easily determine the type of the user pointer. @@ -27,34 +27,34 @@ class TriangleMesh; class Moveable; class Flyable; class Kart; -class MovingPhysics; +class PhysicalObject; class UserPointer { public: enum UserPointerType {UP_UNDEF, UP_KART, UP_FLYABLE, UP_TRACK, - UP_MOVING_PHYSICS}; + UP_PHYSICAL_OBJECT}; private: void* m_pointer; UserPointerType m_user_pointer_type; public: - bool is(UserPointerType t) const {return m_user_pointer_type==t; } - TriangleMesh* getPointerTriangleMesh() const {return (TriangleMesh*)m_pointer; } - Moveable* getPointerMoveable() const {return (Moveable*)m_pointer; } - Flyable* getPointerFlyable() const {return (Flyable*)m_pointer; } - Kart* getPointerKart() const {return (Kart*)m_pointer; } - MovingPhysics* getPointerMovingPhysics() const {return (MovingPhysics*)m_pointer; } - void set(MovingPhysics* p) { m_user_pointer_type=UP_MOVING_PHYSICS; - m_pointer =p; } - void set(Kart* p) { m_user_pointer_type=UP_KART; - m_pointer =p; } - void set(Flyable* p) { m_user_pointer_type=UP_FLYABLE; - m_pointer =p; } - void set(TriangleMesh* p) { m_user_pointer_type=UP_TRACK; - m_pointer =p; } - UserPointer() { zero(); } - void zero() { m_user_pointer_type=UP_UNDEF; - m_pointer = NULL; } + bool is(UserPointerType t) const {return m_user_pointer_type==t; } + TriangleMesh* getPointerTriangleMesh() const {return (TriangleMesh*)m_pointer; } + Moveable* getPointerMoveable() const {return (Moveable*)m_pointer; } + Flyable* getPointerFlyable() const {return (Flyable*)m_pointer; } + Kart* getPointerKart() const {return (Kart*)m_pointer; } + PhysicalObject *getPointerPhysicalObject() const {return (PhysicalObject*)m_pointer;} + void set(PhysicalObject* p) { m_user_pointer_type=UP_PHYSICAL_OBJECT; + m_pointer =p; } + void set(Kart* p) { m_user_pointer_type=UP_KART; + m_pointer =p; } + void set(Flyable* p) { m_user_pointer_type=UP_FLYABLE; + m_pointer =p; } + void set(TriangleMesh* p) { m_user_pointer_type=UP_TRACK; + m_pointer =p; } + UserPointer() { zero(); } + void zero() { m_user_pointer_type=UP_UNDEF; + m_pointer = NULL; } }; #endif /* EOF */