//------------------------------------------------------------------------------- // @ SimObject::Integrate() //------------------------------------------------------------------------------- // Move to next time step //------------------------------------------------------------------------------- void SimObject::Integrate( float dt ) { // compute acceleration IvVector3 accel = 1.0f/mMass * CurrentForce( mTranslate, mVelocity, mRotate, mAngularVelocity ); // clear small values accel.Clean(); // compute new velocity, position mVelocity += dt*accel; // clear small values mVelocity.Clean(); mTranslate += dt*mVelocity; IvVector3 torque = CurrentTorque( mTranslate, mVelocity, mRotate, mAngularVelocity ); // compute new angular momentum, orientation mAngularMomentum += dt*torque; mAngularMomentum.Clean(); // update angular velocity IvMatrix33 rotateMat(mRotate); mWorldMomentsInverse = rotateMat*mMomentsInverse*::Transpose(rotateMat); mAngularVelocity = mWorldMomentsInverse*mAngularMomentum; mAngularVelocity.Clean(); IvQuat w(mAngularVelocity); mRotate += 0.5f*dt*(w*mRotate); mRotate.Clean(); mRotate.Normalize(); } // End of SimObject::Integrate()
// yaw void Camera::pan(float degrees) { //rodriguez_rotate(degrees, eye, up); float scale = .30f; float the = degrees*3.1451/180*scale; Point pointTowards = Point::normalize(focus-eye); Point pointAway = pointTowards*-1; Point oldCenter = eye + pointTowards*distance; //possible to use focus as center? mat3 axisAngle = rotateMat(the, up); pointAway = Point::normalize(pointAway*axisAngle); eye = oldCenter + pointAway*distance; focus = oldCenter + pointAway*(distance/2.0f); }
//pitch void Camera::tilt(float degrees) { // Point newAxis = Point::cross(up, eye); // rodriguez_rotate(degrees, eye, newAxis); // rodriguez_rotate(degrees, up, newAxis); float scale = .30f; float the = -degrees*3.1451/180*scale; Point pointTowards = Point::normalize(focus-eye); Point pointAway = pointTowards*-1; Point oldCenter = eye + pointTowards*distance; //possible to use focus as center? Point axis = Point::normalize(Point::cross(up, pointTowards)); mat3 axisAngle = rotateMat(the, axis); pointAway = Point::normalize(pointAway*axisAngle); eye = oldCenter + pointAway*distance; focus = oldCenter + pointAway*(distance/2.0f); up = Point::normalize(up*axisAngle); }
vec3 Transform::forward() { return rotateMat() * vec3(0,0,1); }
vec3 Transform::up() { return rotateMat() * vec3(0,1,0); }
vec3 Transform::left() { return rotateMat() * vec3(1,0,0); }
mat4 Transform::modelMat() { return rotateMat() * scaleMat() * translateMat(); }