Showing posts with label Delphi. Show all posts
Showing posts with label Delphi. Show all posts

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:

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);
var
    PArrow: array [1 .. points] of TPoint;
    i: integer;
    theta: Double;
    x, y : double;
    beforeBrushColor, beforePenColor: TColor;
    beforePenWidth: integer;
begin
    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
    begin
        theta := Pi * ((i-1)/(points/2));
        x := xcenter + (Radius* Cos(theta));
        y := ycenter + (Radius* Sin(theta));
        PArrow[i] := Point(Round(x), Round(y));
    end;
    FCanvas.Polygon(PArrow);

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

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!.

Monday, 25 April 2011

NIS 2010 SONAR raised when running executables compiled with Delphi 2010

Going on with my previous post (Signing your Delphi applications with Microsoft Signtool) in this post I'll explain different solutions to avoid false positives by the Antivirus. I've recently got an alert from my NIS 2010 (Norton Internet Security) SONAR indicating that my application contains a HackTool and it has been processed and eliminated by SONAR (I'm trying to run one of my applications and now is a high-risk program and should be deleted every time I try to run it):

Even though it socks, you need to go through the NIS and configure it using the instructions from here.


1.   Executable files created by compilers etc on development machines are deleted

We have identified the issue and are making incremental changes to fix the problem. Please ensure that you have the latest NIS patch installed 17.1.0.19 as that should minimize the occurrence of the issue.

In addition to this, developers should exclude dev directories from security scans using the following steps:

  • On the main UI panel, under Computer click Settings. This will bring up the Settings dialog box.
  • Under Scan Exclusions click Configure. This will display the Scan Exclusions dialogue box.
  • Under the lower-half of the screen under Auto-Protect Exclusions click the Add button. This will bring up a dialogue to add a new item.
  • Add the folder you want to exclude from SONAR.



If you are certain that SONAR has incorrectly quarantined a file, you may restore this file to its original location by selecting the appropriate entry in the Quarantine Log and clicking Options. This will display the Security Risk Details dialog:

Click Restore this file. This will show the Quarantine Restore dialog. Ensure that the Exclude this risk from future scans is checked. The file will be restored to its original location and will no longer be detected by SONAR. According to Symantec this is unfortunately a known problem and they are working on a fix for it. From now on the best thing you can do is to set the scan exclusions in the settings, with this, those folders will not be scanned and the files will not be false-detected.


It's important to update the Antivirus to the latest version because most of these issues are already solved and there is no need on doing this.

Other important thing is to bear in mind the digital signature for our applications. If our executables are digitally signed you won't have the false positive problem with the AV because the application is trusted. Please, go on with the related links section to dig more with this issue and do not hesitate to comment if you have any doubt.

NIS version: 17.8.0.5

Related links:

Saturday, 23 April 2011

Signing your Delphi applications with Microsoft Signtool

Today I'm coming with an interesting post about signing your Delphi applications (win32) with Microsoft Signtool. The SignTool tool is a command-line tool that digitally signs files, verifies signatures in files, or time stamps files. The tool is installed in the \Bin folder of the Microsoft Windows Software Development Kit (SDK) installation path. SignTool is available as part of the Windows SDK, which you can download from here.
With few steps I'll show you how to create PKCS#12 certificate with OpenSSL for windows and how to import this certificate into your applications. In most occasions we should use the certificate as a means of identifying the author of an application and establishing trust relationships between applications.

Creating a PKCS#12 certificate with OpenSSL:
Once I have installed OpenSSL on your machine, we need to run the following commands to create the certificate. To create a PKCS#12 certificate, you’ll need a private key and a certificate, so first of all, let´s create the certificate and the private key:

# create a file containing key and self-signed certificate
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem


Now we are ready to generate the .pfx file (.PFX file (Personal Information Exchange format) is the file containing both a public (.cer file) and a private (.pvk file) keys) with myCert.pem:

# export mycert.pem as PKCS#12 file, mycert.pfx
openssl pkcs12 -export -out mycert.pfx -in mycert.pem -name "My Certificate"


You'll be asked to enter a password for your certificate.

Importing the certificate with Signtool:
Now copy the mycert.pfx file into the folder where your executable is placed and run the following command with Signtool:

Signtool sign /f mycert.pfx /p password thundaxballsdemo.exe


Now if we check our application it will be digitally signed with our certificate:

Then you can install this certificate into the "windows trusted certification store".

Related links:

Friday, 22 April 2011

Tuesday, 5 April 2011

Assertion failure ..\win32src\thread32.cpp at line 434

For the ones who are using Delphi 2009 under Windows 7 (64-bits), this error will show up during the debugging of your applications. This just happened to me today and I found a really interesting solution on Embarcadero's Forums. This just happened to me few days ago and I thought it was normal because of the OS, but then I realised that something was going wrong and every minute I got that annoying message leaving my applications non-functional and with the problem of restarting the Delphi IDE again.The solution provided is quite easy and I can guarantee you that it works!.
First of all, you need an hexadecimal editor. I used mh-nexus, an open source version that you can get from here. Then the steps for solving the issue are the following ones:

1. Close Delphi
2. Locate bordbk120N.dll (C:\Program Files (x86)\CodeGear\RAD Studio\6.0\bin)
3. Make a backup of the library (just in case).
4. Open bordbk120N.dll with mh-nexus and locate the hex values: “01 00 48 74 47 80 3D

5. Replace “74” with  “EB”and save the changes.

6. Restart Delphi and the error message should be gone.


Related links:

Saturday, 5 February 2011

Building my own Delphi Physics Engine part V

Today I felt inspired (after parts I, II, III and IV) and I tried to do a cloth simulation in the Thundax Physics Engine. There are a lot of things to do, but at least I can start simulating different components very fast without too much implementation. I saw one amazing implementation of the "processing cloth" in JRC313.com. Even though the applet is written in JavaScript, the performance is quite impressive and it's a nice work.

but, How it works?
"Every line in the cloth simulation is technically called a constraint and every point is a point mass (an object with no dimension, just location and mass). All the constraints do is control the distance between each point mass. If two points move too far apart, it will pull them closer. If two points are too close together, it will push them apart. The cloth is really then just a collection of constraints and point masses in a never ending struggle."

using Relaxation in simple linear systems:
In the case of this cloth simulation all I needed to do was try satisfying the constraints as fast as I can. For things like simple rope simulations it may be necessary to satisfy several times (maybe 4 or 5). The more times you satisfy, the more rigid the constraint becomes. This process is known as relaxation and is amazing!. The displacement will then be of the form y(t) = Ae − t / Tcos(μt − δ). The constant T is called the relaxation time of the system and the constant μ is the quasi-frequency. (Wikipedia).

In the following videos you'll be able to check the performance of the simulated cloth. I took advantage of my previous bridge (spring + particles) and I've concatenated a series of bridges to set up a virtual cloth. Now the movement is quite astonishing:


In the second video I'm showing one of the new features for the next release: "the cutting tool". I still need to think about it, but for simple objects it could be simple to cut an object and see its reaction, like in the next video:


You can download the last version of the executable file here: thundax Balls demo v1.52. And maybe in a near future you'll be able to see something similar to the Puzzler for iPhone.


Other interesting video about physics and games is Crayon Physics from Petri Purho:

I hope you enjoy the videos!

Related Links:

Friday, 4 February 2011

Building my own Delphi Physics Engine part IV

I'm still working on my solution, but I can advance you a preview of the smoothness of the application. I have improved the bridge particle and its interaction with external events. I'm working on a TStyle class that will enhance the GDIRender allowing the different particles to have a custom style on the screen and refactor all the classes to improve the scalability and interoperability of the Engine. If you are interested on testing the application, you can get the latest version of it from here: Thundax Ball Demo v1.1. In this version you will notice the improved interaction with the mouse and the circle particles. I have to work out a solution for the other particles, but I'm still designing the whole product and I need to test some of the features that I want to release in the next version. Once the version is ready, I will upload it on Sourceforge just in case you feel the urge to play with it!.
Here you can see the new performance:


Wednesday, 2 February 2011

Building my own Delphi Physics Engine part III

Now I'm working on the interactive part (Controller). Since now I only have developed the model and the view section of the MVC pattern and I'm implementing and testing the controller part. The main problem is that the Engine is quite simple to implement and use until the visual control appears. Now I have to take into account all the events that come from the outside (mouse, keyboard) and add subscribers to the object particles. With the design that I've implemented it is easy to make extensible the model and the view section because the Engine follows the "low cohesion high coupling" principle. My sister challenged me by trying to do something similar to the ruicode project, where its ofxRuiPhysics2d project (Simple 2d physics addon for OF (OpenFrameworks) using the Verlet integrator where it includes particles, collisions and springs) is quite astonishing. Here you can see one of its videos:


And here is my project: Thundax balls demo.exe, a Delphi win32 application that will start a demo with balls, springs and collisions. In the following videos you'll see different performances of my tests. In the first video I'm trying to simulate the environment with all the forces playing at the same time, and in the second video you can see myself using the mouse interacting with the balls and the springs.


I hope you enjoy the videos!.

Related links:

Related frameworks:
It's amazing the large amount of physics Engine that are available on the net. I just google the words "Physics Engine" and here are the results:
Javascript, C, and Java Frameworks:
ActionScript Frameworks:

3D and Realistic Frameworks:

Sunday, 16 January 2011

Depth of field calculator

This year I'm going to start talking about one of my passions: Photography. And for starting, here you can get one of my last applications: Thundax Depth of Field Calculator. With this Delphi win32 front-end application you'll be able to calculate the Depth of field (the portion of a scene that appears sharp in the image) measurements needed in photography. You need to select the CoC (Circles of Confusion) in microns from the sidebar (there is a little sheet with the normal values for different types of cameras), the focal length from the choices, and the lens aperture from the choices. Enter the subject distance in meters from the lens and the calculated values are returned for various other designations of subject distance as well as the near limit of acuity, far limit of acuity, and the total depth of field, all in both meters and feet, accurate and rounded. The calculations are based on the very well known on-line DoF javascript calculator.

In my application you can see the difference of using different apertures (F numbers) while taking the photo. In the example you can see that the distance is the same, but the DoF grows. The aperture is getting smaller and smaller, and the shutter speed is getting longer to compensate. The distance and aperture both play a big role in depth of field. You you want to play with it, for example: for a short depth of field (blurry background) get close and use a lower f-stop. And for a long depth of field (clear all the way through) get farther away and use a higher f-stop. The following example will help you to understand better the DoF:
Picture from: Photo Basics.
The different calculations are the following ones:
procedure TDoF.Calc(Sender: TObject);
var
    focal: integer;
    aperture: double;
    CoC: double;
    Hyperfocal: double;
    distance: double;
    NearF, FarF, doftotal: double;
begin
    distance := StrToFloat(Edit2.Text) * 1000 * 0.3048;
    focal := getFocal(ComboBox1.Text);
    aperture := getAperture(ComboBox2.Text);
    CoC := StrToFloat(Edit1.Text);
    photovalues.Values['Subject distance (inches)'] := FloatToStr(StrToFloat(Edit2.Text) * 12) + ' in';
    photovalues.Values['Subject distance (meters)'] := FloatToStr(StrToFloat(Edit2.Text) * 0.3048) + ' m';
    photovalues.Values['Subject distance (millimeters)'] := FloatToStr(StrToFloat(Edit2.Text) * 0.3048 * 1000) + ' mm';
    Hyperfocal := 0;
    if (aperture * CoC) > 0 then
        Hyperfocal := Sqr(focal) / (aperture * CoC);
    photovalues.Values['Hyperfocal distance for this lens/aperture combination (meters)'] := FloatToStr(Hyperfocal) + ' m';
    photovalues.Values['Hyperfocal rounded distance for this lens/aperture combination (meters)'] := FormatFloat(f, Hyperfocal) + ' m';
    photovalues.Values['Hyperfocal distance for this lens/aperture combination (ft)'] := FloatToStr(Hyperfocal * feet) + ' ft';
    photovalues.Values['Hyperfocal rounded distance for this lens/aperture combination (ft)'] := FormatFloat(f, Round(Hyperfocal * feet)) + ' ft';
    NearF := ((Hyperfocal * 1000 * distance) / ((Hyperfocal * 1000) + (distance - focal))) / 1000;
    photovalues.Values['Near limit of acceptable sharpness (meters)'] := FloatToStr(NearF) + ' m';
    photovalues.Values['Rounded near limit of acceptable sharpness (meters)'] := FormatFloat(f, Round(NearF)) + ' m';
    photovalues.Values['Near limit of acceptable sharpness (ft)'] := FloatToStr(NearF * feet) + ' ft';
    photovalues.Values['Rounded near limit of acceptable sharpness (ft)'] := FormatFloat(f, Round(NearF * feet)) + ' ft';
    FarF := ((Hyperfocal * 1000 * distance) / ((Hyperfocal * 1000) - (distance - focal)) / 1000);
    if FarF < 0 then
    begin
        photovalues.Values['Far limit of acceptable sharpness (meters)'] := 'Infinity';
        photovalues.Values['Rounded far limit of acceptable sharpness (meters)'] := 'Infinity';
        photovalues.Values['Far limit of acceptable sharpness (ft)'] := 'Infinity';
        photovalues.Values['Rounded far limit of acceptable sharpness (ft)'] := 'Infinity';
    end
    else
    begin
        photovalues.Values['Far limit of acceptable sharpness (meters)'] := FloatToStr(FarF) + ' m';
        photovalues.Values['Rounded far limit of acceptable sharpness (meters)'] := FormatFloat(f, Round(FarF)) + ' m';
        photovalues.Values['Far limit of acceptable sharpness (ft)'] := FloatToStr(FarF * feet) + ' ft';
        photovalues.Values['Rounded far limit of acceptable sharpness (ft)'] := FormatFloat(f, Round(FarF * feet)) + ' ft';
    end;
    doftotal := Round(FarF - NearF);
    if doftotal < 0 then
    begin
        photovalues.Values['Total depth of field (meters)'] := 'Infinity';
        photovalues.Values['Total rounded depth of field (meters)'] := 'Infinity';
        photovalues.Values['Total depth of field (ft)'] := 'Infinity';
        photovalues.Values['Total rounded depth of field (ft)'] := 'Infinity';
    end
    else if (doftotal >= 0) and (doftotal < 0.001) then
    begin
        photovalues.Values['Total depth of field (meters)'] := '> 1 mm';
        photovalues.Values['Total rounded depth of field (meters)'] := '> 1 mm';
        photovalues.Values['Total depth of field (ft)'] := '> 0.0393 in';
        photovalues.Values['Total rounded depth of field (ft)'] := '> 0.0393 in';
    end
    else
    begin
        photovalues.Values['Total depth of field (meters)'] := FloatToStr(doftotal) + ' m';
        photovalues.Values['Total rounded depth of field (meters)'] := FormatFloat(f, Round(doftotal)) + ' m';
        photovalues.Values['Total depth of field (ft)'] := FloatToStr(doftotal * feet) + ' ft';
        photovalues.Values['Total rounded depth of field (ft)'] := FormatFloat(f, Round(doftotal * feet)) + ' ft';
    end;
end;

Tell me if it's useful to you and if you need any other calculations.
PS: The program is free for non-commercial use.


Related links:

Tuesday, 11 January 2011

Comparing Methods using Generics

This is my first post of 2011. I will hopefully be doing more posts this year. These will include my work, tutorials, snippets of code and what I find on the web. Hopefully this year will be a good one, with new projects, more ideas and more motivation.
In Delphi 2009 appeared the Generics (containers-of-type-T) in the Delphi programming language. I have been playing with them in Delphi 2010 and here you can see my results. The new library is quite easy to use and with the help of this libraries we can enhance our code. We can also use the Anonymous methods and call the function "inline" in the sort method. 
Using the Generics.defaults and Generics.Collections we can build new container or comparer classes and pass to them the type-T (Integer, String, TObject, etc.).
  • Default comparer:
This example will create an Integer comparer and it will use a TIntegerList to sort its values:

unit uComparing;

interface

uses
    generics.defaults, generics.collections;

type
    TIntegerComparer = class(TComparer<Integer>);
    TIntegerList = class(TList<Integer>);

implementation

end. 
usage:
procedure TForm1.Button1Click(Sender: TObject);
var
    integerList : TIntegerList;
    i: Integer;
begin
    integerList := TIntegerList.Create(TIntegerComparer.default);
    for i := 0 to memo1.Lines.count - 1 do
        integerList.Add(StrToInt(Memo1.Lines[i]));
    integerList.Sort;
    for i := 0 to integerList.count - 1 do
        Memo2.Lines.Add(IntToStr(integerList[i]));
end;
  • Custom Comparer:
The custom comparer will use a comparer method to sort the values in a descendant way.

unit uComparing;

interface

uses
    generics.defaults, generics.collections;

type
    TIntegerComparer = class(TComparer<Integer>)
    public
        function Compare(const Left, Right : Integer) : Integer; override;
    end;

    TIntegerList = class(TList<Integer>);


implementation

{ TIntegerComparer }

function TIntegerComparer.Compare(const Left, Right: Integer): Integer;
begin
    result := Right - Left;
end;

end. 
usage:
procedure TForm1.Button1Click(Sender: TObject);
var
    integerList : TIntegerList;
    i: Integer;
begin
    integerList := TIntegerList.Create(TIntegerComparer.create);
    for i := 0 to memo1.Lines.count - 1 do
        integerList.Add(StrToInt(Memo1.Lines[i]));
    integerList.Sort;
    for i := 0 to integerList.count - 1 do
        Memo2.Lines.Add(IntToStr(integerList[i]));
end;
  • Anonymous Comparer:
The Anonymous comparer is created inside the sort method:

procedure TForm1.Button1Click(Sender: TObject);
var
    integerList : TIntegerList;
    i: Integer;
begin
    integerList := TIntegerList.Create();
    for i := 0 to memo1.Lines.count - 1 do
        integerList.Add(StrToInt(Memo1.Lines[i]));
    integerList.Sort(TIntegerComparer.Construct(
       function (const Left , Right : integer): integer
       begin
         result := Left - Right;
       end
       ));
    for i := 0 to integerList.count - 1 do
        Memo2.Lines.Add(IntToStr(integerList[i]));
end;

Monday, 20 December 2010

Piecewise function plotter

I've been working lately on a front-end application to draw and generate the piecewise-defined functions that are mainly used for the input fuzzy sets. This application is developed with Delphi and for generating the outputs it uses the GNUplot and the LateX equation editor. The application is called Thundax Piecewise v1.1 and you can download it from here. This win32 installation package contains the required files to work with the GNUplot. This software is for academical purposes and with it you can define the piecewise-defined functions without wasting your time trying to draw the graphs and the equations.

Using the application:
If you want to get the equations from the previous image, you only need to add the points (x,y) (defined as 4 points per graph), add the equation description, the range and the number of samples:
The description of the parameters:
  • Points per graph: default value = 4. Number of points that are used to define the function:
  • Range-x: Default value [0:30]. Range to be displayed at x-axis.

  • Range-y: Default value [-0.1:1.1]. Range to be displayed at y-axis.
  • Samples: default value = 1. Number of samples for the x-axis. In a range from 1 to 10 with a sample of 1 it will show all the numbers.

Once everything is done, you just need to let the application generate the graph output automatically using GNUPlot (If the function is not plotted, check the script and execute it into the GNUplot command prompt):
And then copy-and paste the output script to Latex editor and get the piecewise function for each one:
The only thing the applications does, is to parse the input data and transform it as scripts for the GNUplot and Latex. The conversion is pretty simple and the scripts examples are like these:
GNUPlot Script example:
cold(x)=(x<=40? 0: cold2(x))
cold2(x)=(x<=40 & x > 40? 1: cold3(x))
cold3(x)=(x<=50 & x > 40? -0.1*x + 5: cold4(x))
cold4(x)=(x<=50 & x > 50? 1: cold5(x))
cold5(x)=(x>50? 0:0)
cool(x)=(x<=40? 0: cool2(x))
cool2(x)=(x<=55 & x > 40? 0.066667*x  -2.666667: cool3(x))
cool3(x)=(x<=55 & x > 55? 1: cool4(x))
cool4(x)=(x<=65 & x > 55? -0.1*x + 6.5: cool5(x))
cool5(x)=(x>65? 0:0)
justright(x)=(x<=60? 0: justright2(x))
justright2(x)=(x<=65 & x > 60? 0.2*x  -12: justright3(x))
justright3(x)=(x<=65 & x > 65? 1: justright4(x))
justright4(x)=(x<=70 & x > 65? -0.2*x + 14: justright5(x))
justright5(x)=(x>70? 0:0)
warm(x)=(x<=65? 0: warm2(x))
warm2(x)=(x<=75 & x > 65? 0.1*x  -6.5: warm3(x))
warm3(x)=(x<=75 & x > 75? 1: warm4(x))
warm4(x)=(x<=85 & x > 75? -0.1*x + 8.5: warm5(x))
warm5(x)=(x>85? 0:0)
hot(x)=(x<=80? 0: hot2(x))
hot2(x)=(x<=90 & x > 80? 0.1*x  -8: hot3(x))
hot3(x)=(x<=90 & x > 90? 1: hot4(x))
hot4(x)=(x<=90 & x > 90? 1: hot5(x))
hot5(x)=(x>90? 0:0)
set yrange[-0.1:1.1]
set xtics 0, 15
set grid
set samples 1001
bind Close "exit gnuplot"
plot [40:90] cold(x) ,cool(x) ,justright(x) ,warm(x) ,hot(x) 

Notice that we use the function bind Close "exit gnuplot" to bind the exit of the application once the user has closed the plotted graph. (And I think this function is available since version 4.4).
Latex Script example:
cold(x)=\begin{Bmatrix}{0}&\mbox{if}& x\leq40\\{1}&\mbox{if}& 40< x \leq40\\{-0.1*x + 5}&\mbox{if}& 40< x \leq50\\{1}&\mbox{if}& 50< x \leq50\\{0}&\mbox{if}& x > 50\end{matrix}\\
cool(x)=\begin{Bmatrix}{0}&\mbox{if}& x\leq40\\{0.066667*x  -2.666667}&\mbox{if}& 40< x \leq55\\{1}&\mbox{if}& 55< x \leq55\\{-0.1*x + 6.5}&\mbox{if}& 55< x \leq65\\{0}&\mbox{if}& x > 65\end{matrix}\\
justright(x)=\begin{Bmatrix}{0}&\mbox{if}& x\leq60\\{0.2*x  -12}&\mbox{if}& 60< x \leq65\\{1}&\mbox{if}& 65< x \leq65\\{-0.2*x + 14}&\mbox{if}& 65< x \leq70\\{0}&\mbox{if}& x > 70\end{matrix}\\
warm(x)=\begin{Bmatrix}{0}&\mbox{if}& x\leq65\\{0.1*x  -6.5}&\mbox{if}& 65< x \leq75\\{1}&\mbox{if}& 75< x \leq75\\{-0.1*x + 8.5}&\mbox{if}& 75< x \leq85\\{0}&\mbox{if}& x > 85\end{matrix}\\
hot(x)=\begin{Bmatrix}{0}&\mbox{if}& x\leq80\\{0.1*x  -8}&\mbox{if}& 80< x \leq90\\{1}&\mbox{if}& 90< x \leq90\\{1}&\mbox{if}& 90< x \leq90\\{0}&\mbox{if}& x > 90\end{matrix}\\

I'm still working on this project and for the next milestone I'll try to add the Weighted average method to calc the area of the graph and the ability to save the data of the project.

Related links:

Friday, 10 December 2010

Building my own Delphi Physics Engine part II

Going on with my DPE (Delphi Physics Engine) I've improved my old version (Building my own Delphi Physics Engine Part I) of the Jansen Mechanism by creating the rest of the legs displaced 120º each one. I've been fixing the damping level of the framework just to be sure that the movements are as realistic as possible. In this version, the movement is quite realistic and we can trace the movement of the leg by plotting the kinetic analysis:

A physics engine is computer software that provides an approximate simulation of certain simple physical systems, such as rigid body dynamics (including collision detection), soft body dynamics, and fluid dynamics, of use in the domains of computer graphics, video games and film. Their main uses are in video games (typically as middleware), in which case the simulations are in real-time. The term is sometimes used more generally to describe any software system for simulating physical phenomena, such as high-performance scientific simulation. Wikipedia.

Here you can see the CGI result with the hanging version of the Jansen mechanism with one leg and with three legs:

And the final version with the development of the Jansen machine. In this version (Thundax Test Forces v2.exe) if you press 'p' the machine will start walking and if you want to change direction, you only need to press the 'z'.

What's next?. Now I'll try to reproduce different physics systems and show how it goes. The Easy Java Simulations tool, offers a wide range of examples that I would like to try.
Enjoy the learning!.

Related Links:

Friday, 3 December 2010

Building my own Delphi Physics Engine part I

 These days I've been working on my own Delphi Physics Engine based on the very well known APE (ActionScript Physics Engine) with some improvements that will help developers to build models very fast. In this beta version I've done the following improvements:
  • Enhance user performance.
  • Drastic reduction of Memory leaks.
  • Improve the interoperability between objects.
  • Improve maths algorithms to collision detection.
  • Use the VLO GDI Render to perform the drawing of the shapes.
In this first insight into the Engine, I'm going to show you a model of the Jansen mechanism, a kinetic sculpture that can move with the help of several pairs of legs.


I've built my own model taking advantage of the physic engine and imagination!.
Here you can see my own model:
The movement is still not very well performed, but it's due to the measures of the different parts of the sculpture. As for the calculation points, I've used the next template:
You can download the demo project from here (Thundax Test Forces). To play with the application, you only need to press 'z' to start the kinetic sculpture, and as for the objects below the sculpture, press 'd' and you'll force a collision between two objects.

The next days I'll be improving the model (you can see the kinetic analysis that is plotted below the sculpture) and adding the extra foot to perform a fully movement.

Enjoy the learning!.

Related links:

Tuesday, 30 November 2010

DelphiDoom for Delphi fans

I've recently found Delphi Doom, an adaptation from the original UNIX Doom C source code to Delphi. The project was finished in 2005 but the latest deploy was released on 3 March 2008 (Version: 1.0.2 build 383). I've been tinkering with it and it's been great!. It cast me back when I was young, trying to pass all the levels by killing some hideous and very nasty monsters. This Application is a WIN32 port of the famous Doom game created by ID Software. The main difference of DelphiDoom is that is written in the Pascal programming language. The source code has been translated from C to Pascal. In addition many new features have been added to to expand the old engine features and take advantage of capabilities of modern computers. Remember that you need the IWAD file just for being able to pay. The IWAD file is the file which contains all of the game data for a complete game.

Enjoy the game!.

Thursday, 18 November 2010

2d Physics with Delphi

I'm modelling a series of objects with some physics and mathematics and I found interesting to talk about the library I am using: Delphi APE. This fantastic library available for Delphi  (Windows) and Lazarus (Linux) allows very simple task as powerful as gravity, collision processes, grouping behaviour and general process. Great the job done by Alex cove and others like Vincent and Jeremy who helped him to make the conversion to Delphi.
This great library which I'm testing with Delphi 2010 is very easy to use and it shows a very interesting example combining different elements and letting them play. You can download the library from here, and test the different modelled items. The results are very well done and with simple steps we can achieve things like this:

Another interesting library is the one done by Algoryx called Phun.:


Related articles:

Wednesday, 3 November 2010

Presentation of the new Rad Studio XE and the new Visual Studio 2010 in Barcelona

On November 24 will be held this seminar in Barcelona, which conveniently will show us the new features of the new RAD Studio XE, Delphi XE, C++ Builder XE, Delphi Prism XE and RadPHP XE. I'll take this opportunity to learn in a practical way the latest additions, see examples of operation, contact other users, chat with the team and meet interesting Danysoft promotions. I'm also attending the Visual Studio 2010 presentation which will show us practical themes that are awakening the community of developers. The new ASP.NET , the MVC Framework and the new features included in the WCF (Windows Communication Foundation) will be the discussed topics.

I'll see you there!.

Related topics:

Thursday, 21 October 2010

Delphi Unicode Migration

One of my colleagues found this interesting document about migrating Delphi versions. I'm sure is very useful and this will help us to release a stable version before we move on to Delphi XE.

Check out this SlideShare Presentation:
Other interesting document: Reasons to migrate from Delphi 7 to Delphi 2009:

Monday, 18 October 2010

Keeping track of a list by comparing it.

Due to my last application developed, I had to compare a list by scanning it and then present the results by including if any item was added or removed. For accomplish this task I've developed a little unit that is able to compare the list and show the results in a TMemo.

//@Author Jordi Coll
//@2010

unit uListCompare;

interface

uses
    Classes, SysUtils;

type
    TListCompare = class(TObject)
        private
            FList2: TStringList;
            FList1: TStringList;
            procedure SetList1(const Value: TStringList);
            procedure SetList2(const Value: TStringList);
        public
            property List1: TStringList read FList1 write SetList1;
            property List2: TStringList read FList2 write SetList2;
            constructor Create();
            destructor Destroy(); override;
            procedure DumpList();
            function ExistInList1(s: string): boolean;
            function ExistInList2(s: string): boolean;
    end;

implementation

{ TListCompare }

constructor TListCompare.Create;
begin
    FList1 := TStringList.Create;
    FList2 := TStringList.Create;
end;

destructor TListCompare.Destroy;
begin
    FreeAndNil(FList1);
    FreeAndNil(FList2);
    inherited;
end;

procedure TListCompare.DumpList;
var
    i: Integer;
begin
    if List2.Count = 0 then
    begin
        for i := 0 to List1.Count - 1 do
        begin
            List2.Add(List1[i]);
           log('New Item ->' + List1[i]);
        end;
    end
    else
    begin
        for i := 0 to List1.Count - 1 do
        begin
            if not ExistInList2(List1[i]) then
                log('New Item ->' + List1[i]);
        end;
        for i := 0 to List2.Count - 1 do
        begin
            if not ExistInList1(List2[i]) then
                log('Item doesn''t exist ->' + List2[i]);
        end;
        List2.Clear;
        for i := 0 to List1.Count - 1 do
            List2.Add(List1[i]);
    end;
end;

function TListCompare.ExistInList1(s: string): boolean;
var
    found: boolean;
    i: Integer;
begin
    i := 0;
    found := false;
    while (i < FList1.Count) and (not found) do
    begin
        found := FList1[i] = s;
        inc(i);
    end;
    result := found;
end;

function TListCompare.ExistInList2(s: string): boolean;
var
    found: boolean;
    i: Integer;
begin
    i := 0;
    foundt := false;
    while (i < FList2.Count) and (not found) do
    begin
        foundt := FList2[i] = s;
        inc(i);
    end;
    result := found;
end;

procedure TListCompare.SetList1(const Value: TStringList);
begin
    FList1 := Value;
end;

procedure TListCompare.SetList2(const Value: TStringList);
begin
    FList2 := Value;
end;

end.

The only thing you have to do is fill the List1 with your items and then execute the procedure DumpList that will dump the information from List1 to List2 and will compare it to show the differences. This object can be called in a thread or a controlled loop.