Projects and Physics
(or how to keep a bag of fleas)

[the screenshots in this article show german labels - CaradNext is bilangual, you can switch between English and German any time]

Carad concentrates on the source code creation for Pascal dialects, mainly Free Pascal, Virtual Pascal and Delphi. There is the possibility to save three different kinds of projects, as there are:

1) Windows API projects

This project type is supported by Free Pascal, Virtual Pascal and Delphi (>2). A window with OpenGL support is created, Windows messages are used directly.

2) VCL / LCL projects

This project type is supported by Delphi > 5 (the earliest Delphi Version with text based forms) and by FreePascal if Lazarus is installed. A VCL/LCL window with a panel with OpenGL support is created and it can be changed directly in the form designer of Delphi or Lazarus. This project type can be managed much more intuitively as a Windows API project, since Lazarus and Delphi include powerful visual designers to manage complex forms.

3) BGP framework projects

This project type is supported by Delphi > 4 (since there are no .frm files) and by FreePascal if Lazarus is installed (you have to choose the correct compiler target from the menu - or in the options displayed below). All BaseGraph Pascal functions can be used, even those for 3D sound and physics. With this project type it's very easy to create impressive demos and games, since everything is here: input functions, sound support, collision detection and physics with ODE. Since the project is a native Delphi or Lazarus projects, it's more expandable than BaseGraph Pascal code, where you are more or less limited to the functions provided.

You see an overview of the project options in Carad, incompatibilites are disabled automatically:

  • you can use the official dglOpenGL unit instead of the (default) bgOpenGL - however, dglOpenGL needs a Delphi Version >= 4 (or FreePascal) and is not supported by Virtual Pascal
  • VCL projects will only work with Delphi > 5
  • LCL projects will only work with Lazarus
  • fxPascal shadercode will only work with Delphi > 5, the ARB assembler code, which is generated, if fxPascal is not checked, will work everywhere however.
  • Physics support with ODE relies on the BGP framework - ODE is linked statically with BeRos DLL loader into the project, no external DLL is needed

With this thoughts in mind, we'd like to create a small program - it shall be a sphere rolling around in a half pipe - of course you can create more impressive demos easily by importing 3DS (or other) models - in one of the next versions you will even be able to create ODE joints interactively, and you will be able to transform ODE primitives interactively (which has to be done by setting values in parameter windows by now)

We can create the half pipe easily with the following parameters:

This should look something like that

We put a sphere above the half pipe like that

Now the objects need useful physics properties - Carad tries (as much as possible) to provide objects with default properties - the sphere will be ok (you can change its mass if you want), since boxes and spheres are provided with the corresponding ODE geoms. The halfpipe is a form which isn't recognized by the "default Geom provider" - such objects are represented with spheres at the time being.

In this case we want the half pipe to be a static Geom represented with a TriMesh, since this is the only possibility to include any, even concave, object into ODE physics. Therefore well mark the half pipe (by clicking on it) and attach a TriMesh to it by clicking on the corresponding check box (this is no ODE TriMesh yet, since BaseGraph also uses it's own TriMeshes for shadowing and non-ODE collisions).

Afterwards we click on the "phys" button to open the physics properties window. On the tab "Geom" we remove the automatically created sphere primitive, since this won't represent our half pipe vere well and add a TriMesh primitive instead. Adding TriMesh primitives is only possible, if an object already has an added TriMesh representation (which is what we did in the section above). Of course the other primitives (Sphere, Capped Cylinder, Box) are faster and you can use as many Geoms to represent an object as you want.

The result should look something like that by now:

.

Now we switch to the tab "Body" and ensure that "static" is checked - we want our half pipe to be an obstacle for other objects, but it shouldn't be influenced itself by gravity or collisions.

To make the whole thing more beautiful, we can create some colored materials (or textures if you want), generate a light source and activate shadows.

You should see the physics by now, if you activate the animation button .

This article shall shed some light on the project types in Carad. This program (the half pipe) shall use physics with ODE - therefore there are two possibilities to create an executable - 1) you create a script in the integrated BaseGraph Pascal or 2) you create a Lazarus (FreePascal) or Delphi project with the BGP framework.

1) The script

Let's look at the BaseGraph Pascal language first: since the scene was already created interactively in Carad, we won't have to initalize any objects (BaseGraph Pascal loads Carad objects as compressed data (which usually is linked into the executable) rather than from source). Since physics support in BaseGraph Pascal is optional (two exe stubs exist, the one without physics support is significantly smaller) ODE data isn't stored in data files bat has to be set programmatically. We don't have to code it ourselves, however (this would be stupid, since Carad already "knows" the physical properties of objects) but Carad is able to generate this code itself.

Just open the BaseGraph Pascal IDE (the yellow P), and choose Edit > insert ODE source. Carad creates a procedure named InitODEWorldAndObjects, which generates exactly the physical properties set in the physics editor. Since it is so beautiful, when the computer does the whole work, we set the cursor into the next empty line and choose Edit> insert standard code - a basic program main routine, which can already be compiled, is inserted into the editor, if we call the routine InitODEWorldAndObjects after the begin, we have our ODE support and can start the script.

If you have installed Lazarus or Delphi (> 5) maybe you'd rather like to use a "real" compiler (even if BaseGraph Pascal is able to create executables - with the integrated resource managemet it may be a good choice for small projects - because scripts can be started directly from Carad - you can even create scenes programmatically and edit them manually in Carad after the script ended):

2) The Lazarus/Delphi projekt

If we want ODE support in native Lazarus / Delphi source, we have to choose a project type with BGP Framework support (the other project types will also work, but they will only create the graphical scene, without any physics). To do this, we choose File> create source > BGP Framework Project > BGP Framework Project for Lazarus (or Delphi respectively). Project properties can be changed afterwards, in example if you'd rather like to use dglOpenGL instead of bgOpenGL. Choose a project name, the directory to save the source into - and you are finished.
You can open the created .lpr (or .dpr) project directly in Lazarus (or Delphi) and get something like the half pipe demo program below:

download the half pipe demo program

Stay tuned and have fun