C# DirectX编程对基本三角形应用平移变换矩阵
生活随笔
收集整理的這篇文章主要介紹了
C# DirectX编程对基本三角形应用平移变换矩阵
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前文;
https://blog.csdn.net/bcbobo21cn/article/details/112729045
平移變換矩陣的定義如下;
除了對角全為1,以及px、py、pz之外,都為0;px、py、pz 是三個軸的平移量;
把一個三維物體各頂點坐標乘以T(p)矩陣,該物體就會被平移px、py、pz;
先在窗體級定義一個矩陣,Microsoft.DirectX.Matrix m1; Render()函數如下;其他代碼見前文的前文;
public void Render(){if (device == null) //如果device為空則不渲染{return;}device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0); //清除windows界面為深藍色device.BeginScene();//在此添加渲染圖形代碼CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3];//定義頂點vertices[0].Position = new Vector4(100f, 200f, 0f, 1f);vertices[0].Color = Color.Red.ToArgb();vertices[1].Position = new Vector4(this.Width / 2, 50f, 0f, 1f);vertices[1].Color = Color.Green.ToArgb();vertices[2].Position = new Vector4(this.Width - 150f, 100f, 0f, 1f);vertices[2].Color = Color.Yellow.ToArgb();m1.M11 = 1; m1.M12 = 0; m1.M13 = 0; m1.M14 = 0;m1.M21 = 0; m1.M22 = 1; m1.M23 = 0; m1.M24 = 0;m1.M31 = 0; m1.M32 = 0; m1.M33 = 1; m1.M34 = 0;m1.M41 = -75.0f; m1.M42 = 5.0f; m1.M43 = 25.0f; m1.M44 = 1;Vector4 v41 = new Vector4(100f, 200f, 0f, 1f);v41.Transform(m1);vertices[0].Position = v41;Vector4 v42 = new Vector4(this.Width / 2, 50f, 0f, 1f);v42.Transform(m1);vertices[1].Position = v42;Vector4 v43 = new Vector4(this.Width - 150f, 100f, 0f, 1f);v43.Transform(m1);vertices[2].Position = v43;device.VertexFormat = CustomVertex.TransformedColored.Format;device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);device.EndScene();device.Present();}? ? 定義m1之后把m1賦值為平移變換矩陣;平移量在第四行賦值;然后對三個頂點用m1作變換;
未應用m1進行變換和進行了變換的輸出對比如下;
如只對?vertices[0].Position 應用m1進行變換則輸出如下;
? ?有時間再繼續;
總結
以上是生活随笔為你收集整理的C# DirectX编程对基本三角形应用平移变换矩阵的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DOS内核学习 - DOS专用中断
- 下一篇: VC++开发简单DLL并调用