|
|
VRML Script Tutorial
Full list
VRML Interactive Tutorial
Introduction
VRML File Structure
Drawing: Shape node
Geometry Nodes:
Appearance
Let there be Light
Materials with Colored Lights
Hierarchical Node Structures
Inlining Files
Defining and Instancing Nodes
Defining Levels of Detail
Events in VRML
Interpolators
Let the Music Play
Bindable Nodes
Adding Realism to the world
Information about your world
Definition for Auxiliary Nodes
|
|
|
|
Collision Node
If you're not familiar to grouping nodes in VRML see the section Creating
Hierarchical Node Structures for general information on grouping.
By default, all objects in the scene are collidable, i.e. you shouldn't
be allowed to walk through walls and all that stuff. This is the theory,
in practice some browsers still allow you to play ghosts.
So why do you need a collision node if collision is by default detected?
Here are a few reasons to use this node:
turn off collision: This may seem a dumb thing to do but it will provide
better performance.
provide alternative representations for collision: collision detection
is hard work for the browser, complex worlds have lots of faces. This node
allows you to provide an alternative graphical representation for collision.
If this alternative representation is simpler than the real thing, then
collision detection is easier to do. The alternative representation is
not drawn, it is only used for collision detection purposes.
do something when collision occurs: The Collision node outputs an event
collideTime, which outputs the time of collision. For example, this
event can be routed to an AudioClip
node to play a sound when the user collides with an object. The example
at the bottom of this page shows the code to implement this.
The following fields are present:
children which contains all the nodes included in the group.
collide, a boolean field which specifies if the children nodes are
eligible for collision detection.
proxy specifies an alternative geometric representation for
collision detection. This field takes as value any node, except those which
can only appear inside another node as AudioClip, MovieTexture, geometry
nodes, etc...
bboxCenter specifies the center of a box that encloses the nodes
in the group. The value for this field is a 3D point.
bboxSize specifies where the size of a box that encloses the
nodes in the group. By default this field has a value of -1 -1 -1, which
implies that no box is defined. The values for this field must be greater
than or equal to zero. If the children nodes do not fit inside the box
defined the results are undefined.
Detecting collision in a complex object
The latter two fields are optional. They can be used by the browser for
optimization purposes.
Syntax:
|
Collision { |
children [ ]
collide TRUE
proxy NULL
bboxCenter 0 0 0
bboxSize -1 -1 -1
|
} |
|
In the following example, when the user collides with the sphere a sound will be heard.
Example:
-
-
#VRML V2.0 utf8
-
DEF col Collision {
-
children [
-
Sound { source DEF ac AudioClip { loop FALSE pitch 1.0 url "ouch.wav"
} }
-
Shape {
-
appearance Appearance { material Material {}}
-
geometry Sphere {}
-
}
-
]
-
}
-
ROUTE col.collideTime TO ac.set_startTime
|