Docsity

Optimizing 3D Spatial Relationships: Collision Detection & Ray Tracing, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
Collision Detection
Navigating a maze
A maze is an extremely optimizable collision-detection
problem. You can store your maze as a 2D array,
char maze[][] = { “##################”,
“# #”,
“#### ######## ##”,
“# #### ##”,
“# ## #”,
“# ## #”,
“##################” };
...or as a dynamically-allocated two-dimensional array drawn
from a bitmap, or what have you. Each cell in your array will
represent one “square” of the maze, and while the user might
move around within a square, they cannot enter squares with
wall in them.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Optimizing 3D Spatial Relationships: Collision Detection & Ray Tracing and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Collision Detection ^ Navigating a maze^ ^ A maze is an extremely optimizable collision-detectionproblem. You can store your maze as a 2D array,^ char maze[][] = { “##################”,

“#^

“####^

“#^

####^ ##”,

“#^

##^ #”,

“#^

##^ #”,

^ ...or as a dynamically-allocated two-dimensional array drawnfrom a bitmap, or what have you. Each cell in your array willrepresent one “square” of the maze, and while the user mightmove around within a square, they cannot enter squares withwall in them.

SpaceSpace

Collision Detection ^ Navigating a maze^ ^ Don’t try to collide against the polygons of the maze model atall; instead, check whether your user can move or not byinspecting the contents of your array. This requires almost nomath and is

much^ faster than poly-to-poly collision detection.

Each square of the mazemay be larger than the player,but it’s either passable or it’snot; test the array of data tosee if the player’s position islegal.^ Space = 0 Space Space

Space Wall Wall Wall

Wall^ Wall Wall^ Wall

Wall = 1

Collision Detection ^ Line-to-poly intersection^ ^ To interesect a polygon with a line, find the point where theline intersects the polygon’s plane.^ ^ Test to see if the point is inside the polygon.- One way to do so: dot the vector from the point to anyvertex with the vector from the point to each of the othervertices in turn. If no dot product is negative, then all thevectors point in the same direction, implying that the pointis outside the polygon. ^ The general case^ ^ The general case of collision detection is to intersect twopolygons together.^ ^ Poly-to-poly intersection is mathematically traumatic and willnot be addressed here.

Collision Detection ^ Some sources for further inspiration:^ ^ http://www.stanford.edu/~jgao/collision-detection.html^ ^ http://www.cosy.sbg.ac.at/~held/projects/collision/collision.html^ ^ http://www.cs.brown.edu/courses/gs007/lect/sim/web/murat.html

Ray Tracing ^ How it works:^ ^ Logically, in order to reach the camera, light has to passthrough the rectangle floating in the virtual world which is therectangle matching the screen in the real world. We’vesometimes called this rectangle the

virtual canvas

. OpenGL

goes to a great deal of effort to paint every object in the sceneonto the canvas, pixel by pixel.  In the end, the virtual canvas becomes the real-world screen.  Instead of painting objects one-by-one, ray-tracing reversesthe question to ask, “who colored this dot on the canvas?”  In ray-tracing a beam is fired from the eye (camera) through each pixel^ of the virtual canvas, then traced onwards to seewhat it hits.

Jamis Buck^ (1999) Docsity.com

Ray Tracing ^ Ray-casting^ ^ Ray-casting is the act of throwing a ray of “light” out from thecamera, through each of the pixels in the scene, until it hits anobject. Whatever color the objectis, that’s the color of that pixel.^ ^ We can calculate the exact shadeand color of the object by gauginghow much light reaches it fromthe light sources in the scene.^ ^ The angle of incidence of the light,combined with the location of the camera and the surfacenormal at the impact point, are used to calculate the properlighting equations.

Jamis Buck^ (1999) Docsity.com

Ray Tracing ^ Some sources for further inspiration:^ ^ http://www.geocities.com/jamisbuck/raytracing.html^ ^ Scenes from

Bunny , an Oscar-winning short film fromBlue Sky Studios (http://bunny.blueskystudios.com/)