PhysicsParticleObject.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 
00022 #if !defined(__INCLUDE_PhysicsParticleObjecth_INCLUDE__)
00023 #define __INCLUDE_PhysicsParticleObjecth_INCLUDE__
00024 
00025 #include <common/FixedVector.h>
00026 #include <common/FixedVector4.h>
00027 #include <engine/ScorchedCollisionIds.h>
00028 
00029 enum PhysicsParticleType
00030 {
00031         ParticleTypeNone = 0,
00032         ParticleTypeShot,
00033         ParticleTypeBounce,
00034         ParticleTypeFalling
00035 };
00036 
00037 struct PhysicsParticleInfo
00038 {
00039         PhysicsParticleInfo(
00040                 PhysicsParticleType type,
00041                 unsigned int playerId,
00042                 void *data) :
00043                 type_(type),
00044                 playerId_(playerId),
00045                 data_(data)
00046         {
00047         }
00048 
00049         PhysicsParticleType type_;
00050         unsigned int playerId_;
00051         void *data_;
00052 };
00053 
00054 class PhysicsParticleObject;
00055 class PhysicsParticleObjectHandler
00056 {
00057 public:
00058         virtual void collision(PhysicsParticleObject &position, 
00059                 ScorchedCollisionId collisionId) = 0;
00060         virtual void wallCollision(PhysicsParticleObject &position,
00061                 ScorchedCollisionId collisionId) {}
00062 };
00063 
00064 class Target;
00065 class ScorchedContext;
00066 class PhysicsParticleObject
00067 {
00068 public:
00069         PhysicsParticleObject();
00070         virtual ~PhysicsParticleObject();
00071 
00072         void setPhysics(
00073                 PhysicsParticleInfo info,
00074                 ScorchedContext &context, 
00075                 FixedVector &position, FixedVector &velocity,
00076                 fixed sphereSize = 0,
00077                 fixed sphereDensity = 0,
00078                 fixed windFactor = 1,
00079                 bool underGroundCollision = false,
00080                 bool rotateOnCollision = false,
00081                 bool wallCollision = true);
00082 
00083         void applyForce(FixedVector &force);
00084         void simulate(fixed frameTime);
00085 
00086         FixedVector &getPosition() { return position_; }
00087         FixedVector &getVelocity() { return velocity_; }
00088         FixedVector4 &getRotationQuat() { return rotation_; }
00089 
00090         void setHandler(PhysicsParticleObjectHandler *handler) { handler_ = handler; }
00091         void setPosition(FixedVector &position) { position_ = position; }
00092 
00093 protected:
00094         PhysicsParticleInfo info_;
00095         ScorchedContext *context_;
00096         PhysicsParticleObjectHandler *handler_;
00097         bool underGroundCollision_;
00098         bool rotateOnCollision_;
00099         bool wallCollision_;
00100         unsigned int iterations_;
00101         FixedVector position_;
00102         FixedVector velocity_;
00103         FixedVector windFactor_;
00104         FixedVector4 rotation_;
00105         FixedVector4 avelocity_;
00106 
00107         enum CollisionAction
00108         {
00109                 CollisionActionNone = 0,
00110                 CollisionActionCollision,
00111                 CollisionActionBounce
00112         };
00113         struct CollisionInfo
00114         {
00115                 ScorchedCollisionId collisionId;
00116                 fixed deflectFactor;
00117                 FixedVector normal;
00118         };
00119 
00120         virtual void shotWallHit(CollisionInfo &collision);
00121         virtual void shotShieldHit(Target *target);
00122         virtual void bounceShieldHit(Target *target);
00123 
00124         void checkCollision();
00125         CollisionAction checkShotCollision(CollisionInfo &collision, Target *target);
00126         CollisionAction checkBounceCollision(CollisionInfo &collision, Target *target);
00127         CollisionAction checkFallingCollision(CollisionInfo &collision, Target *target);
00128 
00129         bool getLandscapeCollision(CollisionInfo &collision);
00130         bool getRoofCollision(CollisionInfo &collision);
00131         bool getWallCollision(CollisionInfo &collision);
00132         bool getShieldCollision(CollisionInfo &collision, Target *target);
00133         bool getTargetCollision(CollisionInfo &collision, Target *target);
00134         bool getTargetBounceCollision(CollisionInfo &collision, Target *target);
00135 };
00136 
00137 class PhysicsParticleActionObject : public PhysicsParticleObject
00138 {
00139 public:
00140         PhysicsParticleActionObject();
00141         virtual ~PhysicsParticleActionObject();
00142 
00143 protected:
00144         virtual void shotWallHit(CollisionInfo &collision);
00145         virtual void shotShieldHit(Target *target);
00146         virtual void bounceShieldHit(Target *target);
00147 };
00148 
00149 #endif

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3