亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? d3dutil.cs

?? Particle System Test Application on C#
?? CS
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// File: D3DUtil.cs
//
// Desc: Shortcut functions for using DX objects
//
// Copyright (c) Microsoft Corporation. All rights reserved
//-----------------------------------------------------------------------------
using System;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;




/// <summary>
/// Various helper functions for graphics samples
/// </summary>
public class GraphicsUtility
{
    /// <summary>
    /// Private Constructor 
    /// </summary>
    private GraphicsUtility() 
    { 
    }



    /// <summary>
    /// Initializes a Material structure, setting the diffuse and ambient
    /// colors. It does not set emissive or specular colors.
    /// </summary>
    /// <param name="c">The ambient and diffuse color</param>
    /// <returns>A defined material</returns>
	public static Direct3D.Material InitMaterial(System.Drawing.Color c)
	{
		Material mtrl = new Material();
		mtrl.Ambient = mtrl.Diffuse = c;
		return mtrl;
	}




    /// <summary>
    /// Initializes a light, setting the light position. The
    /// diffuse color is set to white; specular and ambient are left as black.
    /// </summary>
    /// <param name="light">Which light to initialize</param>
    /// <param name="ltType">The type</param>
	public static void InitLight(Light light, LightType ltType, float x, float y, float z)
	{
		light.Type        = ltType;
		light.Diffuse = System.Drawing.Color.White;
		light.Position = new Vector3(x,y,z);
		light.Direction = Vector3.Normalize(light.Position);
		light.Range        = 1000.0f;
	}




    /// <summary>
    /// Helper function to create a texture. It checks the root path first,
    /// then tries the DXSDK media path (as specified in the system registry).
    /// </summary>
	public static Texture CreateTexture(Device device, string textureFilename, Format format)
	{
		// Get the path to the texture
		string path = DXUtil.FindMediaFile(null, textureFilename);

		// Create the texture using D3DX
		return TextureLoader.FromFile(device, path, D3DX.Default, D3DX.Default, D3DX.Default, 0, format, 
			Pool.Managed, Filter.Triangle|Filter.Mirror, 
			Filter.Triangle|Filter.Mirror, 0);
	}




    /// <summary>
    /// Helper function to create a texture. It checks the root path first,
    /// then tries the DXSDK media path (as specified in the system registry).
    /// </summary>
    public static Texture CreateTexture(Device device, string textureFilename)
	{
		return GraphicsUtility.CreateTexture(device, textureFilename, Format.Unknown);
	}





    /// <summary>
    /// Returns a view matrix for rendering to a face of a cubemap.
    /// </summary>
	public static Matrix GetCubeMapViewMatrix(CubeMapFace face)
	{
		Vector3 vEyePt = new Vector3(0.0f, 0.0f, 0.0f);
		Vector3 vLookDir = new Vector3();
		Vector3 vUpDir = new Vector3();

		switch (face)
		{
			case CubeMapFace.PositiveX:
				vLookDir = new Vector3(1.0f, 0.0f, 0.0f);
				vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
				break;
			case CubeMapFace.NegativeX:
				vLookDir = new Vector3(-1.0f, 0.0f, 0.0f);
				vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
				break;
			case CubeMapFace.PositiveY:
				vLookDir = new Vector3(0.0f, 1.0f, 0.0f);
				vUpDir   = new Vector3(0.0f, 0.0f,-1.0f);
				break;
			case CubeMapFace.NegativeY:
				vLookDir = new Vector3(0.0f,-1.0f, 0.0f);
				vUpDir   = new Vector3(0.0f, 0.0f, 1.0f);
				break;
			case CubeMapFace.PositiveZ:
				vLookDir = new Vector3(0.0f, 0.0f, 1.0f);
				vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
				break;
			case CubeMapFace.NegativeZ:
				vLookDir = new Vector3(0.0f, 0.0f,-1.0f);
				vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
				break;
		}

		// Set the view transform for this cubemap surface
		Matrix matView = Matrix.LookAtLH(vEyePt, vLookDir, vUpDir);
		return matView;
	}




    /// <summary>
    /// Returns a quaternion for the rotation implied by the window's cursor position
    /// </summary>
	public static Quaternion GetRotationFromCursor(System.Windows.Forms.Form control, float fTrackBallRadius)
	{
		System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
		System.Drawing.Rectangle rc = control.ClientRectangle;
		pt = control.PointToClient(pt);
		float xpos = (((2.0f * pt.X) / (rc.Right-rc.Left)) - 1);
		float ypos = (((2.0f * pt.Y) / (rc.Bottom-rc.Top)) - 1);
		float sz;

		if (xpos == 0.0f && ypos == 0.0f)
			return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);

		float d2 = (float)Math.Sqrt(xpos*xpos + ypos*ypos);

		if (d2 < fTrackBallRadius * 0.70710678118654752440) // Inside sphere
			sz = (float)Math.Sqrt(fTrackBallRadius*fTrackBallRadius - d2*d2);
		else                                                 // On hyperbola
			sz = (fTrackBallRadius*fTrackBallRadius) / (2.0f*d2);

		// Get two points on trackball's sphere
		Vector3 p1 = new Vector3(xpos, ypos, sz);
		Vector3 p2 = new Vector3(0.0f, 0.0f, fTrackBallRadius);

		// Get axis of rotation, which is cross product of p1 and p2
		Vector3 axis = Vector3.Cross(p1,p2);

		// Calculate angle for the rotation about that axis
		float t = Vector3.Length(Vector3.Subtract(p2,p1)) / (2.0f*fTrackBallRadius);
		if (t > +1.0f) t = +1.0f;
		if (t < -1.0f) t = -1.0f;
		float fAngle = (float)(2.0f * Math.Asin(t));

		// Convert axis to quaternion
		return Quaternion.RotationAxis(axis, fAngle);
	}




    /// <summary>
    /// Returns a quaternion for the rotation implied by the window's cursor position
    /// </summary>
	public static Quaternion GetRotationFromCursor(System.Windows.Forms.Form control)
	{
		return GetRotationFromCursor(control, 1.0f);
	}




    /// <summary>
    /// Axis to axis quaternion double angle (no normalization)
    /// Takes two points on unit sphere an angle THETA apart, returns
    /// quaternion that represents a rotation around cross product by 2*THETA.
    /// </summary>
	public static Quaternion D3DXQuaternionUnitAxisToUnitAxis2(Vector3 fromVector, Vector3 toVector)
	{
		Vector3 axis = Vector3.Cross(fromVector, toVector);    // proportional to sin(theta)
		return new Quaternion(axis.X, axis.Y, axis.Z, Vector3.Dot(fromVector, toVector));
	}




    /// <summary>
    /// Axis to axis quaternion 
    /// Takes two points on unit sphere an angle THETA apart, returns
    /// quaternion that represents a rotation around cross product by theta.
    /// </summary>
	public static Quaternion D3DXQuaternionAxisToAxis(Vector3 fromVector, Vector3 toVector)
	{
		Vector3 vA = Vector3.Normalize(fromVector), vB = Vector3.Normalize(toVector);
		Vector3 vHalf = Vector3.Add(vA,vB);
		vHalf = Vector3.Normalize(vHalf);
		return GraphicsUtility.D3DXQuaternionUnitAxisToUnitAxis2(vA, vHalf);
	}



    
    /// <summary>
    /// Gets the number of ColorChanelBits from a format
    /// </summary>
	static public int GetColorChannelBits(Format format)
	{
		switch (format)
		{
			case Format.R8G8B8:
				return 8;
			case Format.A8R8G8B8:
				return 8;
			case Format.X8R8G8B8:
				return 8;
			case Format.R5G6B5:
				return 5;
			case Format.X1R5G5B5:
				return 5;
			case Format.A1R5G5B5:
				return 5;
			case Format.A4R4G4B4:
				return 4;
			case Format.R3G3B2:
				return 2;
			case Format.A8R3G3B2:
				return 2;
			case Format.X4R4G4B4:
				return 4;
			case Format.A2B10G10R10:
				return 10;
			case Format.A2R10G10B10:
				return 10;
			default:
				return 0;
		}
	}




    /// <summary>
    /// Gets the number of alpha channel bits 
    /// </summary>
	static public int GetAlphaChannelBits(Format format)
	{
		switch (format)
		{
			case Format.R8G8B8:
				return 0;
			case Format.A8R8G8B8:
				return 8;
			case Format.X8R8G8B8:
				return 0;
			case Format.R5G6B5:
				return 0;
			case Format.X1R5G5B5:
				return 0;
			case Format.A1R5G5B5:
				return 1;
			case Format.A4R4G4B4:
				return 4;
			case Format.R3G3B2:
				return 0;
			case Format.A8R3G3B2:
				return 8;
			case Format.X4R4G4B4:
				return 0;
			case Format.A2B10G10R10:
				return 2;
			case Format.A2R10G10B10:
				return 2;
			default:
				return 0;
		}
	}



    
    /// <summary>
    /// Gets the number of depth bits
    /// </summary>
	static public int GetDepthBits(DepthFormat format)
	{
		switch (format)
		{
			case DepthFormat.D16:
				return 16;
			case DepthFormat.D15S1:
				return 15;
			case DepthFormat.D24X8:
				return 24;
			case DepthFormat.D24S8:
				return 24;
			case DepthFormat.D24X4S4:
				return 24;
			case DepthFormat.D32:
				return 32;
			default:
				return 0;
		}
	}




    /// <summary>
    /// Gets the number of stencil bits
    /// </summary>
	static public int GetStencilBits(DepthFormat format)
	{
		switch (format)
		{
			case DepthFormat.D16:
				return 0;
			case DepthFormat.D15S1:
				return 1;
			case DepthFormat.D24X8:
				return 0;
			case DepthFormat.D24S8:
				return 8;
			case DepthFormat.D24X4S4:
				return 4;
			case DepthFormat.D32:
				return 0;
			default:
				return 0;
		}
	}




    /// <summary>
    /// Assembles and creates a file-based vertex shader
    /// </summary>
	public static VertexShader CreateVertexShader(Device device, string filename)
	{
		GraphicsStream code = null;
		string path = null;
	
		// Get the path to the vertex shader file
		path = DXUtil.FindMediaFile(null, filename);

		// Assemble the vertex shader file
		code = ShaderLoader.FromFile(path, null, 0);

		// Create the vertex shader
		return new VertexShader(device, code);
	}

}




/// <summary>
/// An arc ball class
/// </summary>
public class GraphicsArcBall
{
	private int internalWidth;   // ArcBall's window width
	private int internalHeight;  // ArcBall's window height
	private float internalradius;  // ArcBall's radius in screen coords
	private float internalradiusTranslation; // ArcBall's radius for translating the target

	private Quaternion internaldownQuat;               // Quaternion before button down
	private Quaternion internalnowQuat;                // Composite quaternion for current drag
	private Matrix internalrotationMatrix;         // Matrix for arcball's orientation
	private Matrix internalrotationDelta;    // Matrix for arcball's orientation
	private Matrix internaltranslationMatrix;      // Matrix for arcball's position
	private Matrix internaltranslationDelta; // Matrix for arcball's position
	private bool internaldragging;               // Whether user is dragging arcball
	private bool internaluseRightHanded;        // Whether to use RH coordinate system
	private int saveMouseX = 0;      // Saved mouse position
	private int saveMouseY = 0;
	private Vector3 internalvectorDown;         // Button down vector
	System.Windows.Forms.Control parent; // parent




    /// <summary>
    /// Constructor
    /// </summary>
	public GraphicsArcBall(System.Windows.Forms.Control p)
	{
		internaldownQuat = Quaternion.Identity;
		internalnowQuat = Quaternion.Identity;
		internalrotationMatrix = Matrix.Identity;
		internalrotationDelta = Matrix.Identity;
		internaltranslationMatrix = Matrix.Identity;
		internaltranslationDelta  = Matrix.Identity;
		internaldragging = false;
		internalradiusTranslation = 1.0f;
		internaluseRightHanded = false;

		parent = p;
		// Hook the events 
		p.MouseDown += new MouseEventHandler(this.OnContainerMouseDown);
		p.MouseUp += new MouseEventHandler(this.OnContainerMouseUp);
		p.MouseMove += new MouseEventHandler(this.OnContainerMouseMove);
	}




    /// <summary>
    /// Set the window dimensions
    /// </summary>
	public void SetWindow(int width, int height, float radius)
	{
		// Set ArcBall info
		internalWidth  = width;
		internalHeight = height;
		internalradius = radius;
	}




    /// <summary>
    /// Screen coords to a vector
    /// </summary>
	private Vector3 ScreenToVector(int xpos, int ypos)
	{
		// Scale to screen
		float x   = -(xpos - internalWidth/2)  / (internalradius*internalWidth/2);
		float y   =  (ypos - internalHeight/2) / (internalradius*internalHeight/2);

		if (internaluseRightHanded)
		{
			x = -x;
			y = -y;
		}

		float z   = 0.0f;
		float mag = x*x + y*y;

		if (mag > 1.0f)
		{
			float scale = 1.0f/(float)Math.Sqrt(mag);
			x *= scale;
			y *= scale;
		}
		else
			z = (float)Math.Sqrt(1.0f - mag);

		// Return vector
		return new Vector3(x, y, z);
	}




    /// <summary>
    /// Fired when the containers mouse button is down
    /// </summary>
	private void OnContainerMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
	{
		// Store off the position of the cursor when the button is pressed
		saveMouseX = e.X;
		saveMouseY = e.Y;

		if (e.Button == System.Windows.Forms.MouseButtons.Left)
		{
			// Start drag mode
			internaldragging = true;
			internalvectorDown = ScreenToVector(e.X, e.Y);
			internaldownQuat = internalnowQuat;
		}
	}




    /// <summary>
    /// Fired when the containers mouse button has been released
    /// </summary>
	private void OnContainerMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
	{
		if (e.Button == System.Windows.Forms.MouseButtons.Left)
		{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产不卡视频一区二区三区| 国产在线精品视频| 日韩综合在线视频| 成人不卡免费av| 日韩欧美一级二级| 综合亚洲深深色噜噜狠狠网站| 午夜精品福利一区二区蜜股av| 美美哒免费高清在线观看视频一区二区| 日韩欧美一二区| 自拍av一区二区三区| 麻豆精品视频在线| 欧美日韩专区在线| 国产精品乱码一区二三区小蝌蚪| 丝袜美腿高跟呻吟高潮一区| 91在线视频18| 中文字幕不卡一区| 国产精品 欧美精品| 日韩一卡二卡三卡国产欧美| 亚洲一区在线免费观看| 91在线你懂得| 一区二区在线看| 97久久精品人人做人人爽| 久久精品视频在线看| 久久激五月天综合精品| 91精品国产麻豆国产自产在线| 亚洲成人综合在线| 91成人国产精品| 夜夜爽夜夜爽精品视频| 国产成人av电影在线| 99国产精品久久久| 国产精品久久久久久久裸模| av电影天堂一区二区在线| 国产精品美女久久久久久久网站| 国产一区二三区好的| 久久女同性恋中文字幕| 国产乱淫av一区二区三区 | 美女性感视频久久| 91精品国产手机| 久久精品国产亚洲一区二区三区| 欧美精品99久久久**| 日韩综合一区二区| 日韩欧美一区二区久久婷婷| 蜜臀av一级做a爰片久久| 日韩三级伦理片妻子的秘密按摩| 日本伊人午夜精品| 精品日产卡一卡二卡麻豆| 国产一区91精品张津瑜| 欧美激情一区三区| 色婷婷精品大视频在线蜜桃视频| 亚洲精品视频一区| 在线成人av影院| 国产一区二区三区av电影 | 国产精品免费免费| 成人性生交大片免费看中文网站| 亚洲欧洲一区二区三区| 在线亚洲高清视频| 全国精品久久少妇| 久久精品水蜜桃av综合天堂| 99久久精品国产毛片| 亚洲一区二区三区爽爽爽爽爽| 日韩午夜小视频| 国产91富婆露脸刺激对白| 亚洲特黄一级片| 欧美一区二区三区小说| 韩国精品在线观看| 亚洲私人黄色宅男| 欧美大度的电影原声| 国产成人精品亚洲777人妖| 亚洲综合久久av| 精品国产3级a| 色一情一伦一子一伦一区| 日韩黄色免费电影| 国产精品无遮挡| 91精品国产综合久久精品麻豆| 国产原创一区二区| 亚洲成av人综合在线观看| 国产日韩三级在线| 欧美日韩一区二区三区不卡| 国产乱子伦视频一区二区三区| 亚洲资源中文字幕| 久久久久久久久久久久电影| 在线免费观看成人短视频| 精品在线观看免费| 亚洲高清不卡在线| 久久久综合网站| 欧美日韩电影在线播放| 粉嫩一区二区三区在线看| 日本伊人色综合网| 亚洲精品乱码久久久久久黑人| 日韩欧美国产高清| 欧美午夜不卡视频| 成人av网站免费观看| 麻豆久久久久久| 五月天国产精品| 一区二区三区高清| 国产精品久久看| 欧美激情一区二区三区在线| 日韩一区二区三区电影在线观看| 在线视频欧美区| 91在线视频18| 96av麻豆蜜桃一区二区| 成人毛片在线观看| 国产成a人无v码亚洲福利| 激情综合色播激情啊| 午夜电影一区二区| 自拍偷拍亚洲综合| 久久亚区不卡日本| 精品91自产拍在线观看一区| 555www色欧美视频| 欧美精品一卡两卡| 中文字幕第一区二区| 久久免费精品国产久精品久久久久| 7878成人国产在线观看| 欧美三电影在线| 欧美色偷偷大香| 欧美三级韩国三级日本一级| 欧美怡红院视频| 欧美午夜视频网站| 欧美精品久久久久久久久老牛影院| 欧美在线三级电影| 欧美剧在线免费观看网站| 在线观看91精品国产入口| 欧美在线看片a免费观看| 在线看不卡av| 欧美精品1区2区3区| 欧美一级午夜免费电影| 欧美第一区第二区| 久久亚洲精品小早川怜子| 久久精品日产第一区二区三区高清版 | 成人app网站| 成人综合在线观看| 成人av在线影院| 91麻豆.com| 欧美日韩视频专区在线播放| 欧美精品777| 久久综合九色综合久久久精品综合| www日韩大片| 欧美国产欧美综合| 亚洲精品视频一区二区| 五月婷婷色综合| 国产乱码精品一区二区三区av| 成人免费视频视频在线观看免费| 91无套直看片红桃| 欧美日高清视频| 久久亚洲精品国产精品紫薇| 国产精品成人免费在线| 亚洲综合免费观看高清完整版| 日本vs亚洲vs韩国一区三区| 国产一二精品视频| 色综合久久天天| 欧美一区二区视频观看视频| 亚洲欧美日韩一区二区| 亚洲一二三级电影| 久久91精品国产91久久小草| www.成人在线| 在线观看91精品国产麻豆| 国产日韩三级在线| 午夜精品一区二区三区电影天堂| 精品一区二区三区视频在线观看| 成人午夜精品一区二区三区| 91.麻豆视频| 国产精品人妖ts系列视频| 五月天视频一区| 成人精品视频.| 日韩一区二区三区免费看 | 在线播放一区二区三区| 国产午夜三级一区二区三| 一区二区在线电影| 粉嫩在线一区二区三区视频| 欧美日韩免费高清一区色橹橹 | 日韩国产欧美视频| 丁香婷婷综合网| 91精品国产麻豆国产自产在线| 自拍偷拍欧美精品| 国产传媒一区在线| 日韩视频免费直播| 亚洲一区视频在线| 99精品欧美一区二区三区小说| 日韩久久久精品| 石原莉奈一区二区三区在线观看| 99re成人精品视频| 国产无一区二区| 另类调教123区| 777午夜精品视频在线播放| 亚洲精品欧美激情| 99久久久免费精品国产一区二区| 欧美xxxx老人做受| 日韩电影在线一区二区三区| 91福利国产精品| 亚洲人午夜精品天堂一二香蕉| 国产传媒日韩欧美成人| 欧美xfplay| 久久精品国产在热久久| 欧美精品三级日韩久久| 一区二区三区四区激情| 99re成人在线| 亚洲欧美电影院| 91国内精品野花午夜精品 | 久久影音资源网| 国产呦精品一区二区三区网站|