Sign in to follow this  
trasseltass

[C#/DirectX/D3D] Problem with transforms and rendering

Recommended Posts

Hi! I'm attempting to make a piece of editor software in MSVS2008, C# and .NET. The editor is a Form which contains a bunch of controls, including four D3D devices (each of them is a separate UserControl). At the moment though, only one of the devices is created at compile-time due to my debugging. I think I've managed to setup the D3D Device ok because I have managed to render a triangle ok. The problem is that when I try to transform the vertices of the triangle it doesn't seem to "take". Nothing happens to the triangle when I assign new matrices/transforms to the D3D device's world/view/projection transforms. Here is the basic code I use to initialise the device:
// Setting up the D3D device
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
m_device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
Here is the code I use to render each frame:
//Clear the backbuffer
m_device.Clear(ClearFlags.Target, m_deviceBackColor, 1.0f, 0);

//Begin the scene
m_device.BeginScene();

device.Transform.World = Matrix.Identity;
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1f, 350f);
device.Transform.View = Matrix.LookAtLH(new Vector3(10.0f, 10.0f, 10.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3];
vertices[0].Position = new Vector4(50, 50, 50, 1.0f);
vertices[0].Color = System.Drawing.Color.FromArgb(0, 0, 255).ToArgb();
vertices[1].Position = new Vector4(250, 50, -50, 1.0f);
vertices[1].Color = System.Drawing.Color.FromArgb(0, 255, 0).ToArgb();
vertices[2].Position = new Vector4(50, 250, 50, 1.0f);
vertices[2].Color = System.Drawing.Color.FromArgb(255, 0, 0).ToArgb();

device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);

//End the scene
m_device.EndScene();
m_device.Present();
No matter how I modify the devices View/World/Projection-transforms and redraw it still displays the same old triangle, from the same angle. However, if I modify the vertex positions or the color of the vertices at runtime and then redraw, it will have effect and the triangle will change. Any ideas? :(

Share this post


Link to post
Share on other sites
Your direct problem is that you're using TransformedColor vertices, which specify to Direct3D that your vertices are already transformed manually and that you don't want them to be affected by any pipeline transforms. So the behavior you are seeing is exactly the behavior you requested.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this