Witam wszystkich,
po zainstalowaniu SharpDevelop (wcześniej bawiłem sie na MS VisualStudio) zauważyłem, że jest tam przykład DirectX. Spodobał mi się ten język, ale w tym konkretnum kodzie nie moge sobie poradzić:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace _d
{
/// <summary>
/// This is the main class of my Direct3D application
/// </summary>
public class MainClass : Form
{
/// <summary>
/// The rendering device
/// </summary>
Device device = null;
CustomVertex.TransformedColored[] vertices;
float angle=1.0f;
public MainClass()
{
this.ClientSize = new System.Drawing.Size(640, 480);
this.Text = "f";
}
public bool InitializeGraphics()
{
try {
// Now let's setup the Direct3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
// Create the device
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
// Setup the event handlers for the device
device.DeviceLost += new EventHandler(this.InvalidateDeviceObjects);
device.DeviceReset += new EventHandler(this.RestoreDeviceObjects);
device.Disposing += new EventHandler(this.DeleteDeviceObjects);
device.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing);
device.Transform.World = Matrix.Identity;
return true;
} catch (DirectXException) {
return false;
}
}
protected virtual void InvalidateDeviceObjects(object sender, EventArgs e)
{
}
protected virtual void RestoreDeviceObjects(object sender, EventArgs e)
{
}
protected virtual void DeleteDeviceObjects(object sender, EventArgs e)
{
}
protected virtual void EnvironmentResizing(object sender, CancelEventArgs e)
{
}
/// <summary>
/// This method moves the scene
/// </summary>
protected virtual void FrameMove()
{
// TODO : Frame movement
device.Transform.World = Matrix.RotationZ((System.Environment.TickCount/450f) / (float)Math.PI);
}
/// <summary>
/// This method renders the scene
/// </summary>
protected virtual void Render()
{
if (device != null) {
device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
device.BeginScene();
// TODO : Scene rendering
vertices = new CustomVertex.TransformedColored[3];
vertices[0].Position = new Vector4(150f, 100f, 0f, 1f);
vertices[0].Color = Color.Red.ToArgb();
vertices[1].Position = new Vector4(this.Width/2+100f, 100f, 0f, 1f);
vertices[1].Color = Color.Green.ToArgb();
vertices[2].Position = new Vector4(250f, 300f, 0f, 1f);
vertices[2].Color = Color.Yellow.ToArgb();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);
device.EndScene();
device.Present();
}
}
/// <summary>
/// Our mainloop
/// </summary>
public void Run()
{
// While the form is still valid, render and process messages
while (Created) {
FrameMove();
Render();
Application.DoEvents();
}
}
protected override void OnPaint(PaintEventArgs e)
{
this.Render();
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
if ((int)e.KeyChar == (int)System.Windows.Forms.Keys.Escape) {
this.Close();
}
}
/// <summary>
/// The main entry point for the application
/// </summary>
static void Main()
{
using (MainClass mainClass = new MainClass()) {
if (!mainClass.InitializeGraphics()) {
MessageBox.Show("Error while initializing Direct3D");
return;
}
mainClass.Show();
mainClass.Run();
}
}
}
}
nie moge obracać tego trójkąta. Wszędzie na necie znajduje tylko:
device.Transform.World = Matrix.RotationZ(kąt);
ale to nie działa. W ogóle co to jest ten Matrix? Czy ja man do tego jakos dodawać moje vertexy?</cpp>
Dziękuję za wszystkie odpowiedzi.