This project is read-only.


The Shapes Library pursues four main goals:
  • highly object oriented class design
  • much functionality
  • ease of use
  • high performance

Object Oriented

The logical parts of the library are as much splitted up as propably possible / reasonable.
The most important decision for the design of the library was to keep all the shapes abstract. This means they just define their geometric form but don't know how they look like.
There is another class - the TextureGenerator - which can make a displayable Texture from a shape. To emphasise the outline of a shape, it is possible to pass a Brush to the TextureGenerator (this Brush is defined by one or more BrushMasks which can manipulate the appearance).
There is also a class for managing collision detection. I wanna quote a user of the library here: "(...) the collision detection I implemented most quickly so far." (translation from German)
To make collision detection more interesting, it is possible to transform the shapes (which means Rotate / Scale or Translate it).
The Transfomation2D is a very good example for the objectives of object oriented programming: It is very abstract so it is reusable for other purposes. For example to save the transformation of a Texture.
In the TestGame project (which comes along with the Library) is a class called Sprite which connects a Texture2D with a Transformation2D. If you need something like this, feel free to use and modify that class.

Much Functionality

The Shapes (and of course the Drawings which is the base class of Shape) does not just save the definition of the geometry as claimed above... It also provides access to some special information.
You can retrieve:
  • the closest point on the outline to a given position (Drawing, GetNearestPointOnEdge())
  • the distance between a given point to the closest point on the outline (Drawing, GetDistanceToEdge())
the outline can be imagined like an infinity amount of connected points.
  • retrieve any of those points by passing a "path-percentage" value (Drawing, GetPositionFromEdgePath())
  • or retrieve that value by passing a point on the outline (Drawing, GetEdgePathValueFromPoint())
  • or just check wether a point is inside a shape or not (Shape, IsPointInside())
All functionality of a Drawing is also available with a Shape. It is possible to work with world-space coordinates or with the local-space coordinates of the transformed geometry. Of course you can transform a point from or to local space within the Transformation2D class.
There is some pre-defined geometry inside GeometryTemplates. It allows to easily create some complex shapes like arrows or stars.
If the supported shapes are not enough for you, you can combine them with the ShapeComposition in different ways to create custom and complex shapes.
One of the most useful kinds of shapes is the SpriteShapes. It allows you to create a shape from a sprite. You can choose between a specified color or a alpha threshold for the generation of the shape.
The CollisionDetector2D can manage collision detections for as many shapes and drawings as you wish. But if you want to manage it yourself, you can use some static methods of that class to check wether a shape or drawing is intersecting with another shape or drawing.
The TextureGenerator can visualize a Shape filled or the outline of it. It also can combine both by using the method CombineTwoTexturesByPixel(). You may use this method to combine some textures together. For example: if you have a character in your game which can change it's cloth, you can combine the naked character together with the cloth to get a single Texture.
The Brush class is very flexible as well. By adding some masks to it you have great control of the visual appearance of the Brush.

(further information are coming soon)

Last edited Oct 18, 2009 at 2:11 PM by JeRET, version 3


Hidra1 Feb 17, 2012 at 4:33 PM 
It would be very helpful if you give some starting tips / advices ( "(further information are coming soon)" Oct 18 2009 )