SlideShare a Scribd company logo
1 of 25
International 5-days Graphics
Programming Workshop
using Cocos-2d-x
DAY 2
Trident College of Information Technology
Takao WADA
1. Review
2. 3-D geometry
3. Using camera
4. World transformation
5. View transformation
6. Projection transformation
7. Affine Transformation
Agenda
 Vertex formats
 position + color + texture coordinate
 Shader variables
 attribute, uniform, varying
 Computing
 v_position = a_position;
 v_position.x = a_position.x + 0.5;
 v_position.xyz = a_position.yzx;
 Texture mapping
 UV coordinate
Review
 To cut off a part, specify the UV coordinate less than 1
Cut off a part of a texture
U
V
0.0
0.0
1.0
1.00.25 0.5 0.75
0.5
0.25
 Create a plane dice
 Copy “dice.png” to your
“Resources/Imgaes” folder
 Draw a whole image
 Cut off the part of “1” and draw
 Cut off another number and draw
Work2-1
3D geometry
Right-handed coordinate system Left-handed coordinate system
X
Y
Z
X
Y
Z
• Mathematics
• Most of modeling tools
• OpenGL, etc.
• DirectX
• Unity, etc.
 Transform calculation of 3-D graphics
Difference between RHS and LHS
x'
y'
z'
w'
æ
è
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
=
a b c d
e f g h
i j k l
m n o p
æ
è
ç
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
÷
x
y
z
w
æ
è
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
x' y' z' w'( )= x y z w( )
a b c d
e f g h
i j k l
m n o p
æ
è
ç
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
÷
RHS (Right-handed system) uses column vector as vectors, i.e.
position, direction, etc.
LHS (Left-handed system) uses row vector as vectors, i.e. position,
direction, etc.
3-D Transformation
Model space World space View space Screen space
Y
XZ
Y
XZ
Y
XZ
Projection space
Cy C
x C
z
World
transform
View
transform
Projection
transform
Screen
transform
World transform
Sx 0 0 0
0 Sy 0 0
0 0 Sz 0
0 0 0 1
æ
è
ç
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
÷
Scaling matrix
cosq 0 sinq 0
0 1 0 0
-sinq 0 cosq 0
0 0 0 1
æ
è
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
Rotation matrix
0 0 0 Tx
0 0 0 Ty
0 0 0 Tz
0 0 0 1
æ
è
ç
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
÷
Translation matrix
1 0 0 0
0 cosq -sinq 0
0 sinq cosq 0
0 0 0 1
æ
è
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
Around X-axis Around Y-axis Around Z-axis
cosq -sinq 0 0
sinq cosq 0 0
0 0 1 0
0 0 0 1
æ
è
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
 Scaling, rotation, translation, etc.
 Transform from the world space to the camera space
View transformation
// Cocos-2d-x
Mat4::createLookAt(eye, center, up, &modelViewMatrix);
X
Y
Z
eye
lookat
up
 eye: Eye position (camera position)
 lookat: Look at point (target to look)
 up: Up vector (camera attitude)
 Create a view matrix
Cont’d
X,Y,Z: Normalized basis vector of a model
X’,Y’,Z’: Normalized basis vector of a camera
E: Camera position
x’ = P X’
y’ = P Y’
z’ = P Z’
Xx ' Xy ' Xz ' -(E'· X')
Yx ' Yy ' Yz ' -(E·Y ')
Zx ' Zy ' Zz ' -(E ·Z ')
0 0 0 1
æ
è
ç
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
÷
Z
X
X’
Z’
P
x
z
x’z’
E
 FOVy – Filed of view (Vertical)
Perspective projection
transformation
FOVy
Near clip plane Far clip plane
// Cocos-2d-x
Mat4::createPerspective(60, (GLfloat)width / height, 0.1f, 100.0f, &projectionMatrix);
width
height
Aspect ratio
= width / height
 Transform from the view space to the normalized 2-D space
 -1≤ x ≤ 1
 -1 ≤ y ≤ 1
 -1 ≤ z ≤ 1
 Draw the normalized pixel data to a screen
Screen transformation
Projection space
1
1
-1
-1
 Draw a cubic dice not using a camera
 Copy the whole project to a new project “WSSample2”
 Create a cube vertices and draw
 For lighting, prepare normal vectors (Nx,Ny,Nz)
Work 2-2
GLfloat vertices[] = {
// x y z Nx Ny Nz R G B A U V
-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // 1
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.25f,
1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.25f, 0.0f,
1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.25f, 0.0f,
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.25f,
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.25f, 0.25f,
// snip…
 Use a camera
Work 2-3
X
Y
5
5
 Add a camera
Cont’d
bool DiceShaderNode::initWithVertex(const std::string &vert, const std::string &frag,
Texture2D* texture, int width, int height)
{
// snip..
// Pass the model-view matrix
Mat4 modelViewMatrix; // Model-View matrix
Vec3 eye(0, 10, 10); // Eye position
Vec3 lookat(0, 0, 0); // Lookat position
Vec3 up(0, 1, 0); // Up vector
Mat4::createLookAt(eye, lookat, up, &modelViewMatrix);
getGLProgramState()->setUniformMat4("u_modelView", modelViewMatrix);
// Pass the projection matrix
Mat4 projectionMatrix; // Projection matrix
Mat4::createPerspective(60, (GLfloat)width / height, 0.1f, 100.0f,
&projectionMatrix);
getGLProgramState()->setUniformMat4("u_proj", projectionMatrix);
//snip...
return true;
}
 Shader programs using a camera
Cont’d.
attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec4 a_color;
attribute vec2 a_texCoord;
uniform mat4 u_modelView;
uniform mat4 u_proj;
varying vec2 v_texCoord;
void main()
{
// Set the transformed position
gl_Position = u_proj * u_modelView *
a_position;
// Pass through parameters
v_texCoord = a_texCoord;
}
uniform sampler2D u_texture0;
varying vec2 v_texCoord;
void main(void) {
gl_FragColor = texture2D(u_texture0,
v_texCoord);
}
Vertex shader Fragment shader
 Alter the value of FOV = Zooming
 0 < FOV < 180 (in degree)
Telephoto <- -> Wide
Work with a camera
Stereoscopic effect is
lost
 Change the FOV and/or the eye position
Work 2-4
FOV: 30 (deg.)
Eye: (5, 5, 5)
FOV: 120 (deg.)
Eye: (2, 2, 2)
 Scaling
Affine transformation 1
Mat4::createScale(2, 3, 4, &worldMatrix);
getGLProgramState()->setUniformMat4("u_world", worldMatrix);
// snip…
uniform mat4 u_world;
// snip…
void main()
{
// snip…
gl_Position = u_proj * u_modelView * u_world * a_position;
// snip…
}
Vertex shader
 Rotation
 Around X,Y or Z axis
 Around any vector
Affine transformation 2
Mat4 worldMatrix;
rotY += 1.0f * M_PI / 180; // Convert from degree to
radian
Mat4::createRotationY(rotY, &worldMatrix);
getGLProgramState()->setUniformMat4("u_world", worldMatrix);
Ex. Rotate 1 degree per frame along Y-
axis
 Translation
Affine transformation 3
Mat4 worldMatrix;
Mat4::createTranslation(4, 0, 0, &worldMatrix);
Ex. Move to (4, 0, 0)
 Scale a model
 Scaling matrix (MS)
 Rotate a model
 Rotation matrix around X or Y or Z axis (MRx, MRy, MRz)
 Translate a model
 Translation matrix (MT)
 Combine transformations by multiplying transformation
matrices
 MS * MR * MT
 MS * MT * MR
 Try other combinations
Work 2-5
 Draw order problem
 Use a depth buffer (2-D array, elements are for pixels)
 Store the z-coordinate of the pixel.
 If another pixel is rendered in the same pixel, compare its z-
coordinate with the buffer value to decide whether replace or not.
 Usually used 16bit depth (unsigned short, 0 – 65535)
 Buffer is to be cleared first each frame
Depth buffer and depth test
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
 Create a 3-D Camera class, “Camera3d” for
Cocos-2d-x
Work 2-6

More Related Content

What's hot

Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...Janis Alnis
 
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212Mahmoud Samir Fayed
 
MTH3101 Tutor 7 lagrange multiplier
MTH3101  Tutor 7 lagrange multiplierMTH3101  Tutor 7 lagrange multiplier
MTH3101 Tutor 7 lagrange multiplierDrradz Maths
 
[shaderx7] 4.1 Practical Cascaded Shadow Maps
[shaderx7] 4.1 Practical Cascaded Shadow Maps[shaderx7] 4.1 Practical Cascaded Shadow Maps
[shaderx7] 4.1 Practical Cascaded Shadow Maps종빈 오
 
The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202Mahmoud Samir Fayed
 
Edge detection
Edge detectionEdge detection
Edge detectionThùy Bùi
 
The not so short
The not so shortThe not so short
The not so shortAXM
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1Por Non
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksJinTaek Seo
 
Introduction of 3D Development
Introduction of 3D DevelopmentIntroduction of 3D Development
Introduction of 3D Developmentsiufu
 
AlphaGo in Depth
AlphaGo in Depth AlphaGo in Depth
AlphaGo in Depth Mark Chang
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
3 d transformation
3 d transformation3 d transformation
3 d transformationMani Kanth
 
Ujug07presentation
Ujug07presentationUjug07presentation
Ujug07presentationBill Adams
 

What's hot (20)

Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
 
golf
golfgolf
golf
 
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.10 book - Part 66 of 212
 
MTH3101 Tutor 7 lagrange multiplier
MTH3101  Tutor 7 lagrange multiplierMTH3101  Tutor 7 lagrange multiplier
MTH3101 Tutor 7 lagrange multiplier
 
[shaderx7] 4.1 Practical Cascaded Shadow Maps
[shaderx7] 4.1 Practical Cascaded Shadow Maps[shaderx7] 4.1 Practical Cascaded Shadow Maps
[shaderx7] 4.1 Practical Cascaded Shadow Maps
 
The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202The Ring programming language version 1.8 book - Part 61 of 202
The Ring programming language version 1.8 book - Part 61 of 202
 
Edge detection
Edge detectionEdge detection
Edge detection
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
The not so short
The not so shortThe not so short
The not so short
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
Introduction of 3D Development
Introduction of 3D DevelopmentIntroduction of 3D Development
Introduction of 3D Development
 
AlphaGo in Depth
AlphaGo in Depth AlphaGo in Depth
AlphaGo in Depth
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
 
Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
 
Ujug07presentation
Ujug07presentationUjug07presentation
Ujug07presentation
 

Similar to Trident International Graphics Workshop 2014 2/5

CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationMark Kilgard
 
Getting Started with OpenGL ES
Getting Started with OpenGL ESGetting Started with OpenGL ES
Getting Started with OpenGL ESJohn Wilker
 
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation PipelineComputer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline💻 Anton Gerdelan
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Takao Wada
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerJanie Clayton
 
Paris Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsParis Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsWolfgang Engel
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf ChicagoJanie Clayton
 
Trident International Graphics Workshop2014 3/5
Trident International Graphics Workshop2014 3/5Trident International Graphics Workshop2014 3/5
Trident International Graphics Workshop2014 3/5Takao Wada
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupMark Kilgard
 
Journey to structure from motion
Journey to structure from motionJourney to structure from motion
Journey to structure from motionJa-Keoung Koo
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardwarestefan_b
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180Mahmoud Samir Fayed
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shahSyed Talha
 
The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189Mahmoud Samir Fayed
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Takao Wada
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics MathMark Kilgard
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184Mahmoud Samir Fayed
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEThiyagarajan G
 

Similar to Trident International Graphics Workshop 2014 2/5 (20)

CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 
Getting Started with OpenGL ES
Getting Started with OpenGL ESGetting Started with OpenGL ES
Getting Started with OpenGL ES
 
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation PipelineComputer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
Paris Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsParis Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow Maps
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
 
Trident International Graphics Workshop2014 3/5
Trident International Graphics Workshop2014 3/5Trident International Graphics Workshop2014 3/5
Trident International Graphics Workshop2014 3/5
 
SA09 Realtime education
SA09 Realtime educationSA09 Realtime education
SA09 Realtime education
 
Windows and viewport
Windows and viewportWindows and viewport
Windows and viewport
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
Journey to structure from motion
Journey to structure from motionJourney to structure from motion
Journey to structure from motion
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shah
 
The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189The Ring programming language version 1.6 book - Part 62 of 189
The Ring programming language version 1.6 book - Part 62 of 189
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics Math
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 

Recently uploaded (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

Trident International Graphics Workshop 2014 2/5

  • 1. International 5-days Graphics Programming Workshop using Cocos-2d-x DAY 2 Trident College of Information Technology Takao WADA
  • 2. 1. Review 2. 3-D geometry 3. Using camera 4. World transformation 5. View transformation 6. Projection transformation 7. Affine Transformation Agenda
  • 3.  Vertex formats  position + color + texture coordinate  Shader variables  attribute, uniform, varying  Computing  v_position = a_position;  v_position.x = a_position.x + 0.5;  v_position.xyz = a_position.yzx;  Texture mapping  UV coordinate Review
  • 4.  To cut off a part, specify the UV coordinate less than 1 Cut off a part of a texture U V 0.0 0.0 1.0 1.00.25 0.5 0.75 0.5 0.25
  • 5.  Create a plane dice  Copy “dice.png” to your “Resources/Imgaes” folder  Draw a whole image  Cut off the part of “1” and draw  Cut off another number and draw Work2-1
  • 6. 3D geometry Right-handed coordinate system Left-handed coordinate system X Y Z X Y Z • Mathematics • Most of modeling tools • OpenGL, etc. • DirectX • Unity, etc.
  • 7.  Transform calculation of 3-D graphics Difference between RHS and LHS x' y' z' w' æ è ç ç ç ç ö ø ÷ ÷ ÷ ÷ = a b c d e f g h i j k l m n o p æ è ç ç ç ç ç ö ø ÷ ÷ ÷ ÷ ÷ x y z w æ è ç ç ç ç ö ø ÷ ÷ ÷ ÷ x' y' z' w'( )= x y z w( ) a b c d e f g h i j k l m n o p æ è ç ç ç ç ç ö ø ÷ ÷ ÷ ÷ ÷ RHS (Right-handed system) uses column vector as vectors, i.e. position, direction, etc. LHS (Left-handed system) uses row vector as vectors, i.e. position, direction, etc.
  • 8. 3-D Transformation Model space World space View space Screen space Y XZ Y XZ Y XZ Projection space Cy C x C z World transform View transform Projection transform Screen transform
  • 9. World transform Sx 0 0 0 0 Sy 0 0 0 0 Sz 0 0 0 0 1 æ è ç ç ç ç ç ö ø ÷ ÷ ÷ ÷ ÷ Scaling matrix cosq 0 sinq 0 0 1 0 0 -sinq 0 cosq 0 0 0 0 1 æ è ç ç ç ç ö ø ÷ ÷ ÷ ÷ Rotation matrix 0 0 0 Tx 0 0 0 Ty 0 0 0 Tz 0 0 0 1 æ è ç ç ç ç ç ö ø ÷ ÷ ÷ ÷ ÷ Translation matrix 1 0 0 0 0 cosq -sinq 0 0 sinq cosq 0 0 0 0 1 æ è ç ç ç ç ö ø ÷ ÷ ÷ ÷ Around X-axis Around Y-axis Around Z-axis cosq -sinq 0 0 sinq cosq 0 0 0 0 1 0 0 0 0 1 æ è ç ç ç ç ö ø ÷ ÷ ÷ ÷  Scaling, rotation, translation, etc.
  • 10.  Transform from the world space to the camera space View transformation // Cocos-2d-x Mat4::createLookAt(eye, center, up, &modelViewMatrix); X Y Z eye lookat up  eye: Eye position (camera position)  lookat: Look at point (target to look)  up: Up vector (camera attitude)
  • 11.  Create a view matrix Cont’d X,Y,Z: Normalized basis vector of a model X’,Y’,Z’: Normalized basis vector of a camera E: Camera position x’ = P X’ y’ = P Y’ z’ = P Z’ Xx ' Xy ' Xz ' -(E'· X') Yx ' Yy ' Yz ' -(E·Y ') Zx ' Zy ' Zz ' -(E ·Z ') 0 0 0 1 æ è ç ç ç ç ç ö ø ÷ ÷ ÷ ÷ ÷ Z X X’ Z’ P x z x’z’ E
  • 12.  FOVy – Filed of view (Vertical) Perspective projection transformation FOVy Near clip plane Far clip plane // Cocos-2d-x Mat4::createPerspective(60, (GLfloat)width / height, 0.1f, 100.0f, &projectionMatrix); width height Aspect ratio = width / height  Transform from the view space to the normalized 2-D space  -1≤ x ≤ 1  -1 ≤ y ≤ 1  -1 ≤ z ≤ 1
  • 13.  Draw the normalized pixel data to a screen Screen transformation Projection space 1 1 -1 -1
  • 14.  Draw a cubic dice not using a camera  Copy the whole project to a new project “WSSample2”  Create a cube vertices and draw  For lighting, prepare normal vectors (Nx,Ny,Nz) Work 2-2 GLfloat vertices[] = { // x y z Nx Ny Nz R G B A U V -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // 1 -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.25f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.25f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.25f, 0.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.25f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.25f, 0.25f, // snip…
  • 15.  Use a camera Work 2-3 X Y 5 5
  • 16.  Add a camera Cont’d bool DiceShaderNode::initWithVertex(const std::string &vert, const std::string &frag, Texture2D* texture, int width, int height) { // snip.. // Pass the model-view matrix Mat4 modelViewMatrix; // Model-View matrix Vec3 eye(0, 10, 10); // Eye position Vec3 lookat(0, 0, 0); // Lookat position Vec3 up(0, 1, 0); // Up vector Mat4::createLookAt(eye, lookat, up, &modelViewMatrix); getGLProgramState()->setUniformMat4("u_modelView", modelViewMatrix); // Pass the projection matrix Mat4 projectionMatrix; // Projection matrix Mat4::createPerspective(60, (GLfloat)width / height, 0.1f, 100.0f, &projectionMatrix); getGLProgramState()->setUniformMat4("u_proj", projectionMatrix); //snip... return true; }
  • 17.  Shader programs using a camera Cont’d. attribute vec4 a_position; attribute vec3 a_normal; attribute vec4 a_color; attribute vec2 a_texCoord; uniform mat4 u_modelView; uniform mat4 u_proj; varying vec2 v_texCoord; void main() { // Set the transformed position gl_Position = u_proj * u_modelView * a_position; // Pass through parameters v_texCoord = a_texCoord; } uniform sampler2D u_texture0; varying vec2 v_texCoord; void main(void) { gl_FragColor = texture2D(u_texture0, v_texCoord); } Vertex shader Fragment shader
  • 18.  Alter the value of FOV = Zooming  0 < FOV < 180 (in degree) Telephoto <- -> Wide Work with a camera Stereoscopic effect is lost
  • 19.  Change the FOV and/or the eye position Work 2-4 FOV: 30 (deg.) Eye: (5, 5, 5) FOV: 120 (deg.) Eye: (2, 2, 2)
  • 20.  Scaling Affine transformation 1 Mat4::createScale(2, 3, 4, &worldMatrix); getGLProgramState()->setUniformMat4("u_world", worldMatrix); // snip… uniform mat4 u_world; // snip… void main() { // snip… gl_Position = u_proj * u_modelView * u_world * a_position; // snip… } Vertex shader
  • 21.  Rotation  Around X,Y or Z axis  Around any vector Affine transformation 2 Mat4 worldMatrix; rotY += 1.0f * M_PI / 180; // Convert from degree to radian Mat4::createRotationY(rotY, &worldMatrix); getGLProgramState()->setUniformMat4("u_world", worldMatrix); Ex. Rotate 1 degree per frame along Y- axis
  • 22.  Translation Affine transformation 3 Mat4 worldMatrix; Mat4::createTranslation(4, 0, 0, &worldMatrix); Ex. Move to (4, 0, 0)
  • 23.  Scale a model  Scaling matrix (MS)  Rotate a model  Rotation matrix around X or Y or Z axis (MRx, MRy, MRz)  Translate a model  Translation matrix (MT)  Combine transformations by multiplying transformation matrices  MS * MR * MT  MS * MT * MR  Try other combinations Work 2-5
  • 24.  Draw order problem  Use a depth buffer (2-D array, elements are for pixels)  Store the z-coordinate of the pixel.  If another pixel is rendered in the same pixel, compare its z- coordinate with the buffer value to decide whether replace or not.  Usually used 16bit depth (unsigned short, 0 – 65535)  Buffer is to be cleared first each frame Depth buffer and depth test glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_DEPTH_TEST);
  • 25.  Create a 3-D Camera class, “Camera3d” for Cocos-2d-x Work 2-6