Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D...
Transcript of Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D...
![Page 1: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/1.jpg)
Computergrafik
Matthias Zwicker
Universität Bern
Herbst 2016
![Page 2: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/2.jpg)
StaffInstructor
• Matthias Zwicker ([email protected])
Teaching assistant
• Marco Manzi ([email protected])
• Tiziano Portenier ([email protected])
Student teaching assistants
• Adrian Wälchli([email protected])
• Paul Frischknecht([email protected])
2
![Page 3: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/3.jpg)
Today
• Course overview
• Course organization
• Vectors and coordinate systems
3
![Page 4: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/4.jpg)
Computer graphics
4
![Page 5: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/5.jpg)
Computer graphics
• „Technology to create images using
computers“
• Core areas
– Rendering
– Modeling
– Animation
5
![Page 6: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/6.jpg)
Rendering• Synthesis of 2D image from 3D scene
descriptionhttp://en.wikipedia.org/wiki/Rendering_(computer_graphics)
– Rendering algorithms interpret data structures that represent scenes using geometric primitives, material properties, and lights
• Input
– Data structures that represent scene (geometry, material properties, lights, virtual camera)
• Output
– 2D image (array of pixels)
– Red, green, blue values for each pixel
6
![Page 7: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/7.jpg)
Rendering
• Wealth of algorithms with different
objectives
– Photorealistic
– Interactive
– Artistic
7
![Page 8: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/8.jpg)
Photorealistic rendering
See also http://en.wikipedia.org/wiki/Rendering_(computer_graphics) 8
![Page 9: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/9.jpg)
Photorealistic rendering
• Physically-based simulation of light,
materials, and camera
– Physical model expressed using the rendering
equation, http://en.wikipedia.org/wiki/Rendering_equation
– Shadows, realistic illumination, multiple light
bounces
• Slow, minutes to hours per image
• Special effects, movies
• Not in this class
9
![Page 10: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/10.jpg)
Interactive rendering
10
![Page 11: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/11.jpg)
Interactive rendering• Focus of this class
• Produce images within milliseconds
• Interactive applications (games, …)
• Using specialized hardware, graphics processing units (GPUs)
• Standardized APIs (OpenGL, DirectX)
• Often “as photorealistic as possible”
– Hard shadows, fake soft shadows, only single bounce of light
11
![Page 12: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/12.jpg)
Artistic rendering• Also “non-photorealistic rendering”
http://en.wikipedia.org/wiki/Non-photorealistic_rendering
• Stylized
• Artwork, illustrations, data visualization
12
![Page 13: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/13.jpg)
Modeling
• Creating 3D geometric data
– The “model” or the “scene”
• Modeling techniqueshttp://en.wikipedia.org/wiki/3D_modeling
– Manually, using software tools
– Algorithmic (procedural)
– Physical measurements, 3D scanning
13
![Page 14: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/14.jpg)
3D modeling tools
• Similar to plastic arts such as sculpting
• Professional tools
– Autodesk (Maya, AutoCAD), LightWave 3D, …
• Free software
– Blenderhttp://www.blender.org/
• Not as easy to
use as Notepad…
Maya Screenshot14
![Page 15: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/15.jpg)
Procedural modeling
• By writing programs, algorithmshttp://en.wikipedia.org/wiki/Procedural_modeling
Procedural tree
Procedural city
See also http://www.esri.com/software/cityengine/ 15
![Page 16: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/16.jpg)
Physical measurementsScanned statue (laser scan)http://graphics.stanford.edu/data/3Dscanrep/• 3D scanning
http://en.wikipedia.org/wiki/3D_scanner
• Other imaging devices
Tomographyhttp://en.wikipedia.org/wiki/Ct_scan
Magnetic resonance imaging
(MRI scanning)http://en.wikipedia.org/wiki/Mri_scan
Etc.
16
![Page 17: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/17.jpg)
Surface representation• Basic 3D models consist of collections of
triangles (triangle mesh, https://en.wikipedia.org/wiki/Triangle_mesh)
• Each triangle consists of 3 vertices
• Each vertex contains
– xyz position
– Optionally otherattributes such ascolor, etc.
• Many more sophisticatedrepresentations existhttp://en.wikipedia.org/wiki/Nonuniform_rational_B-splinehttp://en.wikipedia.org/wiki/Subdivision_surface
17
![Page 18: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/18.jpg)
Animation
• Deforming or editing the data
• Change over time
• Faces, articulated characters, fire, water,
rigid objects, elastic objects, fracturing
objects, …
18
![Page 20: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/20.jpg)
Physics simulation
http://www.youtube.com/watch?v=XH28gAb8FiQ
See also http://www.nvidia.com/object/physx_new.html 20
![Page 21: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/21.jpg)
In this classThe Basics…
• Rendering 3D models
– Camera simulation
– Interactive viewing
– Lighting, shading
• Modeling
– Triangle meshes
– Smooth surfaces
• Experience with linear algebra, Java, OpenGL, GPU programming
• Background for advanced topics
21
![Page 22: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/22.jpg)
Schedule1. Introduction
2. Homogeneous coordinates, transformations
3. Projection
4. Rasterization
5. Color
6. Shading I
7. Shading II
8. Textures
9. Scene management
10. Curves
11. Surfaces
12. Advanced shading, shadows
13. Virtual reality
14. Reserve22
![Page 23: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/23.jpg)
Questions?
23
![Page 24: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/24.jpg)
Today
• Course overview
• Course organization
• Vectors and coordinate systems
24
![Page 25: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/25.jpg)
Course organization
Lecture
• Fridays, 14:00-16:00
• Engehaldenstrasse 8, Raum 001
Exercises
• Fridays, 16:00-17:00
• Engehaldenstrasse 8, Raum 001
25
![Page 26: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/26.jpg)
Class web page
• Overview of topicshttp://www.cgg.unibe.ch/teaching/computergrafik
26
![Page 27: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/27.jpg)
Ilias• Search for “Computergrafik HS2016” in
https://ksl.unibe.ch, Ilias link provided
• Use your campus account to log in
• Join without password
• All relevant content for the class
– Schedule
– Slides
– Project descriptions
– Scanned chapters from textbook
– Online forum for questions and discussion
• Take advantage of online forum to get advice!
27
![Page 28: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/28.jpg)
Textbooks
• Fundamentals of Computer
Graphics, Peter Shirley,
2nd or 3rd edition (recommended)
– Available in the student bookstore
– Scanned chapters on Ilias
• Opengl Shading Language, Rost,
Addison Wesley, 2nd edition
(optional)
28
![Page 29: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/29.jpg)
Exercises• Six programming projects
• Two exercise series on paper
• Successful completion of exercises is requirement for exam
– Each assignment is worth 10 points
– Total 80 points
– Requirement is 75% (60 points)
• Late penalty
– 50% of original score
– Exceptions for military service, illness
29
![Page 30: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/30.jpg)
Programming Projects• Assignments and schedule on Ilias
• Java base code and documentation on githubhttps://github.com/mzwicker/Computergrafik-Basecode
• Turn-in electronically on Ilias anddemonstration to TA in ExWi pool
– More details, how to sign-up in exercise session
30
![Page 31: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/31.jpg)
Programming Projects• Use ExWi pool or your own computer
• Need support of OpenGL 3.0 or later
– Update your graphics driver!
• Older Intel integrated graphics processors do not currently support OpenGL 3.0
– “HD graphics” series, Sandy Bridge processors are first to provide supporthttp://en.wikipedia.org/wiki/Intel_GMA
– For Intel integrated graphics on Linux, drivers may not be available that support our code
31
![Page 32: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/32.jpg)
Programming ProjectsBuild your own 3D rendering engine
• Project 1: Matrices, Vectors, and Coordinate Transformations
• Project 2: Interactive Viewing
• Project 3: Rasterization
• Project 4: Lighting and Texturing
• Project 5: Scene Graphs
• Project 6: Curves and Surfaces, Virtual Reality
32
![Page 33: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/33.jpg)
Exercises on paper
• Two exercise series on paper
• Schedule TBA
• As preparation for exam
33
![Page 34: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/34.jpg)
Prerequisites
Familiarity with
• Linear algebra (matrix calculations)
• Java
• Object oriented programming
34
![Page 35: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/35.jpg)
Questions?
35
![Page 36: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/36.jpg)
Today
• Course overview
• Course organization
• Vectors and coordinate systems
36
![Page 37: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/37.jpg)
3D scene representation
• Goal: describe 3D scenes
– Position, orientation, motion of objects
– Relation of objects to virtual camera
– Projection of scene onto image plane
• Linear algebra provides mathematical tools
– Vectors, coordinate systems, matrices, etc.
– As little abstract theory as possible in this
class
37
![Page 38: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/38.jpg)
Topics today
Linear algebra & vector geometry review
• Vectors
• Linear combination, linear dependency
• Coordinate systems
• Dot product, cross product
• Normal vectors
• Representation of planes using vectors
38
![Page 39: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/39.jpg)
Vectors
• Direction and length in 3D
– No anchor point
• Vectors can describe
– Difference between two 3D points
– Speed of an object
• Vectors are in bold-face
39
![Page 40: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/40.jpg)
Vectors
Multiplication by scalar
40
![Page 41: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/41.jpg)
Vectors
Addition
41
![Page 42: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/42.jpg)
Vectors
Addition
42
![Page 43: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/43.jpg)
Vectors
Linear combination
43
![Page 44: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/44.jpg)
Vectors
Linear combination
Linearly dependent vectors
• A set of vectors is linearly
dependent if there exist scalars such
that
• Otherwise, they are linearly independent44
![Page 45: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/45.jpg)
Coordinate systems• Describe any vector with respect to three
basis vectors
• The basis vectors form a coordinate system 45
![Page 46: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/46.jpg)
Coordinate systems
• Any three vectors that are linearly
independent could be used as a basis
– Different lengths
– Not perpendicular to each other
46
![Page 47: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/47.jpg)
Coordinate systems
• Any three vectors that are linearly
independent could be used as a basis
– Different lengths
– Not perpendicular to each other
• Why linearly independent?
• Why exactly three vectors?
• Other coordinate systems?
47
![Page 48: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/48.jpg)
Coordinate systems
Cartesian coordinate systemshttp://en.wikipedia.org/wiki/Cartesian_coordinate_system
• Basis vectors
– Have unit length
– Are perpendicular to each other
• Orthonormal
48
![Page 49: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/49.jpg)
Coordinate Systems
Handedness
Right handed Left handed
49
![Page 50: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/50.jpg)
Vector arithmetic using coordinates
a
ax
ay
az
b
bx
by
bz
a b
ax bx
ay by
az bz
a b
ax bx
ay by
az bz
sa
sax
say
saz
a
ax
ay
az
50
![Page 51: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/51.jpg)
Vector Magnitude• The magnitude (length) of a vector is:
• A vector with length=1.0 is called a unit vector
• We can also normalize a vector to make it a unit vector
• Unit vectors are often used as surface normals
v2 vx
2 vy2 vz
2
v vx2 vy
2 vz2
v
v
51
![Page 52: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/52.jpg)
Questions?
52
![Page 53: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/53.jpg)
Dot product
• Scalar value that tells us something about
the relationship between two vectors
– Product of lengths of vectors and cosine of
angle between vectors
• Definition does not refer to a coordinate
system
– Result is independent of Cartesian coordinate
system
53
![Page 54: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/54.jpg)
Dot product
• If a·b > 0 then θ < 90º
– Vectors point in the same
general direction
• If a·b < 0 then θ > 90º
– Vectors point in opposite
direction
• If a·b = 0 then θ = 90º
– Vectors are perpendicular
– (or one or both of the vectors is degenerate
(0,0,0))
54
![Page 55: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/55.jpg)
• Result is independent of coordinate
system!
• What is the meaning of ?
Dot product using coordinates
a b aibia b axbx ayby azbz
a b a b cos
55
![Page 56: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/56.jpg)
a
b
a b a b cos
cos a b
a b
cos1a b
a b
Angle between vectors
56
![Page 57: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/57.jpg)
Dot products with unit vector
a
u
a·u
• If |u|=1.0 then a·u is the length of the
orthogonal projection of a onto u
57
![Page 58: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/58.jpg)
Dot products with unit vectors
a=b
a·b = 1
a b 1.0
a b cos
58
![Page 59: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/59.jpg)
Dot products with unit vectors
ba
0 < a·b < 1
a·b = 1
a·b
a b 1.0
a b cos
59
![Page 60: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/60.jpg)
Dot products with unit vectors
ba
0 < a·b < 1
a·b = 1
a·b
a b 1.0
a b cos
a·b = 0
60
![Page 61: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/61.jpg)
Dot products with unit vectors
ba
0 < a·b < 1
a·b = 1
a·b
a b 1.0
a b cos
a·b = 0
-1 < a·b < 0
61
![Page 62: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/62.jpg)
Dot products with unit vectors
ba
0 < a·b < 1
a·b = 1
a·b
a b 1.0
a b cos
a·b = 0
-1 < a·b < 0
a·b = -1
62
![Page 63: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/63.jpg)
Surface normals• Vectors are direction and length in 3D
• Can describe
– Difference between two 3D points
– Speed of an object
– Surface normals: directions perpendicular to tangent plane of surfaces
Surface normals Surface
Normal vector
Normal
Tangent
plane
http://en.wikipedia.org/wiki/Normal_(geometry)
63
![Page 64: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/64.jpg)
Representing planes
• A plane can be defined by
– Its closest distance to the origin
– and its normal vector
• How can we determine if a point lies on
the plane using the dot product?
64
![Page 65: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/65.jpg)
Cross product
• Written as a x b
• A vector perpendicular to a and b
– In the direction defined by the right hand rule
– Length is area of parallelogram spanned by a
and b
• Definition does not refer to coordinate
system!
65
![Page 66: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/66.jpg)
Cross product
• If vectors a, b are unit length and
perpendicular, then a, b, a x b
is a right handed coordinate system
• a x b = -(b x a)
66
![Page 67: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/67.jpg)
Cross product
Vectors lie in the plane of the
projection screen. Does point
towards you or away from you? What
about ?
is a vector perpendicular to
both a and b, in the direction
defined by the right hand rule
a b
67
![Page 68: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/68.jpg)
area of parallelogram ab
if a and b are parallel
(or one or both degenerate)
a b
a b a b sin
a b
a b 0
Cross product
is a vector perpendicular to
both a and b, in the direction
defined by the right hand rule
68
![Page 69: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/69.jpg)
Cross product
• Using coordinates
69
![Page 70: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/70.jpg)
Questions?
70
![Page 71: Matthias Zwicker Universität Bern Herbst 2016zwicker/courses/computergraphics/...Build your own 3D rendering engine •Project 1: Matrices, Vectors, and Coordinate Transformations](https://reader030.fdocuments.us/reader030/viewer/2022041102/5edd2807ad6a402d6668247d/html5/thumbnails/71.jpg)
Coming up
Exercise session
• Introduction to the Java base code
• Representation of 3D shapes using triangle
meshes
Next class
• Matrices and transformations
71