版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2015年西藏中考英语真题及解析
- 深度解析(2026)《GBT 30246.11-2013家庭网络 第11部分:控制网络接口一致性测试规范》
- 深度解析(2026)《GBT 30167.1-2013纺织机械 织机边撑 第1部分:边撑刺轴》
- 2026年甘肃中考语文试题及答案
- 发热待查诊治专家共识总结2026
- 《GBT 5704-2008人体测量仪器》(2026年)合规红线与避坑实操手册
- 《GBT 2029-2008铸钢吸入通海阀》(2026年)合规红线与避坑实操手册
- 《DLT 5037-2022轴流式水轮机埋件安装工艺导则》(2026年)合规红线与避坑实操手册
- 2026年食品加工厂设备改造合同
- 单片基础原理教程 3
- 2025年度国家广播电视总局直属事业单位公开招聘310人笔试备考题库及答案解析
- 江苏省连云港市海州区新海实验中学2025届中考生物全真模拟试卷含解析
- 2024-2025成都各区初二年级下册期末数学试卷
- 知行合一 - 社会实践•创新创业学习通超星期末考试答案章节答案2024年
- 公安机关保密协议
- 老年人能力评估师理论知识考核要素细目表一级
- 人工智能训练师理论知识考试题库(浓缩500题)
- 护理翻转课堂
- 相关知识培训课件
- 汉代典客、大行、鸿寐考述
- 船舶焊接工艺船舶材料与焊接第三章演示文稿
评论
0/150
提交评论