const Quaternion Quaternion::Rotation(const vec3& unitVec0, const vec3& unitVec1) { float cosHalfAngleX2, recipCosHalfAngleX2; cosHalfAngleX2 = sqrt((2.0f * (1.0f + unitVec0.Dot(unitVec1)))); recipCosHalfAngleX2 = (1.0f / cosHalfAngleX2); return Quaternion((unitVec0.Cross(unitVec1) * recipCosHalfAngleX2), (cosHalfAngleX2 * 0.5f)); }
void Camera::set(const vec3& eyepos, const vec3& look, const vec3& up) { eye = eyepos; n = eyepos - look; v = up.Cross(n); u = n.Cross(v); mRadius = n.Length(); // cache this distance u.Normalize(); v.Normalize(); n.Normalize(); }
void ACamera::set(const vec3& eyepos, const vec3& look, const vec3& up) { mEye = eyepos; mN = eyepos - look; mV = up.Cross(mN); mU = mN.Cross(mV); mRadius = mN.Length(); // cache this distance mU.Normalize(); mV.Normalize(); mN.Normalize(); }
static CQuaternion CreateFromVectors(vec3 v0, vec3 v1) { CQuaternion q; if (v0 == -v1) {//Create from Axis Angle //int a = 1; } vec3 c = v0.Cross(v1); float d = v0.Dot(v1); float s = (float) sqrt((1+d)*2); q.x = c.x /s; q.y = c.y/s; q.z = c.z/s; q.w = s / 2.0f; return q; }
const mat4 FreeCamera(vec3 eye, vec3 dir, vec3 up) { // Builds a look-at style view matrix. // This is essentially the same matrix used by gluLookAt(). vec3 target = eye + dir; vec3 zAxis = eye - target; zAxis.Normalize(); vec3 xAxis = up.Cross(zAxis); xAxis.Normalize(); vec3 yAxis = zAxis.Cross(xAxis); yAxis.Normalize(); mat4 res; float* m = &res[0]; m[0*4 + 0] = xAxis[0]; m[1*4 + 0] = xAxis[1]; m[2*4 + 0] = xAxis[2]; m[3*4 + 0] = -xAxis.Dot(eye); m[0*4 + 1] = yAxis[0]; m[1*4 + 1] = yAxis[1]; m[2*4 + 1] = yAxis[2]; m[3*4 + 1] = -yAxis.Dot(eye); m[0*4 + 2] = zAxis[0]; m[1*4 + 2] = zAxis[1]; m[2*4 + 2] = zAxis[2]; m[3*4 + 2] = -zAxis.Dot(eye); m[0*4 + 3] = 0.0f; m[1*4 + 3] = 0.0f; m[2*4 + 3] = 0.0f; m[3*4 + 3] = 1.0f; return res; }
void RigidBody3::ApplyForceAtBodyPoint(const vec3& force, const vec3& point) { // forces += force; torques += force.Cross( modelMatrix.RotateFromLocalToGlobal(point) ); }