Computer Graphics Cheatsheet
Computer Graphics Cheatsheet
Computer Graphics Cheatsheet
⃗v = b⃗t c ⇒ b⃗t M c
Where the matrix M depends on the linear transformation.
1
Lecture 5: Respect
Left-of rule: Point is transformed w.r.t. the frame that appears immediately to the left of the
transform matrix.
f⃗t ⇒ f⃗t S
f⃗t is transformed by S with respect to f⃗t .
f⃗t = a⃗t A−1 ⇒ a⃗t SA−1 :
f⃗t is transformed by S with respect to a⃗t .
p̃ = f⃗t c ⇒ f⃗t Sc:
p̃ is transformed by S with respect to f⃗t .
p̃ = f⃗t c = a⃗t A−1 c ⇒ a⃗t SA−1 c = f⃗t ASA−1 c:
p̃ is transformed by S with respect to a⃗t .
p̃ = o⃗t c = w
⃗ t Oc = e⃗t E −1 Oc
Lecture 8: Arcball
This is black magic
Lecture 9: Quaternion 2
ω
Quaternion , where ω is scalar and ĉ is 3D coordinate vector
ĉ
ω αω
α =
ĉ αĉ
ω1 ω2 ω1 ω2 − ĉ1 · ĉ2
=
ĉ2 ĉ2 ω1 ĉ2 + ω2 ĉ1 + ĉ1 × ĉ2
cos( θ2 )
: rotation of angle θ about unit length axis k̂
sin( θ2 )k̂
−1
cos( θ2 ) cos( θ2 )
0
Rotation:
sin( θ2 )k̂ ĉ sin( θ2 )k̂
−1
cos( θ2 ) cos( θ2 ) cos( −θ
2 )
where = =
sin( θ2 )k̂ −sin( θ2 )k̂ sin( −θ
2 )k̂
2
1−α α
cos( θ20 ) cos( θ21 )
SLERP: +
sin( θ20 )k̂0 sin( θ21 )k̂1
α
cos( θ2 ) cos( αθ
2 )
where =
sin( θ2 )k̂ sin( αθ
2 )k̂
3
Lecture 12: Geometric Modeling
Implicit surface - torus: (x2 + y 2 + z 2 − R2 − a2 )2 − 4R2 (x2 + y 2 ) = 0
Catmull-Clark subdivision surface
a new vertex for each vertex, edge, and face in existing mesh, resulting in all faces are quads.
vf = m1f j vj , ve = 14 (v1 + v2 + vf 1 + vf 2 ), vv = nvn−2 v + n12 j vj + n12 j vf j
P P P
v v v
OpenGL Example
struct Geometry {
GlBufferObject vbo, ibo;
int vboLen, iboLen;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * iboLen, idx, GL_STATIC_DRAW);
}
// bind vbo
glBindBuffer(GL_ARRAY_BUFFER, vbo);
safe_glVertexAttribPointer(curSS.h_aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPN), FIELD_OFFSET(VertexPN, p));
safe_glVertexAttribPointer(curSS.h_aNormal, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPN), FIELD_OFFSET(VertexPN, n));
// bind ibo
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
// draw!
glDrawElements(GL_TRIANGLES, iboLen, GL_UNSIGNED_SHORT, 0);
4
const Cvec3 eyeLight1 = Cvec3(invEyeRbt * Cvec4(g_light1, 1)); // g_light1 position in eye coordinates
const Cvec3 eyeLight2 = Cvec3(invEyeRbt * Cvec4(g_light2, 1)); // g_light2 position in eye coordinates
safe_glUniform3f(curSS.h_uLight, eyeLight1[0], eyeLight1[1], eyeLight1[2]);
safe_glUniform3f(curSS.h_uLight2, eyeLight2[0], eyeLight2[1], eyeLight2[2]);
// draw ground
// ===========
//
const Matrix4 groundRbt = Matrix4(); // identity
Matrix4 MVM = invEyeRbt * groundRbt;
Matrix4 NMVM = normalMatrix(MVM);
sendModelViewNormalMatrix(curSS, MVM, NMVM);
safe_glUniform3f(curSS.h_uColor, 0.1, 0.95, 0.1); // set color
g_ground->draw(curSS);
// draw cubes
// ==========
MVM = invEyeRbt * g_objectRbt[0];
NMVM = normalMatrix(MVM);
sendModelViewNormalMatrix(curSS, MVM, NMVM);
safe_glUniform3f(curSS.h_uColor, g_objectColors[0][0], g_objectColors[0][1], g_objectColors[0][2]);
g_cube->draw(curSS);
}
drawStuff();
checkGlErrors();
}