Nima Kalantari
CSCE 441 - Computer Graphics
Linear Algebra
Some slides from Ravi Ramamoorthi
Motivation
Important concepts
Points
Vectors
=
x
y
Normalized vectors
Coordinates
x
y
Operations
Point addition and subtraction
x
y
Vector Addition
a
b
a+b
= b+a
Vector Multiplication
Dot (scalar) product
Dot (scalar) product
Properties
Dot product: some applications in CG
Angle between two vectors
Angle between two vectors
Dot product of two unit-vectors is the
cosine of the angle between them
Projections (of b on a)
Length
Projections (of b on a)
Length
Vector
Vector Multiplication
Coordinate systems
z
x
y
x
z
y
Left- and right-handed coordinates
Image from Drew Noaks
Examples
Image from Drew Noaks
z
x
y
x
z
y
Left-handed
Right-handed
Cross (vector) product
Right-hand rule
Image from Wikipedia
Cross (vector) product
Cross product: Cartesian formula?
Cross product: Cartesian formula?
Cross product: Cartesian formula?
Cross product
area of the parallelogram
Cross product: Properties
Cross product: Properties
Matrices
Matrices
What is a matrix?
Matrix-matrix multiplication
Matrix-matrix multiplication
Matrix-matrix multiplication
(row i of 1st matrix) x (column j of 2nd matrix)
Matrix-matrix multiplication
(row i of 1st matrix) x (column j of 2nd matrix)
Matrix-matrix multiplication
(row i of 1st matrix) x (column j of 2nd matrix)
Matrix-matrix multiplication
(row i of 1st matrix) x (column j of 2nd matrix)
Matrix-matrix multiplication
Matrix-matrix multiplication
Transpose of a Matrix
Transpose of a Matrix
Transpose of a Matrix
Identity matrix and inverses
Vector multiplication in matrix form
Dual matrix of vector
Assignment 1
What is OpenGL?
What OpenGL does not have?
Assignment 1 code structure
int main()
{
InitializeWindowAndEvents();
while (WindowIsOpen() == true)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}
Assignment 1 code structure
int main()
{
InitializeWindowAndEvents();
while (glfwWindowShouldClose(window) == false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}
Creates a window and mouse and keyboard events
Assignment 1 code structure
void InitializeWindowAndEvents()
{
…
glfwInit();
window = glfwCreateWindow(…);
glfwMakeContextCurrent(window);
glfwSetCursorPosCallback(window, CursorPositionCallback);
glfwSetCharCallback(window, CharacterCallback);
…
}
void CursorPositionCallback(GLFWwindow* window, double xpos, double ypos)
{
…
}
Assignment 1 code structure
int main()
{
InitializeWindowAndEvents();
while (glfwWindowShouldClose(window) == false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}
Creates a window and mouse and keyboard events
Assignment 1 code structure
int main()
{
InitializeWindowAndEvents();
while (glfwWindowShouldClose(window) == false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}
Assignment 1 code structure
int main()
{
InitializeWindowAndEvents();
while (glfwWindowShouldClose(window) == false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}
red
green
blue
alpha
usually called once outside the loop
Assignment 1 code structure
int main()
{
InitializeWindowAndEvents();
while (glfwWindowShouldClose(window) == false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}
Fills in the framebuffer either from geometric primitives or images
Assignment 1 code structure
int RenderTheScene()
{
glDrawPixels(…, frameBuffer);
}
Assignment 1 code structure
void main()
{
InitializeWindowAndEvents();
while (glfwWindowShouldClose(window) == false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
RenderTheScene();
UpdateWindowAndEvents();
}
return 0;
}