![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Once the light has been created, a frame is created to position the light. The frame is positioned 30 units above the origin. The light source is attached to the new frame with the AddLight() function. The next step is the creation of the Direct3DRMShadow object: LPDIRECT3DRMSHADOW shadow; d3drm->CreateShadow( forkbuilder, pointlight, D3DVALUE(0), box.max.y+D3DVALUE(0.1), D3DVALUE(0), D3DVALUE(0), box.max.y+D3DVALUE(1.0), D3DVALUE(0), (LPDIRECT3DRMVISUAL*)&shadow ); forkframe->AddVisual( shadow ); shadow->Release(); shadow=0; forkframe->Release(); forkframe=0; pointlight->Release(); pointlight=0; The shadow is created with the Direct3DRM CreateShadow() function, which expects nine arguments. The first argument is a pointer to the visual object that is to cast the shadow. The second argument is a pointer to the light source that is to be used when calculating the shadows shape. The next six arguments define the plane on which the shadow is to appear (the first three arguments indicate a point on the plane, and the following three arguments specify a vector that is perpendicular to the plane). The last argument expected by the Direct3DRM CreateShadow() function is the address of the pointer that is to be initialized. For inexplicable reasons, the CreateShadow() subject expects a pointer to the Direct3DRMVisual interface instead of the Direct3DRMShadow interface for its final argument. A cast is required to get the compiler to accept the pointers address. The tenth and final step of the CreateScene() function is the creation of the viewport: d3drm->CreateFrame( scene, &camera ); camera->SetPosition( scene, D3DVALUE(0.0), D3DVALUE(25.0), D3DVALUE(-20.0) ); camera->SetOrientation( scene, D3DVALUE(0), D3DVALUE(-25), D3DVALUE(20), D3DVALUE(.1), D3DVALUE(1), D3DVALUE(0) ); d3drm->CreateViewport( device, camera, 0, 0, device->GetWidth(), device->GetHeight(), &viewport ); The camera frame is initialized with the Direct3DRM CreateFrame() function, and positioned above and in front of the origin, pointing at the origin. The CreateViewport() function is used to initialized the viewport pointer. The last thing that the CreateScene() function does is return TRUE to indicate that the scene has been created successfully. The ShadowWin::AdjustSpin() FunctionThe AdjustSpin() function is a callback function that changes the fork frames rotation attribute periodically. The function uses the D3DRMVectorRandom() function to generate random vectors. void ShadowWin::AdjustSpin(LPDIRECT3DRMFRAME frame, void*, D3DVALUE) { static UINT delay; if (++delay<11) return; delay=0; LPDIRECT3DRMFRAME scene; frame->GetScene( &scene ); D3DVECTOR spinvect; D3DRMVectorRandom( &spinvect ); D3DVALUE spin=D3DDivide( rand()%100+1, 200 ); frame->SetRotation( scene, spinvect.x, spinvect.y, spinvect.z, spin ); } This function appears (with a different name) in the OrbStar demo. See Chapter 5 for an explanation. The Shadow Demo Render FunctionsOne final note on the Shadow demo. In order to implement the Render menu, the message handlers must modify the settings of two meshbuilders instead of just one. The code for the Render|Wireframe menu selection looks like this: void ShadowWin::OnRenderWireframe() { if (floorbuilder) floorbuilder->SetQuality( D3DRMRENDER_WIREFRAME ); if (forkbuilder) forkbuilder->SetQuality( D3DRMRENDER_WIREFRAME ); } ConclusionHopefully, you now know all you want to know about Direct3D light sources and shadows. Probably, you now know more than you want to know! In Chapter 7, well get away from using simple animation (i.e., rotation attributes), as we study frame hierarchies, key-framing, animation sets, and animating cameras.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |