Rotating a 3D Cube and Sphere with GDI+

This program rotates a 3d cube and a sphere with GDI+.

Description: This program rotates a 3d cube and a sphere with GDI+.

To compile: Run the file "Compile.Bat" from the command line.

About the source code:

This program has 6 classes:

  • Matrix: in order to rotate anything, one of the most simple ways, is by using matrices. this class implements the matrices. these are good not only for rotating stuff but also for any linear algebrics stuff anyone may need. (determinants?)

  • Vector: the Vector is the 3d point used to draw the models. some of its important methods are addition, substraction and transformation. this one too, might be used for any linear algebrics (and not so linear also).

  • Polygon: this is the most basic 3d object. it can be drawn to the screen and can be rotated, by multiplying it with the appropriate matrice (done by the Mateix class)

  • Shape3D: now, this is a complex model. it is made out of many polygons and has two important methods: rotate and draw.
  • RotateMatrix: this class is derived from Matrix, and is kind of a special Matrice - when multiplied with a Vector, it rotates the vector in any degree we wish to.

  • Main: well, this is the form used for the application. it sets-up some gui, the clock which calls the Shpe3D Draw method every 10mili-Seconds.

Note that the zip also contains a compiled version, and some other files, used by SharpDevelop, a free (GPL) development environment for C#; its really good!  

Editor's note: You can also compile the same code in in Visual Studio .NET

To compile same code in VS.NET, create a Windows application and unzip the code and copy all files in your project directory. Now use Add Existing Item project menu item to add classes to the Windows application as you can see in Figure 1.

Figure 1.

Add all files to the project. See Figure 2.

Figure 2.

Now replace contents of Form1.cs with the contents of Main.cs. Compile and run the project.


Thanks Ariel. Nice application ;).