Sei sulla pagina 1di 39

Moreabouttransformation

3DTransformation 3DTransformation
Meshdatastructure
Recap:2DTranslation
Movingthereferenceframebyavector
(
(

+
(
(

(
(

(
(

0 1 '
x x
t x x t x
(
(
(

+ =
(
(
(

(
(
(

=
(
(
(

1 1 1 0 0
1 0
1
'
y
x
y
x
t y y t y
) , ( '
y x
t y t x p + + =
Byatranslationmatrix

) , ( y x p =
(
(
(

= 1 0
0 1
) (
x
t
t
t t T
) , (
y x
t t t =
(
(

=
1 0 0
1 0 ) , (
y y x
t t t T
Recap:2DRotation
Rotationallverticesaroundtheorigin
Anticlockwise
(
(
(

=
(
(
(

(
(
(


=
(
(
(

cos sin
sin cos
0 cos sin
0 sin cos
'
'
u u
u u
u u
u u
y x
y x
y
x
y
x
(
(

(
(

(
(

(
(

1 1 1 0 0 1
y y y
Byarotationalmatrix
u (
(

0 sin cos u u
u
(
(
(

=
1 0 0
0 cos sin ) ( u u u R
Recap:Scaling
Shrinkorgrow
Simply
( (
x ax
(
(
(

=
(
(
(

=
1
) , (
1
' y
x
b a S by
ax
p
a andb couldbeve
(

1 1
(
(

0 0 a
Byascalingmatrix
OpenGLfunction:
(
(
(

=
1 0 0
0 0 ) , ( b b a S
p
glScalef(x,y,z);
Recap:CompositeTransformation
Wheneveryouaddanewtransformation,youadditto
theRIGHTofthematrices
p T p ) 5 . 0 , 0 ( ' =
p R T p ) 45 ( ) 5 0 0 ( ' '

= p R T p ) 45 ( ) 5 . 0 , 0 ( =
Mp p = ' '
Recap: Order of Transformation Recap:OrderofTransformation
Differentordersmakedifferent
it t f ti compositetransformations
p R T p ) 45 ( ) 5 . 0 , 0 ( ' '

=
p T R p ) 5 . 0 , 0 ( ) 45 ( ' '

=
NOT NOTALWAYS ALWAYS
COMMUTATIVE COMMUTATIVE!! !!
BA AB =
TheWayThatOpenGLDoesit
Wheneveryoudrawapointp,OpenGLwilldrawitatthe
position
Mp p = ' '
InwhichM istheModelViewMatrix
Whenyouwanttochangethistransformationmatrix
M,youcan:
Choices:
GL_MODELVIEW
, y
glMatrixMode(GL_MODELVIEW);
Switchtothistransformationmatrix
glLoadIdentity();
GL_PROJECTION
GL_TEXTURE
GL_COLOR
g y();
SetM tobetheidentitymatrix
glTranslatef()
SetM :=MT
glRotatef()
SetM :=MR
TheWayOpenGLDoesit
glScalef()
SetM :=MS
glPushMatrix();
PushthecurrentM ontothestack
MeaningSavingthecurrentreferenceframe
glPopMatrix();
f h k d l h PopamatrixM fromthestack,andreplacethecurrent
MwithM
MeaningResumingthelastsavedreferenceframe Meaning Resumingthelastsavedreferenceframe
Hierarchical
Transformation
HierarchicalTransformation
Example
Drawastickfigure
AfunctioncalleddrawAUnitLine()
Drawalinefrom(0,0)to(0,1)
D h Drawtheeastarm
Translate(0,0.5)
Rotate(90) Rotate( 90)
drawAUnitLine()
HierarchicalTransformation
drawLeftArm()
{
glPushMatrix();
glRotatef(-90,0,0,1);
drawAUnitLine();
glPopMatrix();
}
HierarchicalTransformation
drawAStickFigure()
{
glPushMatrix();
glTranslatef(0,0.5,0);
drawLeftArm();
drawRightArm();
glPopMatrix();
glPushMatrix();
drawLeftLeg(); g
drawRightLeg();
glPopMatrix();
}}
HowdoIDrawthis?
myDisplay()
{
glPushMatrix();
glTranslatef(some where..);
glRotatef(some angle);
drawAStickFigure();
glPopMatrix();
.
.
.
// draw many many
}}
MaketheLeftArmWave
drawAStickFigure(double angle)
{
glPushMatrix();
glTranslatef(0,0 5,0); glTranslatef(0,0.5,0);
glPushMatrix();
glRotatef(angle,0,0,1);
drawLeftArm();
() glPopMatrix();
drawRightArm();
glPopMatrix();
glPushMatrix(); g ();
drawLeftLeg();
drawRightLeg();
glPopMatrix();
}}
HowdoIDrawthis?
myDisplay()
{
glPushMatrix();
glTranslatef(some where..);
glRotatef(some angle);
drawAStickFigure(angle);
glPopMatrix();
.
.
.
// draw many many
}}
HierarchicalTransformation
Thefigurecanbeunderstoodasahierarchyas
Stick
Figure Figure
Right
Arm
Left
Leg
Right
Leg
Left
Arm
Whenweapplyatransformationtoanode,allits
hild i it b t ff t d
Leg Leg
childreninitssubtreeareaffected
E.g.whenwetranslatethestickfigure,allthelimbsare
translated translated
HierarchicalTransformation
Moredeeperlevelsofhierarchy
Applythetransformationtoanylevel
Stick
Figure
E.g.Rotationattheleftarm2
Thelowersubtreerotates
Right
Arm
Left
Arm1
Left
.
Left
Arm2
Palm
Finger1 Finger2
.
3DTranslationMatrix
Nowapointin3Dis
p =[xyz1]
T
Wecanalsoexpresstranslationusinga4x4matrixT
inhomogeneouscoordinates
y
p' = Tp
h (d d d )
(
(
(

0 1 0
0 0 1
x
d
d
z
x
y
where T = T(d
x
, d
y
, d
z
) =
(
(
(
(

1 0 0 0
1 0 0
0 1 0
z
y
d
d
x
y

1 0 0 0
z
(d
x
,d
y
,d
z
)
3DRotationMatrix
Sameargumentasforrotationaboutzaxis
(
(
(
(


0 0 cos sin
0 0 sin cos


R
z
(u )=
(
(

1 0 0 0
0 1 0 0
z
( )
RotationAboutx- andyAxes
xaxisandyaxis
(
0 0 0 1
R
x
(u )=
(
(
(
(
(

0 cos sin 0
0 sin cos 0
0 0 0 1


(

1 0 0 0
(
0 sin 0 cos
R
y
(u )=
(
(
(
(
(

0 cos 0 sin
0 0 1 0
0 sin 0 cos


(

1 0 0 0
3DRotationinOpenGL
glRotatef(alpha, x, y, z)
ApointP1 willberotatedaroundthevector(x, y, z) (that
th h th i i ) b l l h passes through the origin) byananglealpha
Scaling Scaling
Expandingorcontractingalonganyaxis
x' = s x
N if l
x' = s
x
x
y' = s
y
y
z' = s z
Nonuniformscale
z s
z
z
Orinhomogeneouscoordinates
p' = S(s
x
, s
y
, s
z
) p
(
(

0 0 0
0 0 0
x
s
(
(
(
(

1 0 0 0
0 0 0
0 0 0
z
y
s
s
S(s
x
,s
y
,s
z
)=
Uniformscale

1 0 0 0
AndPolygonalMeshes AndPolygonalMeshes
VariousObjectRepresentations
Polygonalmeshes
Parametricpatches
Constructivesolidgeometry(CSG)
Spatialsubdivisiontechniques
Implicitrepresentation
1
2 2 2
= + + z y x
VariousObjectRepresentations
Polygonalmeshes
VariousObjectRepresentations
Parametricpatches(Lecture9)
VariousObjectRepresentations
Constructivesolidgeometry(CSG)
VariousObjectRepresentations
Spatialsubdivisiontechniques
I li i i Implicitrepresentation
1
2 2 2
= + + z y x
P l l M h PolygonalMeshes
Wecanusesoupsofpolygons(preferablytriangles) p p yg (p y g )
tomodel(actuallyapproximate)objects
BasicRepresentationof3DObjects
Pointerstoneighbor
polygon(s)
ClockwiseorAnti
clockwiseSequence
MeshRepresentation
Anexampleofasimplemesh
ontheright
Thereare8nodesand12edges
v
6
v
8
v
5
e
8
e
3
e
2
e
9
Thereare8nodesand12edges
5interiorpolygons
6interior(shared)edges
v
7
8
v
4 e
1 e
11
e
7
e
10
e
4
g
Eachvertexhasalocation
v
i
=(x
i
y
i
z
i
)
hi k fi h
v
1
v
2
v
3 e
6
e
5
e
12
Wecanthinkofitasagraph,
verticesareconnectedby
edges
2
g
MeshTopology
TheedgesformtheTopologyof
themesh
h h i
v
6
v
8
v
5
e
8
e
3
e
2
e
9
Notethattheseconnectionsare
notchangedevenifwemodify
thepositionsofthevertices
v
7
8
v
4 e
1 e
11
e
7
e
10
e
4
thepositionsofthevertices
Weoftenconsiderthetopology
(connections)tobeindependent
v
1
v
2
v
3 e
6
e
5
e
12
p
ofthegeometry(actual3Dpoint
positions)
2
Vertex List and Polygon List VertexListandPolygonList
Storethevertexcoordinatesinaseparatelist
Advantages:savememory avoidconfusion/numeric Advantages:savememory,avoidconfusion/numeric
errors
VertexIndex
P1
P2
v1x,v1y,v1z
v2x,v2y,v2z
v
1
v
8
VertexList
VertexIndex
(Topology)
Polygons
P2
P3
.
v3x,v3y,v3z
v4x,v4y,v4z

v
6
v
8
v
5
v
6
.
.
P5
v5x,v5y,v5z
v6x,v6y,v6z
v7x,v7y,v7z
topology
geometry
v8x,v8y,v8z
* We call this data structure a polygon list
or triangle list (if the polygons=triangles)
Sometimes the polygons are called faces
PolygonOrientations
v
1
v
2
Foratrianglewiththreeverticesv
1
, v
2
and v
3
Theorder(v
1
, v
3
, v
2
) and(v
3
, v
2
, v
1
) areconsideredtobe
equivalent
B tth d ( ) i id dt b diff t
v
3
Buttheorder(v
1
, v
2
, v
3
) isconsideredtobedifferent
(oropposite)
(v
1
, v
3
, v
2
) and(v
3
, v
2
, v
1
) describeafacingdirection
ofapolygon/triangle ofapolygon/triangle
Righthandrule
The order (v
1
, v
2
, v
3
) creates an opposite facing
direction
So,geometryisthesame,butnormalvector for
thatpolygonwillbedifferent
Usuallywefollowthenaturalorderinthe Usua y we o ow t e atu a o de t e
polygonlisttodefinetheoutwarddirectionofan
object
SwitchingtheWindinginOpenGL
OpenGLdefaultisthatoutwardfacingpolygonsarespecifiedin
counterclockwisefashion
Because,thereisaspeedupfeaturesuchthatOpenGLwillSTOP drawing
thosepolygonswhentheoutwarddirectionisnot facingyoureyes
Butyouchangethisby:
glFrontFace(GL_CW); // Clockwise Winding = outward face
glFrontFace(GL_CCW); // Counter-Clockwise Winding =
// outward face

Potrebbero piacerti anche