SlideShare a Scribd company logo
1 of 16
SER332
Introduction to Graphics and
Game Development
Lecture 06:
Transformations - ModelView
Javier Gonzalez-Sanchez
javiergs@asu.edu
PERALTA 230U
Office Hours: By appointment
Part 4: OpenGL
Transformations
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 3
Stages of Vertex Transformation
1 2 3
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 4
Transformations in OpenGL
Transformation
Model-View
glRotate*()
glTranslate*()
glScale*()
glLookAt()
Projection
glOrtho2D*()
glOrtho()
glPerspective()
Viewport glViewPort()
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 5
Model (Local or World)
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 6
ModelView Transformation
• glTranslate{fd}(TYPE x, TYPE, y, TYPE, z)
• glRotate{fd}(TYPE angle, TYPE x, TYPE, y, TYPE, z)
• glScale{fd}(TYPE x, TYPE, y, TYPE, z)
Translate Rotate Scale
Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 7
Translation then rotation Rotation then translation
Thinking about Transformations
OpenGL Transformations are specified in reverse order!
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 8
Thinking about Transformations
§ Will the snippets below generate same results?
§ Think of glRotate, glTranslate, glScale as matrix
multiplication to the current (ModelView) matrix
§ OpenGL does post-multiplication. So, if current
ModelView matrix is Mvold , calling glMultMatrixf(M)
will result in MVnew = MVold * M
glTranslatef
(10.0f, 0.0f, 0.0f);
glRotatef
(45.0f, 0.0f, 0.0f, 1.0f);
// draw a cube
glRotatef
(45.0f, 0.0f, 0.0f, 1.0f);
glTranslatef
(10.0f, 0.0f, 0.0f);
// draw a cube
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 9
Projection Transformations
§ determine how a scene is mapped onto the
computer screen.
§ The projection transformation specifies the
mechanics of how the mapping should occur, and
• 2D Orthographic Projection:
Viewing volume is a clipping rectangle.
§ gluOrtho2D (left, right, bottom, top)
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 10
Example 1: Transformations
/**
https://github.com/javiergs/SER332/blob/master/L06/
*/
#include "glut.h"
int year = 0, day = 0;
void myInit() {
glClearColor(0.764f, 0.129f, 0.282f, 1.0); // maroon clear color
// projection transformations
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5.0, 5.0, -5.0, 5.0); // units inside
}
// main
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("simple");
myInit();
glutDisplayFunc(myDisplay);
glutKeyboardFunc(myKeyboard);
glutMainLoop(); //event loop
}
Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 11
void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
/* draw 1 */
glBegin(GL_POLYGON); // fill connected polygon
glColor3f(1.0f, 0.843f, 0.0f);
glVertex2f(-0.7, 0.7); // vertices of the triangl 1
glVertex2f(0.6, 0.7);
glVertex2f(-0.7, -0.6);
glEnd();
/* draw 2 */
glRotatef((GLfloat)year, 0.0, 0.0, 1.0);
glTranslatef(2.0, 0.0, 0.0);
glRotatef((GLfloat)day, 0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.843f, 0.0f);
glVertex2f(0.7, 0.6); // vertices of the triangle 2
glVertex2f(-0.6, -0.7);
glVertex2f(0.7, -0.7);
glEnd();
glPopMatrix();
glFlush();
}
Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 12
void myKeyboard(unsigned char key, int x, int y) {
switch (key) {
case 'd':
day = (day + 10) % 360;
glutPostRedisplay();
break;
case 'D':
day = (day - 10) % 360;
glutPostRedisplay();
break;
case 'y':
year = (year + 5) % 360;
glutPostRedisplay();
break;
case 'Y':
year = (year - 5) % 360;
glutPostRedisplay();
break;
default:
break;
}
}
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 13
Example 1: Transformations
Press the key ‘d’ or ‘D’
Press the key ‘y’ or ‘Y’
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 14
Reading
• In general, you should :
§ Read Hearn Baker ch5 p232-p252 for 2D geometric transformation
§ Read Hearn Baker ch6 p297-p305 for 2D viewing
§ Extend your understanding of 2D transformation and viewing to 3D
§ Read Red Book(pdf): ch3
• A relatively quicker path (just to survive the 1st project):
§ Required Reading: Red Book (pdf): ch3 p73-p78, shows you the underlying
OpenGL matrix multiplication scheme. This is essential, though not obvious.
§ Tips: there is no 2D translation, rotation and scale in OpenGL. Instead, think of
your 2D scene as projected onto x-y plane
§ You may not have to set up your camera and call gluLookAt in your 1st 2D
project, but do read about 3D viewing for your future projects
§ Required Reading: Red Book (pdf): ch3 p86-p92
§ Tips: Do not mess with glDepthRange, if you are not confident about Z-depth
value
§ Suggested Reading: example 3-4 to understand matrix stack
§ Suggested Reading: example 3-6, 3-7 to assembly everything in Chapter 3
§ A summary of GLUT functions you may need to create a display application:
Hearn Baker p341
Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 15
Homework
Start Programming
practice, practice, practice...
SER332 Introduction to Graphics
Javier Gonzalez-Sanchez
javiergs@asu.edu
Spring 2017
Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.

More Related Content

Similar to 201707 SER332 Lecture 06

GPGPU Programming @DroidconNL 2012 by Alten
GPGPU Programming @DroidconNL 2012 by AltenGPGPU Programming @DroidconNL 2012 by Alten
GPGPU Programming @DroidconNL 2012 by AltenArjan Somers
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
BIM/GIS Integration: A Practical Approach in Real Cases
BIM/GIS Integration: A Practical Approach in Real CasesBIM/GIS Integration: A Practical Approach in Real Cases
BIM/GIS Integration: A Practical Approach in Real CasesSANGHEE SHIN
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...ICS
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing StuffMark Kilgard
 

Similar to 201707 SER332 Lecture 06 (20)

201707 SER332 Lecture10
201707 SER332 Lecture10   201707 SER332 Lecture10
201707 SER332 Lecture10
 
201707 SER332 Lecture 03
201707 SER332 Lecture 03   201707 SER332 Lecture 03
201707 SER332 Lecture 03
 
201707 SER332 Lecture 05
201707 SER332 Lecture 05   201707 SER332 Lecture 05
201707 SER332 Lecture 05
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201707 SER332 Lecture 12
201707 SER332 Lecture 12   201707 SER332 Lecture 12
201707 SER332 Lecture 12
 
GPGPU Programming @DroidconNL 2012 by Alten
GPGPU Programming @DroidconNL 2012 by AltenGPGPU Programming @DroidconNL 2012 by Alten
GPGPU Programming @DroidconNL 2012 by Alten
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Viewing
ViewingViewing
Viewing
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
BIM/GIS Integration: A Practical Approach in Real Cases
BIM/GIS Integration: A Practical Approach in Real CasesBIM/GIS Integration: A Practical Approach in Real Cases
BIM/GIS Integration: A Practical Approach in Real Cases
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
BYO3D 2011: Rendering
BYO3D 2011: RenderingBYO3D 2011: Rendering
BYO3D 2011: Rendering
 
Bai 1
Bai 1Bai 1
Bai 1
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
Open gl tips
Open gl tipsOpen gl tips
Open gl tips
 
OpenGL ES on iOS
OpenGL ES on iOSOpenGL ES on iOS
OpenGL ES on iOS
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 

Recently uploaded

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

201707 SER332 Lecture 06

  • 1. SER332 Introduction to Graphics and Game Development Lecture 06: Transformations - ModelView Javier Gonzalez-Sanchez javiergs@asu.edu PERALTA 230U Office Hours: By appointment
  • 3. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 3 Stages of Vertex Transformation 1 2 3
  • 4. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 4 Transformations in OpenGL Transformation Model-View glRotate*() glTranslate*() glScale*() glLookAt() Projection glOrtho2D*() glOrtho() glPerspective() Viewport glViewPort()
  • 5. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 5 Model (Local or World)
  • 6. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 6 ModelView Transformation • glTranslate{fd}(TYPE x, TYPE, y, TYPE, z) • glRotate{fd}(TYPE angle, TYPE x, TYPE, y, TYPE, z) • glScale{fd}(TYPE x, TYPE, y, TYPE, z) Translate Rotate Scale
  • 7. Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 7 Translation then rotation Rotation then translation Thinking about Transformations OpenGL Transformations are specified in reverse order!
  • 8. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 8 Thinking about Transformations § Will the snippets below generate same results? § Think of glRotate, glTranslate, glScale as matrix multiplication to the current (ModelView) matrix § OpenGL does post-multiplication. So, if current ModelView matrix is Mvold , calling glMultMatrixf(M) will result in MVnew = MVold * M glTranslatef (10.0f, 0.0f, 0.0f); glRotatef (45.0f, 0.0f, 0.0f, 1.0f); // draw a cube glRotatef (45.0f, 0.0f, 0.0f, 1.0f); glTranslatef (10.0f, 0.0f, 0.0f); // draw a cube
  • 9. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 9 Projection Transformations § determine how a scene is mapped onto the computer screen. § The projection transformation specifies the mechanics of how the mapping should occur, and • 2D Orthographic Projection: Viewing volume is a clipping rectangle. § gluOrtho2D (left, right, bottom, top)
  • 10. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 10 Example 1: Transformations /** https://github.com/javiergs/SER332/blob/master/L06/ */ #include "glut.h" int year = 0, day = 0; void myInit() { glClearColor(0.764f, 0.129f, 0.282f, 1.0); // maroon clear color // projection transformations glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-5.0, 5.0, -5.0, 5.0); // units inside } // main void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow("simple"); myInit(); glutDisplayFunc(myDisplay); glutKeyboardFunc(myKeyboard); glutMainLoop(); //event loop }
  • 11. Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 11 void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); /* draw 1 */ glBegin(GL_POLYGON); // fill connected polygon glColor3f(1.0f, 0.843f, 0.0f); glVertex2f(-0.7, 0.7); // vertices of the triangl 1 glVertex2f(0.6, 0.7); glVertex2f(-0.7, -0.6); glEnd(); /* draw 2 */ glRotatef((GLfloat)year, 0.0, 0.0, 1.0); glTranslatef(2.0, 0.0, 0.0); glRotatef((GLfloat)day, 0.0, 1.0, 0.0); glBegin(GL_POLYGON); glColor3f(1.0f, 0.843f, 0.0f); glVertex2f(0.7, 0.6); // vertices of the triangle 2 glVertex2f(-0.6, -0.7); glVertex2f(0.7, -0.7); glEnd(); glPopMatrix(); glFlush(); }
  • 12. Javier Gonzalez-Sanchez | SER431 | Fall 2016 | 12 void myKeyboard(unsigned char key, int x, int y) { switch (key) { case 'd': day = (day + 10) % 360; glutPostRedisplay(); break; case 'D': day = (day - 10) % 360; glutPostRedisplay(); break; case 'y': year = (year + 5) % 360; glutPostRedisplay(); break; case 'Y': year = (year - 5) % 360; glutPostRedisplay(); break; default: break; } }
  • 13. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 13 Example 1: Transformations Press the key ‘d’ or ‘D’ Press the key ‘y’ or ‘Y’
  • 14. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 14 Reading • In general, you should : § Read Hearn Baker ch5 p232-p252 for 2D geometric transformation § Read Hearn Baker ch6 p297-p305 for 2D viewing § Extend your understanding of 2D transformation and viewing to 3D § Read Red Book(pdf): ch3 • A relatively quicker path (just to survive the 1st project): § Required Reading: Red Book (pdf): ch3 p73-p78, shows you the underlying OpenGL matrix multiplication scheme. This is essential, though not obvious. § Tips: there is no 2D translation, rotation and scale in OpenGL. Instead, think of your 2D scene as projected onto x-y plane § You may not have to set up your camera and call gluLookAt in your 1st 2D project, but do read about 3D viewing for your future projects § Required Reading: Red Book (pdf): ch3 p86-p92 § Tips: Do not mess with glDepthRange, if you are not confident about Z-depth value § Suggested Reading: example 3-4 to understand matrix stack § Suggested Reading: example 3-6, 3-7 to assembly everything in Chapter 3 § A summary of GLUT functions you may need to create a display application: Hearn Baker p341
  • 15. Javier Gonzalez-Sanchez | SER332 | Spring 2017 | 15 Homework Start Programming practice, practice, practice...
  • 16. SER332 Introduction to Graphics Javier Gonzalez-Sanchez javiergs@asu.edu Spring 2017 Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.