[ Pobierz całość w formacie PDF ]
.Alternatively, you can create a shadow using the CreateObject()function of this same interface and then call the Init() function of IDirect3DRMShadow2.Bothapproaches were discussed in detail in Chapter 16, as well as the functions inIDirect3DRMShadow2 interface.At this point we are interest-ed in the programming required togenerate shadows in retained mode.Creating a shadowIn creating a shadow you must define the three elements mentioned previously; that is, the objectthat casts the shadow, the light that produces the shadow, and the plane onto which the shadow isprojected.These elements can be seen in Figure 24-4.Figure 24-4: Elements of a shadow The only retained mode object that can cast a shadow is a mesh.In practical programming wesometimes use the meshbuilder object to add a visual onto a frame, this saving having to create amesh.However, when programming shadows we must have available the mesh object that caststhe shadow, therefore we must specifically create the mesh.The light that produces the shadow must be a directed light.Ambient lights are multidirectional andproduce no shadows.In addition, the position of the camera, the light, the mesh, and the planemust be such that the shadow is visible at render-ing time.It is quite possible to position one ormore of these elements so that the generated shadow lies outside of the viewing frustum.Assuming that the mesh object that generates the shadow has already been created, and also thatthere is a directed light conveniently positioned, then producing a shadow consists of three steps:creating the shadow, defining the shadow option, and attaching the shadow as a visual to theframe.The following code fragment shows the processing.// Routine variablesLPDIRECT3DRMFRAME3 aChildFrame = NULL;LPDIRECT3DRMLIGHT dirLt = NULL;LPDIRECT3DRMSHADOW2 aShadow = NULL;LPDIRECT3DRMMESH teapotMesh = NULL;.// Code assumes that a teapotMesh and a directed light object// already exist in the sceneretval = lpD3DRM->CreateShadow( teapotMesh, // Mesh objectdirLt, // LightD3DVAL(0), // |D3DVAL(-2), _// | Plane for _// | shadowD3DVAL(0), // |D3DVAL(0), // |D3DVAL(1), // | Shadow planeD3DVAL(0), // | normal&aShadow); // Shadow objectif(FAILED(retval)){// Shadow creation error handler goes here}// Set shadow optionsretval = aShadow->SetOptions(D3DRMSHADOW_TRUEALPHA);if(FAILED(retval)){// Shadow option error handler goes here}// Attach shadow to frame as visual retval = aChildFrame->AddVisual(aShadow);if(FAILED(retval)){// Add visual error handler goes here}3DRM Shadow Demo programThe 3DRM Shadow Demo program in the book's CD-ROM shows a rotating teapot that generates ashadow onto the x-plane.The code used in the sample program is similar to the one listedpreviously. SummaryWe have now concluded our tour of retained mode light and shadow programming.In it weexplored the lighting models and formulas, the creation and control of ambient and directed lights,the positioning of lights within a scene, and the generation of shadows.It is through lightprogramming that the objects of our scenes become visible at rendering time.What is more, by theadequate selection and placement of lights and shadows we can significantly enhance the visualquality of 3D objects.With the discussion of lights and shadows we conclude our discussion of static rendering in DirectXretained mode, which includes the simple movements that can be directly applied to frames.In thefollowing chapter we explore retained mode animation.It is animation that makes 3D applicationsunique and powerful.The static rendering of a 3D object is visually identical to the display of a 2Dimage. Chapter 25: 3D AnimationOverviewAnimation is often the central feature of a 3D application.We have already encountered Direct3Danimation in the context of frame movements.In Chapter 19, we covered topics related to thecontinuous scaling, rotation, and translation of frames which make possible a rudimentary level ofanimation.The SetRotation() and SetVelocity() functions implement this functionality atthe frame level, whereas the Move() and Tick() functions of IDirect3DRM provide a timingmechanism that drives the animation.The 3DRM Move Demo program in the book's CD-ROMshows the basic processing.Simple, frame-level manipulations by means of SetVelocity() and SetRotation() providean easy way of producing interesting effects.In some cases, these methods are all that is requiredfor an animated application.However, in programs that require more powerful animations thecontrols that are available with SetRotation() and SetVelocity() are too limited.For thesecases retained mode provides other more powerful and flexible animation mechanisms.In addition to the animation facilities provided by retained mode functions there is a simple, oftenoverlooked, approach to animation.The technique is based on creating an intercept routine thatreceives control at every beat of the animation pulse, then executing step-by-step image changeswithin this intercept.This approach usually requires implementing a move callback function that iscalled by the rendering loop.Code can use this intercept to produce any desired changes in thevisuals.We start our discussion of animation techniques by examining this approach.An alternativeanimation method is based on a technique called key-framing.Retained mode contains extensivesupport for several flavors of key frame animation.Key frame animation by tranformation keys andby interpolators are also discussed in this chapter. Direct Intercept AnimationA simple approach to animation consists of creating a callback function that is called at everyanimation beat, and providing the necessary processing in the intercept routine.This technique,which could be called the direct intercept method, is both powerful and laborious.It is powerfulbecause you can use the intercept routine to produce any scene change that is available inretained mode.There is no limit to the number or types of movements, or to the number ofchanges that can be applied to a single scene.For example, you can use the callback function totransform objects, to morph meshes, to change the color, intensity, or position of lights, to modifythe color tint of objects, to change materials and textures, to manipulate fog intensity, or to performany other valid action on the scene's objects [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • necian.htw.pl