| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Articles DCECollision

Page history last edited by PBworks 18 years, 6 months ago

GLScene has a dynamic collision engine (DCE) which provides automatic collision detection with objects in a scene. It is useful when creating a Quake like game where a player walks around a town and it is necessary to stop the player from crashing into walls and objects placed on the scene. DCE Collision detection works by adding behaviours to a scene object. The behaviour can either be static (TGLDCEStatic) or dynamic (TGLDCEDynamic). Static behaviour means that the object is stationary and is an object you collide with (eg a Quake 3 map) while dynamic behaviour is for objects that will collide with the static objects (eg a dummycube with a TGLCamera child). Typically a dynamic object is a camera. Since a camera has no behaviour property a dummycube can be created as the cameras parent and the dynamic behaviour is added to the dummycube.

The following are some steps for using DCE collision:

1. Add a TGLDCEManager to the application. If you want gravity in your scene set it to a negative number such as -30. This will mean that objects added to the scene will automatically move down until they collide with something.

2. For static objects in your scene click on the behaviour property and click on 'DCE Static Collider'. Set the manager of 'DCE Static Collider' to the DCEManager added in step 1. Set the shape property of the behaviour. If the static object is a freeform set it to cdFreeForm.

3. For dynamic objects add a 'DCE Dynamic Collider' behaviour to the object and also set the manager to the one in step 1.

In a GLScene application it will then be possible to move the dynamic objects around and they will slide or bounce off objects they collide with. Objects can be moved by applying force to the object or specifying the position you want to move the object to. The procedure GetOrCreateDCEDynamic provides a reference the objects TGLDCEDynamic behaviour class. The TGLDCEDynamic class has procedures that can move an object. In the following example the dummycube gldummycube2 has force applied in the z direction:

force[2]:=10000;

GetOrCreateDCEDynamic(gldummycube2).ApplyAccel(Force);

It will move the dummycube in the z direction. Objects in the path of the dummycube will effect how far it moves. For example if there is a cube in front of the object in the z direction it will bounce or slide off the cube when it hits it.

It is also possible to move an object to a certain position. The following example tries to move the dummycube to position 2,3,4
position[0]:=2;

position[1]:=3;
position[2]:=4;

GetOrCreateDCEDynamic(gldummycube2).MoveTo(Position,1);

There is also a jump method that allows an object to leap up with a certain amount of force:

GetOrCreateDCEDynamic(gldummycube2).Jump(1,20);

For a demonstration of DCE refer to the demo in CVS at:

Demos/behaviours/DCEDemo

skinhat

Comments (0)

You don't have permission to comment on this page.