Presentation is loading. Please wait.

Presentation is loading. Please wait.

Seminar 5 Game EDA221 Introduction to Computer Graphics Universitetsadjunkt Mathias Haage Author: Carl Johan Gribel, PhD student.

Similar presentations


Presentation on theme: "Seminar 5 Game EDA221 Introduction to Computer Graphics Universitetsadjunkt Mathias Haage Author: Carl Johan Gribel, PhD student."— Presentation transcript:

1 Seminar 5 Game EDA221 Introduction to Computer Graphics Universitetsadjunkt Mathias Haage (mathias.haage@cs.lth.se) Author: Carl Johan Gribel, PhD student (cjgribel@cs.lth.se)

2 Today Final assignment: make a game – Some ideas New stuff – Collision detection – Physics (inertia)

3 Game ideas Asteroids – Shoot asteroids randomly towards camera/spaceship Objective: Avoid and/or shoot them down Torus ride – Place tori ”rings” along path Objective: Gain points by flying through Your own idea

4 General considerations Static camera & moving objects – or the other way around? Maneuverable camera/ship – Fixed or flying – Steer up/down/left/right (WASD) or by mouse – Optional: inertia, force vector, dynamic spline generation...

5 Asteroids Fixed array of asteroids – Geometry *asteroids[N] – Respawn when behind camera or shot down Randomize position, velocity vector etc Alter appearances using size, shaders, tessellation...

6 Torus Ride Fixed array of tori – Geometry *tori[N] – Fixed or infinite (respawn) path Place tori e.g. along random spline Alter appearances using size, rotation (spin?), shaders, tessellation...

7 When you’re done... Make a short post on the course forum presenting your game – Title and game objectives – Features and how you implemented them – Screenshots – Names of the creators

8 Collision detection Use bounding spheres (BS) and perform sphere – sphere or ray – sphere collision tests – Cheap tests – Avoid other primitives Note: no need to use an actual sphere – just the radius!

9 Sphere – Sphere Intersection if | p 1 - p 2 | < r 1 + r 2 bool testSphereSphere(p1, r1, p2, r2) p1p1 p2p2

10 Collision detection: Spaceship & asteroids example Spaceship and its BV radius: Geometry*ship float ship_BVradius Asteroid list and parallel list of asteroid BV radii: Geometry *asteroids[N] float asteroid_BVradii[N] Each frame, test spaceship against all asteroids: for each asteroid if testSphereSphere(ship->getWorldPosition(), ship_BVradius, asteroids[i]->getWorldPosition(), asteroid_BVradii[i])...lose life/award point...

11 Ray origin p v, unit direction v Sphere at p s, radius r Intersection if | rejection( p s – p v, v ) | < r bool testRaySphere(pv, v, ps, r) Ray – Sphere psps pvpv v

12 Ray shooting ”Shoot” ray from camera p v = camera->getWorldPosition() v = camera->getFront() If camera not in world space, extract v like this mat4f cw = camera->getWorldMatrix() vec3f v = – vec3f( cw.R20, cw.R21, cw.R22 ) v.normalize() pvpv v

13 Physics: Inertia Force-based approach for more realistic acceleration Spaceshipp = position (Euclidean, along spline...) v = velocity m = mass f = ”engine power” in Newtons Per framep += v * dt v += F/m * dt (clamp v if necessary) To accelerate set F = f, maintain speed: F = 0 (The secret: explicit Euler integration of F = ma)

14 Inertia: example Spaceshipp = (0, 0, 0) m v = (0, 0, 0) m/s(not moving) m = 1000 kg f = (0, 0, -1000) N Per framedt = Platform::getFrameTimeStep() p +=... v +=... Speed up/down (in z-direction): F = +/- f Cruise: F = 0

15 General guidance Print scores, messages etc to console (printf) Random numbers: int rand(), #include Keep it simple: start out with basic features, shaders etc – Add complexity progressively – Total time consumption equivalent to a normal lab Reuse your achievements from assignment 1-4 Have fun & Good luck!

16 Summary Minimum requirements (Asteroids, Torus Ride) – Ship maneuverability – Use of tessellated objects with shaders – Translational and rotational animation – Fixed object array (respawn if needed) – Collision detection – Game presentation on course forum Optional – Inertia, force vectors, dynamic splines... Own idea – Consult us

17 Inertia: rotations...same goes for rotations Each frame:θ += w * dt w += T/I * dt θ = absolute angle w = angular velocity T = torque I = angular inertia, I sphere = 2mr 2 /5


Download ppt "Seminar 5 Game EDA221 Introduction to Computer Graphics Universitetsadjunkt Mathias Haage Author: Carl Johan Gribel, PhD student."

Similar presentations


Ads by Google