AnnPhysicsEngine.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include "systemMacro.h"
10 
11 #include <memory>
12 
13 //Bullet
14 #include <btBulletCollisionCommon.h>
15 #include <btBulletDynamicsCommon.h>
16 
17 //btOgre
18 #include <BtOgre.hpp>
19 
20 //Annwvyn
21 #include <AnnTypes.h>
22 #include <AnnSubsystem.hpp>
23 
24 //easy bitmasks
25 #define MASK(x) (1 << (x))
26 
27 namespace Annwvyn
28 {
29  class AnnPhysicsEngine;
31 
32  class AnnPlayerBody;
33  class AnnGameObject;
34  class AnnVect3;
35 
37 }
38 
39 namespace Annwvyn
40 {
43  {
44  public:
46  {
47  const auto major = BT_BULLET_VERSION / 100;
48  const auto minor = BT_BULLET_VERSION - (major * 100);
49  return std::to_string(major) + "." + std::to_string(minor);
50  }
51 
53  enum CollisionMasks : int {
54  Player = MASK(0),
55  General = MASK(1),
56 
57  ColideWithAll = Player | General,
58  };
59 
61  AnnPhysicsEngine(Ogre::SceneNode* rootNode, AnnPlayerBodyPtr player);
62 
65 
67  void addPlayerPhysicalBodyToDynamicsWorld() const;
68 
70  void createPlayerPhysicalVirtualBody(Ogre::SceneNode* node);
71 
73  void createVirtualBodyShape(float radius = 0.125f) const;
74 
76  btDiscreteDynamicsWorld* getWorld() const;
77 
80  void step(float delta) const;
81 
83  void processCollisionTesting() const;
84 
86  void removeRigidBody(btRigidBody* body) const;
87 
89  void initPlayerStandingPhysics(Ogre::SceneNode* playerAnchorNode);
90 
92  void initPlayerRoomscalePhysics(Ogre::SceneNode* playerAnchorNode) const;
93 
95  void setDebugPhysics(bool state);
96 
98  void stepDebugDrawer() const;
99 
101  void changeGravity(AnnVect3 gravity) const;
102 
104  void resetGravity() const;
105 
107  void toggleDebugPhysics();
108 
110  void setDebugDrawerColorMultiplier(float value) const;
111 
113  btCollisionShape* _getGameObjectShape(AnnGameObject* obj, phyShapeType type);
114 
115  private:
116  friend class AnnEngine;
118  void update() override;
119 
122 
125 
128 
131 
134 
137 
140 
142  BtOgre::RigidBodyState* playerRigidBodyState;
143 
146 
149  };
150 }
std::unique_ptr< btDiscreteDynamicsWorld > DynamicsWorld
Bullet Dynamics World.
file for defining macros used for symbol export regarding the way the OS does things.
std::unique_ptr< btBroadphaseInterface > Broadphase
Bullet Broadphase.
T to_string(T... args)
std::unique_ptr< btDefaultCollisionConfiguration > CollisionConfiguration
Bullet Default Collision Configuration.
#define MASK(x)
Main engine class. Creating an instance of this class make the engine start.
Definition: AnnEngine.hpp:70
Class that abstract the physics engine initialization and collision information queries for Annwvyn...
A 3D Vector.
Definition: AnnVect3.hpp:16
bool debugPhysics
Should use the debug drawer.
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
static std::string getBulletVersion()
An object that exist in the game. Graphically and Potentially Physically.
phyShapeType
Definition: AnnTypes.h:43
std::unique_ptr< btCollisionDispatcher > Dispatcher
Bullet Collision Dispatcher.
BtOgre::RigidBodyState * playerRigidBodyState
Rigid body state from BtOgre for the Player object.
class that represent the player. This is the user&#39;s "Virtual body" in the world. It&#39;s the object that...
AnnVect3 defaultGravity
Default value for gravity. Should be initialized to (0, -9.82f, 0) unless something is wrong with thi...
std::unique_ptr< BtOgre::DebugDrawer > debugDrawer
Debug drawer object from BtOgre.
Parent class of all Annwvyn SubSystem.
AnnPlayerBodyPtr playerObject
Shared pointer to the player.
Data types definition for Annwvyn.
#define AnnDllExport
Definition: systemMacro.h:24
CollisionMasks
Flag for collisions.
std::unique_ptr< btSequentialImpulseConstraintSolver > Solver
Bullet Sequential Impulse Constraint Solver.