//! Physical object base class for the "sju" Physics Engine. All objects must be subclasses of IPhysicalObject /*! * The sju Physics Engine works with subclasses of IPhysicalObject. * These subclasses _MUST_ implement their own way of responding to the effects * applied to them, as well as their own way of being updated at the end of each * simulation cycle. */ /* Copyright (C) 2008-2009 Alejandro Valenzuela Roca, * * This file is part of MotorJ, a free framework for videogame creation. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #ifndef PHYSICALOBJECT_CLASS_H #define PHYSICALOBJECT_CLASS_H #include "support.h" #include "sjuengine-types.h" class IPhysicalObject { public: //! Empty constructor IPhysicalObject(){}; //! Empty destructor virtual ~IPhysicalObject() {}; //! Respond to effects applied (this method MUST be implemented in the subclass) virtual void ApplyEffect(vector3 effect, vector3& pointOfAction, sjuPETypes effectType, IPhysicalObject* interactionObject) = 0; //! Reset accelerations at the end of each simulation cycle virtual void ResetAccels() {v3_0(&a); v3_0(&rota);}; //! Update position at the beginning of each simulation cycle based on acceleration //! Update speed at the end of each simulation cycle due to collisions. t_elapsed is in seconds (for example, 0.016 seconds for a simulation running at 60 fps) virtual void Update(float t_elapsed){ }; //! Respond to collisions //! Respond to collision detection virtual void OnCollisionDetected(IPhysicalObject* object) { }; //! Position vector3 p; //! Velocity vector3 v; //! Acceleration vector3 a; //! Orientation vector3 dir; //! "Up" vector vector3 up; //! Rotation velocity vector3 rotv; //! Rotation acceleration vector3 rota; //! Mass float mass; //! Moment of inertia float mInertia; //! Drag factor - resistance to movement. float dragFactor; //! Participate in collision detection bool hasCollision; //! Is affected by forces (if false, the object is immovable) bool affectedByForces; //! Is affected by gravitation bool hasGravitation; //! Is affected by gravity bool hasGravity; //! Is affected by electrical attraction/repulsion forces bool hasCharge; //! Electrical charge float q; //! Restitution coefficient (e < 1 for inelastic collisions; e == 1 for completely elastic collisions) float e; //! Collision geometry model sjuCGTypes cGeometry; //! Pointer to geometry data void * cGeometryData; //! Collision status (mostly internal management) int collStatus; //! Which kind of interaction it has with other objects when overlapping sjuPETypes objectInteractionEffect; //! Parameter for interacting with other objects (varies with the objectInteractionEffect) vector3 objectInteractionParam; //! Old position, for collision detection-related corrections vector3 oldPos; //! Detailed object type. To be implemented as needed by each project. The physics engine will ignore this parameter and only take cGeometry into account int customType; protected: }; #endif