Computer
Graphics
Summary
Chapter 1: Introduction to Computer Graphics
Overview of Computer Graphics
Computer graphics is the field of creating, manipulating, and rendering visual content using
computers.It is widely used in movies, video games, virtual reality, and various simulations.
A Historical Perspective
One of the early breakthroughs in computer graphics was in movies.
A notable example is Terminator 2: Judgment Day (1991),
which demonstrated the potential of CGI (Computer-Generated
Imagery) in filmmaking.
Since then, the field has evolved significantly, leading to more realistic
and immersive visual effects.
Computer graphics can be divided into two main categories:
•
Computer Animation: Involves creating
sequences of moving images entirely
generated by a computer.
These can be fully animated characters,
scenes, or environments.
•
Visual Effects (VFX): Enhances live-action
footage by integrating digital elements such
as explosions, weather effects, or fictional
creatures.
Unlike animation, VFX blends computergenerated imagery with real-world footage.
This course, based on Introduction to Computer Graphics with OpenGL ES by J. Han,
explores the fundamentals of creating such graphics, with all materials available at
https://github.com/medialab-ku/openGLESbook.
Key Areas of Computer Graphics
5 Major steps in 3D computer graphics production
1. Modeling
Modeling refers to the process of creating digital representations of
objects. These objects can be anything from a simple cube to complex
characters in video games or movies.
Model: Is a digital representation of an object used in computer graphics.
It defines the shape and structure of an object without applying materials
or textures.
Mesh: Is a collection of vertices, edges, and faces that define the shape of
a 3D object. It forms the structural framework of a model.
Polygon Meshes: Is a specific type of mesh made up of polygons (typically triangles or
quadrilaterals) connected by their edges. These are the most common way to represent 3D
models in computer graphics because they are efficient for rendering and animation.
There are many Software Tools dedicated to 3D computer graphics, such as Blender, Maya,
and 3ds Max. Using them, artists perform modeling semi-manually.
The scope of modeling includes creating textures.
Textures: Textures are images applied to a model’s
surface to add details like colors, patterns, and
materials.
2. Rigging
Rigging is the process of creating a skeleton (rig) inside a 3D model. This skeleton defines how
the model moves.
Rig: A rig consists of a series of interconnected bones and joints that control the movement
of a 3D model.
Skinning: is the process of attaching the 3D mesh to the rig so that the model deforms
naturally when animated.
• Example: In a video game, a human character needs to run, jump, and perform actions.
Rigging ensures that these motions look natural.
3. Animation
Animation brings models to life by making them move over time.
Animation creates the illusion of movement by displaying a sequence of
slightly altered images.
Artists design a series of skeletal motions, which the computer
interpolates to produce smooth transitions between poses.
4. Rendering
Rendering is the process of generating an image from a 3D scene by computing how light
interacts with objects.
Rendering converts a 3D scene into a 2D image. This complex process incorporates lighting
and texturing to achieve realism—for instance, shadows are calculated based on light
sources. Realistic rendering is computationally intensive but essential for visual quality.
•
•
Lighting: A crucial component in rendering, as it determines shadows, reflections, and
highlights.
Rendering Output: The final rendered image depends on factors like material
properties, texture mapping, and the light sources in the scene.
5. Post-Processing
Post-processing involves applying additional effects to rendered images to enhance their
realism.
• Motion Blur: A visual effect that simulates how real-world cameras capture moving
objects.
• Other Enhancements: Various techniques can be used to adjust brightness, contrast,
and other visual elements.
Physics-Based Simulation
Physics-based simulations enhance realism by ensuring objects behave according to realworld physics.
Example: In a baseball game, the ball's movement follows physical principles such as gravity
and momentum.
• Mathematical Model: The principle of conservation of momentum is used to calculate
how objects move upon collision.
• Euler’s Method: A numerical technique used to compute object motion over small time
steps based on position, velocity, and acceleration.
Calculating a baseball’s trajectory after being hit involves the conservation of
momentum, expressed as:
Here, ๐๐ and ๐๐ are the masses of the bat and ball, ๐๐๐
and ๐๐๐ are their velocities before collision, and ๐๐๐ and ๐๐๐
are their velocities after collision.
In a simpler 2D simulation (e.g., a shell’s trajectory), the state is
defined by position ๐(๐) and velocity ๐(๐).
Using Euler’s method, these are updated over time steps (e.g.,
Δt=0.1 seconds):
Acceleration ๐(๐) is derived from Newton’s second law (๐ = ๐๐), with gravity ( ๐ ≈
๐๐ ๐/๐๐ ) often being the primary force. An example calculation shows a shell’s position
and velocity evolving under gravity, producing a parabolic trajectory.
Physics-based simulation is integral to modern graphics, especially in games, and modifies
the production pipeline to include simulation alongside animation
Real-Time Graphics
The computer-generated images are called frames.
Frame: is a single moment in an animation.
Videos plays animations frame by frame
• If an animation runs at 24 FPS (frames per second), it means 24 frames will be shown
every second.
Real-time graphics refers to the process of
generating and displaying computer-generated
images, known as frames, at a speed that
appears instantaneous to the human eye. This
typically requires producing at least 30 frames
per second (fps)
Unlike traditional film visual effects (VFX), which
may take minutes, or even hours to render a
single frame to achieve photorealistic quality,
real-time graphics prioritizes speed to enable immediate interaction.
This capability is fundamental to applications such as video games, virtual reality (VR),
augmented reality (AR), and most graphical user interfaces (GUIs) found in devices like
smartphones and computers.
The distinction between real-time and non-real-time graphics lies in their purpose and
execution.
Real-Time Graphics vs. Non-Real-Time Graphics
• Real-Time Graphics: Used in video games and VR applications where frames must be
rendered quickly (30+ fps).
balances quality with performance, ensuring that frames are rendered quickly enough
to respond to user inputs or environmental changes in real time. For instance, in a video
game, a player’s actions—like moving a character—must be reflected on-screen
instantly, requiring the system to complete all rendering tasks within a fraction of a
second.
•
Non-Real-Time Graphics: Used in movies and visual effects, where rendering each
frame can take minutes or even hours to achieve higher quality. focuses on maximizing
visual fidelity without time constraints, allowing for complex calculations like detailed
lighting and reflections.
The focus of this class is mostly on real-time graphics.
Technical Requirements and Constraints of Real-Time Graphics
To achieve real-time performance, graphics systems must adhere to strict timing constraints.
For example, targeting 40 fps means each frame must be fully processed—modeled,
animated, rendered, and displayed—within 25 milliseconds (๐๐๐๐๐ ๐ ๐๐๐๐๐๐
/๐๐ = ๐. ๐๐๐). This
tight deadline demands optimization at every stage of the graphics pipeline. Two key
components enable this efficiency:
1. Optimized Game Engines: These are software
frameworks, such as Unity or Unreal Engine, that
provide pre-built tools and libraries for animation,
rendering, and post-processing.
Game engines streamline development by handling
complex tasks—like calculating object positions or
applying textures—allowing developers to focus on
creative aspects while ensuring performance meets
real-time standards.
In this class, we study the core algorithms embedded
in game engines, not the engines themselves.
2. Hardware Support: Graphics Processing Units (GPUs) are specialized processors
designed to accelerate graphics computations. Unlike general-purpose CPUs,
GPUs excel at parallel processing, performing thousands of calculations simultaneously
to render frames quickly. Real-time graphics relies heavily on GPUs to execute tasks
like lighting and shading within the required time frame.
The interplay between software (game engines) and hardware (GPUs) is critical. For instance,
a game might use a GPU to compute shadows for dozens of objects in a scene while the
engine manages the overall sequence of frames, ensuring smooth playback.
Graphics APIs
Graphics Application Programming Interfaces (APIs) bridge the gap between software and
hardware.
APIs like OpenGL, Direct3D, and OpenGL ES (a subset of OpenGL for embedded systems, such
as mobile devices) provide standardized functions for tasks like texturing or shading. These
functions translate high-level commands from a game engine or application into low-level
instructions that a GPU can execute.
•
OpenGL & Direct3D: Widely used APIs for rendering 3D graphics.
OpenGL (Open Graphics Library) is a cross-platform API launched in 1992 by Silicon
Graphics Inc., It offers functions to define geometry, apply textures, and render
scenes, working across systems like Windows and Linux. OpenGL ES, a lightweight
subset, is optimized for devices like smartphones, balancing efficiency and
capability. This course uses OpenGL ES to study real-time graphics algorithms.
•
OpenGL ES: A subset of OpenGL optimized for mobile and embedded devices.
Integration and Significance
Think of a graphics API as a translator: an application might request “apply a brick texture to
this wall,” and the API converts this into GPU-specific commands to map the texture onto the
wall’s polygon mesh.
OpenGL ES, the focus of this course, is optimized for resource-constrained devices, making it
ideal for studying real-time graphics fundamentals. By learning its algorithms, you’ll
understand how game engines achieve efficiency and how GPUs accelerate rendering.
Applications of Real-Time Graphics
1. Games
Games use real-time graphics for seamless gameplay,
rendering frames (e.g., 40 fps in 25 ms) with engines like
Unreal Engine 5 and GPUs. Physics simulations enhance
realism, as seen in advanced demos.
2. Virtual Reality (VR)
VR creates immersive worlds via head-mounted displays,
using tracking (HMD position) and real-time rendering.
Examples include VR games and simulations like virtual
parasailing with motion simulators.
3. Augmented Reality (AR)
AR overlays digital content on reality, requiring tracking,
3D reconstruction, registration, and rendering.
Applications range from Pokémon GO to industrial tools
(e.g., HoloLens).
Chapter 2: Mathematics: Basics
Overview
This chapter introduces key mathematical concepts such as matrices, vectors, coordinate
systems, dot and cross products, lines, and interpolation, all of which are essential for 3D
graphics computations.
Matrices and Vectors
Matrices and vectors are used extensively in graphics transformations
and calculations.
•
Matrix (๐ × ๐): A rectangular array of numbers arranged in ๐
rows and ๐ columns.
Square Matrix: A matrix where ๐ = ๐.
Matrix Multiplication: If matrix ๐จ has dimensions ๐ × ๐ and matrix ๐ฉ has dimensions
๐ × ๐ , the product results in a matrix of dimension ๐ × ๐ .
For example, a 3 × 2 matrix times a 2 × 3 matrix gives a 3 × 3 matrix.
•
•
Matrix-Vector Multiplication
Vectors are lists of numbers, like(๐, ๐) for 2D or (๐, ๐, ๐) for 3D, written as rows or columns
Multiplying a matrix by a vector changes
the vector’s values
•
OpenGL uses column vectors and the vector-on-the-right representation for matrixvector multiplication, while Direct3D uses row vectors and the vector-on-the-left
representation.
•
Transpose of a Matrix (๐ด๐ป ): Interchanges rows and columns.
Transposition Rule: (๐จ๐ฉ)๐ป = ๐ฉ๐ป ๐จ๐ป .
Identity and Inverse Matrices
•
Identity Matrix (๐ฐ): A square matrix where
all diagonal elements are 1, and all others are 0.
Multiplying any matrix ๐ด by ๐ฐ (Identity
Matrix) gives ๐ด.
•
•
Inverse of a Matrix (๐จ−๐ ): If ๐จ๐ฉ = ๐ฐ, then ๐ฉ is the inverse of ๐จ and vice versa.
Theorem: (๐จ๐ฉ)−๐ = ๐ฉ−๐ ๐จ−๐.
Vector Length and Normalization
•
The length of a vector ๐ is denoted as โ๐โ.
A vector’s length is found with √๐๐ ๐ + ๐๐ ๐ (2D) or √๐๐ ๐ + ๐๐ ๐ + ๐๐ ๐ (3D).
•
Normalization: Dividing a vector by its length ๐/โ๐โ results in a unit vector
(length = 1), which is useful for direction calculations in graphics.
Coordinate System and Basis
A coordinate system consists of an origin and a basis.
• Origin: The fixed reference point in a coordinate system, typically represented as (0,0)
in 2D and (0,0,0) in 3D. All positions are measured relative to this point.
•
•
Basis: A set of vectors used to define a coordinate system. Every point in space is
represented as a linear combination of these basis vectors.
o
Standard Basis: The most commonly used basis in Cartesian coordinates, where
the basis vectors are aligned with the coordinate axes.
o
Non-Standard Basis: A basis where the vectors are not aligned with the
standard axes but can still represent points in space.
Orthonormal Basis: A set of basis vectors that are both perpendicular (orthogonal)
and have unit length (normalized).
o Standard Orthonormal Basis: The typical Cartesian
coordinate system where basis vectors are mutually
perpendicular and have unit length (e.g., ๐1 = (1,0,0) ,
๐2 = (0,1,0) , ๐3 = (0,0,1) in 3D)
Any vector, like (๐, ๐, ๐), can be written using these
basis vectors (e.g., ๐๐๐ + ๐๐๐ + ๐๐๐ ).
o
•
Non-Standard Orthonormal Basis: A rotated or transformed basis where the
vectors remain perpendicular and unit length but are not aligned with the
standard axes.
Non-Orthonormal Basis: A basis where the vectors are not perpendicular or do not
have unit length. This type of basis is used in skewed or stretched coordinate systems.
Example:
Dot Product
The dot product is a fundamental operation in vector mathematics used to determine how
much two vectors point in the same direction.
The dot product of two n-dimensional vectors ๐ and ๐ is:
๐ โ ๐ = ๐๐ ๐๐ + ๐๐ ๐๐ + โฏ + ๐๐ ๐๐
Alternatively, using an angle ๐ฝ :
It allows us to compute the angle between two vectors.
๐ โ ๐ = โ๐โ โ๐โ ๐๐จ๐ฌ(๐ฝ)
Geometric Interpretation
• If ๐ and ๐ are perpendicular, then ๐ โ ๐ = ๐ .
• If ๐ฝ is acute, then ๐ โ ๐ > ๐ .
• If ๐ฝ is obtuse, then ๐ โ ๐ < ๐.
• If ๐ฝ = ๐๐จ (vectors are parallel), then ๐ โ ๐ is maximized.
• If ๐ฝ = ๐๐๐๐จ (vectors point in opposite directions), then ๐ โ ๐ is minimized.
Orthonormal Basis Property: In an orthonormal basis, basis vectors
satisfy:
๐
๐๐ โ ๐๐ = {
๐
๐๐ ๐ = ๐
๐๐ ๐ ≠ ๐
Cross Product
The cross product is a mathematical operation
that finds a vector perpendicular to two given
vectors in three-dimensional space.
The cross product of two 3D vectors ๐ =
(๐๐ , ๐๐ , ๐๐ ) and ๐ = (๐๐ , ๐๐ , ๐๐ ) is calculated as:
๐ × ๐ = (๐๐ ๐๐ − ๐๐ ๐๐ , ๐๐ ๐๐ − ๐๐ ๐๐ , ๐๐ ๐๐ − ๐๐ ๐๐ )
Also you can compute cross product of two 3D vectors using the determinant of a matrix
formed by the unit vectors ๐, ๐, ๐ and the components of the vectors.
Example:
๐ฟ๐ = (๐, −๐, ๐) and ๐ฟ๐ = (−๐, ๐, ๐)
Geometric Interpretation
The magnitude of ๐ × ๐ equals the area of the parallelogram spanned by ๐ and ๐ :
โ๐ × ๐ โ = โ๐โโ๐โ ๐ฌ๐ข๐ง(๐ฝ)
Antisymmetry Property:
๐ × ๐ = −(๐ × ๐ )
If ๐ = ๐ , then ๐ × ๐ = ๐ (zero vector).
Line, Ray, and Line Segment
A line, ray, and line segment are different ways of representing paths in space.
Point ๐ : A location in space, usually represented as coordinates (๐, ๐, ๐) in 3D.
Parameter ๐ : A variable that controls movement along the path, determining different
positions on the line, ray, or segment.
•
Line: An infinite path that extends in both
directions without end. It is defined by a
parametric equation:
๐(๐) = ๐๐ + ๐(๐๐ − ๐๐ ),
๐ ∈ (−∞, ∞)
This means the line passes through the points ๐๐ and ๐๐ , and extends infinitely in both
directions.
•
Ray: A portion of a line that starts at one point
and extends infinitely in one direction. It is
defined similarly, but with ๐ > ๐ :
๐(๐) = ๐๐ + ๐(๐๐ − ๐๐ ),
•
๐ ∈ (0, ∞)
Line Segment: A finite portion of a line that
connects two points. It is defined by restricting ๐
between 0 and 1:
๐(๐) = ๐๐ + ๐(๐๐ − ๐๐ ),
๐ ∈ (0,1)
Linear Interpolation
Linear interpolation (LERP) is a method for finding intermediate points between two given
points along a straight line.
• Point (๐): A position in space that we are calculating.
• Parameter (๐): A value between 0 and 1 that controls the interpolation.
Formula:
๐(๐) = (๐ − ๐)๐โ + ๐ ๐โ,
•
๐๐๐๐๐ ๐ ∈ [๐, ๐]
How it Works:
o If ๐ = ๐, then ๐(๐) = ๐โ, meaning we are exactly at the first point.
o If ๐ = ๐, then ๐(๐) = ๐โ, meaning we are exactly at the second point.
o If ๐ = ๐. ๐, the result is the midpoint between ๐โ and ๐โ.
o The larger ๐, the closer ๐(๐) is to ๐โ; the smaller ๐, the closer it is to ๐โ.
The x, y and zcoordinates of ๐(๐)are defined independently by linear interpolation.
Applications
Suppose that the endpoints are associated with colors ๐๐ and ๐๐ , respectively, where ๐๐ =
(๐น๐ , ๐ฎ๐ , ๐ฉ๐ ) and ๐๐ = (๐น๐ , ๐ฎ๐ , ๐ฉ๐ ). Then, the color ๐(๐) is defined as follows:
Linear Interpolation
(Finding a Vector at a Point on a Line Segment)
Linear interpolation is used not only to find a position between two points but also to compute
other quantities (such as vectors) at an intermediate location.
If a point ๐ lies between two given points ๐โ and ๐โ, the
interpolation factor ๐ is calculated as:
๐=
where:
๐ − ๐๐
๐๐ − ๐๐
•
๐๐ and ๐๐ are the x-coordinates of the given
•
points ๐โ and ๐โ.
๐ is the x-coordinate of the desired point ๐.
Once ๐ is determined, we find the interpolated vector at the
given point using:
๐๐ = (๐ − ๐)๐โ + ๐ ๐โ,
where:
•
•
๐โ and ๐โ are the vectors assigned to ๐โ and ๐โ, respectively.
๐๐ is the vector at the intermediate point.
Barycentric Coordinates
Barycentric coordinates are a coordinate system used to
express the position of a point inside a triangle relative to its
three vertices. This system is particularly useful in computer
graphics for tasks like texture mapping, shading, and point-intriangle tests.
Definition
For a given triangle with vertices ๐๐ , ๐๐ , and ๐๐ , any point ๐ inside the triangle can be
expressed as a weighted sum of the three vertices:
๐ท = ๐๐จ + ๐๐ฉ + ๐๐ช
where ๐, ๐, ๐ are the barycentric
coordinates, and they satisfy:
๐ + ๐ + ๐ = ๐
•
How It Works:
o If ๐ is exactly at ๐๐ , then ๐ = ๐ and ๐ = ๐ = ๐.
o If ๐ is on the edge between ๐๐ and ๐๐ , then ๐ = ๐ and ๐ + ๐ = ๐.
o If ๐ is at the triangle's centroid (center), then ๐ = ๐ = ๐ = ๐/๐.
Exmples:
Point ๐ coordinates:
Applications of Barycentric Coordinates in Computer Graphics
1. Texture Mapping: Used to map textures onto 3D models smoothly by interpolating
texture coordinates.
2. Shading & Color Interpolation: Helps in smooth shading (e.g., Gouraud shading),
where vertex colors are interpolated across a triangle.
Chapter 2 Exercises
Answer:
Answer:
Chapter 3: Modeling in Computer Graphics
Introduction
Modeling in computer graphics involves creating digital representations of objects. A key
approach to modeling is using polygon meshes, which approximate smooth surfaces using a
collection of polygons, typically triangles. This chapter explores polygon meshes, their
representations, surface normals, and the process of exporting/importing 3D models.
Polygon Mesh
Mesh: Is a collection of vertices, edges, and faces that define the shape of a 3D object. It
forms the structural framework of a model.
Polygon Meshes: Is a specific type of mesh made up of polygons (typically triangles or
quadrilaterals) connected by their edges.
These are the most common way to represent 3D models in computer graphics because they
are efficient for rendering and animation.
There are two ways to represent surfaces:
• Implicit representation defines surfaces using mathematical functions (using
equations) (e.g., sphere equations).
•
Explicit representation (polygon meshes) directly defines objects using a set of
vertices and faces.
In real-time applications like games, the explicit polygon mesh is preferred because GPUs
are designed to process polygons efficiently.
However, a polygon mesh is not an accurate representation
but an approximate one, as its vertices sample points on a
smooth surface, not capturing the exact shape.
The simplest polygon is a triangle, In a typical closed mesh (one with no gaps), the number
of triangles is about twice the number of vertices. For example, a mesh with 100 vertices
has roughly 200 triangles.
While triangle meshes are widely used, quad meshes (made of four-sided polygons) are often
preferred during the modeling stage because they are easier to work with.
Triangle Mesh vs. Quad Mesh
• A triangle mesh is a collection of interconnected triangles, commonly used because
triangles are always planar and easy to process.
•
A quad mesh consists of four-sided polygons. It is often used in modeling because it
provides smoother surface deformations.
A quad mesh can be converted to a triangle mesh by splitting each quad into two
triangles.
Mesh Simplification and Refinement
The number of vertices in a mesh determines its resolution,
it’s described as level of detail (LOD).
Higher resolution means more vertices, making the mesh closer to the original smooth
surface but requiring more processing time.
This creates a tradeoff between accuracy and efficiency.
•
Simplification reduces the number of polygons while maintaining shape, improving
performance.
•
Refinement increases polygon count for greater detail, making the model appear
smoother.
Polygon Mesh Storage: Non-Indexed and Indexed Representation
Polygon meshes are stored in memory for processing and It can be stored in two main ways:
Non-Indexed Representation
•
Stores every vertex separately in vertex array, listing all vertices for each polygon,
and three vertices are read in order to form a triangle.
•
This method is Inefficient because many vertices are repeated, leading to
unnecessary memory usage.
Note: Vertices in a triangle follow a counterclockwise (CCW) order to ensure correct
rendering and back-face culling. The starting vertex is chosen to maintain consistency across
all triangles but does not affect the shape.
Indexed Representation
•
•
•
Uses a vertex array to store unique vertices.
Uses an index array to reference vertices and define polygons.
More efficient since each vertex is stored only once, reducing redundancy.
The vertex array can also store additional data like normals or colors, not just positions.
The space saved by removing duplicates in the vertex array outweighs the extra space
needed for the index array, making this method more efficient.
Surface Normals
Surface normals are vectors perpendicular to a polygonal
surface. They are used for lighting calculations and shading in
rendering.
Triangle Normal Calculation
Given a triangle with vertices ๐๐ , ๐๐ , ๐๐ :
Ordered counter-clockwise (CCW), define two vectors:
(from ๐๐ to ๐๐ ): ๐๐ = ๐๐ − ๐๐
(from ๐๐ to ๐๐ ): ๐๐ = ๐๐ − ๐๐
The triangle’s normal is computed using the cross
product:
๐ต=
๐๐ × ๐๐
โ๐๐ × ๐๐ โ
This normal is a unit vector (length 1) and points outward if the vertices are ordered CCW,
following the right-hand rule.
Importance of Vertex Order in Normals
• Counterclockwise (CCW) Order: If the vertices of a triangle are arranged in
counterclockwise order when viewed from the front, the computed normal will point
outward, away from the surface. This is the correct orientation for rendering in most
graphics applications.
•
Clockwise (CW) Order:
If the vertices are arranged in clockwise
order, the computed normal will point
inward, into the surface. This can cause
rendering errors, as lighting calculations
and visibility checks will be incorrect.
The triangle’s normal will computed by:
๐ต=
•
๐๐ × ๐๐
โ๐๐ × ๐๐ โ
Why It Matters: Many graphics engines use the direction of the normal to determine
which side of the surface is visible (backface culling). Incorrectly oriented normals can
result in missing or incorrectly shaded surfaces.
Vertex Normals
Vertex normals are also important, as they approximate the normal of the smooth surface at
each vertex.
A vertex normal is calculated by averaging the normals of all triangles sharing that vertex.
•
Each vertex normal is computed by
averaging the normals of all triangles sharing
that vertex.
•
Vertex normals help achieve smooth
shading effects.
Modeling tools like 3ds Max compute these vertex normals, which are stored in the vertex
array for use in rendering.
Exporting and Importing 3D Models
3D models are often created in offline modeling software (e.g., Blender, 3ds Max) and then
imported into applications (e.g., game engines).
Exporting
• Exporting is the process of saving the mesh data (3D models) in a format that other
programs can read.
• Common export formats: .obj.
• Some applications provide scripting tools (e.g., MAXScript in 3ds Max) for exporting.
Importing
• The process of loading an exported model into a different application.
• Parsing the exported file allows reconstructing the vertex and index arrays.
Example: Importing an .OBJ File
• Vertex data: Specifies positions of the vertices.
• Face data: Defines how vertices are connected to form polygons.
• Normals and textures: Additional attributes stored for rendering.
Chapter 3 Exercises
Answer:
Vertex
Array
p
q
r
s
0
1
2
3
Index
Array
0
1
2
3
4
5
0
1
2
3
1
0
๐๐
๐๐
Answer:
Vertex
Array
0
1
2
3
(0, 0, 0)
(1, 0, 0)
(0, 1, 0)
(0, 0, 1)
Index
Array
0
2
1
0
1
3
0
3
2
1
2
3
๐๐
๐๐
๐๐
๐๐
Answer:
The triangular mesh has 8 triangles
Non-Indexed Representation
Each triangle lists 3 vertices in the vertex array, even if shared.
For 8 triangles: ๐ × ๐ = ๐๐ elements in vertex array
Indexed Representation
The triangular mesh has 8 triangles made of 6 unique
vertices,
so the vertex array has 6 elements.
4
5
3
The index array defines each triangle with 3 indices. For 8
triangles: ๐ × ๐ = ๐๐ elements in index array.
1
6
2
Answer:
• Latitude lines run parallel to the equator, dividing the sphere into
horizontal slices. They range from -90° (South Pole) to 90°
(North Pole).
•
Longitude lines run from the North Pole to the South Pole,
dividing the sphere vertically. They range from -180° to 180°.
Calculating the Number of Vertices
• Latitude Steps: From -90° to 90° in 10° steps gives:
๐๐๐
= ๐๐
๐๐
However, this only counts the divisions between the latitudes, one pole was
already included in the count and one is not.
Since we include both poles (-90° and 90° as extra points), we add 1:
๐๐ + ๐ = ๐๐ latitude layers (including poles)
Longitude Steps: From -180° to 180° in 10° steps gives:
๐๐๐
= ๐๐
๐๐
Calculating the Total Vertices
• The poles (North and South) are single points, not circles.
•
The middle latitudes (excluding poles) each have 36 longitude divisions.
•
Since there are 19 total latitude layers, and the poles are single points, the
number of circles between them is: ๐๐ − ๐ = ๐๐
So, the total number of vertices is:
(๐๐ × ๐๐) + ๐ = ๐๐๐ Vertices
Answer:
Vertex
Array
0
1
2
3
(0, 0, 0)
(1, 0, 0)
(0, 1, 0)
(0, 0, 1)
Index
Array
0
2
1
0
1
3
3
2
0
1
2
3
๐๐
๐๐
๐๐
๐๐
Answer:
We need to derive the relationship between the number of vertices (๐) and edges (๐) in
a closed triangle mesh, given ๐ = ๐๐ − ๐, where ๐ is the number of faces.
Use Euler’s Formula for a Closed Mesh
For a closed polyhedron (like a triangle mesh), Euler’s formula states:
๐−๐+๐=๐
Substitute the given ๐ = ๐๐ − ๐:
๐ − ๐ + (๐๐ − ๐) = ๐
Simplify the Equation
Combine terms:
๐ + ๐๐ − ๐ − ๐ = ๐ โน ๐๐ − ๐ = ๐
The relationship between ๐ and ๐ is:
๐ = ๐๐ − ๐
Chapter 4: Spaces & Transformations
Introduction
In computer graphics, transformations are essential for manipulating objects within a scene.
They help position, rotate, and scale objects efficiently.
Transformations
Transformations such as rotation, scaling, and translation are represented as matrix
operations, enabling efficient computation in graphics pipelines like OpenGL ES.
1. Translation
Translation moves a point (๐, ๐) by a displacement (๐
๐ , ๐
๐ ):
Translation is an addition, not a linear transformation, so it cannot be directly represented as a
๐๐๐ matrix multiplication.
Homogeneous Coordinates:
A technique for representing translations, rotations, and scaling using
matrix operations.
Introduces an extra coordinate ๐, transforming a 2D point (๐, ๐) is
represented as (๐, ๐, ๐). Translation is then expressed as a ๐๐๐ matrix:
Enables uniform transformation calculations through matrix multiplication
Translation matrix multiplication
The Cartesian coordinates point can be converted into multiple homogeneous coordinates
For example (๐, ๐) → (๐, ๐, ๐), (๐, ๐, ๐), (๐, ๐, ๐)
General Form of Homogeneous Coordinates:
A point (๐, ๐) can be represented as (๐๐, ๐๐, ๐) for any
non-zero ๐.
To convert back to Cartesian coordinates, divide by ๐:
๐๐ ๐๐ ๐
,
, ) = (๐, ๐, ๐)
๐ ๐ ๐
then take the first two components (๐, ๐). For example,
(๐๐, ๐๐, ๐) → (
๐ ๐
(๐, ๐, ๐) → ( , , ๐) = (๐, ๐, ๐) → (๐, ๐).
๐ ๐
In 3D, translation uses 4x4 matrices in homogeneous coordinates (๐, ๐, ๐, ๐):
3D Translation matrix multiplication
2. Scaling
Scaling transforms a 2D vector (๐, ๐)
to(๐′ , ๐′ ) = (๐๐ ๐, ๐๐ ๐),where ๐๐ and
๐๐ are scaling factors along the ๐- and
๐-axes, respectively.
This is represented as matrix
multiplication:
To work with homogeneous coordinates, 2D transformation matrices are extended to ๐๐๐:
Scaling in 3D extends the 2D concept with factors ๐๐ , ๐๐ , ๐๐ :
Example in 3D:
Scaling Types:
•
Uniform Scaling: If ๐๐ = ๐๐ , the scaling is uniform, preserving the shape’s proportions
(e.g., (๐๐ , ๐๐ ) = (๐, ๐)).
•
Non-Uniform Scaling: If ๐๐ ≠ ๐๐ , the scaling distorts the shape (e.g., (๐๐ , ๐๐ ) = (๐, ๐)).
•
Application to Polygons: All vertices of a polygon are scaled using the same matrix to
maintain the shape’s structure.
๐
3. Rotation
Rotation in 2D involves rotating a vector (๐, ๐) by an
angle ๐ฝ around the origin. This can be expressed using
trigonometry and matrix multiplication.
This can be written as a matrix operation:
The matrix ๐น(๐ฝ) is the 2D rotation matrix
By default, the rotation is counter-clockwise.
Example: Rotate the point (๐, ๐) a ๐๐โ degrees counter-clockwise (CCW)
Clockwise Rotation:
To rotate clockwise by ๐ฝ, use −๐ฝ in the matrix: ๐น(−๐ฝ)
Example:
Rotation by −๐ฝ is equivalent to rotation by ๐๐
− ๐ฝ
To work with homogeneous coordinates, 2D transformation matrices are extended to ๐๐๐:
Rotation in 2D
In 2D, rotation always happens around the origin (๐, ๐) unless specified otherwise.
Rotation About a Specific Point in 2D
• If we want to rotate an object around an arbitrary (specific) point (๐, ๐) instead of
the origin, we follow three steps:
1. Translate the object so the rotation point becomes the origin by subtracting
its coordinates::
๐ป(−๐, − ๐)
2. Rotate using the standard 2D rotation matrix.
3. Translate back to the original position:
๐ป(๐, ๐)
The final transformation matrix is: ๐ป(−๐, − ๐) × ๐น(๐ฝ) × ๐ป(๐, ๐)
Example: Rotating a Point Around a Specific Point in 2D
Steps:
Final result:
3D Rotation
In 3D, rotation happens around an axis rather than a fixed point. unlike 2D rotatio
Rotation about the ๐-axis (๐น๐ ): Rotates in the ๐๐plane, leaving ๐ unchanged:
Rotation about the ๐-axis (๐น๐ ):
Using the right-hand rule (Rotates in the ๐๐-plane,
leaving ๐ unchanged:):
Rotation about the ๐-axis (๐น๐ ):
Using the right-hand rule (Rotates in the ๐๐-plane,
leaving ๐ unchanged:):
Direction of Rotation: A positive angle ๐ฝ indicates CCW rotation when the axis points toward
the viewer, following the right-hand rule. A clockwise rotation uses −๐ฝ.
Summary of Transformation Matrices
Transformation
2D Matrix
3D Matrix
Translation
Scaling
Rotation
(origin (๐, ๐))
N/A
Rotation (X-axis)
N/A
Rotation (Y-axis)
N/A
Rotation (Z-axis)
N/A
Transform Composition
Combining Transformations: Multiple transformations can be applied sequentially to an
object. Using homogeneous coordinates, these transformations are represented as 3x3
matrices and can be combined into a single matrix through multiplication.
Example: Rotate a point (๐, ๐) by ๐๐โ CCW, then translate by (๐, ๐):
First, rotate:
Then, translate:
As all transforms are represented in 3๏ด3 matrices, they can be concatenated into a single
matrix.
Applying the combined matrix:๐ป๐น matching the sequential application.
Order matters:
Matrix multiplication is not commutative, meaning the order of transformations matters:
Scaling before translating produces different results than translating before scaling.
๐ป๐น vs. ๐ป๐น๐ป: For a rotation ๐น(๐ฝ) followed by translation ๐ป(๐
๐ , ๐
๐ )
Affine Transformations
An affine transformation in 2D combines linear transformations (e.g., scaling, rotation,
reflection, shearing) with translation.
It is represented as a ๐๐๐ matrix in homogeneous coordinates:
General Form:
, where ๐ณ is a ๐๐๐ linear transformation matrix,
and ๐ is a 2D translation vector.
Property: The third row of an affine matrix is always (๐, ๐, ๐), allowing multiple affine
transformations to be combined into a single matrix.
Example (Rotation, Translation):
Example (Scaling, Rotation, Translation):
An affine matrix applies the linear transformation ๐ณ first, followed by translation by ๐.
โ
For example, in ๐น(๐๐โ ) ๐ป(๐, ๐), ๐ณ is the ๐๐๐ submatrix of ๐น(๐๐ ), but ๐ is modified due to the
composition.
3D Affine Transformations
3D affine transformations mirror 2D concepts, using 4x4 matrices:
General Form:
, where ๐ณ is a ๐๐๐ linear transformation matrix,
and ๐ is a 2D translation vector.
Fourth Row: The fourth row of a 3D affine matrix is always (๐, ๐, ๐, ๐).
Example:
Inverse of Transformation
The inverse of a transformation is a matrix that, when applied, reverses the effect of the
original transformation (undo), bringing the object back to its starting position or state.
1. Inverse of Translation
Translation moves a point by a displacement vector. In 2D, a translation by (๐
๐ , ๐
๐ ) is
represented in homogeneous coordinates as a ๐๐๐ matrix ๐ป(๐
๐ , ๐
๐ )
The inverse of this translation, denoted ๐ป−๐ (๐
๐ , ๐
๐ ), must move the point back to (๐, ๐, ๐). To
reverse a translation by (๐
๐ , ๐
๐ ), we need to translate by the opposite displacement
(−๐
๐ , −๐
๐ ),:
In 3D, translation by (๐
๐ , ๐
๐ , ๐
๐ ) uses a 4x4 matrix and the inverse of this translation
๐ป−๐ (๐
๐ , ๐
๐ , ๐
๐ )
2. Inverse of Scaling
Scaling transforms a point by stretching or shrinking it along each axis. In 2D, a scaling by
factors (๐๐ , ๐๐ ) is represented as ๐บ(๐๐ , ๐๐ )
The inverse of scaling, ๐บ−๐ (๐๐ , ๐๐ ), must return the point to (๐, ๐, ๐). To reverse a scaling by
๐
๐
(๐๐ , ๐๐ ), we scale by the reciprocal factors ( , ), assuming ๐๐ ≠ ๐ and ๐๐ ≠ ๐:
๐๐ ๐ ๐
In 3D, scaling by (๐๐ , ๐๐ , ๐๐ ) uses a ๐๐๐ matrix and the inverse of scaling ๐บ−๐ (๐๐ , ๐๐ , ๐๐ ),
3. Inverse of Rotation
In 2D, a rotation by angle ๐ฝ counterclockwise (CCW) about the origin
The inverse of this rotation, ๐น−๐ (๐ฝ), must rotate the point back to its original position.
Since rotation matrices are orthogonal (i.e., ๐น−๐ ๐น = ๐ฐ), the inverse of a rotation matrix is its
transpose. For ๐น(๐ฝ), the inverse is:
๐น−๐ (๐ฝ) = ๐น๐ป (๐ฝ)
Compute the transpose:
Notice that this matrix is equivalent to a rotation by −๐ฝ:
This means that to undo a CCW rotation by ๐ฝ, we perform a clockwise (CW) rotation by the
same angle, or equivalently, a CCW rotation by −๐ฝ.
Inverse of Rotation in 3D
In 3D, rotations are defined about a specific axis (๐, ๐, ๐)
to undo a counterclockwise (CCW) rotation by an angle ๐ฝ, we perform a clockwise (CW)
rotation by the same angle, which is equivalent to a CCW rotation by −๐ฝ. This applies to
rotations in both 2D and 3D spaces
Spaces
A coordinate space provides a reference for defining object positions. Multiple coordinate
spaces exist in computer graphics, each serving a specific role in rendering objects.
a. Object Space (OS) (Local Space)
•
•
•
This is the local coordinate system of an individual object. Each object has its own OS.
The origin is usually at the object's center.
Used for defining the shape and structure of an object before placing it in the scene.
b. World Space (WS)
•
•
This is the global coordinate system of the entire scene.
Objects are positioned relative to the world origin.
•
The WS serves as a common reference frame, allowing multiple objects to interact and
be rendered together. A point’s coordinates in WS are determined by applying the
object’s transformation (position and orientation) to its OS coordinates.
For instance, the point (๐, ๐, ๐) in the teapot’s OS might transform to (๐๐, ๐, ๐) in WS
after applying the teapot’s pose.
c. View Space (Camera Space)
•
•
The space relative to the camera.
Objects are transformed into this space before projection.
In computer graphics, we need to place 3D objects, such as a teapot, in a virtual scene so
they can be rendered on the screen.
Each object has its own local coordinate system, Object Space (OS), where its shape is
defined.
However, the scene has a global coordinate system World Space (WS), where all objects are
placed together.
Initially, an object’s OS is identical to WS. To place the object in the scene, we apply a world
transform (a combination of rotations, translations, etc.) to move it from OS to WS.
Key Idea: The world transform changes the object’s position and orientation in WS, but its
coordinates in OS remain unchanged.
Rotation and Object-space Basis
Objects and Their Fixed Spaces
Once an object (e.g., a teapot) is modeled, it remains fixed within its object space. Think of the
object as "stuck" to its own coordinate system.
Any changes to its orientation or position are handled by transforming its object space
relative to world space.
Basis Vectors and Rotation
Both world space and object space use a set of three basis vectors to define directions:
•
World Space Basis: {๐๐ , ๐๐ , ๐๐ }, the standard basis where ๐๐ = (๐, ๐, ๐), ๐๐ = (๐, ๐, ๐),
and ๐๐ = (๐, ๐, ๐), representing the ๐, ๐, and ๐ axes.
•
Object Space Basis: {๐, ๐, ๐}, which initially matches the world space basis but
changes when the object is rotated.
These bases are orthonormal, meaning each vector is unit length (magnitude 1) and
perpendicular to the others.
When a rotation ๐น (e.g., about the ๐ -axis) is applied, the object space basis {๐, ๐, ๐}, rotates
with the object. For example:
• If ๐ starts as = (๐, ๐, ๐), after a rotation ๐น, it becomes (๐๐ , ๐๐ , ๐๐ ),.
•
Similarly, ๐ (initially (๐, ๐, ๐)) becomes (๐๐ , ๐๐ , ๐๐ ), and ๐ (initially (๐, ๐, ๐)) becomes
(๐๐ , ๐๐ , ๐๐ ).
These new vectors define the teapot’s orientation in world space after the rotation.
Chapter 4 Exercises
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )