diff options
Diffstat (limited to 'source/gameengine/Physics/common')
9 files changed, 514 insertions, 0 deletions
diff --git a/source/gameengine/Physics/common/Makefile b/source/gameengine/Physics/common/Makefile new file mode 100644 index 00000000000..3783d959e14 --- /dev/null +++ b/source/gameengine/Physics/common/Makefile @@ -0,0 +1,59 @@ +# +# $Id$ +# +# ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. The Blender +# Foundation also sells licenses for use in proprietary software under +# the Blender License. See http://www.blender.org/BL/ for information +# about this. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): none yet. +# +# ***** END GPL/BL DUAL LICENSE BLOCK ***** +# +# + +LIBNAME = common +DIR = $(OCGDIR)/gameengine/blphys/$(LIBNAME) + +include nan_compile.mk + +CCFLAGS += $(LEVEL_1_CPP_WARNINGS) + +CPPFLAGS += -I$(OPENGL_HEADERS) +CPPFLAGS += -I$(NAN_STRING)/include +CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) +CPPFLAGS += -I$(NAN_FUZZICS)/include -I$(NAN_SUMO)/include -I$(NAN_MOTO)/include +CPPFLAGS += -I../../blender +# these two needed because of blenkernel +CPPFLAGS += -I../../blender/makesdna +CPPFLAGS += -I../../blender/include +CPPFLAGS += -I../../blender/blenlib +CPPFLAGS += -I../../blender/blenkernel +CPPFLAGS += -I../../blender/render/extern/include +CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include +CPPFLAGS += -I../Expressions -I../Rasterizer -I../GameLogic -I../SoundSystem +CPPFLAGS += -I../Ketsji -I../BlenderRoutines -I../SceneGraph +CPPFLAGS += -I../../kernel/gen_system +CPPFLAGS += -I../Rasterizer/RAS_OpenGLRasterizer +CPPFLAGS += -I../Network -I../Ketsji/KXNetwork +CPPFLAGS += -I../Physics +CPPFLAGS += -I../Physics/Dummy diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h new file mode 100644 index 00000000000..4b10a29e1e7 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -0,0 +1,68 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef __PHY_DYNAMIC_TYPES +#define __PHY_DYNAMIC_TYPES + +/// PHY_ScalarType enumerates possible scalar types. +/// See the PHY_IMeshInterface for its use +typedef enum PHY_ScalarType { + PHY_FLOAT, + PHY_DOUBLE, + PHY_INTEGER, + PHY_SHORT, + PHY_FIXEDPOINT88 +} PHY_ScalarType; + +/// PHY_PhysicsType enumerates all possible Physics Entities. +/// It is mainly used to create/add Physics Objects + +typedef enum PHY_PhysicsType { + PHY_CONVEX_RIGIDBODY=16386, + PHY_CONCAVE_RIGIDBODY=16399, + PHY_CONVEX_FIXEDBODY=16388,//'collision object' + PHY_CONCAVE_FIXEDBODY=16401, + PHY_CONVEX_KINEMATICBODY=16387,// + PHY_CONCAVE_KINEMATICBODY=16400, + PHY_CONVEX_PHANTOMBODY=16398, + PHY_CONCAVE_PHANTOMBODY=16402 +} PHY_PhysicsType; + +/// PHY_ConstraintType enumerates all supported Constraint Types +typedef enum PHY_ConstraintType { + PHY_POINT2POINT_CONSTRAINT=1, + PHY_LINEHINGE_CONSTRAINT, + +} PHY_ConstraintType; + +typedef float PHY_Vector3[3]; + +#endif //__PHY_DYNAMIC_TYPES diff --git a/source/gameengine/Physics/common/PHY_IMotionState.cpp b/source/gameengine/Physics/common/PHY_IMotionState.cpp new file mode 100644 index 00000000000..106f453424d --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IMotionState.cpp @@ -0,0 +1,37 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#include "PHY_IMotionState.h" + +PHY_IMotionState::~PHY_IMotionState() +{ + +} diff --git a/source/gameengine/Physics/common/PHY_IMotionState.h b/source/gameengine/Physics/common/PHY_IMotionState.h new file mode 100644 index 00000000000..6dd97427b59 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IMotionState.h @@ -0,0 +1,57 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef PHY__MOTIONSTATE_H +#define PHY__MOTIONSTATE_H + + +/** + PHY_IMotionState is the Interface to explicitly synchronize the world transformation. + Default implementations for mayor graphics libraries like OpenGL and DirectX can be provided. +*/ +class PHY_IMotionState + +{ + public: + + virtual ~PHY_IMotionState(); + + virtual void getWorldPosition(float& posX,float& posY,float& posZ)=0; + virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)=0; + virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0; + + virtual void setWorldPosition(float posX,float posY,float posZ)=0; + virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)=0; + + virtual void calculateWorldTransformations()=0; +}; + +#endif //PHY__MOTIONSTATE_H diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.cpp b/source/gameengine/Physics/common/PHY_IPhysicsController.cpp new file mode 100644 index 00000000000..ec0f7b9df3e --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IPhysicsController.cpp @@ -0,0 +1,39 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#include "PHY_IPhysicsController.h" + + +PHY_IPhysicsController::~PHY_IPhysicsController() +{ + +} + diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.h b/source/gameengine/Physics/common/PHY_IPhysicsController.h new file mode 100644 index 00000000000..e8309c0ca40 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IPhysicsController.h @@ -0,0 +1,89 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef PHY_IPHYSICSCONTROLLER_H +#define PHY_IPHYSICSCONTROLLER_H + +/** + PHY_IPhysicsController is the abstract simplified Interface to a physical object. + It contains the IMotionState and IDeformableMesh Interfaces. +*/ + + +class PHY_IPhysicsController +{ + + public: + + virtual ~PHY_IPhysicsController(); + /** + SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding') + */ + virtual bool SynchronizeMotionStates(float time)=0; + /** + WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding') + */ + + virtual void WriteMotionStateToDynamics(bool nondynaonly)=0; + virtual void WriteDynamicsToMotionState()=0; + // controller replication + virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)=0; + + // kinematic methods + virtual void RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local)=0; + virtual void RelativeRotate(const float drot[9],bool local)=0; + virtual void getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal)=0; + virtual void setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)=0; + virtual void setPosition(float posX,float posY,float posZ)=0; + virtual void setScaling(float scaleX,float scaleY,float scaleZ)=0; + + // physics methods + virtual void ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local)=0; + virtual void ApplyForce(float forceX,float forceY,float forceZ,bool local)=0; + virtual void SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local)=0; + virtual void SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local)=0; + virtual void applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)=0; + virtual void SetActive(bool active)=0; + + // reading out information from physics + virtual void GetLinearVelocity(float& linvX,float& linvY,float& linvZ)=0; + virtual void GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ)=0; + virtual void getReactionForce(float& forceX,float& forceY,float& forceZ)=0; + + // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted + virtual void setRigidBody(bool rigid)=0; + + // clientinfo for raycasts for example + virtual void* getClientInfo()=0; + virtual void setClientInfo(void* clientinfo)=0; +}; + +#endif //PHY_IPHYSICSCONTROLLER_H diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.cpp b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.cpp new file mode 100644 index 00000000000..7c0660976fb --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.cpp @@ -0,0 +1,45 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include "PHY_IPhysicsEnvironment.h" + +/** +* Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.) +* A derived class may be able to 'construct' entities by loading and/or converting +*/ + + + +PHY_IPhysicsEnvironment::~PHY_IPhysicsEnvironment() +{ + +} diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h new file mode 100644 index 00000000000..5867e27ce42 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -0,0 +1,60 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef _IPHYSICSENVIRONMENT +#define _IPHYSICSENVIRONMENT + +#include <vector> +#include "PHY_DynamicTypes.h" + + +/** +* Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.) +* A derived class may be able to 'construct' entities by loading and/or converting +*/ +class PHY_IPhysicsEnvironment +{ + public: + virtual ~PHY_IPhysicsEnvironment(); + /// Perform an integration step of duration 'timeStep'. + virtual void proceed(double timeStep)=0; + virtual void setGravity(float x,float y,float z)=0; + + virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, + float pivotX,float pivotY,float pivotZ, + float axisX,float axisY,float axisZ)=0; + virtual void removeConstraint(int constraintid)=0; + + virtual PHY_IPhysicsController* rayTest(void* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, + float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)=0; +}; + +#endif //_IPHYSICSENVIRONMENT diff --git a/source/gameengine/Physics/common/PHY_Pro.h b/source/gameengine/Physics/common/PHY_Pro.h new file mode 100644 index 00000000000..58f3badaff6 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_Pro.h @@ -0,0 +1,60 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ +#ifndef PHY_PROPSH +#define PHY_PROPSH + +#include <MT_Scalar.h> + +// Properties of dynamic objects +struct PHY_ShapeProps { + MT_Scalar m_mass; // Total mass + MT_Scalar m_inertia; // Inertia, should be a tensor some time + MT_Scalar m_lin_drag; // Linear drag (air, water) 0 = concrete, 1 = vacuum + MT_Scalar m_ang_drag; // Angular drag + MT_Scalar m_friction_scaling[3]; // Scaling for anisotropic friction. Component in range [0, 1] + bool m_do_anisotropic; // Should I do anisotropic friction? + bool m_do_fh; // Should the object have a linear Fh spring? + bool m_do_rot_fh; // Should the object have an angular Fh spring? +}; + + +// Properties of collidable objects (non-ghost objects) +struct PHY_MaterialProps { + MT_Scalar m_restitution; // restitution of energie after a collision 0 = inelastic, 1 = elastic + MT_Scalar m_friction; // Coulomb friction (= ratio between the normal en maximum friction force) + MT_Scalar m_fh_spring; // Spring constant (both linear and angular) + MT_Scalar m_fh_damping; // Damping factor (linear and angular) in range [0, 1] + MT_Scalar m_fh_distance; // The range above the surface where Fh is active. + bool m_fh_normal; // Should the object slide off slopes? +}; + +#endif //PHY_PROPSH |