Advertisement Jump to content
Sign in to follow this  

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

This topic is 3550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!