16 #include "eventQueue.h" 17 #include "eventParameter.h" 19 #include "physxController.h" 20 #include "physxManager.h" 21 #include "physxActor.h" 22 #include "physxBoxController.h" 23 #include "physxCapsuleController.h" 32 void PhysxController::
35 nassertv(_error_type == ET_ok);
39 cm->releaseController(*ptr());
48 factory(NxControllerType controllerType) {
50 switch (controllerType) {
52 case NX_CONTROLLER_BOX:
55 case NX_CONTROLLER_CAPSULE:
62 physx_cat.error() <<
"Unknown controller type.\n";
76 nassertr(_error_type == ET_ok, NULL);
77 return (
PhysxActor *)(ptr()->getActor()->userData);
90 nassertv(_error_type == ET_ok);
120 nassertv(_error_type == ET_ok);
121 nassertv(sharpness > 0.0f);
122 nassertv(sharpness <= 1.0f);
124 _sharpness = sharpness;
137 nassertr(_error_type == ET_ok, 0.0f);
150 nassertv(_error_type == ET_ok);
151 ptr()->setCollision(enable);
167 nassertv(_error_type == ET_ok);
168 nassertv(min_dist > 0.0f);
170 _min_dist = min_dist;
181 nassertv(_error_type == ET_ok);
182 nassertv(offset > 0.0f);
184 ptr()->setStepOffset(offset);
196 nassertv(_error_type == ET_ok);
197 nassertv_always(!speed.
is_nan());
199 _speed = NxVec3(speed.get_x(), speed.get_y(), speed.get_z());
211 nassertv(_error_type == ET_ok);
212 nassertv_always(!speed.
is_nan());
215 nassertv(!np.is_empty());
217 NxQuat q = ptr()->getActor()->getGlobalOrientationQuat();
218 NxVec3 s = NxVec3(speed.get_x(), speed.get_y(), speed.get_z());
219 _speed = (q * _up_quat_inv).rot(s);
233 nassertv(_error_type == ET_ok);
248 nassertv(_error_type == ET_ok);
251 NxQuat q(_heading, _up_vector);
252 ptr()->getActor()->moveGlobalOrientationQuat(_up_quat * q);
264 nassertr(_error_type == ET_ok, 0.0f);
280 nassertv(_error_type == ET_ok);
281 ptr()->reportSceneChanged();
289 void PhysxController::
290 update_controller(
float dt) {
292 nassertv(_error_type == ET_ok);
295 NxU32 mask = 0xFFFFFFFF;
296 NxU32 collision_flags;
299 ptr()->getActor()->getScene().getGravity(gravity);
301 NxVec3 d = (_speed + gravity) * dt;
303 NxReal heightDelta = get_jump_height(dt, gravity);
304 if (heightDelta != 0.0f) {
305 ((_up_axis == NX_Z) ? d.z : d.y) += heightDelta;
308 ptr()->move(d, mask, _min_dist, collision_flags, _sharpness);
310 if (collision_flags & NXCC_COLLISION_DOWN) {
315 if (_omega != 0.0f) {
316 NxReal delta = _omega * dt;
318 NxQuat q(_heading, _up_vector);
319 ptr()->getActor()->moveGlobalOrientationQuat(_up_quat * q);
332 NxReal PhysxController::
333 get_jump_height(
float dt, NxVec3 &gravity) {
335 if (_jumping ==
false) {
341 float G = (_up_axis == NX_Z) ? gravity.z : gravity.y;
342 float h = 2.0f * G * _jump_time * _jump_time + _jump_v0 * _jump_time;
355 nassertv(_error_type == ET_ok);
357 if (_jumping ==
true) {
376 nassertv(_error_type == ET_ok);
378 if (_jumping ==
false) {
387 Event *
event =
new Event(
"physx-controller-down");
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.
static const LPoint3f & zero()
Returns a zero-length point.
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.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
LPoint3f get_pos() const
Retruns the position of the controller is global space.
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
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.
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...
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.
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.
void set_pos(const LPoint3f &pos)
Sets the position of the controller is global space.