Game Programming Algorithms and Techniques

Slides:



Advertisements
Similar presentations
Review Chapter 4.
Advertisements

Defining the Viewing Coordinate System
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Geometry Primer Lines and rays Planes Spheres Frustums Triangles Polygon Polyhedron.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Animation Following “Advanced Animation and Rendering Techniques” (chapter 15+16) By Agata Przybyszewska.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
Simple 3D Camera Game Design Experience Professor Jim Whitehead March 6, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Views.
Introduction What is this ? What is this ? This project is a part of a scientific research in machine learning, whose objective is to develop a system,
Screw Rotation and Other Rotational Forms
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Lecture 12: Structure from motion CS6670: Computer Vision Noah Snavely.
©2008 by W.H. Freeman and Company Chapter 2 Motionin One Dimension.
Rotations and Translations
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
COMP 175: Computer Graphics March 24, 2015
Viewing and Projections
Introduction Tracking the corners Camera model and collision detection Keyframes Path Correction Controlling the entire path of a virtual camera In computer.
Kinetic Energy, Work, Power, and Potential Energy
Kinetic Energy, Work, Power, and Potential Energy
Simple Machines Objectives: To learn about the theory behind Simple Machines To be able to calculate and understand mechanical advantages gained from using.
Chapter 11 Motion.
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Rotations and Translations
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
CS 445 / 645 Introduction to Computer Graphics Lecture 23 Bézier Curves Lecture 23 Bézier Curves.
3D Sensing and Reconstruction Readings: Ch 12: , Ch 13: , Perspective Geometry Camera Model Stereo Triangulation 3D Reconstruction by.
1 Fundamentals of Robotics Linking perception to action 2. Motion of Rigid Bodies 南台科技大學電機工程系謝銘原.
Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003.
Multitouch and Collision Detection MOBILE SOFTWARE DEVELOPMENT.
Centripetal Force Today you are going to study an object that moves in a circle. Today you are going to study an object that moves in a circle. An object.
Games Development 1 Camera Projection / Picking CO3301 Week 8.
3D Imaging Motion.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
Advanced Computer Graphics Shadow Techniques CO2409 Computer Graphics Week 20.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Three-Dimensional Viewing Hearn & Baker Chapter 7
Aerodynamic forces on the blade, COP, Optimum blade profiles
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Arizona’s First University. Command and Control Wind Tunnel Simulated Camera Design Jacob Gulotta.
DYNAMICS VECTOR MECHANICS FOR ENGINEERS: DYNAMICS Tenth Edition Ferdinand P. Beer E. Russell Johnston, Jr. Phillip J. Cornwell Lecture Notes: Brian P.
Three Dimensional Viewing
Visible Surface Detection
Character Animation Forward and Inverse Kinematics
Calculus III Exam Review
CS 445 / 645 Introduction to Computer Graphics
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
CIS 410/510: Isosurfacing (pt 2)
CSCE 441 Computer Graphics 3-D Viewing
Scene Modeling for a Single View
3D Graphics Rendering PPT By Ricardo Veguilla.
© University of Wisconsin, CS559 Fall 2004
Chapter 11: Motion.
Representing Motion Chapter 2.
Lighting.
Computer Graphics Lecture 20
Chapter V Vertex Processing
The View Frustum Lecture 10 Fri, Sep 14, 2007.
Viewing (Projections)
Chapter 10 Section 2.
Game Programming Algorithms and Techniques
Game Programming Algorithms and Techniques
Game Programming Algorithms and Techniques
Chapter 4 . Trajectory planning and Inverse kinematics
GPAT – Chapter 2, 4, and 8 Graphics and Cameras
Presentation transcript:

Game Programming Algorithms and Techniques Chapter 8 Cameras

Chapter 8 Objectives Types of Cameras Learn about all the different types of cameras used in games, including fixed, first-person, and follow. Perspective Projection How FOV affects the visible scene Common aspect ratios Camera Implementations Basic and spring follow cameras Orbit camera First-person camera Spline camera Camera Support Algorithms Camera collision and picking

Fixed Camera Popular in older survival horror games such as Resident Evil Top-down view of a sample scene, and where fixed cameras might be placed

First-person camera in Quadrilateral Cowboy Gives an immersive first-person perspective First-person camera in Quadrilateral Cowboy

Follow Camera Follows behind a target object, such as a car: A follow camera behind a car

Field of View Angle that represents the amount of the world that can be seen. Binocular field of view of humans is approximately 120°. When determining the field of view for a game, we must take into account how close the player is to the screen.

Viewing Angle The viewing angle is the angle that is occupied by the screen: 50” HDTV with a 40° viewing angle (a), and PC monitor with a 90° viewing angle (b)

Field of View, Cont'd We want an in-game field of view that's greater than or equal to the view angle. A too-narrow field of view can cause motion sickness!

Field of View Comparison Sample scene shown with a 65° field of view (a) and a 90° field of view (b) ©York/fotolia

16:9 has a wider horizontal FOV (a) and a narrower vertical FOV (b) Aspect Ratio Ratio between width and height of screen. Two ways we can resolve differences between aspect: ratios: 16:9 has a wider horizontal FOV (a) and a narrower vertical FOV (b) ©York/fotolia

Basic follow camera tracking a car Follows right behind the target Basic follow camera tracking a car

Basic Follow Camera, Cont'd // tPos, tUp, tForward = Position, up, and forward vector of target // hDist = horizontal follow distance // vDist = vertical follow distance function BasicFollowCamera(Vector3 tPos, Vector3 tUp, Vector3 tForward, float hDist, float vDist) // Eye is offset from the target position Vector3 eye = tPos – tForward * hDist + tUp * vDist // Camera forward is FROM eye TO target Vector3 cameraForward = tPos - eye cameraForward.Normalize() // Cross products to calculate camera left, then camera up Vector3 cameraLeft = CrossProduct(tUp, cameraForward) cameraLeft.Normalize() Vector3 cameraUp = CrossProduct(cameraForward, cameraLeft) cameraUp.Normalize() // CreateLookAt parameters are eye, target, and up return CreateLookAt(eye, tPos, cameraUp) end

Basic Follow Camera Problems It's very rigid. No real sense of turning. Difficult to tell whether object or world is moving.

A spring connects the camera’s ideal and actual positions. Spring Follow Camera Set up a spring between the camera's ideal and actual positions: A spring connects the camera’s ideal and actual positions.

Spring Follow Camera: Update // First calculate the ideal position Vector3 idealPosition = target.position – target.forward * hDist + target.up * vDist // Calculate the vector FROM ideal TO actual Vector3 displacement = actualPosition – idealPosition // Compute the acceleration of the spring, and then integrate Vector3 springAccel = (-springConstant * displacement) – (dampConstant * velocity) velocity += springAccel * deltaTime actualPosition += velocity * deltaTime

Orbit Camera Orbits around a particular object: Orbit camera

Orbit Camera, Cont'd Easiest system is to store the offset from the camera. If we rotate this offset, the camera will then orbit around the object. Typically allow yaw/pitch rotation.

Orbit Camera: Update // Updates based on the incremental yaw/pitch angles for this frame function Update(float yaw, float pitch) // Create a quaternion that rotates about the world up Quaternion quatYaw = CreateFromAxisAngle(Vector3(0,1,0), yaw) // Transform the camera offset and up by this quaternion offset = Transform(offset, quatYaw) up = Transform(up, quatYaw) // The forward is target.position - (target.position + offset) // Which is just -offset Vector3 forward = -offset forward.Normalize() Vector3 left = CrossProduct(up, forward) left.Normalize() // Create quaternion that rotates about camera left Quaternion quatPitch = CreateFromAxisAngle(left, pitch) // Transform camera offset and up by this quaternion offset = Transform(offset, quatPitch) up = Transform(up, quatPitch) // Now compute the matrix cameraMatrix = CreateLookAt(target.position + offset, target.position, up) end

First-person camera implementation Orbit the target offset instead: First-person camera implementation

Catmull-Rom spline with the minimum four points Simple type of spline where we interpolate between two control points: The path can have more than four control points, and it'll work so long as there's one point before and one after Catmull-Rom spline with the minimum four points

Catmull-Rom Spline Code class CRSpline // Vector (dynamic array) of Vector3s Vector controlPoints // First parameter is the control point that corresponds to t=0 // Second parameter is the t value function Compute(int start, float t) // Check that start – 1, start, start + 1, and start + 2 // all exist ... Vector3 P1 = controlPoints[start – 1] Vector3 P2 = controlPoints[start] Vector3 P3 = controlPoints[start + 1] Vector3 P4 = controlPoints[start + 2] // Use Catmull-Rom equation to compute position Vector3 position = 0.5*((2*P1)+(-P0+P2)*t+ (2*P0-5*P1+4*P2-P3)*t*t+ (-P0+3*P1-3*P2+P3)*t*t*t) return position end

Spline Camera We can have a camera follow a spline path: The camera position is at the current t value. The target point can be t + a small delta t. If the camera can't spin upside down, the up can always just be world up.

Camera Collision How to solve the problem where the camera is blocked by an opaque object? One solution is to move the camera up past the object: Camera blocked by an object (a), and camera moved up so it’s no longer blocked (b)

Picking Clicking on and selecting a 3D object: Picking casts a ray from the near to far plane and selects an object that intersects with the line segment.

Picking, Cont'd To do this, we need to take a 2D point (cursor position) and convert it into a 3D world space line segment. This process is known as an unprojection. To perform an unprojection, we need a 4D point: (cursor.x, cursor.y, z, 1) Here, z = 0 means convert to a point on the near plane, and z = 1 means convert to a point on the far plane.

Unprojection Code function Unproject(Vector4 screenPoint, Matrix camera, Matrix projection) // Compute inverse of camera * projection Matrix unprojection = camera * projection unprojection.Invert() return Transform(screenPoint, unprojection) end