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

Last change on this file since 1768 was 1768, checked in by touky, 8 years ago

Added Attachment/base logic with working attachment with EasyCharacterController.
Added RayCastResult & a naïve integration for EasyCharacterController.
Enjoy !

File size: 2.6 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://sam.zoy.org/projects/COPYING.WTFPL for more details.
10//
11
12//
13// The EasyPhysic class
14// ------------------
15//
16
17#if !defined __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
18#define __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__
19
20#ifdef HAVE_PHYS_USE_BULLET
21#include "core.h"
22#include "EasyPhysics.h"
23#include <BulletDynamics/Character/btKinematicCharacterController.h>
24#endif
25
26namespace lol
27{
28
29namespace phys
30{
31
32class EasyCharacterController : public EasyPhysic,
33                                                                public Entity
34{
35
36#ifdef HAVE_PHYS_USE_BULLET
37
38public:
39        EasyCharacterController(WorldEntity* NewOwnerEntity) :
40                EasyPhysic(NewOwnerEntity),
41                m_pair_caching_object(NULL),
42                m_character(NULL),
43                m_step_height(.0f),
44                m_base_is_updating(false),
45                m_base_cached_movement(vec3(0.f)),
46                m_frame_cached_movement(vec3(0.f))
47        {
48                m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
49                m_up_axis = 1;
50        }
51        ~EasyCharacterController()
52        {
53                delete m_character;
54        }
55
56        virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false);
57        virtual void InitBodyToGhost();
58        virtual void AddToSimulation(class Simulation* current_simulation);
59        virtual void RemoveFromSimulation(class Simulation* current_simulation);
60        virtual void SetMovementForFrame(vec3 const &MoveQuantity);
61
62        virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
63protected:
64        virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
65public:
66        virtual void TickGame(float seconds);
67
68protected:
69
70        virtual btGhostObject* GetGhostObjectInstance();
71
72        btPairCachingGhostObject*               m_pair_caching_object;
73        btKinematicCharacterController* m_character;
74
75        float                                                   m_step_height;
76        int                                                             m_up_axis;
77        bool                                                    m_base_is_updating;
78        vec3                                                    m_base_cached_movement;
79        vec3                                                    m_frame_cached_movement;
80
81#else  // NO PHYSIC IMPLEMENTATION
82
83        virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false) { }
84        virtual void InitBodyToGhost() { }
85        virtual void AddToSimulation(class Simulation* current_simulation) { }
86        virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
87        virtual void SetMovementForFrame(vec3 const &MoveQuantity) { }
88
89#endif // PHYSIC IMPLEMENTATION
90
91};
92
93} /* namespace phys */
94
95} /* namespace lol */
96
97#endif /* __EASYCHARACTERCONTROLLER_EASYCHARACTERCONTROLLER_H__ */
98
Note: See TracBrowser for help on using the repository browser.