Question

I would like to do something like this: a rotating cube on a form. I don't want to use any external library or dll, just pure .NET 3.5 (without directx). And a cube build with lines only. Could you please tell me how to do this?

I don't want to use external libraries because I don't need > 100 MB library to do this thing right? I want only to animate a rotating cube made with lines.

Was it helpful?

Solution

This is how you go about making a Cube in GDI+

C# 3D Drawing with GDI+ Euler Rotation

http://www.vcskicks.com/3d-graphics-improved.html

C# 3D-Drawing Cube with Shading

http://www.vcskicks.com/3d_gdiplus_drawing.html

OTHER TIPS

Study assignment? This can be done with some simple 3D maths. You just need to understand the basics of matrix algebra, 3D transformations, and 3D->2D view transformation. The DirectX tutorial covers this, but you can google for it and you'll get plenty of other tutorials.

Added: Just to clarify - I'm not suggesting to use DirectX or anything. You can do this with standard System.Drawing tools. You just need to understand the math, and that's explained in the DirectX tutorials.

You might try using WPF and the 3D Tools source code released by the WPF team.

3DTools

Assuming you are using WPF for your GUI:

  1. Make an animated PNG of the cube using a graphics program.
  2. Use the APNG WPF Control to insert the image into your GUI.

This will yield a small assembly size and transparent background if needed.

You need a way to represent 3d points. There is no ready struct for that in .NET unless you use directx or WPF.

Then with a standard euler rotation matrix applied to the points you get the transformed points. If you only do rotations you can get away with 3x3 matrix, but if you want translation you better use 4x4 matrices and homogenous points.

After this you need a way to project those 3d points to the 2d canvas. Depending whether you are using perspective or orthographic projection the projection matrix will look a bit different.

Look into WPF in general, it will help you do this with a few measly lines of code. You can also host a WPF window in Forms.

http://msdn.microsoft.com/en-us/library/aa970268.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top