//I got this method for rotating around an arbitary axis from the //GLspec15.pdf. (page number 42 in the image, page 55 of the pdf file) //IMPORTANT!!! The angle 'radians' is in the direction of the //"finger curl of the right hand rule" around the vector {x,y,z} //------------------------------------------------------------------------------------------ public void RotateAnyAxis(float radians, IVector3H1 axisUnitVector) //unitize Axis first!!!!! { //but remember the cross product of 2 unit vectors is only a unit vector if the original 2 vectors are @ 90degrees ..... ///................... should I go ahead & always run the unit calculation here for safety? ///maybe not b/c in FlightSimulator I pretty much always unit-ize the vectors before haand //double myAxis[3] = {Axis.vect[0], Axis.vect[1], Axis.vect[2]}; //int mySize = 3; //UnitVOfArray(myAxis, mySize); Matrix3X3 S = new Matrix3X3(); S.Data[0, 0] = 0; S.Data[0, 1] = -axisUnitVector.Z; S.Data[0, 2] = axisUnitVector.Y; S.Data[1, 0] = axisUnitVector.Z; S.Data[1, 1] = 0; S.Data[1, 2] = -axisUnitVector.X; S.Data[2, 0] = -axisUnitVector.Y; S.Data[2, 1] = axisUnitVector.X; S.Data[2, 2] = 0; Matrix3X3 outter = (Matrix3X3)Vector3H1.OutterProduct(axisUnitVector, axisUnitVector); Matrix3X3 Id = new Matrix3X3(); Id.SetIdentity(); //I'm not sure what to do about this error - may be necessary to have different interfaces for Matrix3H4 & Matrix4X4..... IMatrix3D Result = outter + ((float)Math.Cos(radians)) * (Id - outter) + ((float)Math.Sin(radians)) * S; //Manually copy for maximum speed this.Data[0, 0] = Result.Data[0, 0]; this.Data[0, 1] = Result.Data[0, 1]; this.Data[0, 2] = Result.Data[0, 2]; this.Data[0, 3] = 0; this.Data[1, 0] = Result.Data[1, 0]; this.Data[1, 1] = Result.Data[1, 1]; this.Data[1, 2] = Result.Data[1, 2]; this.Data[1, 3] = 0; this.Data[2, 0] = Result.Data[2, 0]; this.Data[2, 1] = Result.Data[2, 1]; this.Data[2, 2] = Result.Data[2, 2]; this.Data[2, 3] = 0; //this.Copy(Result); //replaces current value of calling matrix //forces bottom row & last col to be all 0s }
//Can only be done in Square Matricies unless you allow for arbitary rows and columns which is not yet supported public void SetTranspose() { IMatrix3D Transpose = this.GetTranspose(); this.Copy(Transpose); }
public Matrix3H4(IMatrix3D OtherMatrix) //copy constructor { Data = new float[3, 4]; this.Copy(OtherMatrix); }
public Matrix4X4(IMatrix3D OtherMatrix) //copy constructor { Data = new float[4, 4]; this.Copy(OtherMatrix); Data[3, 3] = 1; //homogenous }