1 / 83

CIS 350 – I Game Programming Instructor: Rolf Lakaemper

CIS 350 – I Game Programming Instructor: Rolf Lakaemper. 3D Basics. What ?. In this lecture we will learn how to use 3D transformations to change the position of 3d vertices. This enables us to create animations and views of different perspective. 3D Basics. Basic 3D Mathematics.

qiana
Download Presentation

CIS 350 – I Game Programming Instructor: Rolf Lakaemper

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 350 – I Game Programming Instructor: Rolf Lakaemper

  2. 3D Basics

  3. What ? In this lecture we will learn how to use 3D transformations to change the position of 3d vertices. This enables us to create animations and views of different perspective.

  4. 3D Basics Basic 3D Mathematics

  5. 3D Basics Everything we describe in our 3D worlds, e.g. vertices to describe objects, speed of objects, forces on objects, will be defined by 3D VECTORS i.e. triplets of 3 real values.

  6. 3D Basics 3D Euclidean Coordinate System (or 3D Cartesian Coordinate System) y V = (x, y, z) X z

  7. 3D Basics A vector v=(x,y,z) has the properties • DIRECTION, the relative values of x,y,z to each other. Two vectors v,w have the same direction iff: • s: v = sw • MAGNITUDE (length) |v|. We’ll use the euclidean length: • |v|=sqrt(x²+y²+z²)

  8. 3D Basics A vector v=(x,y,z) is normalized if |v| = 1 Normalizing a vector v is easy, just scale it by 1/length: V  v / |v| i.e. | v/|v| | = 1 Proof ?

  9. 3D Basics It’s usually handy to deal with normalized vectors. We’ll see.

  10. 3D Basics Basic Vector Operations Vector addition: v + w = (vx+wx, vy+wy, vz+wz) w v+w v

  11. 3D Basics Basic Vector Operations Scalar multiplication with s: s*v = v*s = (s*vx, s*vy, s*vz) • Does not change direction • Changes magnitude: • |s*v| = s * |v| s*v v

  12. 3D Basics Dot Product v . w = vx*wx + vy*wy + vz*wz = |v| * |w| * cos ((v,w)) w v w * cos ((v,w))

  13. 3D Basics • The dot product is a scalar value ! • Having 2 vectors v,w it can be used to determine the angle between v and w: • (v,w) = acos (v.w / (|v| * |w|)) • For normalized vectors: • (v,w) = acos (v.w)

  14. 3D Basics • The dot product determines the INNER angle between v and w • always 0 <= (v,w) <= 180 • v.w > 0 => (v,w) < 90° • v.w < 0 => (v,w) > 90° • in 2D direction of angle can be determined by • sign(vx*wy – vy*wx)

  15. 3D Basics The Cross Product v x w = ( vy*wz – vz*wy, no x comp. vx*wz – vz*wx, no y comp. vx*wy – vy*wx) no z comp. = |v| * |w| * sin((v,w)) * n with n being a normal vector: n orthogonal to v and w

  16. 3D Basics • The result of the cross product is a vector ! • (The result of the dot product is a scalar value) • The cross product gives us the NORMAL vector to the plane defined by v and w. This is an extremely important tool in game programming (lighting, physical modelling,…)

  17. 3D Basics Basic 3D Transformations To move/animate objects or to change the camera’s position we have to transform the vertices defining our objects.

  18. 3D Basics • The basic transformations are • Scaling • Translation • Rotation

  19. 3D Basics Scaling Component wise multiplication with scaling vector s = (sx,sy,sz): S(v,s) = (sx*vx, sy*vy, sz*vz) y v = (x, y, z) X S(v,s) = (2x,1y, 3z), with s = (2,1,3) z

  20. 3D Basics Translation (Shift) Component wise addition with translation vector t = (tx, ty, tz) T(v,t) = (tx+vx, ty+vy, tz+vz) y t v = (x, y, z) v + t X z

  21. 3D Basics Rotation To make it easier: 2D rotation first: Defined by center c and angle a: R(v,c,a) Rotation around center can be described by translation and rotation around origin: v  T(v,-c)  R(v,0,a)  T(v,c) We therefore only need to define the rotation around the origin, R(v,0,a) =: R(v,a)

  22. 3D Basics Rotation around origin The counterclockwise (=positive angle) 2D rotation is described by : R(v,a) = (cos(a)*vx-sin(a)*vy, sin(a)*vx+cos(a)*vy)

  23. 3D Basics Rotation around origin written as matrix:

  24. 3D Basics 3D Rotation Defined by angle, center and rotation axis. As in 2D case, the center can be translated to origin. The rotation around an arbitrary axis can be substituted by subsequent rotation around the main coordinate axes.

  25. 3D Basics We therefore only need to define the rotation around the x, y and z axis.

  26. 3D Basics Rotation around x axis: y X z

  27. 3D Basics Rotation around y axis: y X z

  28. 3D Basics Rotation around z axis: y X z

  29. 3D Basics The order of rotation is NOT exchangeable ! e.g. R(R(v,a1,X),a2,Y)  R(R(v,a2,Y),a1,X)

  30. 3D Basics Combinations of transformations can be described by Matrix Multiplication

  31. 3D Basics Remember ? = *

  32. 3D Basics Remember ? = *

  33. 3D Basics With Rx being a rotation matrix around the X axis, Ry being a rotation matrix around the Y axis, Ry * Rx * v is a rotation of v around X followed by a rotation around Y. Since Ry*Rx = Rc is a single 3x3 matrix, the 2 rotations can be written as Rc * c, i.e. a single rotation.

  34. 3D Basics If we describe all transformations as matrices, the combination of subsequent transformations can be written as matrixmultiplication, and, if all parameters are known, as a SINGLE transformation matrix !

  35. 3D Basics Rotation was already defined as matrix. Here comes scaling:

  36. 3D Basics What about translation ? Impossible as 3x3 matrix, since addition not multiplication is involved. Here comes a nice trick: increase the dimension !

  37. 3D Basics Homogeneous Coordinates (x,y,z)  (x,y,z,1) 

  38. 3D Basics Now the translation by (tx,ty,tz) can be written as:

  39. 3D Basics Homogeneous coordinates allow us to describe ALL transformations mentioned as matrix multiplications. Sequences of transformations can hence be described by a SINGLE 4x4 matrix.

  40. 3D Basics Example Transformations translation scaling Rotation (y) Translation by t and Rotation (y) (which one’s first ?)

  41. 3D Basics Projections Though we handle 3D worlds, they are displayed in 2D by our monitors. We have to project our 3D world into 2D.

  42. 3D Basics Orthographic Projection (Parallel Projection) a system of drawing views of an object using perpendicular projectors from the object to a plane of projection… …or…

  43. Illustrations taken from http://engineering-ed.org/CAD/documents/Orthographic%20Projection.ppt 3D Basics Display object by rotation followed by z coordinate removal

  44. 3D Basics Parallel lines…

  45. 3D Basics The six main projections

  46. 3D Basics The six main projections

  47. 3D Basics The six main projections

  48. 3D Basics The projection matrix of the front view is very simple:

  49. 3D Basics • Perspective Projection • Produces a view where the object’s size depends on the distance from the viewer • An object farther away becomes smaller

  50. 3D Basics Perspective Projection

More Related