public static void CreateRotationX(float radians, out Matrix4 result) { result = Matrix4.Identity; result.M22 = (float)Math.Cos(radians); result.M23 = (float)Math.Sin(radians); result.M32 = -result.M23; result.M33 = result.M22; }
public MainWindow() { this.InitializeComponent(); this.FileExitButton.Click += this.FileExitButton_Click; this.CompileButton.Click += this.CompileButton_Click; this.ImportPictureButton.Click += this.ImportPictureButton_Click; using (Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("FragmentShaderPhotoStudio.glsl.xshd")) using (XmlTextReader reader = new XmlTextReader(file)) { var xshd = HighlightingLoader.LoadXshd(reader); this.ShaderCodeBox.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance); } this.ShaderCodeBox.Text = defaultFragmentShaderCode; this.GraphicsBox.GraphicsContextCreated += this.GraphicsBox_GraphicsContextCreated; this.GraphicsBox.Render += this.GraphicsBox_Render; this.transform = new Matrix4() { M33 = 1f, M44 = 1f, M41 = -1f, M42 = 1f }; this.stopwatch = new Stopwatch(); }
protected override void Draw(GameTime time) { this.Graphics.Clear(Color4.CornflowerBlue); Matrix4 projection = new Matrix4() { M11 = 2f / this.Window.Width, M22 = -2f / this.Window.Height, M33 = 1f, M44 = 1f, M41 = -1f, M42 = 1f }; totalElapsedSeconds += (float)time.ElapsedTime.TotalSeconds; this.shader.SetValue("projection", ref projection); this.shader.SetValue("startX", (float)((this.Window.Width - this.texture.Width) / 2)); this.shader.SetValue("time", totalElapsedSeconds); this.shader.SetValue("texture0", this.texture); this.Graphics.Draw(PrimitiveType.Triangles, this.vertexBuffer, this.indexBuffer); this.Graphics.SwapBuffers(); }
/// <summary> /// Determines the product of two matrices. /// </summary> /// <param name="left">The first matrix to multiply.</param> /// <param name="right">The second matrix to multiply.</param> /// <returns>The product of the two matrices.</returns> public static Matrix4 Multiply(Matrix4 left, Matrix4 right) { Matrix4 result; Multiply(ref left, ref right, out result); return result; }
public static Matrix4 operator *(Matrix4 matrix1, Matrix4 matrix2) { Matrix4 returnMatrix = new Matrix4(); Matrix4.Multiply(ref matrix1, ref matrix2, out returnMatrix); return returnMatrix; }
public static void InvertYAxis(ref Matrix4 matrix) { matrix.M22 = -matrix.M22; }
/// <summary> /// Determines the product of two matrices. /// </summary> /// <param name="left">The first matrix to multiply.</param> /// <param name="right">The second matrix to multiply.</param> /// <param name="result">The product of the two matrices.</param> public static void Multiply(ref Matrix4 left, ref Matrix4 right, out Matrix4 result) { result = new Matrix4(); result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41); result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42); result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43); result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44); result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41); result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42); result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43); result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44); result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41); result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42); result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43); result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44); result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41); result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42); result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43); result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44); }
public static void CreateTranslation(float xPosition, float yPosition, float zPosition, out Matrix4 result) { result = Matrix4.Identity; result.M41 = xPosition; result.M42 = yPosition; result.M43 = zPosition; }
public static void CreateTranslation(ref Vector3 position, out Matrix4 result) { result = Matrix4.Identity; result.M41 = position.X; result.M42 = position.Y; result.M43 = position.Z; }
public static void CreateScale(ref Vector3 scales, out Matrix4 result) { result = Matrix4.Identity; result.M11 = scales.X; result.M22 = scales.Y; result.M33 = scales.Z; }
public static void CreateScale(float xScale, float yScale, float zScale, out Matrix4 result) { result = Matrix4.Identity; result.M11 = xScale; result.M22 = yScale; result.M33 = zScale; }
public static void CreateScale(float scale, out Matrix4 result) { result = Matrix4.Identity; result.M11 = scale; result.M22 = scale; result.M33 = scale; }
public static void CreateRotationZ(float radians, out Matrix4 result) { result = Matrix4.Identity; result.M11 = (float)Math.Cos(radians); result.M12 = (float)Math.Sin(radians); result.M21 = -result.M12; result.M22 = result.M11; }
public static void CreateRotationY(float radians, out Matrix4 result) { result = Matrix4.Identity; result.M11 = (float)Math.Cos(radians); result.M13 = (float)Math.Sin(radians); result.M31 = -result.M13; result.M33 = result.M11; }