Using the Newton Physics Engine in GLScene
- Copy newton.dll and dJointLibrary.dll from GLSceneLCL\external folder to the directory containing lazarus.exe.
- Select menu item and then select GLSceneLCL_NGD.
- Select menu item and accept both invitations to continue.
These points apply to all five Newton samples.
- Use a recent 32-bit version of Lazarus.
- Copy newton.dll and dJointLibrary.dll from GLSceneLCL\external to the project folder.
- 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_NGD to the corresponding new names such as GLSceneLCL_NGD.
- Accept any invitations to continue when loading.
- 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.
This example illustrates the density and viscosity of a fluid.
We changed line 132 to PlaneEquation.Z := MyForm.GLPlane1.Position.Y;.
Select GLLeadSphere in the Object Inspector and click on the Material ellipsis to see that the colour is brown. Click on the Behaviours ellipsis and select the only item (0 - NGD Dynamic) in the pop-up editor. Now you can see in the Object Inspector that the density is 10. Similarly, you can see that the paper sphere has colour grey and density 0.1.
When you execute the program you can change the density, linear viscosity and angular viscosity of the fluid. Increase the "Water Density" to the maximum (20) to see the lead sphere rise to the surface and to see the brown colour above the fluid surface. You can also observe a cone, capsule, cube and cylinder as you change the properties of the fluid.
This is an impressive demonstration of several labelled types of joint that you can enjoy testing with the mouse in the executed program. The types of joint are ball, ball and socket, corkscrew, hinge, slider, and universal. Some have limits applied. Use the Object Inspector to see the value of its JointType property (e.g. nj_CustomSlider).
Deduce from the key combination settings that pressing left and right buttons of the mouse will enable zoom.
You should be able to use this sample as a basis from which to develop your collisions and sliding motions between pairs of objects in your own programs. (This would be very difficult without a working example!) See from the Object Inspector that for each surface pair you can set up properties such as elasticity, softness, and both kinetic and static friction. There is plenty of scope for experimentation!
Repeatedly add spheres, cones, capsules, cubes and cylinders to see them fall and interact with the other objects as shown in this screenshot.
Screenshot of NewtonSpawn in action
GLCone1 := TGLCone.CreateAsChild(GLDummyCube1); GLCone1.Material.FrontProperties.Diffuse.RandomColor;
We needed to make the following changes to make this example work for us.
- In NewtonWalkCarryShoot.lpi we removed a space before the GLSceneLCL_RunTime package and another space before this GLApplicationFileIO.pas. We updated the name of packageGLS_NGD to GLSceneLCL_NGD.
- We copied ngdchair.3ds, mushroom.3ds and ngdmap1.3ds from media to the project directory.
- We changed line 209 to Ball.Translate(delta.X, delta.Y, delta.Z);
- We changed line 302 to f.Y := 0; // Do not allow the body to go up or down.
Read the initial comment in Unit1 to see the inputs that are expected. Pressing X several times then arranging the view gave us this screenshot.
Screenshot of NewtonWalkCarryShoot in action