29 void PhysxController::
32 nassertv(_error_type == ET_ok);
36 cm->releaseController(*ptr());
43 factory(NxControllerType controllerType) {
45 switch (controllerType) {
47 case NX_CONTROLLER_BOX:
50 case NX_CONTROLLER_CAPSULE:
57 physx_cat.error() <<
"Unknown controller type.\n";
68 nassertr(_error_type == ET_ok,
nullptr);
69 return (
PhysxActor *)(ptr()->getActor()->userData);
79 nassertv(_error_type == ET_ok);
89 nassertr(_error_type == ET_ok, LPoint3f::zero());
102 nassertv(_error_type == ET_ok);
103 nassertv(sharpness > 0.0f);
104 nassertv(sharpness <= 1.0f);
106 _sharpness = sharpness;
116 nassertr(_error_type == ET_ok, 0.0f);
126 nassertv(_error_type == ET_ok);
127 ptr()->setCollision(enable);
139 nassertv(_error_type == ET_ok);
140 nassertv(min_dist > 0.0f);
142 _min_dist = min_dist;
151 nassertv(_error_type == ET_ok);
152 nassertv(offset > 0.0f);
154 ptr()->setStepOffset(offset);
163 nassertv(_error_type == ET_ok);
164 nassertv_always(!speed.is_nan());
166 _speed = NxVec3(speed.get_x(), speed.get_y(), speed.get_z());
175 nassertv(_error_type == ET_ok);
176 nassertv_always(!speed.is_nan());
179 nassertv(!np.is_empty());
181 NxQuat q = ptr()->getActor()->getGlobalOrientationQuat();
182 NxVec3 s = NxVec3(speed.get_x(), speed.get_y(), speed.get_z());
183 _speed = (q * _up_quat_inv).rot(s);
194 nassertv(_error_type == ET_ok);
206 nassertv(_error_type == ET_ok);
209 NxQuat q(_heading, _up_vector);
210 ptr()->getActor()->moveGlobalOrientationQuat(_up_quat * q);
219 nassertr(_error_type == ET_ok, 0.0f);
231 nassertv(_error_type == ET_ok);
232 ptr()->reportSceneChanged();
238 void PhysxController::
239 update_controller(
float dt) {
241 nassertv(_error_type == ET_ok);
244 NxU32 mask = 0xFFFFFFFF;
245 NxU32 collision_flags;
248 ptr()->getActor()->getScene().getGravity(gravity);
250 NxVec3 d = (_speed + gravity) * dt;
252 NxReal heightDelta = get_jump_height(dt, gravity);
253 if (heightDelta != 0.0f) {
254 ((_up_axis == NX_Z) ? d.z : d.y) += heightDelta;
257 ptr()->move(d, mask, _min_dist, collision_flags, _sharpness);
259 if (collision_flags & NXCC_COLLISION_DOWN) {
264 if (_omega != 0.0f) {
265 NxReal delta = _omega * dt;
267 NxQuat q(_heading, _up_vector);
268 ptr()->getActor()->moveGlobalOrientationQuat(_up_quat * q);
279 NxReal PhysxController::
280 get_jump_height(
float dt, NxVec3 &gravity) {
282 if (_jumping ==
false) {
288 float G = (_up_axis == NX_Z) ? gravity.z : gravity.y;
289 float h = 2.0f * G * _jump_time * _jump_time + _jump_v0 * _jump_time;
300 nassertv(_error_type == ET_ok);
302 if (_jumping ==
true) {
318 nassertv(_error_type == ET_ok);
320 if (_jumping ==
false) {
329 Event *
event =
new Event(
"physx-controller-down");
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_sharpness(float sharpness)
Sharpness is used to smooth motion with a feedback filter, having a value between 0 (so smooth it doe...
void report_scene_changed()
The character controller uses caching in order to speed up collision testing, this caching can not de...
void set_global_speed(const LVector3f &speed)
Sets the linear speed of the controller in global space.
void set_h(float heading)
Sets the heading of the controller is global space.
An optional parameter associated with an event.
A capsule character controller.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_collision(bool enable)
Enable/Disable collisions for this controller and actor.
PhysxActor * get_actor() const
Retrieves the actor which this controller is associated with.
void stop_jump()
Leaves the jump mode.
LPoint3f get_pos() const
Retruns the position of the controller is global space.
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static NxExtendedVec3 point3_to_nxExtVec3(const LPoint3f &p)
Converts from LPoint3f to NxExtendedVec3.
void set_min_distance(float min_dist)
Sets the the minimum travelled distance to consider when moving the controller.
static LPoint3f nxExtVec3_to_point3(const NxExtendedVec3 &p)
Converts from NxExtendedVec3 to LPoint3f.
Box character controller.
Abstract base class for character controllers.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Actors are the main simulation objects.
void set_step_offset(float offset)
Sets the step height/offset for the controller.
float get_h() const
Returns the heading of the controller in global space.
float get_sharpness() const
Returns the sharpness used to ease the motion curve when the auto-step feature is used.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_omega(float omega)
Sets the angular velocity (degrees per second) of the controller.
A named event, possibly with parameters.
void set_local_speed(const LVector3f &speed)
Sets the linear speed of the controller in local coordinates.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysxScene * get_scene() const
Retrieves the scene which this actor belongs to.
TypeHandle is the identifier used to differentiate C++ class types.
NodePath get_node_path() const
Retrieves a previously attached NodePath.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
void start_jump(float v0)
Enters the jump mode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_pos(const LPoint3f &pos)
Sets the position of the controller is global space.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.