/** get the world tansform of the linked position * @param worldTrans out parameter to palce transform in * @warning this method is called by physics library and should * not be called directly */ void MotionState::getWorldTransform(btTransform &worldTrans) const { // set the location/origin Vector3 l = this->shape._getTranslation(); if (this->position != nullptr) l += this->position->getLocation(); worldTrans.setOrigin (btVector3(l.x(), l.y(), l.z())); // set the basis/rotational matrix // since openGL matrix is column major and Bullet is row // major, we have to do some converting Matrix3 matrix; if (this->position != nullptr) { matrix.setColumn(0, this->position->getLocalXAxis()); matrix.setColumn(1, this->position->getUpVector()); matrix.setColumn(2, this->position->getForwardVector()); } matrix.multiply(this->shape._getRotation()); btMatrix3x3 rot; rot.setValue( // fill in x axis, first column matrix.getColumn(0).x(), matrix.getColumn(0).y(), matrix.getColumn(0).z(), // fill in y axis, second column matrix.getColumn(1).x(), matrix.getColumn(1).y(), matrix.getColumn(1).z(), // fill in z axis, thrid column matrix.getColumn(2).x(), matrix.getColumn(2).y(), matrix.getColumn(2).z() ); worldTrans.setBasis(rot); }
Real estimateScalingFactor(Matrix3 const & m) { return (m.getColumn(0).fastLength() + m.getColumn(1).fastLength() + m.getColumn(2).fastLength()) / 3.0f; }
Matrix3 orthonormalBasisMatrix(Matrix3 const & m) { return orthonormalBasisMatrix(m.getColumn(0), m.getColumn(1), m.getColumn(2)); }
inline Vector3 Camera::getWorldRVector() const { Matrix3 m = world.getRotate(); return m.getColumn(2); }
inline Vector3 Camera::getRVector () const { Matrix3 m = local.getRotate(); return m.getColumn(2); }
bool WindowedApp3d::moveObject () { // The coordinate system in which the rotations are applied is that of // the object's parent, if it has one. The parent's world rotation // matrix is R, of which the columns are the coordinate axis directions. // Column 0 is "direction", column 1 is "up", and column 2 is "right". // If the object does not have a parent, the world coordinate axes are // used, in which case the rotation matrix is I, the identity. Column 0 // is (1,0,0) and is "direction", column 1 is (0,1,0) and is "up", and // column 2 is (0,0,1) and is "right". This choice is consistent with // the use of rotations in the Camera and Light classes to store // coordinate axes. // // Roll is about the "direction" axis, yaw is about the "up" axis, and // pitch is about the "right" axis. if ( !m_bCameraMoveable || !motionObject ) return false; RenderObject* pkParent = motionObject->getParent(); Vector3 kAxis; float fAngle; Matrix3 kRot, kIncr; Matrix3 m; if ( m_iDoRoll ) { motionObject->localTrans.getMatrix(m); kRot = m; fAngle = m_iDoRoll*m_fRotSpeed; if ( pkParent ) { pkParent->worldTrans.getMatrix(m); kAxis = m.getColumn(0); } else kAxis = Vector3::UNIT_X; kIncr.fromAxisAngle(kAxis,fAngle); motionObject->localTrans.setMatrix(kIncr*kRot); return true; } if ( m_iDoYaw ) { motionObject->localTrans.getMatrix(m); kRot = m; fAngle = m_iDoYaw*m_fRotSpeed; if ( pkParent ) { pkParent->worldTrans.getMatrix(m); kAxis = m.getColumn(1); } else kAxis = Vector3::UNIT_Y; kIncr.fromAxisAngle(kAxis,fAngle); motionObject->localTrans.setMatrix(kIncr*kRot); return true; } if ( m_iDoPitch ) { motionObject->localTrans.getMatrix(m); kRot = m; fAngle = m_iDoPitch*m_fRotSpeed; if ( pkParent ) { pkParent->worldTrans.getMatrix(m); kAxis = m.getColumn(2); } else kAxis = Vector3::UNIT_Z; kIncr.fromAxisAngle(kAxis,fAngle); motionObject->localTrans.setMatrix(kIncr*kRot); return true; } return false; }