/// <summary> /// Rotates the vector about the given axis with the given angle. /// </summary> /// <param name="axis"> Axis of rotation. </param> /// <param name="angle"> Angle of rotation. </param> public Vector Rotate(Vector axis, Angle angle) { // quaternion method Quaternion R = new Quaternion(); R.Scalar = (angle/2.0).Cos(); R.Vector = axis.Normalize() * (angle/2.0).Sin(); Quaternion v = new Quaternion(0.0, this); Quaternion res = R * v * R.T(); return res.Vector; }
/// <summary> /// Gets the view vectors for the given view position. /// </summary> /// <param name="direction"> A <see cref="ViewDirection"/>./ </param> /// <param name="centerOut"> The center. </param> /// <param name="posOut"> The position. </param> /// <param name="upVecOut"> The up vector. </param> public void GetDirectionVectors(ViewDirection direction, out Vector centerOut, out Vector posOut, out Vector upVecOut) { // _scene.RenderList.ResetBounds(); Bounds bounds = _scene.RenderList.Bounds; // determine the distance needed to view all renderables double dist = 0; if (_scene.RenderList.ActorCount > 0 && bounds.IsSet) { dist = bounds.MaxWidth / (fov * 0.5).Tan(); centerOut = bounds.Center; } else { dist = 1 / (fov * 0.5).Tan(); centerOut = new Vector(); } Vector travel; switch (direction) { case ViewDirection.Front: travel = new Vector(0, -1, 0); upVecOut = new Vector(0, 0, 1); break; case ViewDirection.Back: travel = new Vector(0, 1, 0); upVecOut = new Vector(0, 0, 1); break; case ViewDirection.Left: travel = new Vector(-1, 0, 0); upVecOut = new Vector(0, 0, 1); break; case ViewDirection.Right: travel = new Vector(1, 0, 0); upVecOut = new Vector(0, 0, 1); break; case ViewDirection.Top: travel = new Vector(0, 0, 1); upVecOut = new Vector(0, 1, 0); break; case ViewDirection.Bottom: travel = new Vector(0, 0, -1); upVecOut = new Vector(0, 1, 0); break; default: travel = new Vector(1, -1, 0.5); travel.Normalize(); dist = 0.8 * dist; upVecOut = new Vector(0, 0, 1); break; } posOut = (travel * dist) + centerOut; }