Articulated cameras and lights

Articulated cameras attach to other graphics anywhere in the group. 3-D groups are described in Chapter 18. If the graphic moves, the camera or light moves with it. Articulated lights are useful for depicting lightgenerating instances such as a desk lamp in a scene. Articulated cameras let you create an effect where the viewer can, for example, see what the video camera on the arm of a robot would see.

Figure 223 shows a 3D graphic that is a camera attached to a robot arm, and Figure 224 shows the group diagram for the camera and robot arm.



In certain situations, you might want to render the graphics as though you were looking through the camera that is attached to the robot. There might also be times when you would render the robot and camera from a position near the robot.

NOTE If the camera is kept separate from the robot, synchronizing the camera movement with respect to the robot would be a difficult task.

A camera should be installed before rendering 3D graphics, and a camera should be able to render itself.

Example

The following code example is one approach to installing a camera that can render itself. The code examples use a dummy TGrafPort (with a NIL device) and the builtin traversal capability offered by the group to install the transformed camera in a scene bundle. The TArticulatedLightCameraControl instance provides information about whether the scene bundle is used by a dummy TGrafPort, and provides ways to generate unique token values that can be used for setting light sources in the scene bundle.

      // Define the camera object with MGraphic3D
      // This object is connected to the group hierarchy as shown above
      class TRobotCamera : public MGraphic3D
      {
          // construct a camera and its geometry
          TRobotCamera( const TCamera& aCamera, 
                    const TCameraGeometry& geometry);
          
          // Draw() performs two operations:
          // 1. set the transformed camera to SceneBundle (residing
          // in grafPort) if the grafPort is a dummy port.
          // 2. otherwise, draw the geometry, if it is desired
          Draw(TGrafPort& grafPort );  
      };
The following code fragment installs the camera in a scene bundle and renders the robot with the new camera setting.

          SceneBundle.SetAttribute(TArticulatedLightCameraControl( DUMMY ) );
          dummyPort.BeginFrame( SceneBundle );
          aRobot.Draw( dummyPort ); 
          dummyPort.EndFrame();
          SceneBundle.SetAttribute( TArticulatedLightCameraControl( REAL ) );
          realPort.BeginFrame( SceneBundle );
          aRobot.Draw( realPort );
The implementation of articulated light sources is not as straightforward as that of the camera because a scene bundle can hold many light sources and setting a light source requires a token. With a simple modification to the TRobotCamera code, the following code fragment installs light sources to a scene bundle so that the light can be rendered.

      class TArticulatedLight : public MGraphic3D
      {
          // construct a light and its geometry
          TArticulatedLight ( const TLight& aLight, 
                    const TLightGeometry& geometry);
          
          // Draw() performs two operations:
          // 1. Set the transformed light to SceneBundle (residing
          // in grafPort) if the grafPort is a dummy port. The token is
          // supplied by an ArticulatedLightCameraControl object.
          // 2. Otherwise, draw the geometry, if it is desired
          Draw(TGrafPort& grafPort );  
      };
The following code fragment installs the light to the scene bundle and renders the robot with the new light (this is almost identical to the code given above for the camera).

          SceneBundle.SetAttribute(TArticulatedLightCameraControl(DUMMY))
          dummyPort.BeginFrame(SceneBundle)
          aGroupWithLights.Draw(dummyPort) 
          dummyPort.EndFrame()
          SceneBundle.SetAttribute(TArticulatedLightCameraControl(REAL))
          realPort.BeginFrame(SceneBundle);
          aGroupWithLights.Draw(realPort);


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker