📄 blockform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.DirectX;
using Microsoft.WindowsMobile.DirectX.Direct3D;
namespace Block
{
public partial class BlockForm : Form
{
public class ImageBackground
{
/// <summary>
/// Texture to be drawn with. Passed into the constructor.
/// </summary>
public Texture BackgroundTexture;
/// <summary>
/// This defines the shape of our background image and the texture of the
/// vertices.
/// </summary>
public CustomVertex.PositionNormalTextured[] Vertices;
/// <summary>
/// Vertex buffer which is used by the display hardware
/// recieve details of what we want to draw.
/// </summary>
public VertexBuffer VertBuffer = null;
public ImageBackground(Device device, System.IO.Stream textureStream, float sz, float z)
{
BackgroundTexture = TextureLoader.FromStream(device, textureStream);
Vertices = new CustomVertex.PositionNormalTextured[6];
Vertices[0] = new CustomVertex.PositionNormalTextured(
-sz, -sz, z, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
0.0f, 1.0f);
Vertices[1] = new CustomVertex.PositionNormalTextured(
-sz, +sz, z, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
0.0f, 0.0f);
Vertices[2] = new CustomVertex.PositionNormalTextured(
+sz, -sz, z, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
1.0f, 1.0f);
Vertices[3] = new CustomVertex.PositionNormalTextured(
+sz, -sz, z, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
1.0f, 1.0f);
Vertices[4] = new CustomVertex.PositionNormalTextured(
-sz, +sz, z, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
0.0f, 0.0f);
Vertices[5] = new CustomVertex.PositionNormalTextured(
+sz, +sz, z, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
1.0f, 0.0f);
VertBuffer = new VertexBuffer(
typeof(CustomVertex.PositionNormalTextured), // type of the buffer
Vertices.Length, // holding vertices array
device, // for our device
Usage.WriteOnly, // never going to read it
CustomVertex.PositionNormalTextured.Format, // source format
Pool.SystemMemory); // mobile 3D requires this
}
/// <summary>
/// Draw the textured image.
/// </summary>
/// <param name="device">target device to draw on</param>
public void Draw(Device device)
{
// Set the data in the vertex buffer to our triangles
VertBuffer.SetData(Vertices, 0, LockFlags.None);
// clear off any existing transformations
device.Transform.World = Matrix.Identity;
// Point the device at our vertex buffer
device.SetStreamSource(0, VertBuffer, 0);
// Assign the texture to the device.
device.SetTexture(0, BackgroundTexture);
// Ask the device to draw the contents of the buffer
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
// Stop using this texture
device.SetTexture(0, null);
}
}
ImageBackground imageBackground;
/// <summary>
/// Currently executing assembly. Cached because it is used
/// to load a lot of resources.
/// </summary>
readonly System.Reflection.Assembly assembly =
System.Reflection.Assembly.GetExecutingAssembly();
/// <summary>
/// Direct3D device we are going to draw on.
/// </summary>
Device device;
public CustomVertex.PositionNormalColored[] Vertices;
public VertexBuffer VertBuffer = null;
public void MakeBlock()
{
Vertices = new CustomVertex.PositionNormalColored[36];
int colour = Color.Red.ToArgb();
/// Front face
Vertices[0] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, -0.5f, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
colour);
Vertices[1] = new CustomVertex.PositionNormalColored(
-0.5f, +0.5f, -0.5f, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
colour);
Vertices[2] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, -0.5f, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
colour);
colour = Color.White.ToArgb();
Vertices[3] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, -0.5f, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
colour);
Vertices[4] = new CustomVertex.PositionNormalColored(
-0.5f, +0.5f, -0.5f, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
colour);
Vertices[5] = new CustomVertex.PositionNormalColored(
+0.5f, +0.5f, -0.5f, // position
0.0f, 0.0f, -1.0f, // normal - looking out of the screen
colour);
colour = Color.Green.ToArgb();
/// Right hand face
Vertices[6] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, -0.5f, // position
1.0f, 0.0f, 0.0f, // normal - looking out towards the right - X axis
colour);
Vertices[7] = new CustomVertex.PositionNormalColored(
+0.5f, +0.5f, -0.5f, // position
1.0f, 0.0f, 0.0f, // normal - looking out towards the right - X axis
colour);
Vertices[8] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, +0.5f, // position
1.0f, 0.0f, 0.0f, // normal - looking out towards the right - X axis
colour);
colour = Color.White.ToArgb();
Vertices[9] = new CustomVertex.PositionNormalColored(
+0.5f, +0.5f, -0.5f, // position
1.0f, 0.0f, 0.0f, // normal - looking out towards the right - X axis
colour);
Vertices[10] = new CustomVertex.PositionNormalColored(
+0.5f, +0.5f, +0.5f, // position
1.0f, 0.0f, 0.0f, // normal - looking out towards the right - X axis
colour);
Vertices[11] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, +0.5f, // position
1.0f, 0.0f, 0.0f, // normal - looking out towards the right - X axis
colour);
colour = Color.Blue.ToArgb();
/// Bottom face
Vertices[12] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, -0.5f, // position
0.0f, -1.0f, 0.0f, // normal - looking down - Y axis
colour);
Vertices[13] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, -0.5f, // position
0.0f, -1.0f, 0.0f, // normal - looking down - Y axis
colour);
Vertices[14] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, +0.5f, // position
0.0f, -1.0f, 0.0f, // normal - looking down - Y axis
colour);
colour = Color.White.ToArgb();
Vertices[15] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, -0.5f, // position
0.0f, -1.0f, 0.0f, // normal - looking down - Y axis
colour);
Vertices[16] = new CustomVertex.PositionNormalColored(
+0.5f, -0.5f, +0.5f, // position
0.0f, -1.0f, 0.0f, // normal - looking down - Y axis
colour);
Vertices[17] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, +0.5f, // position
0.0f, -1.0f, 0.0f, // normal - looking down - Y axis
colour);
colour = Color.Yellow.ToArgb();
/// left hand face
Vertices[18] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, -0.5f, // position
-1.0f, 0.0f, 0.0f, // normal - looking left - negative X axis
colour);
Vertices[19] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, +0.5f, // position
-1.0f, 0.0f, 0.0f, // normal - looking left - negative X axis
colour);
Vertices[20] = new CustomVertex.PositionNormalColored(
-0.5f, +0.5f, -0.5f, // position
-1.0f, 0.0f, 0.0f, // normal - looking left - negative X axis
colour);
colour = Color.White.ToArgb();
Vertices[21] = new CustomVertex.PositionNormalColored(
-0.5f, +0.5f, -0.5f, // position
-1.0f, 0.0f, 0.0f, // normal - looking left - negative X axis
colour);
Vertices[22] = new CustomVertex.PositionNormalColored(
-0.5f, -0.5f, +0.5f, // position
-1.0f, 0.0f, 0.0f, // normal - looking left - negative X axis
colour);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -