计算机图形学computer graphics课件11_第1页
计算机图形学computer graphics课件11_第2页
计算机图形学computer graphics课件11_第3页
计算机图形学computer graphics课件11_第4页
计算机图形学computer graphics课件11_第5页
已阅读5页,还剩55页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PPT&Programs&Labcourse2/share/ComputerGraphics/12TransformationsShandongUniversitySoftwareCollegeInstructor:ZhouYuanfengE-mail:yuanfeng.zhou@3ObjectivesIntroducestandardtransformationsRotationTranslationScalingShearDerivehomogeneouscoordinatetransformationmatricesLearntobuildarbitrarytransformationmatricesfromsimpletransformationsWhytransformation?4BeforeAfterAfterBeforeWhytransformation?5Snowconstruction6GeneralTransformationsAtransformationmapspointstootherpointsand/orvectorstoothervectorsQ=T(P)v=T(u)7AffineTransformationsLineartransformation+translationHowever,anaffinetransformationhasonly12degreesoffreedom

because4oftheelementsinthematrixarefixedandareasubsetofallpossible4x4lineartransformations8AffineTransformationsLinepreservingCharacteristicofmanyphysicallyimportanttransformationsRigidbodytransformations:rotation,translationScaling,shearImportanceingraphicsisthatweneedonlytransformendpointsoflinesegmentsandletimplementationdrawlinesegmentbetweenthetransformedendpoints9PipelineImplementationtransformationrasterizer

uv

u

vTT(u)T(v)T(u)T(u)T(v)T(v)verticesverticespixelsframebuffer(fromapplicationprogram)10NotationWewillbeworkingwithbothcoordinate-freerepresentationsoftransformationsandrepresentationswithinaparticularframe

P,Q,R:pointsinanaffinespaceu,v,w:vectorsinanaffinespace

a,b,g:scalars

p,q,r:representationsofpoints -arrayof4scalarsinhomogeneouscoordinatesu,v,w:representationsofvectors -arrayof4scalarsinhomogeneouscoordinates11TheWorldandCameraFramesWhenweworkwithrepresentations,weworkwithn-tuplesorarraysofscalarsChangesinframearethendefinedby4x4matricesInOpenGL,thebaseframethatwestartwithistheworldframeEventuallywerepresententitiesinthecameraframebychangingtheworldrepresentationusingthemodel-viewmatrixInitiallytheseframesarethesame(M=I)12MovingtheCameraIfobjectsareonbothsidesofz=0,wemustmovecameraframeM=13TranslationMove(translate,displace)apointtoanewlocationDisplacementdeterminedbyavectorvThreedegreesoffreedomP’=P+vPP’v14Howmanyways?Althoughwecanmoveapointtoanewlocationininfiniteways,whenwemovemanypointsthereisusuallyonlyonewayobjecttranslation:everypointdisplacedbysamevector15TranslationUsingRepresentationsUsingthehomogeneouscoordinaterepresentationinsomeframep=[xyz1]Tp’=[x’y’z’1]Tv=[vxvyvz0]THencep’=p+vor

x’=x+vx

y’=y+vy

z’=z+vznotethatthisexpressionisinfourdimensionsandexpressespoint=vector+point16TranslationMatrixWecanalsoexpresstranslationusinga4x4matrixTinhomogeneouscoordinatesp’=TpwhereT=T(vx,vy,vz)=Thisformisbetterforimplementationbecauseallaffinetransformationscanbeexpressedthiswayandmultipletransformationscanbeconcatenatedtogether17Rotation(2D)Considerrotationabouttheoriginby

q

degreesradiusstaysthesame,angleincreasesbyqx’=xcos

q

–ysinqy’=xsinq+ycosq18RotationaboutthezaxisRotationaboutzaxisinthreedimensionsleavesallpointswiththesamezEquivalenttorotationintwodimensionsinplanesofconstantzorinhomogeneouscoordinatesp’=Rz(q)px’=xcosq–ysinqy’=xsinq+ycos

qz’=z19RotationMatrixR=Rz(q)=20RotationaboutxandyaxesSameargumentasforrotationaboutzaxisForrotationaboutxaxis,xisunchangedForrotationaboutyaxis,yisunchangedR=Rx(q)=R=Ry(q)=21ScalingS=S(sx,sy,sz)=x’=sxxy’=syyz’=szzp’=SpExpandorcontractalongeachaxis(fixedpointoforigin)22Reflectioncorrespondstonegativescalefactorsoriginalsx=-1sy=1sx=-1sy=-1sx=1sy=-123InversesAlthoughwecouldcomputeinversematricesbygeneralformulas,wecanusesimplegeometricobservationsTranslation:T-1(dx,dy,dz)=T(-dx,-dy,-dz)Rotation:R

-1(q)=R(-q)HoldsforanyrotationmatrixNotethatsincecos(-q)=cos(q)andsin(-q)=-sin(q)R

-1(q)=RT(q)Scaling:S-1(sx,sy,sz)=S(1/sx,1/sy,1/sz)

24ConcatenationWecanformarbitraryaffinetransformationmatricesbymultiplyingtogetherrotation,translation,andscalingmatricesBecausethesametransformationisappliedtomanyvertices,thecostofformingamatrixM=ABCDisnotsignificantcomparedtothecostofcomputingMpformanyverticespThedifficultpartishowtoformadesiredtransformationfromthespecificationsintheapplication25OrderofTransformationsNotethatmatrixontherightisthefirstappliedMathematically,thefollowingareequivalentp’=ABCp=A(B(Cp))Notemanyreferencesusecolumnmatricestorepresentpoints.Intermsofcolumnmatrices((AB)T=BTAT)p’T=pTCTBTAT26GeneralRotationAbouttheOriginqxzyvArotationbyqaboutanarbitraryaxiscanbedecomposedintotheconcatenationofrotationsaboutthex,y,andzaxesR(q)=Ry(-qy)Rx(-qx)Rz(qz)Ry(qy)Rx(qx)qxqyqzarecalledtheEuleranglesNotethatrotationsdonotcommuteWecanuserotationsinanotherorderbutwithdifferentangles27RotationAboutaFixedPointotherthantheOriginMovefixedpointtooriginRotateMovefixedpointbackM=T(pf)R(q)T(-pf)28InstancetransformationInmodeling,weoftenstartwithasimpleobjectcenteredattheorigin,orientedwiththeaxis,andatastandardsizeWeapplyaninstancetransformationtoitsverticesto Scale Orient Locate29ShearHelpfultoaddonemorebasictransformationEquivalenttopullingfacesinoppositedirections30ShearMatrixConsidersimpleshearalongxaxisx’=x+ycotqy’=yz’=zH(q)=

RotationaroundarbitraryvectorR(Ax,Ay,Az)Ifthenv=w×u31R=Rz(q)=32OpenGLMatricesInOpenGLmatricesarepartofthestateMultipletypesModel-View(GL_MODELVIEW)Projection(GL_PROJECTION)Texture(GL_TEXTURE)(ignorefornow)Color(GL_COLOR)(ignorefornow)SinglesetoffunctionsformanipulationSelectwhichtomanipulatedbyglMatrixMode(GL_MODELVIEW);glMatrixMode(GL_PROJECTION);33CurrentTransformationMatrix(CTM)Conceptuallythereisa4x4homogeneouscoordinatematrix,thecurrenttransformationmatrix(CTM)thatispartofthestateandisappliedtoallverticesthatpassdownthepipelineTheCTMisdefinedintheuserprogramandloadedintoatransformationunitCTMverticesverticespp’=CpC34CTMoperationsTheCTMcanbealteredeitherbyloadinganewCTMorbypostmutiplicationLoadanidentitymatrix:C

ILoadanarbitrarymatrix:C

MLoadatranslationmatrix:C

TLoadarotationmatrix:C

RLoadascalingmatrix:C

SPostmultiplybyanarbitrarymatrix:C

CMPostmultiplybyatranslationmatrix:C

CTPostmultiplybyarotationmatrix:C

C

RPostmultiplybyascalingmatrix:C

C

S35RotationaboutaFixedPointStartwithidentitymatrix:C

IMovefixedpointtoorigin:C

CTRotate:C

CRMovefixedpointback:C

CT-1Result:C=TRT–1

whichisbackwards.Thisresultisaconsequenceofdoingpostmultiplications.Let’stryagain.36ReversingtheOrderWewant

C=T–1RTsowemustdotheoperationsinthefollowingorderC

IC

CT-1C

CRC

CTEachoperationcorrespondstoonefunctioncallintheprogram.Notethatthelastoperationspecifiedisthefirstexecutedintheprogram37CTMinOpenGLOpenGLhasamodel-viewandaprojectionmatrixinthepipelinewhichareconcatenatedtogethertoformtheCTMCanmanipulateeachbyfirstsettingthecorrectmatrixmode38Rotation,Translation,ScalingglRotatef(theta,vx,vy,vz)glTranslatef(dx,dy,dz)glScalef(sx,sy,sz)glLoadIdentity()Loadanidentitymatrix:Multiplyonright:thetaindegrees,(vx,vy,vz)defineaxisofrotationEachhasafloat(f)anddouble(d)format(glScaled)39ExampleRotationaboutzaxisby30degreeswithafixedpointof(1.0,2.0,3.0)RememberthatlastmatrixspecifiedintheprogramisthefirstappliedDemoglMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(1.0,2.0,3.0);glRotatef(30.0,0.0,0.0,1.0);glTranslatef(-1.0,-2.0,-3.0);40ArbitraryMatricesCanloadandmultiplybymatricesdefinedintheapplicationprogramThematrixmisaonedimensionarrayof16elementswhicharethecomponentsofthedesired4x4matrixstoredbycolumnsInglMultMatrixf,mmultipliestheexistingmatrixontherightglLoadMatrixf(m)glMultMatrixf(m)Matrixmultiply//沿Y轴向上平移10个单位

glTranslatef(0,10,0);

//画第一个球体

DrawSphere(5);

//沿X轴向左平移10个单位

glTranslatef(10,0,0);

//画第二个球体

DrawSphere(5);41procedureRenderScene();

begin

glMatrixMode(GL_MODELVIEW);

//沿Y轴向上平移10个单位

glTranslatef(0,10,0);

//画第一个球体

DrawSphere(5);

//加载单位矩阵

glLoadIdentity();

//沿X轴向上平移10个单位

glTranslatef(10,0,0);

//画第二个球体

DrawSphere(5);

end;42MatrixStacksInmanysituationswewanttosavetransformationmatricesforuselaterTraversinghierarchicaldatastructuresAvoidingstatechangeswhenexecutingdisplaylistsOpenGLmaintainsstacksforeachtypeofmatrixAccesspresenttype(assetbyglMatrixMode)byglPushMatrix()glPopMatrix()GL_PROJECTIONGL_MODEVIEWMatrixStacksprocedureRenderScene();

begin

glMatrixMode(GL_MODELVIEW);

//pushmatrixstack

glPushMatrix;

//translate10alongYaxis

glTranslatef(0,10,0);

//drawthefirstsphere

DrawSphere(5);

//comebacktothelastsavedstate

glPopMatrix;

//translate10alongXaxis

glTranslatef(10,0,0);

//drawthesecondsphere

DrawSphere(5);

end;4344ReadingBackMatricesCanalsoaccessmatrices(andotherpartsofthestate)byqueryfunctionsFormatrices,weuseasglGetIntegervglGetFloatvglGetBooleanvglGetDoublevglIsEnabledfloatm[16];glGetFloatv(GL_MODELVIEW,m);45UsingTransformationsExample:useidlefunctiontorotateacubeandmousefunctiontochangedirectionofrotationStartwithaprogramthatdrawsacube(colorcube.c)inastandardwayCenteredatoriginSidesalignedwithaxesWilldiscussmodelinginnextlecture46main.cvoidmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutInitWindowSize(500,500);glutCreateWindow("colorcube");glutReshapeFunc(myReshape);glutDisplayFunc(display);glutIdleFunc(spinCube);glutMouseFunc(mouse);glEnable(GL_DEPTH_TEST);glutMainLoop();}47IdleandMousecallbacksvoidspinCube(){ theta[axis]+=2.0; if(theta[axis]>360.0)theta[axis]-=360.0; glutPostRedisplay();}voidmouse(intbtn,intstate,intx,inty){char

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论