版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
计算机三维图形程序设计
徐岗
gxu@
虚拟现实、军事仿真三维游戏网上三维交互
电子商务、虚拟商城、虚拟社区编辑ppt三维图形实时渲染引擎开源系统
OGRE(/)OSG()
IrrIichtengine(/)
delta3d商业游戏引擎
WorldofWarcraft(没发布)AIONCryEngine2,Crytek出品
由EpciGames研发的Unreal引擎
编辑pptOpenGL现状TheKhronosGroup-MediaAuthoringandAccelerationTheKhronosGroupisanindustryconsortiumcreatingopenstandardsfortheauthoringandaccelerationofparallelcomputing,graphicsanddynamicmediaonawidevarietyofplatformsanddevices.AllKhronosmembersareabletocontributetothedevelopmentofKhronosAPIspecifications,areempoweredtovoteatvariousstagesbeforepublicdeployment,andareabletoacceleratethedeliveryoftheircutting-edge3Dplatformsandapplicationsthroughearlyaccesstospecificationdraftsandconformancetests./编辑pptOpenGL现状TheOpenGL4.2andOpenGLShadingLanguage4.20SpecificationswerereleasedonAugust8,2011DirectX11编辑pptOpenCLOpenCL-Theopenstandardforparallelprogrammingofheterogeneoussystems.OpenCL™isthefirstopen,royalty-freestandardforcross-platform,parallelprogrammingofmodernprocessorsfoundinpersonalcomputers,serversandhandheld/embeddeddevices.OpenCL(OpenComputingLanguage)greatlyimprovesspeedandresponsivenessforawidespectrumofapplicationsinnumerousmarketcategoriesfromgamingandentertainmenttoscientificandmedicalsoftware.WebCL-HeterogeneousparallelcomputinginHTML5webbrowsers.TheWebCLworkinggroupisworkingtodefineaJavaScriptbindingtotheKhronosOpenCLstandardforheterogeneousparallelcomputing.WebCLwillenablewebapplicationstoharnessGPUandmulti-coreCPUparallelprocessingfromwithinaWebbrowser,enablingsignificantaccelerationofapplicationssuchasimageandvideoprocessingandadvancedphysicsforWebGLgames.WebCLisbeingdevelopedinclosecooperationwiththeWebcommunityandhasthepotentialtoextendthecapabilitiesofHTML5browserstoacceleratecomputationallyintensiveandrichvisualcomputingapplications.编辑ppt第一章OpenGL概览图形硬件的软件接口跨平台—Windows,linuxGLU(OpenGLUtilityLibrary)建模(曲线、曲面(NURBS))是一个状态机。它将一直处于您指定的各种状态(或模式)中,直到您修改这些状态为止。编辑pptOpenGL程序框架打开一个窗口创建一个OpenGLContextWhile(!Stop){if(有事件)
{更新数据
绘制当前帧}else空闲处理
}编辑ppt一个简单的OpenGL程序#include<whateverYouNeed.h>main(){InitializeAWindowPlease();glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,1.0,1.0);glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);glBegin(GL_POLYGON);glVertex3f(0.25,0.25,0.0);glVertex3f(0.75,0.25,0.0);glVertex3f(0.75,0.75,0.0);glVertex3f(0.25,0.75,0.0);glEnd();glFlush();UpdateTheWindowAndCheckForEvents();}编辑pptOpenGL的要点OpenGL函数的语法OpenGL是一个状态机OpenGL渲染流水线显示列表求值程序顶点操作图元装配PrimitiveAssembly像素操作纹理装配光栅化片元操作编辑ppt数据类型编辑ppt动画open_window();for(i=0;i<1000000;i++){clear_the_window();draw_frame(i);wait_until_a_24th_of_a_second_is_over();}双buffer状态下的绘制open_window_in_double_buffer_mode();for(i=0;i<1000000;i++){clear_the_window();draw_frame(i);swap_the_buffers();}编辑ppt帧频的变化theswap_the_buffers()routinewaitsuntilthecurrentscreenrefreshperiodisoversothatthepreviousbufferiscompletelydisplayed.编辑pptOpenGL程序练习编辑ppt第二章状态管理和绘制几何体ClearingtheWindow编辑pptSpecifyingaColor
glColor3f(1.0,0.0,0.0);redglColor3f(0.0,1.0,0.0);greenglColor3f(1.0,1.0,0.0);yellowglColor3f(0.0,0.0,1.0);blueglColor3f(1.0,0.0,1.0);magentaglColor3f(0.0,1.0,1.0);cyanglColor3f(1.0,1.0,1.0);white编辑pptForcingCompletionofDrawing
glFlush()glFinish()编辑pptCoordinateSystemSurvivalKitExample2-1:ReshapeCallbackFunctionvoidreshape(intw,inth){glViewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);}编辑pptPoints,Lines,PolygonsVertex(x,y,z,w)First,theedgesofOpenGLpolygonscan'tintersect(amathematicianwouldcallapolygonsatisfyingthisconditionasimplepolygon).OpenGLpolygonsmustbeconvex,meaningthattheycannothaveindentations.Statedprecisely,aregionisconvexif,givenanytwopointsintheinterior,thelinesegmentjoiningthemisalsointheinterior.编辑pptRectangles,CurvesandCurvedSurfaces
voidglRect{sifd}(TYPEx1,TYPEy1,TYPEx2,TYPEy2);编辑pptSpecifyingVerticesvoidglVertex{234}{sifd}[v](TYPEcoords);CallstoglVertex*()areonlyeffectivebetweenaglBegin()andglEnd()pair.编辑pptOpenGL的几何绘图图元编辑pptSpecifyingVertexList编辑pptExample1Example2-4:OtherConstructsbetweenglBegin()andglEnd()#definePI3.1415926535898GLintcircle_points=100;glBegin(GL_LINE_LOOP);for(i=0;i<circle_points;i++){angle=2*PI*i/circle_points;glVertex2f(cos(angle),sin(angle));}glEnd();编辑pptExample2glBegin(GL_POINTS);glColor3f(0.0,1.0,0.0);/*green*/glColor3f(1.0,0.0,0.0);/*red*/glVertex(...);glColor3f(1.0,1.0,0.0);/*yellow*/glColor3f(0.0,0.0,1.0);/*blue*/glVertex(...);glVertex(...);glEnd();编辑pptBasicStateManagement
Bydefault,mostofthesestatesareinitiallyinactive.Toturnonandoffmanyofthesestates,usethesetwosimplecommands:voidglEnable(GLenumcap);voidglDisable(GLenumcap);Youcanalsocheckifastateiscurrentlyenabledordisabled.GLbooleanglIsEnabled(GLenumcapability)编辑pptThereare5queryingroutinesusedto
findoutwhatvaluesaresetformanystates
voidglGetBooleanv(GLenumpname,GLboolean*params);voidglGetIntegerv(GLenumpname,GLint*params);voidglGetFloatv(GLenumpname,GLfloat*params);voidglGetDoublev(GLenumpname,GLdouble*params);voidglGetPointerv(GLenumpname,GLvoid**params);additional16queryingroutines编辑pptDisplayingPoints,Lines,andPolygons
Bydefault,apointisdrawnasasinglepixelonthescreen,alineisdrawnsolidandonepixelwide,andpolygonsaredrawnsolidlyfilledin.编辑pptPointDetails
voidglPointSize(GLfloatsize);ifthewidthis1.0,thesquareis1pixelby1pixel;ifthewidthis2.0,thesquareis2pixelsby2pixels,andsoon.Withantialiasingenabled,acirculargroupofpixelsisdrawn,andthepixelsontheboundariesaretypicallydrawnatlessthanfullintensitytogivetheedgeasmootherappearance.Inthismode,non-integerwidthsaren'trounded.编辑pptLineDetails
WideLinesvoidglLineWidth(GLfloatwidth);StippledLinesTomakestippled(dottedordashed)lines,youusethecommandglLineStipple()todefinethestipplepattern,andthenyouenablelinestipplingwithglEnable().voidglLineStipple(GLintfactor,GLushortpattern);glLineStipple(1,0x3F07);glEnable(GL_LINE_STIPPLE);Ifthisseemsbackward,rememberthatthelow-orderbitisusedfirst.编辑pptStippleLineexampleRunLines.cprogram编辑pptPolygonsasPoints,Outlines,orSolidsvoidglPolygonMode(GLenumface,GLenummode);glPolygonMode(GL_FRONT,GL_FILL);glPolygonMode(GL_BACK,GL_LINE);voidglFrontFace(GLenummode);voidglCullFace(GLenummode);编辑pptStipplingPolygons
voidglPolygonStipple(constGLubyte*mask);Definesthecurrentstipplepatternforfilledpolygons.Theargumentmaskisapointertoa32×32bitmapthat'sinterpretedasamaskof0sand1s.Wherea1appears,thecorrespondingpixelinthepolygonisdrawn,andwherea0appears,nothingisdrawn.polys.c编辑pptMarkingPolygonBoundaryEdges
Example2-7:MarkingPolygonBoundaryEdgesglPolygonMode(GL_FRONT_AND_BACK,GL_LINE);glBegin(GL_POLYGON);glEdgeFlag(GL_TRUE);glVertex3fv(V0);glEdgeFlag(GL_FALSE);glVertex3fv(V1);glEdgeFlag(GL_TRUE);glVertex3fv(V2);glEnd();编辑pptNormalVectors
Anormalvector(ornormal,forshort)isavectorthatpointsinadirectionthat'sperpendiculartoasurface.Anobject'snormalvectorsdefinetheorientationofitssurfaceinspacevoidglNormal3{bsidf}(TYPEnx,TYPEny,TYPEnz);Theb,s,andiversionsscaletheirparametervalueslinearlytotherange[-1.0,1.0].编辑pptVertexArraysOpenGLhasvertexarrayroutinesthatallowyoutospecifyalotofvertex-relateddatawithjustafewarraysandtoaccessthatdatawithequallyfewfunctioncalls.编辑pptStep1.EnablingArrays
voidglEnableClientState(GLenumarray)voidglDisableClientState(GLenumarray);编辑pptStep2.SpecifyingDatafortheArrays
voidglVertexPointer(GLintsize,GLenumtype,GLsizeistride,constGLvoid*pointer);voidglColorPointer(GLintsize,GLenumtype,GLsizeistride,constGLvoid*pointer);voidglIndexPointer(GLenumtype,GLsizeistride,constGLvoid*pointer);voidglNormalPointer(GLenumtype,GLsizeistride,constGLvoid*pointer);voidglTexCoordPointer(GLintsize,GLenumtype,GLsizeistride,constGLvoid*pointer);voidglEdgeFlagPointer(GLsizeistride,constGLvoid*pointer);编辑pptStep3:DereferencingandRendering
voidglArrayElement(GLintith)voidglDrawElements(GLenummode,GLsizeicount,GLenumtype,void*indices);voidglDrawArrays(GLenummode,GLintfirst,GLsizeicount);voidglInterleavedArrays(GLenumformat,GLsizeistride,void*pointer)编辑pptAttributeGroups
voidglPushAttrib(GLbitfieldmask);voidglPopAttrib(void);编辑pptChapter3
Viewing编辑pptTakeaphoto编辑pptTransformationPipeline编辑pptTransformation在内存中存贮的顺序为若按照列向量进行运算的话,在内存中存贮的顺序是先列后行。编辑ppt变换过程Theviewingandmodelingtransformationsyouspecifyarecombinedtoformthemodelviewmatrix,编辑pptAsimpletransformationCube.c编辑pptViewingTransformationpositioningandaimingacamera编辑pptTheModelingTransformationYouusethemodelingtransformationtopositionandorientthemodel.
glScale,glRotate,glTranslate编辑pptModelViewmatrixNotethatinsteadofmovingthecamera(withaviewingtransformation)sothatthecubecouldbeviewed,youcouldhavemovedthecubeawayfromthecamera(withamodelingtransformation).
编辑pptTheProjectionTransformation
Specifyingtheprojectiontransformationislikechoosingalensforacamera.Choosingamongwide-angle,normal,andtelephotolensesPerspectiveprojection
gluPerspective(fovy,aspect,near,far)glFrustumOrthographicprojection
glOrtho(GLdoubleleft,GLdoubleright,GLdoublebottom,GLdoubletop,GLdoublenear,GLdoublefar)编辑pptTheViewportTransformationtheprojectiontransformationandtheviewporttransformationdeterminehowascenegetsmappedontothecomputerscreen.Theprojectiontransformationspecifiesthemechanicsofhowthemappingshouldoccur,andtheviewportindicatestheshapeoftheavailablescreenareaintowhichthesceneismapped.编辑ppt视点坐标系、归一化的设备坐标系、屏幕坐标系投影变换和除法视图变换编辑ppt如何看待模型变换(1)glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMultMatrixf(N);/*applytransformationN*/glMultMatrixf(M);/*applytransformationM*/glMultMatrixf(L);/*applytransformationL*/glBegin(GL_POINTS);glVertex3f(v);/*drawtransformedvertexv*/glEnd();变换顺序非常重要当前的矩阵起作用编辑ppt如何看待模型变换(2)全局固定坐标系统Matrixmultiplicationsaffecttheposition,orientation,andscalingofyourmodel-youhavetothinkofthemultiplicationsasoccurringintheoppositeorderfromhowtheyappearinthecode.glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMultMatrixf(T);/*translation*/glMultMatrixf(R);/*rotation*/draw_the_object();编辑ppt如何看待模型变换(3)移动坐标系统Alocalcoordinatesystemistiedtotheobjectyou'redrawing.Alloperationsoccurrelativetothischangingcoordinatesystem.Withthisapproach,thematrixmultiplicationsnowappearinthenaturalorderinthecode.glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMultMatrixf(T);/*translation*/glMultMatrixf(R);/*rotation*/draw_the_object();编辑pptModelingTransformationsTransformanobjectbymoving,rotating,stretching,shrinking,orreflectingit.Allthreecommandsareequivalenttoproducinganappropriatetranslation,rotation,orscalingmatrix,andthencallingglMultMatrix*()withthatmatrixastheargument.voidglTranslate{fd}(TYPEx,TYPEy,TYPEz);voidglRotate{fd}(TYPEangle,TYPEx,TYPEy,TYPEz);voidglScale{fd}(TYPEx,TYPEy,TYPEz);编辑pptModelingTransformationExamplemodel.c编辑pptViewingTransformationsAviewingtransformationchangesthepositionandorientationoftheviewpoint.theviewingtransformationpositionsthecameratripod,pointingthecameratowardthemodel.UsingthreewaystomakeviewingtransformationglRotateandglTranslategluLookAt()Createyourownutilityroutinethatencapsulatesrotationsandtranslations编辑pptUsingglTranslateandglRotatetosetviewingtransformationInthesimplestcase,youcanmovetheviewpointbackward,awayfromtheobjects;thishasthesameeffectasmovingtheobjectsforward,orawayfromtheviewpoint.操作照相机,相当于模型空间作相应的逆变换。编辑pptUsingthegluLookAt()UtilityRoutinegluLookAt(cx,cy,cz,rx,ry,rz,ux,uy,uz)编辑pptCreatingaCustomUtilityRoutinevoidpilotView{GLdoubleplanex,GLdoubleplaney,GLdoubleplanez,GLdoubleroll,GLdoublepitch,GLdoubleheading){glRotated(-roll,0.0,0.0,1.0);glRotated(-pitch,0.0,1.0,0.0);glRotated(-heading,1.0,0.0,0.0);glTranslated(-planex,-planey,-planez);}编辑pptPerspectiveProjectiontransformationsvoidglFrustum(GLdoubleleft,GLdoubleright,GLdoublebottom,GLdoubletop,GLdoublenear,GLdoublefar);voidgluPerspective(GLdoublefovy,GLdoubleaspect,GLdoublenear,GLdoublefar);编辑pptOrthographicProjectionvoidglOrtho(GLdoubleleft,GLdoubleright,GLdoublebottom,GLdoubletop,GLdoublenear,GLdoublefar);编辑pptViewportTransformationvoidglViewport(GLintx,GLinty,GLsizeiwidth,GLsizeiheight);编辑pptManipulatingtheMatrixStacks
glMatrixMode(GL_MODELVIEW)glMatrixMode(GL_PROJECTION)编辑ppt矩阵堆栈的操作函数glMatrixMode(….)glPushMatrix();glMultiMatrix(M);glPopMatrix();glLoadMatrix(M);voidglRotate{fd}(TYPEangle,TYPEx,TYPEy,TYPEz);glTranslatef(Tx,Ty,Tz);glScalef(Sx,Sy,Sz);编辑ppt矩阵堆栈操作的原则首先要明确对那个堆栈操作只有堆栈的栈顶矩阵起作用glScale,glRotate,gluLookAt,gluPerspective,glTranslate等都是默认对原来的栈顶矩阵乘上该矩阵若把顶点看成行向量,则矩阵相乘都是左乘。若把顶点看成列向量,则矩阵相乘都是右乘。编辑pptAdditionalClippingPlanes编辑pptvoidglClipPlane(GLenumplane,constGLdouble*equation);
Definesaclippingplane.Theequationargumentpointstothefourcoefficientsoftheplaneequation,Ax+By+Cz+D=0.Allpointswitheyecoordinates(xe,ye,ze,we)thatsatisfy(ABCD)M-1(xeyezewe)T>=0lieinthehalf-spacedefinedbytheplane,whereMisthecurrentmodelviewmatrixatthetimeglClipPlane()iscalled.Allpointsnotinthishalf-spaceareclippedaway.TheplaneargumentisGL_CLIP_PLANEi,whereiisanintegerspecifyingwhichoftheavailableclippingplanestodefine.iisanumberbetween0andonelessthanthemaximumnumberofadditionalclippingplanes.glEnable(GL_CLIP_PLANEi);编辑pptReversingTransformations
intgluUnProject(GLdoublewinx,GLdoublewiny,GLdoublewinz,constGLdoublemodelMatrix[16],constGLdoubleprojMatrix[16],constGLintviewport[4],GLdouble*objx,GLdouble*objy,GLdouble*objz);Mapthespecifiedwindowcoordinates(winx,winy,winz)intoobjectcoordinates,usingtransformationsdefinedbyamodelviewmatrix(modelMatrix),projectionmatrix(projMatrix),andviewport(viewport).编辑pptMimickingTransformationsintgluProject(GLdoubleobjx,GLdoubleobjy,GLdoubleobjz,constGLdoublemodelMatrix[16],constGLdoubleprojMatrix[16],constGLintviewport[4],GLdouble*winx,GLdouble*winy,GLdouble*winz);编辑ppt矩阵与空间转换的总结必须明确当前所在的空间。比较明确的空间是:标准屏幕空间。[-1,1]x[-1,1]x[-1,1]。视点空间(以视点为原点的空间)。模型空间—模型所在的空间。标准的屏幕坐标是固定的。模型空间是经常变化的。把变换分成两个阶段来考虑,分别对应两个矩阵堆栈,projection堆栈和modelview堆栈。Projection堆栈对应一个透视或正交变换。Modelview堆栈对应是把模型变换到视点空间的变换。所以在编程时要分开处理。ModelView变换是比较复杂的,它是把模型从局部空间变换到视点空间。也就是说当你发起glVertex命令的时候,必须明白当前在那个空间中。编辑ppt具体解释robot例子程序编辑pptChapter4Color
编辑pptDithering
Somegraphicshardwareusesditheringtoincreasethenumberofapparentcolors.Ditheringisthetechniqueofusingcombinationsofsomecolorstocreatetheeffectofothercolors.编辑pptColor-IndexDisplayMode
编辑pptSpecifyingaColorinRGBAMode
voidglColor3{bsifdubusui}(TYPEr,TYPEg,TYPEb);voidglColor4{bsifdubusui}(TYPEr,TYPEg,TYPEb,TYPEa);voidglColor3{bsifdubusui}v(constTYPE*v);voidglColor4{bsifdubusui}v(constTYPE*v);编辑pptSpecifyingaColorinColor-IndexMode
voidglIndex{sifdub}(TYPEc);voidglIndex{sifdub}v(constTYPE*c);Setsthecurrentcolorindextoc.Thefirstsuffixforthiscommandindicatesthedatatypeforparameters:short,integer,float,double,orunsignedbyte.Thesecond,optionalsuffixisv,whichindicatesthattheargumentisanarrayofvaluesofthegivendatatype(thearraycontainsonlyonevalue).编辑pptSpecifyingaShadingModel
voidglShadeModel(GLenummode);Setstheshadingmodel.ThemodeparametercanbeeitherGL_SMOOTH(thedefault)orGL_FLAT.编辑pptFlat-ShadedPolygon编辑pptChapter5Lighting
编辑pptAHidden-SurfaceRemovalSurvivalKitglEnable(GL_DEPTH_TEST);...while(1){glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);get_viewing_point_from_mouse_position();draw_3d_object_A();draw_3d_object_B();}编辑pptReal-WorldandOpenGLLightingOpenGLapproximateslightandlightingasiflightcanbebrokenintored,green,andbluecomponents.TheOpenGLlightingmodelconsidersthelightingtobedividedintofourindependentcomponents:emissive,ambient,diffuse,andspecular.Allfourcomponentsarecomputedindependentlyandthenaddedtogether.编辑pptAmbient,Diffuse,andSpecularLight
Ambientilluminationislightthat'sbeenscatteredsomuchbytheenvironmentthatitsdirectionisimpossibletodetermine-itseemstocomefromalldirections.Thediffusecomponentisthelightthatcomesfromonedirection,soit'sbrighterifitcomessquarelydownonasurfacethanifitbarelyglancesoffthesurface.specularlightcomesfromaparticulardirection,andittendstobounceoffthesurfaceinapreferreddirection.编辑pptMaterialColors
TheOpenGLlightingmodelmakestheapproximationthatamaterial'scolordependsonthepercentagesoftheincomingred,green,andbluelightitreflects.Materialshavedifferentambient,diffuse,andspecularcolors,whichdeterminetheambient,diffuse,andspecularreflectancesofthematerial.Amaterial'sambientreflectanceiscombinedwiththeambientcomponentofeachincominglightsourceAmbientanddiffusereflectancesdefinethecolorofthematerialandaretypicallysimilarifnotidentical.Specularreflectanceisusuallywhiteorgray,sothatspecularhighlightsendupbeingthecolorofthelightsource'sspecularintensity.Ifyouthinkofawhitelightshiningonashinyredplasticsphere,mostofthesphereappearsred,buttheshinyhighlightiswhite.emissivecolordoesnotintroduceanyadditionallightintotheoverallscene编辑pptRGBValuesforLightsandMaterials
Foralight,thenumberscorrespondtoapercentageoffullintensityforeachcolor.Formaterials,thenumberscorrespondtothereflectedproportionsofthosecolors.ifanOpenGLlighthascomponents(LR,LG,LB),andamaterialhascorrespondingcomponents(MR,MG,MB),then,ignoringallotherreflectivityeffects,thelightthatarrivesattheeyeisgivenby(LR*MR,LG*MG,LB*MB).编辑pptASimpleExample:RenderingaLitSphere
Definenormalvectorsforeachvertexofalltheobjects.Thesenormalsdeterminetheorientationoftheobjectrelativetothelightsources.Create,select,andpositiononeormorelightsources.Createandselectalightingmodel,whichdefinesthelevelofglobalambientlightandtheeffectivelocationoftheviewpoint(forthepurposesoflightingcalculations).Definematerialpropertiesfortheobjectsinthescene.编辑pptCreatingLightSourcesvoidglLight{if}(GLenumlight,GLenumpname,TYPEparam);voidglLight{if}v(GLenumlight,GLenumpname,TYPE*param);Createsthelightspecifiedbylight,whichcanbeGL_LIGHT0,GL_LIGHT1,...,orGL_LIGHT7.编辑pptDefaultValuesforpnameParameterofglLight*()编辑pptLightPositiondirectionallightsourceGLfloatlight_position[]={1.0,1.0,1.0,0.0};glLightfv(GL_LIGHT0,GL_POSITION,light_position);
positionallightsourceGLfloatlight_position[]={1.0,1.0,1.0,1.0};glLightfv(GL_LIGHT0,GL_POSITION,light_position);编辑pptAttenuationSinceadirectionallightisinfinitelyfaraway,itdoesn'tmakesensetoattenuateitsintensityoverdistance,soattenuationisdisabledforadirectionallight.However,youmightwanttoattenuatethelightfromapositionallight.OpenGLattenuatesalightsourcebymultiplyingthecontributionofthatsourcebyanattenuationfactor:whered=distancebetweenthelight'spositionandthevertexkc=GL_CONSTANT_ATTENUATIONkl=GL_LINEAR_ATTENUATIONkq=GL_QUADRATIC_ATTENUATION编辑pptSpotlights
编辑pptSpotlightfunctionGL_SPOT_CUTOFFisrestrictedtobeingwithintherange[0.0,90.0](unlessithasthespecialvalue180.0).glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,45.0);Youalsoneedtospecifyaspotlight'sdirection,whichdeterminestheaxisoftheconeoflight:GLfloatspot_direction[]={-1.0,-1.0,0.0};glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spot_direction);Bydefault,thedirectionis(0.0,0.0,-1.0),Also,keepinmindthataspotlight'sdirectionistransformedbythemodelviewmatrixjustasthoughitwereanormalvector,andtheresultisstoredineyecoordinates.settheGL_SPOT_EXPONENTparameter,whichbydefaultiszero,tocontrolhowconcentratedthelightis.Thelight'sintensityishighestinthecenterofthecone.It'sattenuatedtowardtheedgesoftheconebythecosineoftheanglebetweenthedirectionofthelightandthedirectionfromthelighttothevertexbeinglit.编辑pptMultipleLightsGLfloatlight1_ambient[]={0.2,0.2,0.2,1.0};GLfloatlight1_diffuse[]={1.0,1.0,1.0,1.0};GLfloatlight1_specular[]={1.0,1.0,1.0,1.0};GLfloatlight1_position[]={-2.0,2.0,1.0,1.0};GLfloatspot_direction[]={-1.0,-1.0,0.0};glLightfv(GL_LIGHT1,GL_AMBIENT,light1_ambient);glLightfv(GL_LIGHT1,GL_DIFFUSE,light1_diffuse);glLightfv(GL_LIGHT1,GL_SPECULAR,light1_specular);glLightfv(GL_LIGHT1,GL_POSITION,light1_position);glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION,1.5);glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION,0.5);glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION,0.2);glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,45.0);glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction);glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,2.0);glEnable(GL_LIGHT1);编辑pptControllingaLight'sPositionandDirectionOpenGLtreatsthepositionanddirectionofalightsourcejustasittreatsthepositionofageometricprimitive.whenglLight*()iscalledtospecifythepositionorthedirectionofalightsource,thepositionordirectionistransformedbythecurrentmodelviewmatrixandstoredineyecoordinates.编辑pptKeepingtheLightStationaryglViewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();if(w<=h)glOrtho(-1.5,1.5,-1.5*h/w,1.5*h/w,-10.0,10.0);elseglOrtho(-1.5*w/h,1.5*w/h,-1.5,1.5,-10.0,10.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();/*laterininit()*/GLfloatlight_position[]={1.0,1.0,1.0,1.0};glLightfv(GL_LIGHT0,GL_POSITION,position);编辑pptIndependentlyMovingtheLightrotateortranslatethelightpositionsothatthelightmovesrelativetoastationaryobjectstaticGLdoublespin;voiddisplay(void){GLfloatlight_position[]={0.0,0.0,1.5,1.0};glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glPushMatrix();gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);glPushMatrix();glRotated(spin,1.0,0.0,0.0);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glPopMatrix();glutSolidTorus(0.275,0.85,8,15);glPopMatrix();glFlush();}编辑pptMovingtheLightSourceTogetherwithYourViewpoint(miner'shat)GLfloatlight_position()={0.0,0.0,0.0,1.0};glViewport(0,0,(GLint)w,(GLint)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(40.0,(GLfloat)w/(GLfloat)h,1.0,100.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glLightfv(GL_LIGHT0,GL_POSITION,light_position);编辑pptSelectingaLightingModelTheOpenGLnotionofalightingmodelhasthreecomponents:TheglobalambientlightintensityWhethertheviewpointpositionislocaltothesceneorwhetheritshouldbeconsideredtobeaninfinitedistanceawayWhetherlightingcalculationsshouldbeperformeddifferentlyforboththefrontandbackfacesofobjects编辑pptglLightModelvoidglLightModel{if}(GLenumpname,TYPEparam);voidglLightModel{if}v(GLenumpname,TYPE*param);编辑pptGlobalAmbientLight
GLfloatlmodel_ambient[]={0.2,0.2,0.2,1.0};glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);evenifyoudon'taddaspecificlightsourcetoyourscene,youcanstillseetheobjectsinthescene.编辑pptLocalorInfiniteViewpointThelocationoftheviewpointaffectsthecalculationsforhighlightsproducedbyspecularreflectance.glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);Thiscallplacestheviewpointat(0,0,0)ineyecoordinates.Toswitchbacktoaninfiniteviewpoint,passinGL_FALSEastheargument.编辑pptTwo-sidedLighting
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);编辑pptDefiningMaterialPropertiesvoidglMaterial{if}(GLenumface,GLenumpname,TYPEparam);voidglMaterial{if}v(GLenumface,GLenumpname,TYPE*param);Specifiesacurrentmaterialpropertyforuseinlightingcalculations.facecanbeGL_FRONT,GL_BACK,orGL_FRONT_AND_BACKtoindicatewhichfaceoftheobjectthematerialshouldbeappliedto.编辑ppt材料前后面定义的属性值编辑pptDiffuseandAmbientReflection
Diffusereflectanceplaysthemostimportantroleindeterminingwhatyouperceivethecolorofanobjecttobe.It'saffectedbythecoloroftheincidentdiffuselightandtheangleoftheincidentlightrelativetothenormaldirection.Thepositionoftheviewpointdoesn'taffectdif
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年运城职业技术大学马克思主义基本原理概论期末考试模拟题及答案解析(必刷)
- 2024年辽宁开放大学马克思主义基本原理概论期末考试题带答案解析(夺冠)
- 2025年浙江农林大学单招职业倾向性测试题库带答案解析
- 中国水利水电第五工程局有限公司2026届秋季招聘282人笔试历年难易错考点试卷带答案解析
- 2026华电煤业集团有限公司校园招聘(第一批)笔试参考题库附带答案详解
- 2025陕西能源(延安)圣地蓝热电有限公司招聘(14人)笔试历年难易错考点试卷带答案解析
- 2025长影集团有限责任公司招聘3人笔试参考题库附带答案详解
- 2025重庆渝金融租赁股份有限公司招聘笔试历年备考题库附带答案详解2套试卷
- 2025重庆市地质矿产勘查开发集团有限公司招聘16人笔试参考题库附带答案详解
- 2025贵州遵义市威盾劳务派遣有限公司招聘30人笔试历年典型考点题库附带答案详解2套试卷
- 2026年湖南现代物流职业技术学院单招职业技能考试题库含答案
- 小学阶段关联词重点归纳
- 华住协议书酒店
- 高标准农田建设工程质量专项整治技术手册
- 海关面试题目解析及答案
- 2025年江西省农村(社区)“多员合一岗”工作人员招聘考试历年参考题库含答案详解(5套)
- (高清版)DB44∕T 1075-2012 《蒸压陶粒混凝土墙板》
- 体育场馆方案汇报
- 2025中国西电集团校园招聘笔试历年参考题库附带答案详解
- 2025年苏州市中考物理试卷真题(含答案)
- 变电站综合自动化课件 二次回路识图
评论
0/150
提交评论