Box, Sphere, Cylinder, and Cone in C#

Here's some free source code to generate primitive shapes in C#. You can set the tesselation, and the radius, height, etc. It uses the renderer independant XnaGeometry as a vector library, but you can port it to use whatever vector library you want easily enough. XnaGeometry is included in the zip. Textures are supported. The code produces a list of tuples, each with a position normal and texture coordinate, these are the vertices. You should be able to easily convert them to whatever format you want. A list of indexes is produced as well, these point to the vertices, and describe a list of triangles. Suppose that the first three indexes, are 1,2, and 4. Then you would take vertice number 1,2, and 4 from the list of vertices and form a triangle with those three vertices. Then get the next three indexes and repeat the process to form another triangle. This is a standard approach in DirectX, MonoGame, etc. Note that this is just code that will generate the indexes and vertices, it is not a complete application. If you need code to load textures, render the primitives on screen, etc., try this.

Here's the code: primitives.zip

Here's a pic of some sample shapes output with the code.


Custom Programming




Ad.




Home    Free Stuff    Politics    Contact
Copyright 2013 TechnologicalUtopia.com