Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


The fourth and final portion of the SpaceStationWin::CreateScene() function creates and configures a viewport. Take another look at the SpaceStation demo (Figure 6.5). Notice that the space station mesh is tilted. This isn’t because we tilted the frame to which the space station mesh is attached. In fact, all we did to the mesh frame is assign a rotation attribute on the Y axis. Yet, if you run the SpaceStation demo, the station is tilted, and it rotates in the same direction as the tilt.

This is because rather than tilting both the mesh and rotation vector, we tilted the viewport. The viewport creation code looks like this:

d3drm->CreateFrame( scene, &camera );
camera->SetPosition( scene,
        D3DVALUE(0), D3DVALUE(25), D3DVALUE(-50) );
camera->SetOrientation( scene,
        D3DVALUE(0), D3DVALUE(-23), D3DVALUE(50),
        D3DVALUE(0.7), D3DVALUE(1), D3DVALUE(0) );
d3drm->CreateViewport( device, camera, 0, 0,
        device->GetWidth(), device->GetHeight(),
        &viewport );

This portion of code differs from the other demos that we’ve looked at. First, the camera frame is positioned differently. Usually, we pull the camera straight back from the origin by using the values <0, 0, –50> as SetPosition() arguments. This time, we’ve positioned the camera 50 units back and 25 units above the origin. By default, frames are aligned with the Z axis. This means that unless we modify the camera frame’s orientation, we probably won’t see the space station mesh at all because the camera will be viewing an area above the mesh.

The SetOrientation() function call that appears after the SetPosition() function call is used for two purposes. First, it is used to point the camera at the mesh. Second, it is used to roll, or tilt the camera. Let’s take a closer look at the SetOrientation() function call:

camera->SetOrientation( scene,
        D3DVALUE(0), D3DVALUE(-23), D3DVALUE(50),
        D3DVALUE(0.7), D3DVALUE(1), D3DVALUE(0) );

The forward vector (defined by the first three numeric arguments) defines a vector that travels from the origin to a point that is 23 units below and 50 units behind the origin. Notice that this vector is almost exactly the opposite of the vector that defines the camera’s position. This is no coincidence. In fact, you can always get a camera to point at the origin by using a forward vector that is the opposite of the camera’s positioning vector. The forward vector for the camera has been adjusted a bit for visual effect (via trial and error), so the vectors are not exactly opposite.

Now let’s look at the up or sky vector (defined by the last three numeric SetOrientation() arguments). In the other demos, we’ve used the values <0, 1, 0> to specify a vector aligned with the Y axis and pointing up (hence the vector’s name). This time we are using the values <0.7, 1, 0>. By using a vector that points almost as far to the right as it does up, the camera is tilted or rolled to the right.

The last function call in the CreateScene() function is the Direct3DRM CreateViewport() function. This function call is the same in the other demos.

Parallel Point Lights

Parallel point lights are similar to directional lights, but parallel point lights cast light in two directions. Parallel point lights are affected by both location and orientation. In regard to performance, parallel point lights are similar to directional lights.

The SpaceDonut Demo

The SpaceDonut demo places a parallel point light between two raspberry (possibly blueberry) frosted donuts. The SpaceDonut demo appears in Figure 6.7.


Figure 6.7  The SpaceDonut demo.

The SpaceDonut demo demonstrates the following techniques:

  Using a parallel point light source
  Using rotation attributes to perform animation
  Using the Direct3DRMMeshBuilder SetColorRGB() function
  Attaching a single mesh to multiple frames
  Using menu options to change rendering settings at runtime

The SpaceDonutWin Class

The SpaceDonut demo provides the bulk of its functionality in the SpaceDonutWin class. The class is defined as follows:

class SpaceDonutWin : public RMWin
{
public:
    SpaceDonutWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(SpaceDonutWin)
    afx_msg void OnRenderWireframe();
    afx_msg void OnRenderFlat();
    afx_msg void OnRenderGouraud();
    afx_msg void OnUpdateRenderFlat(CCmdUI* pCmdUI);
    afx_msg void OnUpdateRenderGouraud(CCmdUI* pCmdUI);
    afx_msg void OnUpdateRenderWireframe(CCmdUI* pCmdUI);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    LPDIRECT3DRMMESHBUILDER meshbuilder;
};

Like all of the demos on the CD-ROM, the SpaceDonut demo derives its window class from the RMWin class. The SpaceDonutWin class provides two public member functions: a constructor and the CreateScene() function. The constructor is responsible for initializing any data members that the class defines (one, in this case). The CreateScene() function constructs the application’s scene.

The six protected member functions provide support for the demo’s Render menu. These functions use the meshbuilder data member to modify the mesh’s settings.


Previous Table of Contents Next


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.