/// <summary> /// Set the pivot point to be used when applying the rotations. /// </summary> /// <param name="p"> /// Vector3 describing the location of the pivot point to be used when /// applying the rotation to the geometry. /// </param> public virtual void SetPivot(Lunatics.Mathematics.Vector3 p) { if (d_pivot != p) { d_pivot = p; d_matrixValid = false; } }
/// <summary> /// Set the scaling to be applied to the geometry in the buffer when it is /// subsequently rendered. /// </summary> /// <param name="scale"> /// Vector3 describing the scale to be used. /// </param> public virtual void SetScale(Lunatics.Mathematics.Vector3 scale) { if (d_scale != scale) { d_scale = scale; d_matrixValid = false; } }
/// <summary> /// Set the translation to be applied to the geometry in the buffer when it /// is subsequently rendered. /// </summary> /// <param name="translation"> /// Vector3 describing the three axis translation vector to be used. /// </param> public virtual void SetTranslation(Lunatics.Mathematics.Vector3 translation) { if (d_translation != translation) { d_translation = translation; d_matrixValid = false; } }
/// <summary> /// Creates a view projection matrix for the Direct3D graphics library (Depth Range from 0 to 1) based /// on this RenderTarget's current settings. /// </summary> /// <returns> /// A freshly created Direct3D view projection matrix for this RenderTarget. /// </returns> public Lunatics.Mathematics.Matrix CreateViewProjMatrixForDirect3D() { var w = d_area.Width; var h = d_area.Height; // We need to check if width or height are zero and act accordingly to prevent running into issues // with divisions by zero which would lead to undefined values, as well as faulty clipping planes // This is mostly important for avoiding asserts var widthAndHeightNotZero = (w != 0.0f) && (h != 0.0f); var aspect = widthAndHeightNotZero ? w / h : 1.0f; var midx = widthAndHeightNotZero ? w * 0.5f : 0.5f; var midy = widthAndHeightNotZero ? h * 0.5f : 0.5f; d_viewDistance = midx / (aspect * d_yfov_tan); var eye = new Lunatics.Mathematics.Vector3(midx, midy, -d_viewDistance); var center = new Lunatics.Mathematics.Vector3(midx, midy, 1f); var up = new Lunatics.Mathematics.Vector3(0, -1, 0); // We need to have a projection matrix with its depth in clip space ranging from 0 to 1 for nearclip to farclip. // The regular OpenGL projection matrix would work too, but we would lose 1 bit of depth precision, which the following // manually filled matrix should fix: var fovy = 30f; var zNear = d_viewDistance * 0.5f; var zFar = d_viewDistance * 2.0f; var f = 1.0f / (float)Math.Tan(fovy * (float)Math.PI * 0.5f / 180.0f); var Q = zFar / (zNear - zFar); var projectionMatrixFloat = new[] { f / aspect, 0.0f, 0.0f, 0.0f, 0.0f, f, 0.0f, 0.0f, 0.0f, 0.0f, Q, -1.0f, 0.0f, 0.0f, Q *zNear, 0.0f }; var projectionMatrix = new Lunatics.Mathematics.Matrix(projectionMatrixFloat); // Projection matrix abuse! var viewMatrix = Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up); //return projectionMatrix * viewMatrix; return(Lunatics.Mathematics.Matrix.Multiply( Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up), Lunatics.Mathematics.Matrix.PerspectiveFovRH(0.523598776f, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f))); //return Lunatics.Mathematics.Matrix.Multiply( // Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up), // Lunatics.Mathematics.Matrix.PerspectiveFovRH(30f, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f)); //return Lunatics.Mathematics.Matrix.Multiply( // Lunatics.Mathematics.Matrix.PerspectiveFovLH(30f, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f), // Lunatics.Mathematics.Matrix.LookAtLH(eye, center, up)); }
/// <summary> /// Set the two dimensional position of the RenderingWindow in pixels. The /// origin is at the top-left corner. /// </summary> /// <param name="position"> /// Vector2 object describing the desired location of the RenderingWindow, /// in pixels. /// </param> /// <remarks> /// This position is an absolute pixel location relative to the screen or /// other root surface. It is \e not relative to the owner of the /// RenderingWindow. /// </remarks> public void SetPosition(Lunatics.Mathematics.Vector2 position) { d_position = position; var trans = new Lunatics.Mathematics.Vector3(d_position.X, d_position.Y, 0.0f); // geometry position must be offset according to our owner position, if // that is a RenderingWindow. if (d_owner.IsRenderingWindow()) { trans.X -= ((RenderingWindow)d_owner).d_position.X; trans.Y -= ((RenderingWindow)d_owner).d_position.Y; } d_geometry.SetTranslation(trans); }
/// <summary> /// Creates a view projection matrix for the OpenGL graphics library (Depth Range from -1 to 1) based /// on this RenderTarget's current settings. /// </summary> /// <returns> /// A freshly created OpenGL view projection matrix for this RenderTarget. /// </returns> public Lunatics.Mathematics.Matrix CreateViewProjMatrixForOpenGL() { var w = d_area.Width; var h = d_area.Height; // We need to check if width or height are zero and act accordingly to prevent running into issues // with divisions by zero which would lead to undefined values, as well as faulty clipping planes // This is mostly important for avoiding asserts var widthAndHeightNotZero = (w != 0.0f) && (h != 0.0f); var fov = 30f; var fovInRad = fov * Lunatics.Mathematics.MathUtils.Pi / 180f; var fovY_halftan = (float)Math.Tan(fovInRad * 0.5f); var aspect = widthAndHeightNotZero ? w / h : 1.0f; var midx = widthAndHeightNotZero ? w * 0.5f : 0.5f; var midy = widthAndHeightNotZero ? h * 0.5f : 0.5f; d_viewDistance = midx / (aspect * /*d_yfov_tan*/ fovY_halftan); var eye = new Lunatics.Mathematics.Vector3(midx, midy, -d_viewDistance); var center = new Lunatics.Mathematics.Vector3(midx, midy, 1f); var up = new Lunatics.Mathematics.Vector3(0f, -1f, 0f); var projectionMatrix = Lunatics.Mathematics.Matrix.PerspectiveFovRH(fovInRad, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f); // Projection matrix abuse! var viewMatrix = Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up); var tm = projectionMatrix * viewMatrix; return(Lunatics.Mathematics.Matrix.Multiply( Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up), Lunatics.Mathematics.Matrix.PerspectiveFovRH(fovInRad, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f))); //return projectionMatrix * viewMatrix; }
public static string ToString(Lunatics.Mathematics.Vector3 v) { return(String.Format(CultureInfo.InvariantCulture, "x:{0} y:{1} z:{2}", v.X, v.Y, v.Z)); }
/// <summary> /// Set the location of the pivot point around which the RenderingWindow /// will be rotated. /// </summary> /// <param name="pivot"> /// Vector3 describing the three dimensional point around which the /// RenderingWindow will be rotated. /// </param> public void SetPivot(Lunatics.Mathematics.Vector3 pivot) { d_pivot = pivot; d_geometry.SetPivot(d_pivot); }