SlideShare a Scribd company logo
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
 
golf
golfgolf
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
Mahmoud Samir Fayed
 
MTH3101 Tutor 7 lagrange multiplier
MTH3101  Tutor 7 lagrange multiplierMTH3101  Tutor 7 lagrange multiplier
MTH3101 Tutor 7 lagrange multiplier
Drradz 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 202
Mahmoud Samir Fayed
 
Edge detection
Edge detectionEdge detection
Edge detection
Thùy Bùi
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
Jussi Pohjolainen
 
The not so short
The not so shortThe not so short
The not so short
AXM
 
Java3 d 1
Java3 d 1Java3 d 1
Java3 d 1
Por Non
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
Richard Jones
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
Introduction of 3D Development
Introduction of 3D DevelopmentIntroduction of 3D Development
Introduction of 3D Development
siufu
 
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 Group
bernice-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 Group
dreambreeze
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
Ahammednayeem
 
Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
Syed Zaid Irshad
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
Mani Kanth
 
Ujug07presentation
Ujug07presentationUjug07presentation
Ujug07presentation
Bill 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 Representation
Mark Kilgard
 
Getting Started with OpenGL ES
Getting Started with OpenGL ESGetting Started with OpenGL ES
Getting Started with OpenGL ES
John 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/5
Takao 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 Primer
Janie 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 Maps
Wolfgang Engel
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
Janie Clayton
 
Trident International Graphics Workshop2014 3/5
Trident International Graphics Workshop2014 3/5Trident International Graphics Workshop2014 3/5
Trident International Graphics Workshop2014 3/5
Takao Wada
 
SA09 Realtime education
SA09 Realtime educationSA09 Realtime education
SA09 Realtime education
fumoto kazuhiro
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
Chandrakant Divate
 
Windows and viewport
Windows and viewportWindows and viewport
Windows and viewport
Technology & Education
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
Journey to structure from motion
Journey to structure from motionJourney to structure from motion
Journey to structure from motion
Ja-Keoung Koo
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
stefan_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 180
Mahmoud Samir Fayed
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shah
Syed 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 189
Mahmoud 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/5
Takao Wada
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics Math
Mark 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 184
Mahmoud Samir Fayed
 

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
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
 
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
 

Recently uploaded

DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 

Recently uploaded (20)

DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 

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