ParallelGraphics  
Home  »  Developer Zone  »  Products  »  Cortona3D Viewer  »  VRML Extensions  »  Object-To-Object Collision Detection Interface
Object-To-Object Collision Detection Interface

Object-to-object collision detection in a three-dimensional scene is a procedure of determining whether a given shape, if it were to undergo some transformation (for example, to be moved, rotated, or scaled), would encounter an obstacle in the form of another shape. In this document we describe the ParallelGraphics' ECMAScript interface with the proprietary implementation of the object-to-object collision detection extension to VRML.

The interface is built around two native ECMAScript objects, Collidee and Collision. The former acts as a proxy for the shape that is transformed, bearing the parameters of the transformation matrix and other relevant data, and the latter describes the point of the shape in question that came into contact with another shape, in the case of a collision. Let us examine each object in turn.

Object Collidee
Properties:
SFNode/MFNodebody
SFVec3fposition
SFRotationorientation
SFVec3fscale
SFVec3fsize
SFVec3foffset
Collisioncollision (read-only)
Collideescenery
SFNode/MFNodeignore

Methods:
Boolean moveTo(SFVec3f position, SFRotation orientation, SFVec3f scale)
(all parameters are optional)

 
body, position, orientation, scale, size and offset
The body property contains a reference to the shape or a list of shapes that are subjected to collision detection and the position, orientation, and scale properties store references to the parameters of the matrix used for transforming the coordinates of elements of that shape. When the body property is set to null, the size and offset properties are used to construct an imaginary shape of parallelepiped with edges parallel to basis vectors, and the center displaced from the origin of the local coordinate frame.

 
collision
The collision property references an object describing the contact point of the shape during the last collision.

 
scenery
The scenery property contains a reference to another Collidee object against which the collision detection is performed; if this property is set to null, then every shape in the scene is used.

 
ignore
The ignore property is a reference to a shape or a list of shapes that should not be processed when detecting collision with the current shape, which itself is considered to be ignored for this purpose.

 
moveTo
The moveTo method does the job of collision detection when transforming the shape that a given Collidee object represents. It builds two transformation matrices for the shape, one from the parameters in the Collidee object, and the other from the arguments received, and checks that no collision occurs at both the initial and final positions, or at any position interpolated between these two. In the case of no collision the method copies the values of arguments to the corresponding properties of the Collidee object and returns true. Otherwise, a transformation matrix corresponding to the position of the shape when it first comes into contact with an obstruction is computed, the properties of the Collision object are updated with the appropriate values, and the method returns false. Also, in this case, the properties of the Collision object are set to the values describing the contact point of the shape. It should be noted that for optimization purposes the values of the position, orientation and scale properties are never changed by the moveTo method; instead, the values of the objects that these properties point to are updated. In practice this makes it possible for the translation, rotation and scale fields of the corresponding Transform node to be automatically updated as a side-effect of a moveTo call.



Object Collision
Properties:
SFVec3fpoint(read-only)
SFVec3fnormal(read-only)
NumberfaceIndex(read-only)
MFNodepath(read-only)

 
point and normal
The point property contains the coordinates, relative to the local coordinate frame of the shape, of the point that contacts the obstruction, and the normal property gives the coordinates of the normal vector at that point.

 
faceIndex
The faceIndex property indicates which face of an IndexedFaceSet contains the specified point; this value is not defined for other geometry nodes.

 
path
The path property is a list of nodes forming a chain in the hierarchy of nodes starting from the one specified in Collidee's body property, and ending with the node that contains the face that collided.

The described interface is, from the programmer's point of view, a filter for the transformations that are sent through it to the shape that it governs. This fact makes the use of collision detection more or less transparent to the author of VRML scenes and even allows for the augmentation of the Interpolator-based animations with collision-detection techniques.


Example
[view]

scene size: 1.4KB
download zipped archive
(archive size: 1.5KB)



Last updated: Sun, 12 Feb 2012
© 2000-2008 ParallelGraphics. All rights reserved.