Computer graphics -- 2008-2009 -- info.uvt.ro/Laboratory 10
From Wikiversity
Quick links: front; laboratories agenda, 1, 2, 3, 4, 5, JOGL template.
[edit] World Box
The world box is nothing else than a simple cube (sphere) which contains all of the scene's objects as well as the camera. The following constraints must be met:
- the world box must be inside the view volume (or at least the sides that are visible)
- the objects outside the world box should not be draws (they will not be visible)
- the camera should not be allowed to exit the bounding box
World boxes are used to add realism to our environment by showing distant mountains, clouds, star fields. Generally they are used to in the scenes objects that are to far from us and thus cannot be reached (near the horizon).
Important: when drawing the world box we should note that it must be drawn, so that the face polygon is on the inside!
[edit] Object Collisions
Collision detection allows programmers to simulate solid objects through which nothing can pass. It is useful in simulating physical laws. For example we could simulate a billiard game or a projectile which explodes when hitting a surface.
One of the simplest techniques involves surrounding each body (including the camera) with either a sphere or a cube. For simplicity we will use a sphere. The following steps detail how we could create a rudimentary collision detection mechanism:
- draw a sphere (cube) around every object
- if any of the spheres (cubes) overlap then you have a collision:
- d = the distance between 2 objects
- a = radius of the circle around the first object
- b = radius of the circle around the second object
- if ( a + b >= d ) then we have a collision
Important:The previous logic should be applied each time a frame is drawn and for small steps of object/camera movement otherwise we could end up passing through an object without detecting the collision. Additionally we could check in advance if two objects would collide by computing their future positions and apply the previous logic.
Links:
[edit] Exercise
- Given the scene in our previous laboratories where there are several textured spheres circling a centered one, add a surrounding world box. It can be either a sphere or a cube. The texture should represent a star field.
- Add a simple collision detection mechanism so that the user should not be allowed to either leave the world box nor to go through the spheres.
- Create a simple scene containing a cube. Inside the cube we have 5 spheres bouncing of the edges. Each time two (or more) spheres touch they disappear.