Transformation and Viewing

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
University of North Carolina at Greensboro
GRAFIKA KOMPUTER ~ M. Ali Fauzi.
Geometric Transformations
CMPE 466 COMPUTER GRAPHICS
Viewing and Transformation
Modeling Objects by Polygonal Approximations
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
OpenGL (II). How to Draw a 3-D object on Screen?
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformations.
2002 by Jim X. Chen George Mason University Transformation and Viewing.1. Plane Example: J2_0_2DTransform.
GRAFIKA KOMPUTER ~ M. Ali Fauzi. Drawing 2 D Graphics.
Hierarchical Modeling CS418 Computer Graphics John C. Hart.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Computer Graphics Bing-Yu Chen National Taiwan University.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
OpenGL: Modeling void DrawPyramid(){ glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.1, 0.0, 0.0); glVertex3f(0.0,
Computer Graphics I, Fall 2010 OpenGL Transformations.
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
3D Transformations. Translation x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T. P tx ty tz xyz1xyz1 x’ y’ z’ 1 x y.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Hierarchical Modeling.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 4 Instructor: Dan Hebert.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
III- 1 III 3D Transformation Homogeneous Coordinates The three dimensional point (x, y, z) is represented by the homogeneous coordinate (x, y, z, 1) In.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
The Modelview Stack Lecture 9 Wed, Sep 12, The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
Hank Childs, University of Oregon
Transformations Introduction to Computer Graphics and Animation
Hank Childs, University of Oregon
2D Geometric Transformations
2D Imaging and Transformation
Summary of Properties of 3D Affine Transformations
Reference1. [OpenGL course slides by Rasmus Stenholt]
Geometric Transformations
Unit-5 Geometric Objects and Transformations-II
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Chapters 5/4 part2 understanding transformations working with matrices
Transformations IV Week 3, Wed Jan 20
Geometric Transformations
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Transformations in OpenGL
Plane 2D GEOMETRICAL TRANSFORMATIONS Example: J2_0_2DTransform
Geometric Objects and Transformations (II)
Transformations III Week 3, Mon Jan 21
Transformations IV Week 3, Wed Jan 23
Geometric Transformations
Hierarchical Modeling
Presentation transcript:

Transformation and Viewing 3D GEOMETRICAL TRANSFORMATIONS Sphere, cylinder, and cone Earth Plane @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .1.

Transformation and Viewing HOMOGENEOUS COORDINATES Every column vector (x, y, z, w) T represents a homogeneous vertex if at least one of its elements is nonzero. If real number a is nonzero, then (x, y, z, w) and (ax, ay, az, aw) represent the same homogeneous vertex. A 3D euclidean space point (x, y, z) becomes the homogeneous vertex (x, y, z, 1.0) As long as w is nonzero, the homogeneous vertex (x, y, z, w) corresponds to the 3D point (x/w, y/w, z/w) . If w = 0.0, it corresponds to a direction or a “point at infinity.” @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .2.

Transformation and Viewing MATRIX REPRESENTATION OF 3D OpenGL Transformations TRANSFORMATIONS @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .3.

glMatrixMode(GLenum mode); GL_PROJECTION - Applies subsequent matrix operations to the projection matrix stack. glLoadMatrix, glLoadIdentity glMultMatrix, glOrtho, glFrustum, glRotate, glTranslate, glScale GL_MODELVIEW - Applies subsequent matrix operations to the modelview matrix stack. glMultMatrix, glRotate, glTranslate, glScale @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

PushMatrix and PopMatrix void drawRobot() { // the robot arm is rotating around y axis gl.glRotatef(5.0f, 0.0f, 1.0f, 0.0f); gl.glPushMatrix(); gl.glRotatef(alpha, 0.0f, 0.0f, 1.0f); // Rz(alpha) is on top of the matrix stack drawArm(O, A); gl.glTranslatef(A[0], A[1], 0.0f); gl.glRotatef(beta, 0.0f, 0.0f, 1.0f); gl.glTranslatef(-A[0], -A[1], 0.0f); // Rz(alpha)T(A)Rz(beta)T(-A) is on top drawArm(A, B); gl.glTranslatef(B[0], B[1], 0.0f); gl.glRotatef(gama, 0.0f, 0.0f, 1.0f); gl.glTranslatef(-B[0], -B[1], 0.0f); // Rz(alpha)T(A)Rz(beta)T(-A) is on top drawArm(B, C); gl.glPopMatrix(); } Example: J2_8_Robot3d @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

Transformation and Viewing @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .6.

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu void drawArm(float End1, float End2) { float scale = End2-End1; gl.glPushMatrix(); // the cylinder lies in the z axis; // rotate it to lie in the x axis gl.glRotatef(90.0f, 0.0f, 1.0f, 0.0f); gl.glScalef(scale/5.0f, scale/5.0f, scale); if (cnt%1500<500) { drawCylinder(); } else if (cnt%1500<1000) { drawCone(); } else { gl.glScalef(0.5f, 0.5f, 0.5f); gl.glTranslatef(0, 0, 1); drawSphere(); } gl.glPopMatrix(); @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

Transformation and Viewing COMPOSITION OF 3D TRANS Solar System Solar system: myLoadIdentity(); transDraw(Sun); myRotatef(e); transDraw(Earth); myTranslatev(E); myRotatef(m, 0, 1, 0); myTranslatev(-E); transDraw(Moon); The earth rotate around the Sun; the moon around the earth Given the earth & moon centers (E & M) and rotation angles (e & m) find the new locations of the earth and moon @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .8.

Transformation and Viewing Float matrix[4][4]; //for a sphere is at the center of the coordinates myLoadIdentity(); transDrawSphere(); //sun myRotatef(e,0,1,0); myTranslatef(E, 0, 0); transDrawSphere(); //earth myRotatef(m,0,1,0); myTranslatef(M, 0, 0); transDrawSphere(); //moon @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .9.

Transformation and Viewing My Implementation with Push&PopMatrix Float matrix[DEPTH][4][4]; myPushMatrix(); myScalef(4,4,4); transDrawSphere(); //sun myPopMatrix(); myRotatef(e,0,1,0); myTranslatef(E, 0, 0); myScalef(2,2,2); transDrawSphere(); //earth myRotatef(m,0,1,0); myTranslatef(M, 0, 0); transDrawSphere(); //moon @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .10.

Transformation and Viewing An OpenGL Implementation Example: J2_9_Solar glMatrixMode (GL_MODELVIEW); …… glLoadIdentity (); glPushMatrix(); glScalef(4,4,4); Sphere(); //sun, matrix multi. automatic in OpenGL glPopMatrix(); glRotatef(e,0,1,0); glTranslatef(E, 0, 0); glScalef(2,2,2); Sphere(); // earth, transformation implied glRotatef(m,0,1,0); glTranslatef(M, 0, 0); Sphere(); //moon, again … @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .11.

Transformation and Viewing The Motion of a Top: Generalized Solar System Example: J2_10_GenSolar Rotate around y (b degree) so E is in xy plane; Rotate around z (a degree) so E will be in y axis; Rotate around y (m degree) so the moon will proceed; Rotate around z (-a degree) so E will be in xy plane; Rotate around y (-b degree) so E returns to its original location. Mnew = Ry(e)Ry(-b)Rz(-a)Ry(m)Rz(a)Ry(b)M @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .12.

Jogl implementation: J2_10_GenSolar gl.glPushMatrix(); gl.glRotatef(earthAngle, 0.0f, 1.0f, 0.0f); // around the "sun"; proceed angle gl.glRotatef(tiltAngle, 0.0f, 0.0f, 1.0f); // tilt between the center and y axis gl.glTranslatef(0.0f, earthDistance, 0.0f); gl.glScalef(WIDTH/20, WIDTH/20, WIDTH/20); drawSphere(); gl.glPopMatrix(); gl.glRotatef(moonAngle, 0.0f, 1.0f, 0.0f); // rotating around the "earth" gl.glTranslatef(moonDistance, 0.0f, 0.0f); gl.glScalef(WIDTH/40, WIDTH/40, WIDTH/40); @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

Transformation and Viewing The Motion of a Top: Example: J2_11_ConeSolar Generalized Solar System Cone and Sphere Earth Lighting Cone Lab @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .14.

Transformation and Viewing Collision Detection: J2_11_ConeSolarCollision Draw a cone, a cylinder, and a sphere that move and collide in the moon’s trajectory in the generalized solar system. The center of a moon from (0, 0, 0) to (moonx, moony, moonz): gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, currM); moonx = currM[12]; moony = currM[13]; moonz = currM[14]; @ 2017 by Jim X. Chen: jchen@cs.gmu.edu .15.

Put a solar system on the Robot Arm J2_12_RobotSolar void drawRobot () { gl.glPushMatrix(); gl.glRotatef(cnt, 0, 1, 0); gl.glRotatef(alpha, 0, 0, 1); drawArm(O, A); gl.glTranslatef(A, 0, 0); gl.glRotatef(beta, 0, 0, 1); drawArm(A, B); gl.glTranslatef(B-A, 0, 0); gl.glRotatef(gama, 0, 0, 1); drawArm(B, C); // put the solar system at the end of the robot arm gl.glTranslatef(C-B, 0, 0); drawSolar(); gl.glPopMatrix(); } @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

@ 2017 by Jim X. Chen: jchen@cs.gmu.edu GLSL Matrix multiplication with point is provided It is uniform across an object (all vertices), so it is better to send the corresponding combined transformation to the vertex shader. @ 2017 by Jim X. Chen: jchen@cs.gmu.edu

How to reason or think about transformation From where you draw at the origin to where you load identity in reverse order of the OpenGL code From where you draw to the origin of a local coordinate system The local coordinate system may be further transformed, which you don’t need to reason or think about again @ 2017 by Jim X. Chen: jchen@cs.gmu.edu