Panda3D
physxControllerReport.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physxControllerReport.cxx
10  * @author enn0x
11  * @date 2009-09-24
12  */
13 
14 #include "physxControllerReport.h"
15 
16 PStatCollector PhysxControllerReport::_pcollector("App:PhysX:Controller Reporting");
17 
18 /**
19  *
20  */
21 void PhysxControllerReport::
22 enable() {
23 
24  _enabled = true;
25 
26  _shape_hit_cbobj = nullptr;
27  _controller_hit_cbobj = nullptr;
28 }
29 
30 /**
31  *
32  */
33 void PhysxControllerReport::
34 disable() {
35 
36  _enabled = false;
37 }
38 
39 /**
40  *
41  */
42 bool PhysxControllerReport::
43 is_enabled() const {
44 
45  return _enabled;
46 }
47 
48 /**
49  *
50  */
51 NxControllerAction PhysxControllerReport::
52 onShapeHit( const NxControllerShapeHit& hit ) {
53 
54  if (!_enabled) {
55  return NX_ACTION_NONE;
56  }
57 
58  _pcollector.start();
59 
60  if (_shape_hit_cbobj) {
61  // Callback
62  PhysxControllerShapeHit cbdata(hit);
63  _shape_hit_cbobj->do_callback(&cbdata);
64  }
65  else {
66  // Default implementation
67  if (1 && hit.shape) {
68  NxActor& actor = hit.shape->getActor();
69  if (actor.isDynamic() && !actor.readBodyFlag(NX_BF_KINEMATIC)) {
70  if (hit.dir.z == 0.0f) {
71  NxF32 controllerMass = hit.controller->getActor()->getMass();
72  NxF32 coeff = actor.getMass() * hit.length * controllerMass;
73  actor.addForceAtLocalPos(hit.dir*coeff, NxVec3(0,0,0), NX_IMPULSE);
74  }
75  }
76  }
77  }
78 
79  _pcollector.stop();
80 
81  return NX_ACTION_NONE;
82 }
83 
84 /**
85  *
86  */
87 NxControllerAction PhysxControllerReport::
88 onControllerHit(const NxControllersHit& hit) {
89 
90  if (!_enabled) {
91  return NX_ACTION_NONE;
92  }
93 
94  _pcollector.start();
95 
96  if (_controller_hit_cbobj) {
97  // Callback
98  PhysxControllersHit cbdata(hit);
99  _controller_hit_cbobj->do_callback(&cbdata);
100  }
101  else {
102  // Default implementation
103  if (1 && hit.other) {
104  // For now other controllers are unpushable. --TODO-- return
105  // NX_ACTION_PUSH; is not implemented!
106  }
107  }
108 
109  _pcollector.stop();
110 
111  return NX_ACTION_NONE;
112 }
A lightweight class that represents a single element that may be timed and/or counted via stats.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.