//! "sju" Physics Engine for MotorJ /*! * * sju Physics Engine, Physics system for MotorJ * * Handles collision tests and responses between several kinds of geometries, * as well as attraction/repulsion forces, friction fields, etc. * */ /* Copyright (C) 2008-2010 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 SJUENGINE_CLASS_H #define SJUENGINE_CLASS_H #include "sjuengine-types.h" #include "physicalobject-class.h" #include "pmesh-class.h" #include "paabb-class.h" #include "support.h" #include "collisions.h" #include // For some parallelisation tricks #ifdef PC_SDL #include #endif //! Update block - for internal concurrent calculation usage typedef struct { std::list::iterator start; std::list::iterator stop; std::list objects; float t_elapsed; int numThread; } mjUpdateBlock; //! "sju" Physics Engine for MotorJ /*! * * sju Physics Engine, Physics system for MotorJ * * Handles collision tests and responses between several kinds of geometries, * as well as attraction/repulsion forces, friction fields, etc. * */ class mjPhysics { public: mjPhysics(); //! Update (must be run on each Universe update method) void Update(float t_elapsed); //! Add a previously instatiated object to the physical simulation void AddObject(IPhysicalObject * object); //! Remove an object from the physical simulation bool RemoveObject(IPhysicalObject * physObject); //! Apply a unique, temporary effect to an object void ApplyEffect(IPhysicalObject * object, vector3 & effect, vector3 & pointOfAction, sjuPETypes effectType, IPhysicalObject* interactionObject); //! Remove all effects for specified object void RemoveEffectsForObject(IPhysicalObject* object); //! Set the gravity acceleration void SetGravity(vector3 & g); void SetGravity(float y); void SetGravity(float x, float y, float z); //! Set the drag factor (the medium's opposition to object movement) void SetDragFactor(float newDragFactor); //! Set the direction for point/sphere vs surface test (NULL = triangle's own normal) void SetRayTrDir(vector3* dir); //! Set the gravitational constant, G (not to be confused with gravity! See SetGravity) void SetGravitationConstant(float G); //! Set the Coulomb constant, ke void SetCoulombConstant(float ke); //! Coulomb force radius void SetCoulombFRadius(float radius); //! Attraction-repulsion model (normal or constant) sjuCoulombModel coulombModel; //! Object list - alter only if you know what you're doing std::list objects; //list_header objects; //! Mesh list - alter only if you know what you're doing std::list meshes; //list_header meshes; private: //list_header forces; std::list forces; //list_header temp_effects; std::list temp_effects; float dragFactor; vector3 gravity; float gravitationConstant; float coulombConstant; float coulombFRadius; vector3* rayTrDir; #ifdef PC_SDL // Multi-processor variables #define MAX_PROCESSORS 2 SDL_Thread **update_children; mjUpdateBlock* update_blocks; #endif }; int thread_Update(void* data); #endif