W
wize010
hi ,
i have just started to read a book called managed directx : kickstart
by Tim Miller for games programming. i have a basic knowledge of
programming in general. as i used to work in java and c, but now i
have to design a simple 3d game using managed directx and direct3d.
i started with the first example below as u can see. this code should
show a triangle in a window frame. but i had an error when i built
the project and i got this message.
i juist like to say that i copied this code directly from the book and
i thought it should work!
can anyone help me here i am really stuck and i have to design a
simple 3D game in 10 days!! where i have an arm that can pick up a
ball and release it.thats all!
can ANY ONE GIVE ME Direction!
thanks
this is my code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Chapter1Code
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Device device = null;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
}
/// <summary>
/// We will initialize our graphics device here
/// </summary>
public void InitializeGraphics()
{
// Set our presentation parameters
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
// Create our device
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target,
System.Drawing.Color.CornflowerBlue, 1.0f, 0);
CustomVertex.TransformedColored[] verts = new
CustomVertex.TransformedColored[3];
verts[0].SetPosition(new Vector4(this.Width / 2.0f,
50.0f, 0.5f, 1.0f));
verts[0].Color =
System.Drawing.Color.Aqua.ToArgb();
verts[1].SetPosition(new Vector4(this.Width -
(this.Width / 5.0f), this.Height - (this.Height /
5.0f), 0.5f, 1.0f));
verts[1].Color =
System.Drawing.Color.Black.ToArgb();
verts[2].SetPosition(new Vector4(this.Width / 5.0f,
this.Height - (this.Height / 5.0f), 0.5f, 1.0f));
verts[2].Color =
System.Drawing.Color.Purple.ToArgb();
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
verts);
device.EndScene();
device.Present();
this.Invalidate();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
using (Form1 frm = new Form1())
{
// Show our form and initialize our graphics engine
frm.Show();
frm.InitializeGraphics();
Application.Run(frm);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
i have just started to read a book called managed directx : kickstart
by Tim Miller for games programming. i have a basic knowledge of
programming in general. as i used to work in java and c, but now i
have to design a simple 3d game using managed directx and direct3d.
i started with the first example below as u can see. this code should
show a triangle in a window frame. but i had an error when i built
the project and i got this message.
i juist like to say that i copied this code directly from the book and
i thought it should work!
not contain a definition for 'SetPosition'Error
'Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored' does
1\PreTransformed\Form1.csC:\Program Files\Sams Publishing\MDXKickStart\C# Code\Chapter
can anyone help me here i am really stuck and i have to design a
simple 3D game in 10 days!! where i have an arm that can pick up a
ball and release it.thats all!
can ANY ONE GIVE ME Direction!
thanks
this is my code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Chapter1Code
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private Device device = null;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque, true);
}
/// <summary>
/// We will initialize our graphics device here
/// </summary>
public void InitializeGraphics()
{
// Set our presentation parameters
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
// Create our device
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target,
System.Drawing.Color.CornflowerBlue, 1.0f, 0);
CustomVertex.TransformedColored[] verts = new
CustomVertex.TransformedColored[3];
verts[0].SetPosition(new Vector4(this.Width / 2.0f,
50.0f, 0.5f, 1.0f));
verts[0].Color =
System.Drawing.Color.Aqua.ToArgb();
verts[1].SetPosition(new Vector4(this.Width -
(this.Width / 5.0f), this.Height - (this.Height /
5.0f), 0.5f, 1.0f));
verts[1].Color =
System.Drawing.Color.Black.ToArgb();
verts[2].SetPosition(new Vector4(this.Width / 5.0f,
this.Height - (this.Height / 5.0f), 0.5f, 1.0f));
verts[2].Color =
System.Drawing.Color.Purple.ToArgb();
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1,
verts);
device.EndScene();
device.Present();
this.Invalidate();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
using (Form1 frm = new Form1())
{
// Show our form and initialize our graphics engine
frm.Show();
frm.InitializeGraphics();
Application.Run(frm);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}