Using Other Physics Examples in GLScene

See the first page in this section for the set-up of GLScene in Lazarus. The following points apply generally to the physics examples.

  1. View the .lpi file of the sample and remove any spaces before the names of the required packages. (You must be able to see GLSceneLCL_RunTime as a required package in the Property Inspector before compiling). Change any of the remaining old names such as GLS_ODE to the corresponding new names such as GLSceneLCL_ODE.
  2. Accept any invitations to continue when loading.
  3. When executing the application, you may receive an error message that WGL_ARB_pbuffer support is required. Check the box with caption Ignore this exception type and press the button to continue.

You should install the package GLSceneLCL_ODE (which you have already compiled) as follows.

  1. Copy ode_single.dll from GLSceneLCL\external folder to the directory containing lazarus.exe.
  2. Select menu item Package > Open Package File (.lpk)... and then select GLSceneLCL_ODE.
  3. Select menu item Use >> > Install and accept both invitations to continue.

clothactor

This is an impressive demonstration of a walker. The introductory comment states that "Verlet physics is used to simulate a cloth-like effect on a mesh".

The code for finding the media folder is searching for a string that no longer exists. We copied the following ten files from the media folder to the clothactor project folder: beigemarble.jpg, cape.3ds, chrome_buckle.bmp, chrome_glass.bmp, clothactor.dbg, trinitypantsF.bmp, trinityRAGE.glsc, trinityRAGE.smd, trinityskin3.bmp and walk.smd. Program Clothify sets the current directory simply with, at the start of the FormCreate procedure:
SetCurrentDir('..\..\..\media\');    
In order to prevent a SIGSEGV fault, we changed line 236 to
  if assigned(VerletWorld) then
    VerletWorld.Progress(deltaTime, newTime);     

We used the following code in procedure RenderAABB:

    GL.Color3f(r, g, b);
    rci.GLStates.LineWidth := w;

    GL.Begin_(GL_LINE_STRIP);
    GL.Vertex3f(AABB.min.X, AABB.min.Y, AABB.min.Z);
    GL.Vertex3f(AABB.min.X, AABB.max.Y, AABB.min.Z);
    GL.Vertex3f(AABB.max.X, AABB.max.Y, AABB.min.Z);
    GL.Vertex3f(AABB.max.X, AABB.min.Y, AABB.min.Z);
    GL.Vertex3f(AABB.min.X, AABB.min.Y, AABB.min.Z);

    GL.Vertex3f(AABB.min.X, AABB.min.Y, AABB.max.Z);
    GL.Vertex3f(AABB.min.X, AABB.max.Y, AABB.max.Z);
    GL.Vertex3f(AABB.max.X, AABB.max.Y, AABB.max.Z);
    GL.Vertex3f(AABB.max.X, AABB.min.Y, AABB.max.Z);
    GL.Vertex3f(AABB.min.X, AABB.min.Y, AABB.max.Z);
    GL.End_;

    GL.Begin_(GL_LINES);
    GL.Vertex3f(AABB.min.X, AABB.max.Y, AABB.min.Z);
    GL.Vertex3f(AABB.min.X, AABB.max.Y, AABB.max.Z);

    GL.Vertex3f(AABB.max.X, AABB.max.Y, AABB.min.Z);
    GL.Vertex3f(AABB.max.X, AABB.max.Y, AABB.max.Z);

    GL.Vertex3f(AABB.max.X, AABB.min.Y, AABB.min.Z);
    GL.Vertex3f(AABB.max.X, AABB.min.Y, AABB.max.Z);
    GL.End_;                       

Clothify

Clothify shows an actor falling down steps. There are several settings for you to experiment with. The following paragraphs describe the changes that we found to be necessary. We used 32-bit Lazarus 1.6 on Windows 8.1.

We added OpenGLTokens to the uses clause and copied ode_single.dll from external to the project folder.

We changed line 128 to
SetCurrentDir('..\..\..\media\');    
We changed line 218 to
    Sides.X := GLCube.CubeWidth * 1.1;
    Sides.Y := GLCube.CubeHeight * 1.1;
    Sides.Z := GLCube.CubeDepth * 1.1;  
We changed line 448 to
 dBodyAddForce(dGeomGetBody(ODESphere),
                       VCSphere.KickbackForce.X,
                       VCSphere.KickbackForce.Y,
                       VCSphere.KickbackForce.Z);    
We changed the lines of procedure RenderAABB to
    glColor3f(r,g,b);
    rci.GLStates.LineWidth := w;
    glBegin(GL_LINE_STRIP);

    glVertex3f(AABB.min.X, AABB.min.Y, AABB.min.Z);
    glVertex3f(AABB.min.X, AABB.max.Y, AABB.min.Z);
    glVertex3f(AABB.max.X, AABB.max.Y, AABB.min.Z);
    glVertex3f(AABB.max.X, AABB.min.Y, AABB.min.Z);
    glVertex3f(AABB.min.X, AABB.min.Y, AABB.min.Z);

    glVertex3f(AABB.min.X, AABB.min.Y, AABB.max.Z);
    glVertex3f(AABB.min.X, AABB.max.Y, AABB.max.Z);
    glVertex3f(AABB.max.X, AABB.max.Y, AABB.max.Z);
    glVertex3f(AABB.max.X, AABB.min.Y, AABB.max.Z);
    glVertex3f(AABB.min.X, AABB.min.Y, AABB.max.Z);
    glEnd;

    glBegin(GL_LINES);
    glVertex3f(AABB.min.X, AABB.max.Y, AABB.min.Z);
    glVertex3f(AABB.min.X, AABB.max.Y, AABB.max.Z);

    glVertex3f(AABB.max.X, AABB.max.Y, AABB.min.Z);
    glVertex3f(AABB.max.X, AABB.max.Y, AABB.max.Z);

    glVertex3f(AABB.max.X, AABB.min.Y, AABB.min.Z);
    glVertex3f(AABB.max.X, AABB.min.Y, AABB.max.Z);
    glEnd;                                  

FurBall

The introductory comment is simply "Using Verlet Hair with ODE; Fur Balls". Hair is notoriously difficult to represent realistically and this example makes a good attempt. You can vary factors such as air resistance, gravity, inertia and shadows. We copied ode_single.dll from external to the project folder. This screenshot shows the fur ball changing direction.

Screenshot of FurBall in action

Screenshot of FurBall in action

Programming - a skill for life!

How learn from the GLScene Samples