SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
Geometric Objects and
Transformations -I
By: Saad Siddiqui
Frames in OpenGL
• 2 frames:
– Camera: regard as fix
– World:
• The model-view matrix position related to camera
• Convert homogeneous coordinates representation of object to camera
frame

• OpenGL provided matrix stack for store model view
matrices or frames
• By default camera and world have the same origin
• If moving world frame distance d from camera the
model-view matrix would be
1
0
A= 
0

0

0
0

0 1 -d 

0 0 1

0 0
1 0

Camera and world frames
Suppose camera at point (1, 0, 1, 1)
• World frame center point of camera
p = (1, 0, 1, 1)T

• Representation of world frame for
camera
n = (-1, 0, -1, 0)T

• Camera orientation: up or down
v = (0, 1, 0, 0)T

• Forming orthogonal product for
determining v let’s say u
u = (1, 0, -1,

0)T

Camera at (1,0,1) pointing
toward the origin
The model view matrix M

Result:
Original origin is 1 unit in the n direction from the origin in the camera frame
which is the point (0, 0, 1, 1)

OpenGL model view matrix
OpenGL set a model-view matrix by send an array of 16 elements to
glLoadMatrix
We use this for transformation like rotation, translation and scales etc.
Modeling a colored cube.
• A number of distinct task that we must perform to generate
the image
–
–
–
–
–
–

Modeling
Converting to the camera frame
Clipping
Projecting
Removing hidden surfaces
Rasterizing
One frame of cube animation
Modeling a Cube
• Model as 6 planes intersection or six polygons as cube facets
• Ex. of cube definition
GLfloat vertices[8][3] = {
{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0},
{1.0,1.0,-1.0}, {-1.0,1.0,-1.0},
{-1.0,-1.0,1.0}, {1.0,-1.0,1.0},
{1.0,1.0,1.0}, {-1.0,1.0,1.0}
};
// or
typedef point3[3];
// then may define as
point3 vertices[8] = {
{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0},
{1.0,1.0,-1.0}, {-1.0,1.0,-1.0},
{-1.0,-1.0,1.0}, {1.0,-1.0,1.0},
{1.0,1.0,1.0}, {-1.0,1.0,1.0}
};

// object may defined as
void polygon(int a, int b, int c , int d) {
/* draw a polygon via list of vertices */
glBegin(GL_POLYGON);
glVertex3fv(vertices[a]);
glVertex3fv(vertices[b]);
glVertex3fv(vertices[c]);
glVertex3fv(vertices[d]);
glEnd();
}
Inward and outward pointing faces
• Be careful about the
order of vertices
• facing outward:
vertices order is 0, 3,
2, 1 etc., obey right
hand rule
Traversal of the edges of a
polygon
Data Structure for Object Representation
• Topology of Cube description
– Use glBegin(GL_POLYGON); six times
– Use glBegin(GL_QUADS); follow by 24 vertices

• Think as polyhedron
– Vertex shared by 3 surfaces
– Each pair of vertices define edges
– Each edge is shared by two faces
Vertex-list representation of a cube
The color cube
• Color to vertex list -> color 6 faces
• Define function “quad” for drawing quadrilateral polygon
• Next define 6 faces, be careful about define outwarding
Glfloat vertices[8][3] = {{-1.0,-1.0, 1.0},{-1.0, 1.0, 1.0}, {1.0,1.0, 1.0}, {1.0,-1.0, 1.0},
{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}};
GLfloat colors[8][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0},
{0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};
void quad(int a, int b, int c , int d) {
glBegin(GL_QUADS);
glColor3fv(colors[a]); glVertex3fv(vertices[a]); glColor3fv(colors[b]); glVertex3fv(vertices[b]);
glColor3fv(colors[c]); glVertex3fv(vertices[c]); glColor3fv(colors[d]); glVertex3fv(vertices[d]);
glEnd();
}
void colorcube() {
quad(0, 3, 2, 1); quad(2, 3, 7, 6); quad(0, 4, 7, 3); quad(1, 2, 6, 5); quad(4, 5, 6, 7); quad(0, 1, 5, 4);
}
Vertex Array
• Use encapsulation, data structure & method together
– Few function call

• 3 step using vertex array
– Enable functionality of vertex array: part of initialization
– Tell OpenGL where and in what format the array are: part of
initialization
– Render the object :part of display call back

• 6 different type of array
– Vertex, color, color index, normal texture coordinate and edge flag
– Enabling the arrays by
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
// The arrays are the same as before and can be set up as globals:
GLfloat vertices[] = {{-1,-1,-1}, {1,-1,1}, {1,1,-1}, {-1,1,-1},{-1,-1,1}, {1,-1,1}, {1,1,1}, {-1,1,1}};
GLfloat colors[] = {{0,0,0}, {1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1}, {1,1,1},{0,1,1}};
// Next identify where the arrays are by
glVertexPointer(3, GL_FLOAT, 0, vertices);
glColorPointer(3, GL_FLOAT, 0, colors);
// Define the array to hold the 24 order of vertex indices for 6 faces

GLubyte cubeIndices[24] = {0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5,

4,5,6,7,

0,1,5,4};

glDrawElements(type, n, format, pointer);
for (i=0; i<6; i++)
glDrawElement(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &cubeIndex[4*i]};

// Do better by seeing each face as quadrilateral polygon

glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices);
// GL_QUADS starts a new quadrilateral after each four vertices
Affine transformation
• Transformation:
– A function that takes a
point (or vector) and
maps that points (or
vector) in to another
point (or vector)

Transformatio
n

Q = f ( P),
v = f u  ,
Translation
Is an operation that displaces points by a fixed distance in a given direction
To specify a translation, just specify a displacement vector d thus

P = P  d

• For all point P of the object

– No reference point to frame or representation
– 3 degree of freedom

Translation. (a) Object in original position.
(b) Object translated
Rotation
• Need axis and angle as input parameter
x = r.cosf ;

Two-dimensional rotation

2D Point rotation θ radian around origin (Z axis)

x’ = r.cos(q  f
= r.cosf.cosq- r.sinf.sinq
= x.cosq – y.sinq
y’ = r.sin(qf)
= r.cosf.sinq +r.sinf.cosq
= x.sinq+y.cosq

These equations can be written in matrix form as
 x  cos q
 y =  sin q
  

y = r.sinf

- sin q   x 
cos q   y 
 
3 features for rotation
(3 degrees of freedom)

• Around fixed point (origin)
• Direction ccw is positive
• A line

Rotation arount a fixed point.
3D rotation
• Must define 3 input parameter
– Fixed Point (Pf)
– Rotation angle (θ)
– A line or vector (rotation axis)

• 3 degrees of freedom
• 2 angle necessary specified
orientation of vector
• 1 angle for amount of rotation

Three-dimensional
rotation
Scaling
• Non rigid-body transformation
• 2 type of scaling
– Uniform: scale in all direction -> bigger, smaller

– Nonuniform: scale in single direction

• Use in modeling and scaling

Non rigid body transformations

Uniform and nonuniform scaling
Scaling: input parameter
• 3 degrees of freedom
– Point (Pf)
– Direction (v)
– Scale factor ()
•  > 1 : get bigger
• 0   < 1 : smaller
•  < 0 : model is reflected

Effect of scale factor

Reflection
3D primitives

Curves in three dimension

Surfaces in three
dimensions
Object are not lying on plane

Volumetric
objects
Homogeneous Coordinate
•
•

We use only 3 basis vector is not enough to make point and vector different
For any point:

P = P0  xv1  yv2  zv3

// General equation for point

In the frame specified by (v1, v2, v3, P0), any point P can be written uniquely as

P = 1v1   2v2  3v3  P0
The we can express this relation formally, using a matrix product, as

P = 1  2  3

 v1 
v 
1  2 
 v3 
 
 P0 

We may say that

 1 
 
P =  2
 3 
 
1

The yellow matrix called homogeneous-coordinate representation of point P
Transformation in homogeneous coordinate
Most graphics APIs force us to work within some reference system. Although we
can alter this reference system – usually a frame – we cannot work with high-level
representations, such as the expression.
Q = P + αv.
Instead, we work with representations in homogeneous coordinates, and with
expressions such as
q = p + αv.
Within a frame, each affine transformation is represented by a 4x4 matrix of the
form

é 11 12 13 14 ù

ê
ú
ê 21  22  23  24 ú

ê
ú
M= ê
 31  32  33  34 ú
ê
ú
ê0
0
0
1 ú
ë
û
Translation
Scaling
Use fixed point parameter as reference
Scaling in one direction means scale in each direction element
Rotation

2D rotation is actual 3D rotation around Z axis
For general equations:
Shear
• Let pull in top right edge and bottom left edge
– Neither y nor z are changed
– Call x shear direction

Shear
Suriyong L.
x = x  y cot q x
y = y
z = z
Leading to the shearing matrix
x
Computation of the shear
matrix

Inverse of the shearing matrix: shear in the opposite direction
Concatenation of transformation
Application of transformations one at a time

The sequence of transformation is
q=CBAp
It can be seen that one do first must be near most to input
We may proceed in two steps
Calculate total transformation matrix:

M=CBA
Matrix operation :
q=Mp

Pipeline transformation
Derive example of M: rotation about a fixed point

<- This is what we try to do.

Rotation of a cube about its center

Sequence of transformation

These are process that
we choose to do
General rotation

Rotation of a cube about the y-axis

Rotation of a cube about the z-axis. The
cube is show (a) before rotation, and (b)
after rotation

R = R xR yR z
Rotation of a cube about the x-axis
The Instance transformation
• From the example object, 2 options to do
with object
– Define object to its vertices and location
with the desire orientation and size
– Define each object type once at a
convenience size, place and orientation ,
next move to its place
• Object in the scene is instance of the
prototype
• If apply transformation, called instance
transformation
• We can use database and identifier for each

Scene of simple objects
Instance transformation

M=TRS
//instant transformation equation of object
Rotation around arbitrary axis
• Input parameter
– Object point
– Vector (line segment or 2 points)
– Angle of rotation

• Idea
– Translate to origin first T(-P0)
– Rotate
• q-axis component
• q around 1 component axis, let say z
Let rotation axis vector is u and
u = P2 – P1
<- Convert u to unit
length vector

<- Shift to origin (T(-P)),
end shift back (T(P))
Rotation of a cube about
an arbitrary axis
Movement of the fixed
point to the origin

R = Rx(-qx).Ry(-qy).Rz(q).Ry(qy).Rx(qx)

<- Individual axis rotation z first
Sequence of rotations

Problem: How we fine θx and θy ?
2
2
 x   y   z2 = 1

<- From v, unit vector

cos2 fx  cos2 fy  cos2 fz = 1 <-

cos fx =  x
cos f y =  y

<-

cos fz =  z
f = angle of vector respect to origin

Direction angles
OpenGL transformation matrices
• Use glMatrixMode function for selected
operation to apply
• Most graphic system use Current
Transformation Matrix (CTM) for any
transformation

Current transformation matrix (CTM)
CTM step
• Applied Identity matrix unless operate every round
– C <- I

• Applied Translation
– C <- CT

• Applied Scaling
– C <- CS

• Applied Rotation
– C <- CR

• Or postmultiply with M
– C <- M

or C <- CM
CTM: Translation, rotation and scaling
• CTM may be viewed as the part of all
primitive product GL_MODELVIEW and
GL_PROJECTION
• From function of glMatrixMode

Model-view and projection matrices
Rotation about a fixed point matrix step
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(4.0, 5.0, 6.0);
glRotatef(45.0, 1.0, 2.0, 3.0);
glTranslatef(-4.0, -5.0, -6.0);
//rotate 45 deg. around a vector line 1,2,3
// with fixed point of (4, 5, 6)
c = a  ib = reiq

The quaternion
• Extension of complex number
• Useful for animation and hardware
implementation of rotation
• Consider the complex number
(a, b)

θ

• Like rotate point (a, b) around z axis with θ radian
• quaternion just like rotate in 3D space
Quaternion form

• q0 define rotation angle
• q define point
Multiplication properties
• Identity
– (1, 0)

• Inverse
Rotation with quaternion
• Let p=(0,p)
// point in space with p= (x,y,z)
• And unit quaternion r and its inverse r-1
Quaternion to Rotation Matrix
Replace:

Weitere ähnliche Inhalte

Was ist angesagt?

Overview of 2D and 3D Transformation
Overview of 2D and 3D TransformationOverview of 2D and 3D Transformation
Overview of 2D and 3D TransformationDheeraj Sadawarte
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D2013901097
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
Homogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearingHomogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearingManthan Kanani
 
2d transformations
2d transformations2d transformations
2d transformationskmrvivek2
 
3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinates3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinatesKRIPA SHNAKAR TIWARI
 
2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinatesTarun Gehlot
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 
04transformation2d
04transformation2d04transformation2d
04transformation2dKetan Jani
 
3 d geometric transformations
3 d geometric transformations3 d geometric transformations
3 d geometric transformationsMohd Arif
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transformPatel Punit
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
seminar on 2D transformation
seminar on 2D transformationseminar on 2D transformation
seminar on 2D transformation9784
 
Two dimensional geometric transformation
Two dimensional geometric transformationTwo dimensional geometric transformation
Two dimensional geometric transformationjapan vasani
 
3 d transformation
3 d transformation3 d transformation
3 d transformationPooja Dixit
 

Was ist angesagt? (20)

Overview of 2D and 3D Transformation
Overview of 2D and 3D TransformationOverview of 2D and 3D Transformation
Overview of 2D and 3D Transformation
 
Computer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2DComputer Graphic - Transformations in 2D
Computer Graphic - Transformations in 2D
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
 
Homogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearingHomogeneous Representation: rotating, shearing
Homogeneous Representation: rotating, shearing
 
2d transformations
2d transformations2d transformations
2d transformations
 
3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinates3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinates
 
2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
04transformation2d
04transformation2d04transformation2d
04transformation2d
 
3 d geometric transformations
3 d geometric transformations3 d geometric transformations
3 d geometric transformations
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
 
2d transformations
2d transformations2d transformations
2d transformations
 
3 d transformations
3 d transformations3 d transformations
3 d transformations
 
3D Transformation
3D Transformation 3D Transformation
3D Transformation
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
seminar on 2D transformation
seminar on 2D transformationseminar on 2D transformation
seminar on 2D transformation
 
Two dimensional geometric transformation
Two dimensional geometric transformationTwo dimensional geometric transformation
Two dimensional geometric transformation
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
 
2d/3D transformations in computer graphics(Computer graphics Tutorials)
2d/3D transformations in computer graphics(Computer graphics Tutorials)2d/3D transformations in computer graphics(Computer graphics Tutorials)
2d/3D transformations in computer graphics(Computer graphics Tutorials)
 

Andere mochten auch

Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 dxyz120
 
CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5fungfung Chen
 
Do you know matrix transformations
Do you know matrix transformationsDo you know matrix transformations
Do you know matrix transformationsTarun Gehlot
 
Hearn and Baker 2 D transformations
Hearn and Baker 2 D transformations   Hearn and Baker 2 D transformations
Hearn and Baker 2 D transformations Taher Barodawala
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNANDINI SHARMA
 
Matrices And Application Of Matrices
Matrices And Application Of MatricesMatrices And Application Of Matrices
Matrices And Application Of Matricesmailrenuka
 

Andere mochten auch (9)

Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
 
Matrices 2
Matrices 2Matrices 2
Matrices 2
 
Matrices
MatricesMatrices
Matrices
 
CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5CG OpenGL vectors geometric & transformations-course 5
CG OpenGL vectors geometric & transformations-course 5
 
Do you know matrix transformations
Do you know matrix transformationsDo you know matrix transformations
Do you know matrix transformations
 
Matrices 1
Matrices 1Matrices 1
Matrices 1
 
Hearn and Baker 2 D transformations
Hearn and Baker 2 D transformations   Hearn and Baker 2 D transformations
Hearn and Baker 2 D transformations
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphics
 
Matrices And Application Of Matrices
Matrices And Application Of MatricesMatrices And Application Of Matrices
Matrices And Application Of Matrices
 

Ähnlich wie Geometric objects and transformations

Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-onlinelifebreath
 
Mesh Shape Editing
Mesh Shape EditingMesh Shape Editing
Mesh Shape Editingssuser24ddad
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf ChicagoJanie Clayton
 
Introduction to Real Time Rendering
Introduction to Real Time RenderingIntroduction to Real Time Rendering
Introduction to Real Time RenderingKoray Hagen
 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.pptDebjit Doira
 
affine transformation for computer graphics
affine transformation for computer graphicsaffine transformation for computer graphics
affine transformation for computer graphicsDrSUGANYADEVIK
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphicsSHIVANI SONI
 
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
 
projections - engineering drawing
projections - engineering drawing projections - engineering drawing
projections - engineering drawing Krishna Gali
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014rolly purnomo
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3SIMONTHOMAS S
 
3D transformation and viewing
3D transformation and viewing3D transformation and viewing
3D transformation and viewingYogita Jain
 

Ähnlich wie Geometric objects and transformations (20)

Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
 
Mesh Shape Editing
Mesh Shape EditingMesh Shape Editing
Mesh Shape Editing
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
 
Transformations
TransformationsTransformations
Transformations
 
Introduction to Real Time Rendering
Introduction to Real Time RenderingIntroduction to Real Time Rendering
Introduction to Real Time Rendering
 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.ppt
 
affine transformation for computer graphics
affine transformation for computer graphicsaffine transformation for computer graphics
affine transformation for computer graphics
 
3D transformation in computer graphics
3D transformation in computer graphics3D transformation in computer graphics
3D transformation in computer graphics
 
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
 
Control chap7
Control chap7Control chap7
Control chap7
 
projections - engineering drawing
projections - engineering drawing projections - engineering drawing
projections - engineering drawing
 
Robot kinematics
Robot kinematicsRobot kinematics
Robot kinematics
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 
CO3303-1 Lecture 2.ppt
CO3303-1 Lecture 2.pptCO3303-1 Lecture 2.ppt
CO3303-1 Lecture 2.ppt
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
 
3D transformation and viewing
3D transformation and viewing3D transformation and viewing
3D transformation and viewing
 
Computer Graphics - transformations in 2d
Computer Graphics - transformations in 2dComputer Graphics - transformations in 2d
Computer Graphics - transformations in 2d
 
D4 trigonometrypdf
D4 trigonometrypdfD4 trigonometrypdf
D4 trigonometrypdf
 
Three dimensional concepts - Computer Graphics
Three dimensional concepts - Computer GraphicsThree dimensional concepts - Computer Graphics
Three dimensional concepts - Computer Graphics
 

Kürzlich hochgeladen

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 

Kürzlich hochgeladen (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Geometric objects and transformations

  • 2. Frames in OpenGL • 2 frames: – Camera: regard as fix – World: • The model-view matrix position related to camera • Convert homogeneous coordinates representation of object to camera frame • OpenGL provided matrix stack for store model view matrices or frames • By default camera and world have the same origin • If moving world frame distance d from camera the model-view matrix would be
  • 3. 1 0 A=  0  0 0 0  0 1 -d   0 0 1 0 0 1 0 Camera and world frames
  • 4. Suppose camera at point (1, 0, 1, 1) • World frame center point of camera p = (1, 0, 1, 1)T • Representation of world frame for camera n = (-1, 0, -1, 0)T • Camera orientation: up or down v = (0, 1, 0, 0)T • Forming orthogonal product for determining v let’s say u u = (1, 0, -1, 0)T Camera at (1,0,1) pointing toward the origin
  • 5. The model view matrix M Result: Original origin is 1 unit in the n direction from the origin in the camera frame which is the point (0, 0, 1, 1) OpenGL model view matrix OpenGL set a model-view matrix by send an array of 16 elements to glLoadMatrix We use this for transformation like rotation, translation and scales etc.
  • 6. Modeling a colored cube. • A number of distinct task that we must perform to generate the image – – – – – – Modeling Converting to the camera frame Clipping Projecting Removing hidden surfaces Rasterizing One frame of cube animation
  • 7. Modeling a Cube • Model as 6 planes intersection or six polygons as cube facets • Ex. of cube definition GLfloat vertices[8][3] = { {-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0} }; // or typedef point3[3]; // then may define as point3 vertices[8] = { {-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0} }; // object may defined as void polygon(int a, int b, int c , int d) { /* draw a polygon via list of vertices */ glBegin(GL_POLYGON); glVertex3fv(vertices[a]); glVertex3fv(vertices[b]); glVertex3fv(vertices[c]); glVertex3fv(vertices[d]); glEnd(); }
  • 8. Inward and outward pointing faces • Be careful about the order of vertices • facing outward: vertices order is 0, 3, 2, 1 etc., obey right hand rule Traversal of the edges of a polygon
  • 9. Data Structure for Object Representation • Topology of Cube description – Use glBegin(GL_POLYGON); six times – Use glBegin(GL_QUADS); follow by 24 vertices • Think as polyhedron – Vertex shared by 3 surfaces – Each pair of vertices define edges – Each edge is shared by two faces
  • 11. The color cube • Color to vertex list -> color 6 faces • Define function “quad” for drawing quadrilateral polygon • Next define 6 faces, be careful about define outwarding Glfloat vertices[8][3] = {{-1.0,-1.0, 1.0},{-1.0, 1.0, 1.0}, {1.0,1.0, 1.0}, {1.0,-1.0, 1.0}, {-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}}; GLfloat colors[8][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}}; void quad(int a, int b, int c , int d) { glBegin(GL_QUADS); glColor3fv(colors[a]); glVertex3fv(vertices[a]); glColor3fv(colors[b]); glVertex3fv(vertices[b]); glColor3fv(colors[c]); glVertex3fv(vertices[c]); glColor3fv(colors[d]); glVertex3fv(vertices[d]); glEnd(); } void colorcube() { quad(0, 3, 2, 1); quad(2, 3, 7, 6); quad(0, 4, 7, 3); quad(1, 2, 6, 5); quad(4, 5, 6, 7); quad(0, 1, 5, 4); }
  • 12. Vertex Array • Use encapsulation, data structure & method together – Few function call • 3 step using vertex array – Enable functionality of vertex array: part of initialization – Tell OpenGL where and in what format the array are: part of initialization – Render the object :part of display call back • 6 different type of array – Vertex, color, color index, normal texture coordinate and edge flag – Enabling the arrays by glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
  • 13. // The arrays are the same as before and can be set up as globals: GLfloat vertices[] = {{-1,-1,-1}, {1,-1,1}, {1,1,-1}, {-1,1,-1},{-1,-1,1}, {1,-1,1}, {1,1,1}, {-1,1,1}}; GLfloat colors[] = {{0,0,0}, {1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1}, {1,1,1},{0,1,1}}; // Next identify where the arrays are by glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(3, GL_FLOAT, 0, colors); // Define the array to hold the 24 order of vertex indices for 6 faces GLubyte cubeIndices[24] = {0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5, 4,5,6,7, 0,1,5,4}; glDrawElements(type, n, format, pointer); for (i=0; i<6; i++) glDrawElement(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &cubeIndex[4*i]}; // Do better by seeing each face as quadrilateral polygon glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices); // GL_QUADS starts a new quadrilateral after each four vertices
  • 14. Affine transformation • Transformation: – A function that takes a point (or vector) and maps that points (or vector) in to another point (or vector) Transformatio n Q = f ( P), v = f u  ,
  • 15. Translation Is an operation that displaces points by a fixed distance in a given direction To specify a translation, just specify a displacement vector d thus P = P  d • For all point P of the object – No reference point to frame or representation – 3 degree of freedom Translation. (a) Object in original position. (b) Object translated
  • 16. Rotation • Need axis and angle as input parameter x = r.cosf ; Two-dimensional rotation 2D Point rotation θ radian around origin (Z axis) x’ = r.cos(q  f = r.cosf.cosq- r.sinf.sinq = x.cosq – y.sinq y’ = r.sin(qf) = r.cosf.sinq +r.sinf.cosq = x.sinq+y.cosq These equations can be written in matrix form as  x  cos q  y =  sin q    y = r.sinf - sin q   x  cos q   y   
  • 17. 3 features for rotation (3 degrees of freedom) • Around fixed point (origin) • Direction ccw is positive • A line Rotation arount a fixed point.
  • 18. 3D rotation • Must define 3 input parameter – Fixed Point (Pf) – Rotation angle (θ) – A line or vector (rotation axis) • 3 degrees of freedom • 2 angle necessary specified orientation of vector • 1 angle for amount of rotation Three-dimensional rotation
  • 19. Scaling • Non rigid-body transformation • 2 type of scaling – Uniform: scale in all direction -> bigger, smaller – Nonuniform: scale in single direction • Use in modeling and scaling Non rigid body transformations Uniform and nonuniform scaling
  • 20. Scaling: input parameter • 3 degrees of freedom – Point (Pf) – Direction (v) – Scale factor () •  > 1 : get bigger • 0   < 1 : smaller •  < 0 : model is reflected Effect of scale factor Reflection
  • 21. 3D primitives Curves in three dimension Surfaces in three dimensions Object are not lying on plane Volumetric objects
  • 22. Homogeneous Coordinate • • We use only 3 basis vector is not enough to make point and vector different For any point: P = P0  xv1  yv2  zv3 // General equation for point In the frame specified by (v1, v2, v3, P0), any point P can be written uniquely as P = 1v1   2v2  3v3  P0 The we can express this relation formally, using a matrix product, as P = 1  2  3  v1  v  1  2   v3     P0  We may say that  1    P =  2  3    1 The yellow matrix called homogeneous-coordinate representation of point P
  • 23. Transformation in homogeneous coordinate Most graphics APIs force us to work within some reference system. Although we can alter this reference system – usually a frame – we cannot work with high-level representations, such as the expression. Q = P + αv. Instead, we work with representations in homogeneous coordinates, and with expressions such as q = p + αv. Within a frame, each affine transformation is represented by a 4x4 matrix of the form é 11 12 13 14 ù  ê ú ê 21  22  23  24 ú  ê ú M= ê  31  32  33  34 ú ê ú ê0 0 0 1 ú ë û
  • 25. Scaling Use fixed point parameter as reference Scaling in one direction means scale in each direction element
  • 26. Rotation 2D rotation is actual 3D rotation around Z axis For general equations:
  • 27.
  • 28. Shear • Let pull in top right edge and bottom left edge – Neither y nor z are changed – Call x shear direction Shear Suriyong L.
  • 29. x = x  y cot q x y = y z = z Leading to the shearing matrix x Computation of the shear matrix Inverse of the shearing matrix: shear in the opposite direction
  • 30. Concatenation of transformation Application of transformations one at a time The sequence of transformation is q=CBAp It can be seen that one do first must be near most to input We may proceed in two steps Calculate total transformation matrix: M=CBA Matrix operation : q=Mp Pipeline transformation
  • 31. Derive example of M: rotation about a fixed point <- This is what we try to do. Rotation of a cube about its center Sequence of transformation These are process that we choose to do
  • 32.
  • 33. General rotation Rotation of a cube about the y-axis Rotation of a cube about the z-axis. The cube is show (a) before rotation, and (b) after rotation R = R xR yR z Rotation of a cube about the x-axis
  • 34. The Instance transformation • From the example object, 2 options to do with object – Define object to its vertices and location with the desire orientation and size – Define each object type once at a convenience size, place and orientation , next move to its place • Object in the scene is instance of the prototype • If apply transformation, called instance transformation • We can use database and identifier for each Scene of simple objects
  • 36. Rotation around arbitrary axis • Input parameter – Object point – Vector (line segment or 2 points) – Angle of rotation • Idea – Translate to origin first T(-P0) – Rotate • q-axis component • q around 1 component axis, let say z
  • 37. Let rotation axis vector is u and u = P2 – P1 <- Convert u to unit length vector <- Shift to origin (T(-P)), end shift back (T(P)) Rotation of a cube about an arbitrary axis Movement of the fixed point to the origin R = Rx(-qx).Ry(-qy).Rz(q).Ry(qy).Rx(qx) <- Individual axis rotation z first
  • 38. Sequence of rotations Problem: How we fine θx and θy ? 2 2  x   y   z2 = 1 <- From v, unit vector cos2 fx  cos2 fy  cos2 fz = 1 <- cos fx =  x cos f y =  y <- cos fz =  z f = angle of vector respect to origin Direction angles
  • 39. OpenGL transformation matrices • Use glMatrixMode function for selected operation to apply • Most graphic system use Current Transformation Matrix (CTM) for any transformation Current transformation matrix (CTM)
  • 40. CTM step • Applied Identity matrix unless operate every round – C <- I • Applied Translation – C <- CT • Applied Scaling – C <- CS • Applied Rotation – C <- CR • Or postmultiply with M – C <- M or C <- CM
  • 41. CTM: Translation, rotation and scaling • CTM may be viewed as the part of all primitive product GL_MODELVIEW and GL_PROJECTION • From function of glMatrixMode Model-view and projection matrices
  • 42. Rotation about a fixed point matrix step glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(4.0, 5.0, 6.0); glRotatef(45.0, 1.0, 2.0, 3.0); glTranslatef(-4.0, -5.0, -6.0); //rotate 45 deg. around a vector line 1,2,3 // with fixed point of (4, 5, 6)
  • 43. c = a  ib = reiq The quaternion • Extension of complex number • Useful for animation and hardware implementation of rotation • Consider the complex number (a, b) θ • Like rotate point (a, b) around z axis with θ radian • quaternion just like rotate in 3D space
  • 44. Quaternion form • q0 define rotation angle • q define point
  • 46. Rotation with quaternion • Let p=(0,p) // point in space with p= (x,y,z) • And unit quaternion r and its inverse r-1
  • 47. Quaternion to Rotation Matrix Replace: