source: trunk/test/Physics/Include/EasyCharacterController.h @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

File size: 3.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//            (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
6//   This program is free software; you can redistribute it and/or
7//   modify it under the terms of the Do What The Fuck You Want To
8//   Public License, Version 2, as published by Sam Hocevar. See
9//   http://www.wtfpl.net/ for more details.
10//
11
12//
13// The EasyCharacterController class
14// ------------------
15//
16
17//Should try to to make a btKinematicCharacterController for real.
18//
19
20#if !defined __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
21#define __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
22
23#ifdef HAVE_PHYS_USE_BULLET
24#include "core.h"
25#include "EasyPhysics.h"
26#include "BulletCharacterController.h"
27#include <BulletDynamics/Character/btKinematicCharacterController.h>
28#endif
29
30namespace lol
31{
32
33namespace phys
34{
35
36class EasyCharacterController : public EasyPhysic,
37                                public Entity
38{
39
40    friend class Simulation;
41    friend class EasyPhysic;
42
43#ifdef HAVE_PHYS_USE_BULLET
44
45public:
46    EasyCharacterController(WorldEntity* NewOwnerEntity) :
47        EasyPhysic(NewOwnerEntity),
48        m_pair_caching_object(NULL),
49        m_character(NULL),
50        m_step_height(.0f),
51        m_base_is_updating(false),
52        m_base_cached_movement(vec3(0.f)),
53        m_frame_cached_movement(vec3(0.f)),
54        m_walk_velocity(vec3(0.f)),
55        m_current_velocity(vec3(0.f))
56    {
57        m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
58        m_up_axis = 1;
59        m_gravity = vec3(.0f, -9.81f, .0f);
60        m_walk_velocity_damping = 0.2f;
61    }
62    ~EasyCharacterController()
63    {
64        delete m_character;
65    }
66
67    virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
68    virtual void InitBodyToGhost();
69    virtual void AddToSimulation(class Simulation* current_simulation);
70    virtual void RemoveFromSimulation(class Simulation* current_simulation);
71    virtual void SetMovementForFrame(vec3 const &MoveQuantity);
72    virtual void Jump();
73
74    virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
75protected:
76    virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
77    virtual char const *GetName();
78public:
79    virtual void TickGame(float seconds);
80
81protected:
82
83    virtual btGhostObject* GetGhostObjectInstance();
84
85    btPairCachingGhostObject*        m_pair_caching_object;
86    //btKinematicCharacterController*    m_character;
87    BulletKinematicCharacterController* m_character;
88
89    float                            m_step_height;
90    int                                m_up_axis;
91    bool                            m_base_is_updating;
92    vec3                            m_base_cached_movement;
93    vec3                            m_frame_cached_movement;
94
95    //----
96    float                            m_walk_velocity_damping;
97
98    //----
99    vec3                            m_gravity;
100
101    //----
102    vec3                            m_walk_velocity;
103    vec3                            m_current_velocity;
104
105#else  // NO PHYSIC IMPLEMENTATION
106
107    virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
108    virtual void InitBodyToGhost() { }
109    virtual void AddToSimulation(class Simulation* current_simulation) { }
110    virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
111    virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
112
113#endif // PHYSIC IMPLEMENTATION
114
115};
116
117} /* namespace phys */
118
119} /* namespace lol */
120
121#endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */
122
Note: See TracBrowser for help on using the repository browser.