void Camera::setOrientAndPosition(const Vect &inUp, const Vect &inLookAt, const Vect &inPos) { // Remember the up, lookAt and right are unit, and are perpendicular. // Treat lookAt as king, find Right vect, then correct Up to insure perpendiculare. // Make sure that all vectors are unit vectors. //this->vDir = inLookAt; //this->vDir.norm(); //this->vUp = inUp; //this->vRight = this->vDir.cross( this->vUp ); //this->vRight.norm(); //this->vUp = this->vRight.cross( this->vDir ); //this->vUp.norm(); this->vDir = inPos - inLookAt; this->vDir.norm(); this->vRight = inUp.cross( this->vDir ); this->vRight.norm(); this->vUp = this->vDir.cross( this->vRight ); this->vUp.norm(); this->vPos = inPos; };
void Quat :: Lqvqc(const Vect &vIn, Vect &vOut) const { const Vect &qV = (const Vect &)(*this); vOut = (2.0f * qV[w]) * vIn.cross(qV); vOut += ( qV[w] * qV[w] - qV.dot(qV) ) * vIn; vOut += qV *( 2.0f * qV.dot(vIn) ); }
void Camera::privCalcFrustumCollisionNormals( void ) { // Normals of the frustum around nearTopLeft Vect A = this->nearBottomLeft - this->nearTopLeft; Vect B = this->nearTopRight - this->nearTopLeft; Vect C = this->farTopLeft - this->nearTopLeft; this->frontNorm = A.cross(B); this->frontNorm.norm(); this->leftNorm = C.cross(A); this->leftNorm.norm(); this->topNorm = B.cross(C); this->topNorm.norm(); // Normals of the frustum around farBottomRight A = this->farBottomLeft - this->farBottomRight; B = this->farTopRight - this->farBottomRight; C = this->nearBottomRight - this->farBottomRight; this->backNorm = A.cross(B); this->backNorm.norm(); this->rightNorm = B.cross(C); this->rightNorm.norm(); this->bottomNorm = C.cross(A); this->bottomNorm.norm(); };
const float TripleProduct( const Vertex& v0, const Vertex& v1, const Vertex& v2 ) { Vect vect0( v0.x, v0.y, v0.z ); Vect vect1( v1.x, v1.y, v1.z ); Vect vect2( v2.x, v2.y, v2.z ); Vect a = vect2 - vect0; Vect b = vect1 - vect0; Vect normal( v0.nx, v0.ny, v0.nz ); return a.cross( b ).dot( normal ); }
void Camera::setOrientationAndPosition(const Vect& inUp, const Vect& inLookAt, const Vect& inPos) { this->lookAt = inLookAt; // Point out of the screen into your EYE this->forward = inPos - inLookAt; this->forward.norm(); // Clean up the vectors (Right hand rule) this->right = inUp.cross(this->forward); this->right.norm(); this->up = this->forward.cross(this->right); this->up.norm(); this->position = inPos; }
TEST( VectCrossCrossNorm, combo_tests ) { Vect A(1.0f, 2.0f, 3.0f, 5.0f); Vect B(10.0f, 11.0f, 12.0f, 13.0f); Vect C; CHECK( A[x] == 1.0f ); CHECK( A[y] == 2.0f ); CHECK( A[z] == 3.0f ); CHECK( A[w] == 5.0f ); CHECK( B[x] == 10.0f ); CHECK( B[y] == 11.0f ); CHECK( B[z] == 12.0f ); CHECK( B[w] == 13.0f ); C = (A-B).cross(B); Vect D = C.cross(B); D.norm(); CHECK( eq( D[x], 0.74790420f, MATH_TOLERANCE) ); CHECK( eq( D[y], 0.04273730f, MATH_TOLERANCE) ); CHECK( eq( D[z], -0.6624290f, MATH_TOLERANCE) ); CHECK( D[w] == 1.0f ); CHECK( C[x] == -9.0f ); CHECK( C[y] == 18.0f ); CHECK( C[z] == -9.0f ); CHECK( C[w] == 1.0f ); CHECK( A[x] == 1.0f ); CHECK( A[y] == 2.0f ); CHECK( A[z] == 3.0f ); CHECK( A[w] == 5.0f ); CHECK( B[x] == 10.0f ); CHECK( B[y] == 11.0f ); CHECK( B[z] == 12.0f ); CHECK( B[w] == 13.0f ); }
void Camera::setOrientAndPosition(const Vect &inUp, const Vect &inLookAt, const Vect &inPos) { // Remember the up, lookAt and right are unit, and are perpendicular. // Treat lookAt as king, find Right vect, then correct Up to insure perpendiculare. // Make sure that all vectors are unit vectors. this->vUp = inUp; // Point out of the screen into your EYE this->vDir = inPos - inLookAt; this->vDir.norm(); // Clean up the vectors (Right hand rule) this->vRight = inUp.cross( this->vDir ); this->vRight.norm(); this->vUp = this->vDir.cross( this->vRight ); this->vUp.norm(); this->vPos = inPos; this->vLookAt = inLookAt; };
const void Quat::Lqvqc(const Vect &vIn, Vect &vOut) { Vect tmp (this->qx, this->qy, this->qz); vOut = ((2 * this->qw) * vIn.cross(tmp)) + (((this->qw * this->qw) - tmp.dot(tmp)) * vIn) + 2 * (tmp.dot(vIn)) * tmp; };
const void Quat::operator *= (const Quat &q) { Vect vLeft (this->qx, this->qy, this->qz); Vect vRight (q.qx, q.qy, q.qz); *this = Quat(Vect(vRight.cross(vLeft) + (q.qw * vLeft) + (this->qw * vRight)), (this->qw * q.qw) - vLeft.dot(vRight)); };
const Quat Quat::operator * (const Quat &q)const { Vect vLeft (this->qx, this->qy, this->qz); Vect vRight (q.qx, q.qy, q.qz); return Quat(Vect(vRight.cross(vLeft) + (q.qw * vLeft) + (this->qw * vRight)), (this->qw * q.qw) - vLeft.dot(vRight)); };