mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
changes from drose for rotation by hpr
This commit is contained in:
parent
e0bfb4c3ef
commit
61a0e67462
@ -82,13 +82,13 @@ child_integrate(Physical *physical,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LVector3f accum_vec(0, 0, 0);
|
LRotationf accum_quat(0, 0, 0, 0);
|
||||||
|
|
||||||
// set up the traversal stuff.
|
// set up the traversal stuff.
|
||||||
ForceNode *force_node;
|
ForceNode *force_node;
|
||||||
AngularForceVector::const_iterator f_cur;
|
AngularForceVector::const_iterator f_cur;
|
||||||
|
|
||||||
LVector3f f;
|
LRotationf f;
|
||||||
|
|
||||||
// global forces
|
// global forces
|
||||||
f_cur = forces.begin();
|
f_cur = forces.begin();
|
||||||
@ -105,10 +105,10 @@ child_integrate(Physical *physical,
|
|||||||
|
|
||||||
// now we go from force space to our object's space.
|
// now we go from force space to our object's space.
|
||||||
assert(index >= 0 && index < matrices.size());
|
assert(index >= 0 && index < matrices.size());
|
||||||
f = cur_force->get_vector(current_object) * matrices[index++];
|
f = matrices[index++] * cur_force->get_quat(current_object);
|
||||||
|
|
||||||
// tally it into the accum vector, applying the inertial tensor.
|
// tally it into the accum vector, applying the inertial tensor.
|
||||||
accum_vec += f;
|
accum_quat += f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// local forces
|
// local forces
|
||||||
@ -125,39 +125,30 @@ child_integrate(Physical *physical,
|
|||||||
|
|
||||||
// go from force space to object space
|
// go from force space to object space
|
||||||
assert(index >= 0 && index < matrices.size());
|
assert(index >= 0 && index < matrices.size());
|
||||||
f = cur_force->get_vector(current_object) * matrices[index++];
|
f = matrices[index++] * cur_force->get_quat(current_object);
|
||||||
|
|
||||||
// tally it into the accum vectors
|
// tally it into the accum vectors
|
||||||
accum_vec += f;
|
accum_quat += f;
|
||||||
}
|
}
|
||||||
assert(index == matrices.size());
|
assert(index == matrices.size());
|
||||||
|
|
||||||
// apply the accumulated torque vector to the object's inertial tensor.
|
// apply the accumulated torque vector to the object's inertial tensor.
|
||||||
// this matrix represents how much force the object 'wants' applied to it
|
// this matrix represents how much force the object 'wants' applied to it
|
||||||
// in any direction, among other things.
|
// in any direction, among other things.
|
||||||
accum_vec = accum_vec * current_object->get_inertial_tensor();
|
accum_quat = current_object->get_inertial_tensor() * accum_quat;
|
||||||
|
|
||||||
// derive this into the angular velocity vector.
|
// derive this into the angular velocity vector.
|
||||||
LVector3f rot_vec = current_object->get_rotation();
|
LRotationf rot_quat = current_object->get_rotation();
|
||||||
rot_vec += accum_vec * dt;
|
rot_quat += (LVecBase4f(accum_quat) * dt);
|
||||||
|
|
||||||
// here's the trick. we've been accumulating these forces as vectors
|
|
||||||
// and treating them as vectors, but now we're going to treat them as pure
|
|
||||||
// imaginary quaternions where r = 0. This vector now represents the
|
|
||||||
// imaginary vector formed by (i, j, k).
|
|
||||||
float len = rot_vec.length();
|
|
||||||
if (len) {
|
|
||||||
LVector3f normalized_rot_vec = rot_vec;
|
|
||||||
normalized_rot_vec *= 1.0f / len;
|
|
||||||
LRotationf rot_quat = LRotationf(normalized_rot_vec, len);
|
|
||||||
|
|
||||||
|
if (rot_quat.normalize()) {
|
||||||
LOrientationf old_orientation = current_object->get_orientation();
|
LOrientationf old_orientation = current_object->get_orientation();
|
||||||
LOrientationf new_orientation = old_orientation * rot_quat;
|
LOrientationf new_orientation = old_orientation * rot_quat;
|
||||||
new_orientation.normalize();
|
new_orientation.normalize();
|
||||||
|
|
||||||
// and write the results back.
|
// and write the results back.
|
||||||
current_object->set_orientation(new_orientation);
|
current_object->set_orientation(new_orientation);
|
||||||
current_object->set_rotation(rot_vec);
|
current_object->set_rotation(rot_quat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,13 @@ AngularForce::
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : get_vector
|
// Function : get_quat
|
||||||
// Access : public
|
// Access : public
|
||||||
// Description : access query
|
// Description : access query
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
LVector3f AngularForce::
|
LRotationf AngularForce::
|
||||||
get_vector(const PhysicsObject *po) {
|
get_quat(const PhysicsObject *po) {
|
||||||
LVector3f v = get_child_vector(po);
|
LRotationf v = get_child_quat(po);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ PUBLISHED:
|
|||||||
virtual ~AngularForce();
|
virtual ~AngularForce();
|
||||||
|
|
||||||
virtual AngularForce *make_copy() const = 0;
|
virtual AngularForce *make_copy() const = 0;
|
||||||
LVector3f get_vector(const PhysicsObject *po);
|
LRotationf get_quat(const PhysicsObject *po);
|
||||||
virtual bool is_linear() const;
|
virtual bool is_linear() const;
|
||||||
|
|
||||||
virtual void output(ostream &out) const;
|
virtual void output(ostream &out) const;
|
||||||
@ -41,7 +41,7 @@ protected:
|
|||||||
AngularForce(const AngularForce ©);
|
AngularForce(const AngularForce ©);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual LVector3f get_child_vector(const PhysicsObject *po) = 0;
|
virtual LRotationf get_child_quat(const PhysicsObject *po) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
@ -17,28 +17,28 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : set_vector
|
// Function : set_quat
|
||||||
// Access : public
|
// Access : public
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void AngularVectorForce::
|
INLINE void AngularVectorForce::
|
||||||
set_vector(const LVector3f &v) {
|
set_quat(const LRotationf &v) {
|
||||||
_fvec = v;
|
_fvec = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : set_vector
|
// Function : set_hpr
|
||||||
// Access : public
|
// Access : public
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void AngularVectorForce::
|
INLINE void AngularVectorForce::
|
||||||
set_vector(float x, float y, float z) {
|
set_hpr(float h, float p, float r) {
|
||||||
_fvec.set(x, y, z);
|
_fvec.set_hpr(LVecBase3f(h, p, r));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : get_local_vector
|
// Function : get_local_quat
|
||||||
// Access : public
|
// Access : public
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE LVector3f AngularVectorForce::
|
INLINE LRotationf AngularVectorForce::
|
||||||
get_local_vector() const {
|
get_local_quat() const {
|
||||||
return _fvec;
|
return _fvec;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ TypeHandle AngularVectorForce::_type_handle;
|
|||||||
// Description : constructor
|
// Description : constructor
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
AngularVectorForce::
|
AngularVectorForce::
|
||||||
AngularVectorForce(const LVector3f &vec) :
|
AngularVectorForce(const LRotationf &vec) :
|
||||||
AngularForce(), _fvec(vec) {
|
AngularForce(), _fvec(vec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,9 +36,9 @@ AngularVectorForce(const LVector3f &vec) :
|
|||||||
// Description : constructor
|
// Description : constructor
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
AngularVectorForce::
|
AngularVectorForce::
|
||||||
AngularVectorForce(float x, float y, float z) :
|
AngularVectorForce(float h, float p, float r) :
|
||||||
AngularForce() {
|
AngularForce() {
|
||||||
_fvec.set(x, y, z);
|
_fvec.set_hpr(LVecBase3f(h, p, r));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -72,12 +72,12 @@ make_copy() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : get_child_vector
|
// Function : get_child_quat
|
||||||
// Access : private, virtual
|
// Access : private, virtual
|
||||||
// Description : query
|
// Description : query
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
LVector3f AngularVectorForce::
|
LRotationf AngularVectorForce::
|
||||||
get_child_vector(const PhysicsObject *) {
|
get_child_quat(const PhysicsObject *) {
|
||||||
return _fvec;
|
return _fvec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,23 +28,23 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_PANDAPHYSICS AngularVectorForce : public AngularForce {
|
class EXPCL_PANDAPHYSICS AngularVectorForce : public AngularForce {
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
AngularVectorForce(const LVector3f& vec);
|
AngularVectorForce(const LRotationf& quat);
|
||||||
AngularVectorForce(float x = 0.0f, float y = 0.0f, float z = 0.0f);
|
AngularVectorForce(float h, float p, float r);
|
||||||
AngularVectorForce(const AngularVectorForce ©);
|
AngularVectorForce(const AngularVectorForce ©);
|
||||||
virtual ~AngularVectorForce();
|
virtual ~AngularVectorForce();
|
||||||
|
|
||||||
INLINE void set_vector(const LVector3f& v);
|
INLINE void set_quat(const LRotationf& quat);
|
||||||
INLINE void set_vector(float x, float y, float z);
|
INLINE void set_hpr(float h, float p, float r);
|
||||||
INLINE LVector3f get_local_vector() const;
|
INLINE LRotationf get_local_quat() const;
|
||||||
|
|
||||||
virtual void output(ostream &out) const;
|
virtual void output(ostream &out) const;
|
||||||
virtual void write(ostream &out, unsigned int indent=0) const;
|
virtual void write(ostream &out, unsigned int indent=0) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LVector3f _fvec;
|
LRotationf _fvec;
|
||||||
|
|
||||||
virtual AngularForce *make_copy() const;
|
virtual AngularForce *make_copy() const;
|
||||||
virtual LVector3f get_child_vector(const PhysicsObject *po);
|
virtual LRotationf get_child_quat(const PhysicsObject *po);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
@ -42,8 +42,6 @@ PUBLISHED:
|
|||||||
|
|
||||||
INLINE ForceNode *get_force_node() const;
|
INLINE ForceNode *get_force_node() const;
|
||||||
|
|
||||||
virtual LVector3f get_vector(const PhysicsObject *po) = 0;
|
|
||||||
|
|
||||||
virtual void output(ostream &out) const;
|
virtual void output(ostream &out) const;
|
||||||
virtual void write(ostream &out, unsigned int indent=0) const;
|
virtual void write(ostream &out, unsigned int indent=0) const;
|
||||||
|
|
||||||
@ -55,8 +53,6 @@ private:
|
|||||||
ForceNode *_force_node;
|
ForceNode *_force_node;
|
||||||
bool _active;
|
bool _active;
|
||||||
|
|
||||||
virtual LVector3f get_child_vector(const PhysicsObject *po) = 0;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
return _type_handle;
|
return _type_handle;
|
||||||
|
@ -38,7 +38,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
INLINE void set_vector_masks(bool x, bool y, bool z);
|
INLINE void set_vector_masks(bool x, bool y, bool z);
|
||||||
|
|
||||||
virtual LVector3f get_vector(const PhysicsObject *po);
|
LVector3f get_vector(const PhysicsObject *po);
|
||||||
|
|
||||||
virtual LinearForce *make_copy() = 0;
|
virtual LinearForce *make_copy() = 0;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ INLINE void PhysicsObject::
|
|||||||
reset_orientation(const LOrientationf &orientation) {
|
reset_orientation(const LOrientationf &orientation) {
|
||||||
nassertv(!orientation.is_nan());
|
nassertv(!orientation.is_nan());
|
||||||
_orientation = orientation;
|
_orientation = orientation;
|
||||||
_rotation.set(0.0f, 0.0f, 0.0f);
|
_rotation = LRotationf::ident_quat();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -226,10 +226,10 @@ set_orientation(const LOrientationf &orientation) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function : set_rotation
|
// Function : set_rotation
|
||||||
// Access : Public
|
// Access : Public
|
||||||
// Description : set rotation on each axis per second.
|
// Description : set rotation as a quaternion delta per second.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void PhysicsObject::
|
INLINE void PhysicsObject::
|
||||||
set_rotation(const LVector3f &rotation) {
|
set_rotation(const LRotationf &rotation) {
|
||||||
nassertv(!rotation.is_nan());
|
nassertv(!rotation.is_nan());
|
||||||
_rotation = rotation;
|
_rotation = rotation;
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ get_orientation() const {
|
|||||||
// Access : Public
|
// Access : Public
|
||||||
// Description : get rotation per second.
|
// Description : get rotation per second.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE LVector3f PhysicsObject::
|
INLINE LRotationf PhysicsObject::
|
||||||
get_rotation() const {
|
get_rotation() const {
|
||||||
return _rotation;
|
return _rotation;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ PhysicsObject() :
|
|||||||
_last_position = _position;
|
_last_position = _position;
|
||||||
_velocity.set(0.0f, 0.0f, 0.0f);
|
_velocity.set(0.0f, 0.0f, 0.0f);
|
||||||
_orientation.set(1.0 ,0.0f, 0.0f, 0.0f);
|
_orientation.set(1.0 ,0.0f, 0.0f, 0.0f);
|
||||||
_rotation.set(0.0f, 0.0f, 0.0f);
|
_rotation = LRotationf::ident_quat();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -75,8 +75,8 @@ PUBLISHED:
|
|||||||
|
|
||||||
INLINE void reset_orientation(const LOrientationf &orientation);
|
INLINE void reset_orientation(const LOrientationf &orientation);
|
||||||
|
|
||||||
INLINE void set_rotation(const LVector3f &rotation);
|
INLINE void set_rotation(const LRotationf &rotation);
|
||||||
INLINE LVector3f get_rotation() const;
|
INLINE LRotationf get_rotation() const;
|
||||||
|
|
||||||
virtual LMatrix4f get_inertial_tensor() const;
|
virtual LMatrix4f get_inertial_tensor() const;
|
||||||
virtual LMatrix4f get_lcs() const;
|
virtual LMatrix4f get_lcs() const;
|
||||||
@ -102,7 +102,7 @@ private:
|
|||||||
|
|
||||||
// angular
|
// angular
|
||||||
LOrientationf _orientation;
|
LOrientationf _orientation;
|
||||||
LVector3f _rotation;
|
LRotationf _rotation;
|
||||||
|
|
||||||
float _terminal_velocity;
|
float _terminal_velocity;
|
||||||
float _mass;
|
float _mass;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user