![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Direct3DRMFrame: The Frame InterfaceDirect3D Retained-Mode relies heavily on frames. The use of this term tends to cause confusion because of the existing use of the word to describe a single image within an animation. The Direct3D meaning of frame comes from frame of reference. Frames are used to place objects in 3D space. Objects such as meshes, faces, cameras, and light sources by themselves have no means of locating or orienting themselves. Instead, these objects are added or attached to frames, and they receive their location and orientation from the attached framewhen the frame moves, the objects move. Frame HierarchiesA Direct3D scene is defined as a hierarchy of frames. Each scene contains a root frame and any number of child frames attached to the root frame. Each child frame can have children of its own. Frames are represented by the Direct3DRMFrame interface and are created with the Direct3DRM CreateFrame() member function. For example: LPDIRECT3DRMFRAME newframe; d3drm->CreateFrame( parentframe, &newframe ); This code declares a pointer to a frame, and then initializes the pointer with the CreateFrame() member function. The parentframe variable is a pointer to the frame that is the parent to the new frame. Specifying NULL for the parent frame creates the root frame for a new scene. Child frames inherit characteristics from parent frames. One inherited characteristic is the frame of reference. Child frames are attached to parent frames, so they follow the parent framewhen a parent frame moves, the child frame moves. This allows for powerful sub-object animation. For example, if you want to create and animate a helicopter (complete with spinning blades, naturally), you would create a frame for the helicopter body, and then create child frames for the helicopter blades. The blades can be animated by applying a rotation to the frames to which the blades are attached. The helicopter body can be animated by translating and orienting the frame to which the helicopter body is attached. Because the blades are children of the helicopter body, they imitate the bodys movements. Frames arent limited to using their parents as their frame of reference. Many frame member functions allow you to indicate which frame should be used as a reference frame (regardless of child-parent relationships). The flexible nature of frame hierarchies is one of the reasons whyDirect3D Retained-Mode is so powerful. Frame PositioningThe Direct3DRMFrame interface offers member functions dedicated to positioning frames. Direct3DRMFrame provides the following member functions:
The GetPosition() and SetPosition() member functions allow the frames location to be inspected and assigned. The GetOrientation() and SetOrientation() member functions allow the frames orientation to be specified. The frame interface also provides a LookAt() member function that orients a frame to face, or point at, another frame. LookAt() is convenient for situations where a camera or light source follows another object. The SetPosition(), SetOrientation(), and LookAt() member functions assign attributes to the frame object without regard for the frames previous settings. The Frame interface supplies AddTranslation(), AddRotation(), and AddScale() member functions to adjust a frames setting instead of replacing them. AddTranslation() adjusts a frames location according to the translation provided. AddRotation() adjusts the frames orientation by adding the supplied rotation to the existing rotation. AddScale() resizes a frame relative to its current size. Frame MovementThe frame interface provides member functions that adjust a frames position on an on-going basis. These functions specify motion attributes that will be applied to the frame with each update of a scene. The GetRotation() and SetRotation() member functions are used to manipulate a frames rotation attribute. Rotations applied with SetRotation() take effect on every scene update. Move CallbacksHaving the ability to place a frame, or assign motion attributes is great, but it can accomplish only so much. Interactive graphics require that the objects in your scene respond to each other, as well as respond to input from the user. The frame interface allows for this runtime adjustment by using callbacks. Callbacks are functions that you write and install, or register, with Direct3D. After you register your callbacks, Direct3D will execute the callbacks whenever a new scene is about to be drawn and allow you to make last-minute changes to the objects in the scene. Callbacks are installed with the AddMoveCallback() member function. Each frame object can install multiple callbacks. Callbacks are called in the order they are installed. To remove callbacks, use the DeleteMoveCallback() member function.
|
![]() |
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. |