Sunday, 22 May 2011

Getting OS information with Delphi

If you would like to know all about your OS, even for the latest versions like Windows 7 64 bits or Windows Server 2008 R2 there is a fantastic library for this purpose.
DelphiDabbler has a system information unit called dd-sysinfo which contains a lot of helping methods to retrieve OS information. It Contains various static classes, constant and type definitions and global variables for use in providing information about the computer and the operating system.

Related Links:

Monday, 2 May 2011

Sunday, 1 May 2011

Polygonal approximation to circle

In order to be able to tackle the "cutting tool" for my TDPhysicsEngine, I need to work with polygon approximations instead of a full drawn circle using the Canvas.Ellipse Delphi function. To achieve this in the view layer is as easy as using Canvas.Polygon function to draw a polygon using a list of calculated points. To calculate the points, we need to divide the circle in discrete chunks and then let the function draw the lines between points. The main reason what I'm doing that is to be sure that I can cut up a polygon and then use the resulting pieces as new objects that will behave as independent objects:

The function below will help you to draw the polygon:

procedure GDIRenderer.CircleApproximation(xcenter, ycenter, Radius, Rotate: Double; style: TStyle);
    PArrow: array [1 .. points] of TPoint;
    i: integer;
    theta: Double;
    x, y : double;
    beforeBrushColor, beforePenColor: TColor;
    beforePenWidth: integer;
    beforeBrushColor := FCanvas.Brush.color;
    beforePenColor := FCanvas.Pen.color;
    beforePenWidth := FCanvas.Pen.Width;

    FCanvas.Pen.color := style.PenColor;
    FCanvas.Pen.Width := style.penWidth;
    FCanvas.Brush.color := style.BrushColor;

    for i := 1 to points do
        theta := Pi * ((i-1)/(points/2));
        x := xcenter + (Radius* Cos(theta));
        y := ycenter + (Radius* Sin(theta));
        PArrow[i] := Point(Round(x), Round(y));

    FCanvas.Brush.color := beforeBrushColor;
    FCanvas.Pen.color := beforePenColor;
    FCanvas.Pen.Width := beforePenWidth;

The big difficulty here is to model this behaviour in the model. I need to work more and think about it because for the moment it's adjusted as a sphere and it's not a good approximation.

Building my own Delphi Physics Engine part VI

I've been quite busy lately and in this article I've focused on the collision container. As you'll see in the following images and video, the spheres will be bouncing around, colliding with one another and with the surfaces inside the container that holds the entire motion of the system. With a simple tweak, the physics engine is able to display the unseen forces when objects are being "kicked". The key feature is that I want to show the resultant vectors that are involved in the collisions and the movement so the observant would have an idea of what's happening inside the model and which forces are being generated.

In the image below, you'll see the resultant force when the sphere has collided with the surface beneath. This leads me to the description of the Elastic collision equations

The following image shows all the vectors involved in the collision:

And the video showing the dynamics:

You can download from here the last version of the application: ThundaxBallsDemo v1.172 that is digitally signed (once the file is downloaded, right click, properties and go to the certificate and install it) to increase security. To add more spheres press 'a' and 's'. To cut one of the bridges press 'z' and play!.

I also have created the new logo for the Engine, let me know if you like it!.

In few months the library would be ready here:

Thanks for reading! and do not hesitate to leave any comment!.