private void Render(object sender, GlControlEventArgs e) { if (_shader == null) { return; } var v = _cameraHelper.CameraMatrix; _shader.M = v; _shader.ShadingLevel = 0; FiguresHelper.Draw3DCross(4, 1); _shader.ShadingLevel = 1; _shader.LightPos = new Vector3(1f, 1f, 1f); var r1 = Matrix4x4.CreateRotationY(Mathf.ToRadian(_phi)); var t = Matrix4x4.CreateTranslation(new Vector3(_radius, 2f, 0f)); var r2 = Matrix4x4.CreateRotationX(Mathf.ToRadian(90)) * Matrix4x4.CreateRotationY(Mathf.ToRadian(90)) * Matrix4x4.CreateRotationZ(Mathf.ToRadian(45)); var scaleM = Matrix4x4.CreateScale(0.2f); var r3 = Matrix4x4.CreateRotationY(Mathf.ToRadian(-_phi * 10)); var r4 = Matrix4x4.CreateRotationZ(Mathf.ToRadian(25)); var m = r3 * r2 * t * r1 * scaleM * r4; _shader.M = m * v; Figure3DHelper.DrawMesh(_boomerang, Colors.Chocolate); _phi += _step; }
protected override void Draw(float deltaSeconds) { UpdateAnimation(deltaSeconds); UpdateUniforms(); _cl.Begin(); _cl.SetFramebuffer(GraphicsDevice.SwapchainFramebuffer); _cl.ClearColorTarget(0, RgbaFloat.Black); _cl.ClearDepthStencil(1f); Matrix4x4 worldMatrix = Matrix4x4.CreateTranslation(0, 15000, -5000) * Matrix4x4.CreateRotationX(3 * (float)Math.PI / 2) * Matrix4x4.CreateScale(0.05f); _cl.UpdateBuffer(_worldBuffer, 0, ref worldMatrix); DrawMesh(); worldMatrix = Matrix4x4.CreateTranslation(0, 15000, -5000) * Matrix4x4.CreateRotationX(3 * (float)Math.PI / 2) * Matrix4x4.CreateScale(0.07f); _cl.UpdateBuffer(_worldBuffer, 0, ref worldMatrix); DrawMesh(); _cl.End(); GraphicsDevice.SubmitCommands(_cl); GraphicsDevice.SwapBuffers(); }
/// <inheritdoc cref="NotuiElement"/> public override IntersectionPoint PureHitTest(Touch touch, bool prevpos, out IntersectionPoint persistentIspoint) { var intersection = PreparePlanarShapeHitTest(touch, prevpos); var phit = intersection != null; if (!phit) { persistentIspoint = null; return(null); } //TODO: Ugly as f**k, fix phase like a human being var uvpos = Coordinates.RectToPolar(Vector2.Transform(intersection.ElementSpace.xy(), Matrix3x2.CreateRotation((float)Math.PI))); var d = uvpos.Y; uvpos.X = uvpos.X / (float)Math.PI; uvpos.Y = uvpos.Y * 4 - 1; intersection.SurfaceSpace = new Vector3(uvpos, 0); var str = Matrix4x4.CreateWorld(intersection.ElementSpace, Vector3.UnitZ, -Vector3.Normalize(intersection.ElementSpace)); intersection.WorldSurfaceTangentTransform = str * DisplayMatrix; persistentIspoint = intersection; return(d < 0.5 ? intersection : null); }
void Update() { var baseModel = CreateMatrixFromTranslation(0.0f, 0.0f, 5.0f) * CreateMatrixFromRotation(rotation, 0.0f, 1.0f, 0.0f); var baseMv = viewMatrix * baseModel; var modelViewMatrix = baseMv * CreateMatrixFromRotation(rotation, 1.0f, 1.0f, 1.0f); #if NET Matrix4.Invert(Matrix4.Transpose(modelViewMatrix), out uniformBuffer.NormalMatrix); #else uniformBuffer.NormalMatrix = Matrix4.Invert(Matrix4.Transpose(modelViewMatrix)); #endif uniformBuffer.ModelviewProjectionMatrix = Matrix4.Transpose(projectionMatrix * modelViewMatrix); // Copy uniformBuffer's content into dynamicConstantBuffer.Contents int rawsize = Marshal.SizeOf(typeof(Uniforms)); var rawdata = new byte [rawsize]; IntPtr ptr = Marshal.AllocHGlobal(rawsize); Marshal.StructureToPtr(uniformBuffer, ptr, false); Marshal.Copy(ptr, rawdata, 0, rawsize); Marshal.FreeHGlobal(ptr); Marshal.Copy(rawdata, 0, dynamicConstantBuffer.Contents + rawsize * constantDataBufferIndex, rawsize); rotation += 0.01f; }
public override void Apply(Graphics.IRenderContext context, System.Numerics.Matrix4x4 viewProjection, Assets.Material material, System.Numerics.Matrix4x4 world) { context.SetState(Engine.RenderStatePool.GetRenderState(new RenderStateInfo() { PrimitiveType = Graphics.PrimitiveType.TriangleList, Shader = shader, Rasterizer = rasterizerState, DepthStencil = depthStencil })); context.SetTexture(shader, "picture", material.Texture.Handle); if (Engine.Settings.GraphicsAPI == GraphicsAPI.Direct3D11) { context.SetSampler(shader, "pictureSampler", sampler); } else if (Engine.Settings.GraphicsAPI == GraphicsAPI.OpenGL4) { context.SetSampler(shader, "picture", sampler); } GCHandle handle; DataArray dataArray = DataArray.FromObject <Matrix4x4>(Matrix4x4.Transpose(world * viewProjection), out handle); try { context.UpdateContext.Update(constantBuffer, dataArray); } finally { handle.Free(); } context.SetConstantBuffer(shader, constantBuffer); }
static void BuildTransform(Vector3 position, Vector2 size, SpriteFlags flags, out Matrix4x4 transform) { var offset = (flags & SpriteFlags.AlignmentMask) switch { 0 => Vector3.Zero, SpriteFlags.MidAligned => new Vector3(0, -0.5f, 0), SpriteFlags.BottomAligned => new Vector3(0, -1.0f, 0), SpriteFlags.LeftAligned => new Vector3(0.5f, 0, 0), SpriteFlags.LeftAligned | SpriteFlags.MidAligned => new Vector3(0.5f, -0.5f, 0), SpriteFlags.LeftAligned | SpriteFlags.BottomAligned => new Vector3(0.5f, -1.0f, 0), _ => Vector3.Zero }; transform = Matrix4x4.CreateTranslation(offset); if (flags.HasFlag(SpriteFlags.Floor)) { transform *= new Matrix4x4( 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1); } transform *= Matrix4x4.CreateScale(new Vector3(size.X, size.Y, size.X)); transform *= Matrix4x4.CreateTranslation(position); }
protected void SetView() { ViewMatrix = Matrix4x4.CreateLookAt(_cameraPosition, _cameraPosition + _cameraFront, _cameraUp); int location = OpenGL.Gl.GetUniformLocation(_currentProgram, "view"); OpenGL.Gl.UniformMatrix4f(location, 1, false, ref ViewMatrix); }
protected override float[] F(float[] xs) { var R2 = Radius * Radius; var v = new Vector2(xs[0], xs[1]); v = Vector2.Transform(v, Matrix4x4.CreateScale(-1) * M); var x = v.X; var y = v.Y; var x2y2 = x * x + y * y; var a1 = new[] { W / x2y2 * y + (1 + R2 / x2y2 - 2 * R2 * x * x / (x2y2 * x2y2)), W / x2y2 * -x - (2 * R2 * x * y / (x2y2 * x2y2)) }; //v = new Vector2(xs[0], xs[1]); //v = Vector2.Transform(v, Matrix4x4.CreateTranslation(-6,0,0)); //x = v.X; //y = v.Y; //x2y2 = x * x + y * y; //var a2 = new[] //{ // W/x2y2 * y + (1 + R2 / x2y2 - 2 * R2 * x * x / (x2y2 * x2y2)), // W/x2y2 * -x - (2 * R2 * x * y / (x2y2 * x2y2)) //}; return(new[] { a1[0], // + a2[0], a1[1], // + a2[1] }); }
private void WriteMatrix4x4(Matrix4x4 value, EndianBinaryWriter writer) { writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", value.M11, value.M12, value.M13, value.M14)); writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", value.M21, value.M22, value.M23, value.M24)); writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", value.M31, value.M32, value.M33, value.M34)); writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", value.M41, value.M42, value.M43, value.M44)); }
private void OnOnKeyDown(object sender, KeyEventArgs e) { if (_isRightMousePressed) { switch (e.KeyCode) { case Keys.W: _cameraPosition += 0.2f * _cameraFront; break; case Keys.A: _cameraPosition -= Vector3.Normalize(Vector3.Cross(_cameraFront, _cameraUp)) * 0.2f; break; case Keys.S: _cameraPosition -= 0.2f * _cameraFront; break; case Keys.D: _cameraPosition += Vector3.Normalize(Vector3.Cross(_cameraFront, _cameraUp)) * 0.2f; break; } return; } switch (e.KeyCode) { case Keys.W: ModelMatrix = ModelMatrix * _transposeYUp; break; case Keys.A: ModelMatrix = ModelMatrix * _transposeXDown; break; case Keys.S: ModelMatrix = ModelMatrix * _transposeYDown; break; case Keys.D: ModelMatrix = ModelMatrix * _transposeXUp; break; case Keys.E: ModelMatrix = ModelMatrix * _rotationLeftZLeft; break; case Keys.Q: ModelMatrix = ModelMatrix * _rotationLeftZRight; break; case Keys.X: ModelMatrix = ModelMatrix * _rotationLeftX; break; case Keys.Y: ModelMatrix = ModelMatrix * _rotationLeftY; break; } }
public static Matrix4x4 FromNumerics(this SN.Matrix4x4 matIn) { Matrix4x4 matOut = new Matrix4x4(); //Numerics matrix are row vector, so X,Y,Z axes are rows 1-3 and 4th row is translation. //Rows => Columns to make it compatible with assimp //X matOut.A1 = matIn.M11; matOut.B1 = matIn.M12; matOut.C1 = matIn.M13; matOut.D1 = matIn.M14; //Y matOut.A2 = matIn.M21; matOut.B2 = matIn.M22; matOut.C2 = matIn.M23; matOut.D2 = matIn.M24; //Z matOut.A3 = matIn.M31; matOut.B3 = matIn.M32; matOut.C3 = matIn.M33; matOut.D3 = matIn.M34; //Translation matOut.A4 = matIn.M41; matOut.B4 = matIn.M42; matOut.C4 = matIn.M43; matOut.D4 = matIn.M44; return(matOut); }
private void Render(object sender, GlControlEventArgs e) { if (_shader == null) { return; } Gl.Clear(ClearBufferMask.DepthBufferBit); Gl.MatrixMode(MatrixMode.Modelview); var v = _cameraHelper.CameraMatrix; var u = Matrix4x4.CreateRotationX(Mathf.ToRadian(90)); var m = u * v; _shader.M = m; FiguresHelper.Draw3DCross(50f, 1f); Figure3DHelper.DrawSphere(15, 20, 20, true, Colors.Yellow); Gl.LineWidth(1); Figure3DHelper.DrawSphere(15, 20, 20, false, Colors.Red); _satelite.Draw(); }
public static Matrix4x4 FromSystemNumerics(System.Numerics.Matrix4x4 dotNetMatrix) { return(new Matrix4x4 { // to row major M00 = dotNetMatrix.M11, M10 = dotNetMatrix.M21, M20 = dotNetMatrix.M31, M30 = dotNetMatrix.M41, M01 = dotNetMatrix.M12, M11 = dotNetMatrix.M22, M21 = dotNetMatrix.M32, M31 = dotNetMatrix.M42, M02 = dotNetMatrix.M13, M12 = dotNetMatrix.M23, M22 = dotNetMatrix.M33, M32 = dotNetMatrix.M43, M03 = dotNetMatrix.M14, M13 = dotNetMatrix.M24, M23 = dotNetMatrix.M34, M33 = dotNetMatrix.M44, }); }
private static UnityEngine.Matrix4x4 ConvertMatrixFromSystemToUnity(System.Numerics.Matrix4x4 matrix) { UnityEngine.Matrix4x4 result = new UnityEngine.Matrix4x4(); result.m00 = matrix.M11; result.m01 = matrix.M12; result.m02 = matrix.M13; result.m03 = matrix.M14; result.m10 = matrix.M21; result.m11 = matrix.M22; result.m12 = matrix.M23; result.m13 = matrix.M24; result.m20 = matrix.M31; result.m21 = matrix.M32; result.m22 = matrix.M33; result.m23 = matrix.M34; result.m30 = matrix.M41; result.m31 = matrix.M42; result.m32 = matrix.M43; result.m33 = matrix.M44; return(result); }
static NumMatrix4x4 GetTransformForFrame(NodeAnimationChannel Ch, int Frame) { VectorKey PosKey = Ch.PositionKeys[Ch.PositionKeys.Count - 1]; if (Frame < Ch.PositionKeys.Count) { PosKey = Ch.PositionKeys[Frame]; } QuaternionKey RotKey = Ch.RotationKeys[Ch.RotationKeys.Count - 1]; if (Frame < Ch.RotationKeys.Count) { RotKey = Ch.RotationKeys[Frame]; } VectorKey SclKey = Ch.ScalingKeys[Ch.ScalingKeys.Count - 1]; if (Frame < Ch.ScalingKeys.Count) { SclKey = Ch.ScalingKeys[Frame]; } NumMatrix4x4 Rot = NumMatrix4x4.CreateFromQuaternion(ConvertQuat(RotKey.Value)); NumMatrix4x4 Pos = NumMatrix4x4.CreateTranslation(ConvertVec(PosKey.Value)); NumMatrix4x4 Scl = NumMatrix4x4.CreateScale(ConvertVec(SclKey.Value)); //return Pos * Rot * Scl; return(Scl * Rot * Pos); }
static System.Numerics.Quaternion ConvertQuat(Assimp.Quaternion Q) { NumMatrix4x4.Decompose(ConvertMatrix(new AssMatrix4x4(Q.GetMatrix())), out Vector3 _S, out System.Numerics.Quaternion Quat, out Vector3 _T); return(Quat); // return new System.Numerics.Quaternion(Q.X, Q.Y, Q.Z, Q.W); }
private bool WorldToScreen(UE.Vector3 _Enemy, out UE.Vector3 _Screen) { _Screen = new UE.Vector3(0, 0, 0); Numerics.Matrix4x4 temp = Numerics.Matrix4x4.Transpose(Memory.Read <Numerics.Matrix4x4>(Base.GetPtr(EFTCore.fpsCamera, new int[] { 0x30, 0x18, 0xC0 }).ToInt64())); UE.Vector3 translationVector = new UE.Vector3(temp.M41, temp.M42, temp.M43); UE.Vector3 up = new UE.Vector3(temp.M21, temp.M22, temp.M23); UE.Vector3 right = new UE.Vector3(temp.M11, temp.M12, temp.M13); float w = D3DXVec3Dot(translationVector, _Enemy) + temp.M44; if (w < 0.098f) { return(false); } float y = D3DXVec3Dot(up, _Enemy) + temp.M24; float x = D3DXVec3Dot(right, _Enemy) + temp.M14; _Screen.x = (this.Width / 2) * (1f + x / w); _Screen.y = (this.Height / 2) * (1f - y / w); _Screen.z = w; return(true); }
private void ComputeBoundingBox(Node node, ref Vector3 min, ref Vector3 max, ref Matrix4x4 trafo) { var prev = trafo; trafo = Matrix4x4.Multiply(prev, FromMatrix(node.Transform)); if (node.HasMeshes) { foreach (var index in node.MeshIndices) { var mesh = _scene.Meshes[index]; for (var i = 0; i < mesh.VertexCount; i++) { var tmp = FromVector(mesh.Vertices[i]); tmp = Vector3.Transform(tmp, trafo); min.X = Math.Min(min.X, tmp.X); min.Y = Math.Min(min.Y, tmp.Y); min.Z = Math.Min(min.Z, tmp.Z); max.X = Math.Max(max.X, tmp.X); max.Y = Math.Max(max.Y, tmp.Y); max.Z = Math.Max(max.Z, tmp.Z); } } } for (var i = 0; i < node.ChildCount; i++) { ComputeBoundingBox(node.Children[i], ref min, ref max, ref trafo); } trafo = prev; }
public void Draw(CommandList cmdList, Camera cam) { cmdList.SetVertexBuffer(0, m_vertexBuffer); cmdList.SetIndexBuffer(m_indexBuffer, IndexFormat.UInt32); cmdList.SetPipeline(m_pipelineState); SN.Matrix4x4 transform = WorldMatrix; for (int i = 0; i < m_meshesToDraw.Count; i++) { MeshDrawCall drawParams = m_meshesToDraw[i]; MeshPart partData = m_meshesData[drawParams.MeshPartIndex]; SimpleMaterial material = m_materials[partData.MaterialIndex]; SN.Matrix4x4 w = drawParams.World * transform; SN.Matrix4x4 wvp = w * cam.ViewProjection; cmdList.UpdateBuffer(m_wvpParam, 0, ref wvp); cmdList.UpdateBuffer(m_worldParam, 0, ref w); cmdList.UpdateBuffer(m_lightPosParam, 0, LightPosition); cmdList.UpdateBuffer(m_camPosParam, 0, cam.Position); cmdList.SetGraphicsResourceSet(0, m_worldLightCBSet); cmdList.SetGraphicsResourceSet(1, material.ColorAndTexture); cmdList.DrawIndexed((uint)partData.IndexCount, 1, (uint)partData.IndexOffset, 0, 0); } }
/// <summary> /// This method bakes transform values to 4x4 matrix /// </summary> private void UpdateMatrix() { if (m_hasRotation) { MathHelper.GetMatrix3d(m_position, m_rotation, m_scale, ref m_matrix); } else // calculation is much simpler without rotation, it saves 3 pairs of sin+cos calculations { MathHelper.GetMatrix3d(m_position, m_scale, ref m_matrix); } if (m_parent != null) // if there is parent transform, baked value contains also parent transforms { m_parent.PrepareMatrix(); // this one is the most expensive thing in whole engine #if USE_NUMERICS m_matrix = Matrix.Multiply(m_matrix, m_parent.m_matrix); #else if (m_parent.m_parent == null && !m_parent.m_hasRotation) // things are little bit easier if parent doesn't have a rotation matrix. We can save 20+ multiplications on this { MathHelper.TransformMatrix3d(m_parent.m_position, m_parent.m_scale, ref m_matrix); } else { MathHelper.Mul(ref m_parent.m_matrix, ref m_matrix, ref m_matrix); } #endif m_parentVersion = m_parent.m_version; } m_iMatrixChanged = true; m_changed = false; m_version++; }
/* VULKAN METHODS*/ // The TryGetProjectionMatrix code was taken from https://github.com/VulcanTechnologies/HoloLensCameraStream/blob/master/HoloLensCameraStream/Plugin%20Project/VideoCaptureSample.cs // Copyright (c) 2017 Vulcan, Inc. All rights reserved. // Licensed under the Apache 2.0 license /// <summary> /// This returns the projection matrix at the time the photo was captured, if location data if available. /// If it's not, that is probably an indication that the HoloLens is not tracking and its location is not known. /// It could also mean the VideoCapture stream is not running. /// If location data is unavailable then the projecgtion matrix will be set to the identity matrix. /// </summary> /// <param name="matrix">The projection matrix used to match the true camera projection. /// The matrix will have to be converted to a Unity matrix before it can be used by methods in the UnityEngine namespace. /// See https://forum.unity3d.com/threads/locatable-camera-in-unity.398803/ for details.</param> public static bool TryGetProjectionMatrix( System.Numerics.Matrix4x4 projectionMatrix, float nearPlane, float farPlane, out UnityEngine.Matrix4x4 outMatrix) { // The following code enforces valid near/far clip plane values float epsilon = 0.01f; if (nearPlane < epsilon) { nearPlane = epsilon; } if (farPlane < nearPlane + epsilon) { farPlane = nearPlane + epsilon; } // Transpose matrix to match expected Unity format outMatrix = ConvertMatrixFromSystemToUnity(System.Numerics.Matrix4x4.Transpose(projectionMatrix)); outMatrix.m22 = -(farPlane + nearPlane) / (farPlane - nearPlane); outMatrix.m23 = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane); return(true); }
// From Veldrid Neo Demo public static System.Numerics.Matrix4x4 CreatePerspective( GraphicsDevice gd, bool useReverseDepth, float fov, float aspectRatio, float near, float far) { System.Numerics.Matrix4x4 persp; if (useReverseDepth) { persp = CreatePerspective(fov, aspectRatio, far, near); } else { persp = CreatePerspective(fov, aspectRatio, near, far); } if (gd.IsClipSpaceYInverted) { persp *= new System.Numerics.Matrix4x4( 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); } /*persp = new System.Numerics.Matrix4x4( * -1, 0, 0, 0, * 0, 1, 0, 0, * 0, 0, 1, 0, * 0, 0, 0, 1) * persp;*/ return(persp); }
protected void SetProjection(int viewPortWidth, int viewPortHeight) { ProjectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView(_fov.ToRadians(), (float)viewPortWidth / viewPortHeight, 0.1f, 100.0f); int location = OpenGL.Gl.GetUniformLocation(_currentProgram, "projection"); OpenGL.Gl.UniformMatrix4f(location, 1, false, ref ProjectionMatrix); }
public static VMatrix AsVMatrix4X4(this SMatrix m) { return(new VMatrix( m.M11, m.M12, m.M13, m.M14, m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34, m.M41, m.M42, m.M43, m.M44)); }
private void DrawSphere(Vector2 pos, Vector2 v, Vector2 a, Color color) { var t = Matrix4x4.CreateTranslation(new Vector3(pos, 0)); var vM = _cameraHelper.CameraMatrix; _shader.M *= t * vM; Figure3DHelper.DrawSphere(2, 20, 20, true, color); }
void Reshape() { // When reshape is called, update the view and projection matricies since this means the view orientation or size changed var aspect = (float)(View.Bounds.Size.Width / View.Bounds.Size.Height); projectionMatrix = CreateMatrixFromPerspective(65.0f * ((float)Math.PI / 180.0f), aspect, 0.1f, 100.0f); viewMatrix = Matrix4.Identity; }
public static void ToNumerics(this Assimp.Matrix4x4 matIn, out SN.Matrix4x4 matOut) { //Assimp matrices are column vector, so X,Y,Z axes are columns 1-3 and 4th column is translation. //Columns => Rows to make it compatible with numerics matOut = new System.Numerics.Matrix4x4(matIn.A1, matIn.B1, matIn.C1, matIn.D1, //X matIn.A2, matIn.B2, matIn.C2, matIn.D2, //Y matIn.A3, matIn.B3, matIn.C3, matIn.D3, //Z matIn.A4, matIn.B4, matIn.C4, matIn.D4); //Translation }
public void Draw(System.Numerics.Matrix4x4 proj, System.Numerics.Matrix4x4 view, System.Numerics.Matrix4x4 model, string[] uniformNames) { for (int i = 0; i < objs.Count; i++) { objs[i].SetUniformfv(uniformNames[0], proj); objs[i].SetUniformfv(uniformNames[1], view); objs[i].SetUniformfv(uniformNames[2], model); objs[i].Render(); } }
private static Matrix Convert(System.Numerics.Matrix4x4 mat) { return(new Matrix { M11 = mat.M11, M12 = mat.M12, M13 = mat.M13, M14 = mat.M14, M21 = mat.M21, M22 = mat.M22, M23 = mat.M23, M24 = mat.M24, M31 = mat.M31, M32 = mat.M32, M33 = mat.M33, M34 = mat.M34, M41 = mat.M41, M42 = mat.M42, M43 = mat.M43, M44 = mat.M44, }); }
// TODO: Tehdäänkö tällä enää mitään? /// <summary> /// Muuntaa matriisin Jypelin ruutukoordinaateista XNA:n ruutukoordinaatteihin. /// </summary> /// <param name="matrix"></param> /// <param name="screenSize"></param> /// <param name="scale"></param> /// <returns></returns> internal static Matrix ToXnaCoords(ref Matrix matrix, Vector screenSize, Vector scale) { // Keskitetään sprite ruudulla, mutta toteutetaan alkuperäinen muunnos Jypelin koordinaateissa. var centralize = Matrix.CreateTranslation((screenSize - scale) / 2); var toXna = Matrix.CreateScale(1, -1, 1) * Matrix.CreateTranslation(screenSize / 2); Matrix.Invert(toXna, out Matrix toJypeli); return(centralize * toJypeli * matrix * toXna); }
internal void SetWorldMatrix(Matrix4x4 worldMatrix) { var worldTransposed = Matrix4x4.Transpose(worldMatrix); var viewTransposed = Matrix4x4.Transpose(viewMatrix); var projectionTransposed = Matrix4x4.Transpose(projectionMatrix); MatricesBuffer matricesBuffer = new MatricesBuffer(ref worldTransposed, ref viewTransposed, ref projectionTransposed); deviceContext.UpdateSubresource<MatricesBuffer>(ref matricesBuffer, this.worldViewProjectionMatrixBuffer); deviceContext.VertexShader.SetConstantBuffer(0, this.worldViewProjectionMatrixBuffer); }
public MatricesBuffer(ref Matrix4x4 world, ref Matrix4x4 view, ref Matrix4x4 projection) { this.worldMatrix = world; this.viewMatrix = view; this.projectionMatrix = projection; }
private void UpdateViewProjectionBuffers() { projectionMatrix = camera.GetProjectionMatrix(); viewMatrix = camera.GetViewMatrix(); }