Franco1 ha scritto:
Grazie, sapresti indicarmi un sito dove trovare un esempio di base già fatto.
Il sito migliore è questo dove ti trovi!
Questo esempio ti mostra un cubo che ruota:
public partial class Form1 : Form
{
My3d my3d;
public Form1()
{
InitializeComponent();
my3d = new My3d(Handle);
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (Visible && (WindowState != FormWindowState.Minimized))
{
my3d.Render();
}
}
}
public class My3d
{
protected Device myDevice;
protected Mesh myCube = null;
public My3d(IntPtr handle)
{
PresentParameters m_presentParams = new PresentParameters();
m_presentParams.Windowed = true;
m_presentParams.SwapEffect = SwapEffect.Discard;
m_presentParams.EnableAutoDepthStencil = true;
m_presentParams.AutoDepthStencilFormat = DepthFormat.D16;
myDevice = new Device(0, DeviceType.Hardware, handle,
CreateFlags.SoftwareVertexProcessing, m_presentParams);
myDevice.DeviceReset += new System.EventHandler(this.OnResetDevice);
OnResetDevice(myDevice, null);
myCube = Mesh.Box(myDevice, 1, 1, 1);
}
protected void OnResetDevice(object sender, EventArgs e)
{
Device device = (Device)sender;
device.RenderState.ZBufferEnable = true;
device.RenderState.Ambient = System.Drawing.Color.White;
myDevice.RenderState.Lighting = true;
}
protected void SetupLights()
{
myDevice.Lights[0].Diffuse = Color.White;
myDevice.Lights[0].Direction = new Vector3(1, -1, 1);
myDevice.Lights[0].Enabled = true;
myDevice.RenderState.Ambient = Color.FromArgb(0x888888);
}
protected void SetDeviceMaterial(Color color)
{
Material material = myDevice.Material;
material.Diffuse = color;
material.Ambient = color;
myDevice.Material = material;
}
public void Render()
{
myDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Blue, 1.0f, 0);
myDevice.BeginScene();
SetupLights();
myDevice.Transform.View = Matrix.LookAtLH(new Vector3(2.0f, 2.0f, -2.0f),
new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
myDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 4), 1.0f, 1.0f, 100.0f);
SetDeviceMaterial(Color.Orange);
myDevice.Transform.World = Matrix.RotationY(Environment.TickCount/1000f);
myCube.DrawSubset(0);
myDevice.EndScene();
myDevice.Present();
}
}