source: trunk/test/Physics/Src/EasyCharacterController.cpp @ 1749

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

Reverted last CL

File size: 2.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//            (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
6//            (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
7//   This program is free software; you can redistribute it and/or
8//   modify it under the terms of the Do What The Fuck You Want To
9//   Public License, Version 2, as published by Sam Hocevar. See
10//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
11//
12
13#if defined HAVE_CONFIG_H
14#   include "config.h"
15#endif
16
17#include "../Include/LolBtPhysicsIntegration.h"
18#include "../Include/LolPhysics.h"
19#include "../Include/EasyCharacterController.h"
20
21namespace lol
22{
23
24namespace phys
25{
26
27#ifdef HAVE_PHYS_USE_BULLET
28
29//-------------------------------------------------------------------------
30//EASY_CHARACTER_CONTROLLER
31//--
32
33//Deactivated for Character controller
34void EasyCharacterController::InitBodyToRigid(bool ZeroMassIsKinematic)
35{
36}
37
38//Return correct Ghost Object
39btGhostObject* EasyCharacterController::GetGhostObject()
40{
41        return new btPairCachingGhostObject();
42}
43
44//Init to Pair caching ghost object, since Character uses that one.
45void EasyCharacterController::InitBodyToGhost()
46{
47        EasyPhysic::InitBodyToGhost();
48
49        m_pair_caching_object = (btPairCachingGhostObject*)m_ghost_object;
50        m_ghost_object->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT | m_ghost_object->getCollisionFlags());
51}
52
53//Add Physic object to the simulation
54void EasyCharacterController::AddToSimulation(class Simulation* current_simulation)
55{
56        EasyPhysic::AddToSimulation(current_simulation);
57
58        btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
59        if (dynamics_world)
60        {
61                if (m_character)
62                        delete m_character;
63
64                m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis);
65                dynamics_world->addAction(m_character);
66        }
67}
68
69//Remove Physic object to the simulation
70void EasyCharacterController::RemoveFromSimulation(class Simulation* current_simulation)
71{
72        EasyPhysic::RemoveFromSimulation(current_simulation);
73
74        btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
75        if (dynamics_world)
76        {
77                if (m_character)
78                        dynamics_world->removeAction(m_character);
79        }
80}
81
82//Set movement for this frame
83void EasyCharacterController::SetMovementForFrame(vec3 const &MoveQuantity)
84{
85        m_character->setWalkDirection(LOL2BT_VEC3(MoveQuantity));
86}
87
88#endif // HAVE_PHYS_USE_BULLET
89
90} /* namespace phys */
91
92} /* namespace lol */
Note: See TracBrowser for help on using the repository browser.