自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C# Direct3D模型概論

開發(fā) 后端
這里介紹C# Direct3D模型由World 空間,View 空間和光源組成。World空間就像我們現(xiàn)實生活中的空間一樣,我們可以把物體放在這個空間的任何地方。

C#語言有很多值得學習的地方,這里我們主要介紹C# Direct3D模型,包括介紹改成PositionColored格式等方面。

什么是真正的3D世界呢?或者說C# Direct3D模型是什么樣的呢?

C# Direct3D模型由World 空間,View 空間和光源組成。World空間就像我們現(xiàn)實生活中的空間一樣,我們可以把物體放在這個空間的任何地方。但僅僅這樣是不夠的。因為現(xiàn)實中,我們是通過眼睛來看事物的,存在的東西不一定我們可以看得到,太遠的東西看不到,被擋住的東西看不到,太近的東西也看不到,在我們視角以外的東西一樣看不到。在 Direct3D中用camera來模擬我們的眼睛。

另外還有一個重要概念,transform,變換。在world空間中,我們可以把物體移動,旋轉(zhuǎn),這需要通過變換來實現(xiàn)。通過camera來決定我們最終能看到的那些東西時也是經(jīng)過變換。在Direct3D中,變換是通過4x4的矩陣來實現(xiàn)的。

不是搞算法的人沒有必要了解矩陣的具體內(nèi)容,可以通過Maxtrix中的靜態(tài)函數(shù)來創(chuàng)建矩陣:
◆Matrix.RotationX()
◆Matrix.RotationY()
◆Matrix,RotationZ()創(chuàng)建分別圍繞X,Y,Z軸旋轉(zhuǎn)的矩陣。
◆Matrix.Translation()用來創(chuàng)建移動物體的矩陣。

而與camera相關(guān)的變換有兩個,View Transform,和Projection Transform.View Transform用來定義camera的信息。而Projection Transform用來定義我們的可見范圍,也就是說那些物體會被繪制到屏幕上去。

另外一個很重要的概念就是光源,在真實世界中,沒有光的情況下我們是看不到東西的,即使他存在。而且我們看到的物體的顏色/亮度,與光源的顏色/亮度,與他本身的材質(zhì)/顏色都有關(guān)系。在Direct3D中也是如此,一旦一個物體在我們的可視范圍內(nèi),并且沒有被遮擋住,那么他能否可見,以及什么顏色/亮度,就由光源,物體的材質(zhì)來決定了。

下面就開始我們的例子。首先把我們的代碼中的頂點格式,改成PositionColored格式。注意坐標哦,這里的坐標可不是屏幕坐標系了,而是World坐標系,是左手笛卡爾3D坐標系。***步的代碼如下:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Windows.Forms;  
  7. using Microsoft.DirectX;  
  8. using Microsoft.DirectX.Direct3D;  
  9. #endregion  
  10. namespace Exam2  
  11. {  
  12. partial class Form1 : Form  
  13. {  
  14. private Device device = null;  
  15. public Form1()  
  16. {  
  17. InitializeComponent();  
  18. this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true );  
  19. }  
  20. public void InitializeGraphics()  
  21. {  
  22. PresentParameters para = new PresentParameters();  
  23. para.Windowed = true;  
  24. para.SwapEffect = SwapEffect.Discard;  
  25. device = new Device( 0, DeviceType.Hardware, this, 
    CreateFlags.HardwareVertexProcessing, para );  
  26. }  
  27. private void Form1_Paint(object sender, PaintEventArgs e)  
  28. {  
  29. device.Clear( ClearFlags.Target, Color.Blue, 0.0f, 0 );  
  30. CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[3];  
  31. verts[0].Position = new Vector3(0.0f, 1.0f, 1.0f);  
  32. verts[0].Color = Color.Aqua.ToArgb();  
  33. verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f);  
  34. verts[1].Color = Color.Black.ToArgb();  
  35. verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f);  
  36. verts[2].Color = Color.Purple.ToArgb();  
  37. device.BeginScene();  
  38. device.VertexFormat = CustomVertex.PositionColored.Format;  
  39. device.DrawUserPrimitives( PrimitiveType.TriangleList, 1, verts );  
  40.  
  41. device.EndScene();  
  42. device.Present();  
  43. this.Invalidate();  
  44. }  
  45. }  

以上介紹C# Direct3D模型。

【編輯推薦】

  1. C#方法重寫全面介紹
  2. C#流程控制語句簡單描述
  3. Java和C#字符串類型概述
  4. C#訪問修飾符詳細剖析
  5. 選擇C#構(gòu)造函數(shù)描述
責任編輯:佚名 來源: 博客園
相關(guān)推薦

2024-06-17 12:33:34

2013-09-02 15:46:06

OpenGLWindows

2018-01-23 10:07:13

LinuxWindowsWine 3.0

2023-06-28 08:29:29

Direct3D工作圖功能

2010-09-30 10:31:43

J2ME3D

2009-08-25 16:03:51

C# SQLDMO對象

2015-10-28 10:21:54

WineUbuntu 15.1Linux

2022-05-20 07:30:38

微軟Windows 11

2023-02-09 16:14:09

微軟Windows

2024-12-10 09:40:00

AI3D模型

2009-08-28 09:25:59

C#查看Excel對象

2013-04-25 10:03:07

unity3D手機游戲引擎

2009-09-03 17:33:08

C#常規(guī)擴展性模型

2009-08-05 16:04:27

C# Actor模型

2009-09-04 15:43:07

C#流模型

2009-09-03 17:18:40

C#擴展性對象模型

2012-12-24 09:14:31

ios

2020-08-26 10:37:21

阿里3D

2009-04-14 22:13:44

LinuxWine 1.1.19

2023-08-18 08:00:00

游戲開發(fā)3D模型
點贊
收藏

51CTO技術(shù)棧公眾號