Cs3241 Lab 10
-
Upload
edison-tsui -
Category
Technology
-
view
550 -
download
1
Transcript of Cs3241 Lab 10
![Page 1: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/1.jpg)
Simple Collision Detection
CS3241 Lab 10
![Page 2: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/2.jpg)
Objectives
Implement
Plane to Sphere collision detection
Sphere to Sphere collision detection
Collision Response
![Page 3: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/3.jpg)
Sphere to Sphere Collision Detection
If sphere1 & sphere2
collide
n = c2 – c1
|n| <= r1 + r2
depth = |n| - (r1+r2)
normal = n / |n|
c1
c2
nr2
r
1
![Page 4: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/4.jpg)
Plane to Sphere Collision
Detection
Forming a plane
Compute normal by 3
vertices, p1, p2, p3
normal = (p2-p1) x (p3-p1)
If plane and sphere
d = c1 * plane’s normal
d <= p + r
normal = plane’s normal
depth = p + r - d
c1
p
d
![Page 5: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/5.jpg)
Collision Response
c1
norma
l
Ori. velocity
Simulate response
From Physics, we know….
As original Velocity can be de-
composited to two part V1, V2
V2 will remain the same but V1 will
flip
Vnew = Vold – 2* (Vold *
Normal)*Normal
How about stickiness?V1 V2
![Page 6: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/6.jpg)
Tasks Task 1 Plane to Sphere collision detection Fill in bool checkCollide(BoundSphere *n1, BoundPlane*n2, float
dt, ContactInfo *ci)
Some notes:
BoundSphere & BoundPlane are just simple structure holding normal, radius…
Please look into ContactInfo as returning these info will help you adding collision response
Task 2 Collision Response Fill in void checkCollision()
Some notes:
Work on sphere to plane collision response
But other responses are similar
![Page 7: Cs3241 Lab 10](https://reader035.fdocuments.in/reader035/viewer/2022080213/55a25f051a28abdc718b463a/html5/thumbnails/7.jpg)
Thanks Hope you enjoy this lab and find it useful for your
assignment 4