Download A Flexible 3D-Visualisation Engine With Force

Transcript
The 'Flight' Simulator
Page 86 of 117
CControlName(CControlData &cdat);
The CControlData class holds data which the Control will use to configure itself. (The parameter, cdat,
is created by the CTask object while reading the task specification file.) The first thing the constructor
should do is call CControl::init(CControlData &cdat), passing cdat as the parameter. This utility
function will extract the required details from the CControlData object, and set certain standard
CControl member variables accordingly (such as initial position).
Next, the constructor should set the value of the member variable landingHeight with the height of the
centre of the Control model. For example, the CControlHelicopter model sets this value to 1.0f,
meaning that if the helicopter were resting on the ground, the centre of the helicopter model (and centre
of the internal view) would be 1 metre from the ground.
The constructor should also initialise any member variables added to the class declaration.
Finally, before the constructor exits, it should create a Data Streamer and Data Logger, if requested.
The member variable logging is a boolean indicating whether a Data Logger is required. If this value is
true, the constructor should create a new CDataLoggerName object, and assign it to the logger member
data variable (which is a CDataLogger pointer). The system will record the state of the Control to disk
via calls through this pointer. A pointer to the actual CControl subclass instance should be provided as
a parameter to the CDataLoggerName constructor. The following lines of code illustrate the procedure.
if(logging)
logger=new CDataLoggerName(this);
The creation of the Data Streamer is similar. The input_mode member variable is an integer specifying
the location of the input for the Control. Possible values for this variable can be found in the
Definitions File, and the standard distribution defines CINPUT_JSTICK and CINPUT_REPLAY. If
the value of this member variable is the latter, a Data Streamer must be constructed to read the state of
the Control from a log file during the simulation. The filename of the log will be available in the fname
field of the CControlData object, and it and a pointer to the actual CControl subclass should be
provided as arguments to the Data Streamer constructor. The newly created CDataStreamerName
should be assigned to the streamer member variable (which is a CDataStreamer pointer). The
following lines of code illustrate the procedure.
if(input_mode==CINPUT_REPLAY)
streamer=new CDataStreamerName(this, cdat.fname);
This should complete the constructor.

The de-constructor should be completed.
Any force feedback effects which could be fired by the CControl subclass (not from within the
CDIData component) should be stopped in the de-constructor of the CControl subclass. Although this
cannot be done at this point, as the CDIData effect numbers are not yet known, a reminder should be
made to return to this function and complete it. An effect is stopped simply with the call
didata->stop(i)
where didata is a standard CControl member variable (a pointer to a CDIData object) and i is the index
of the effect to be stopped.

The DirectInput set-up function.
The function CControl::setupDIandView() registers an external view with the Control, and creates the
CDIData object for the Control. A pointer to this object is then assigned to the didata member variable
(mentioned above) before being returned to the calling system. The function will look almost identical
to the code shown below, of course, replacing Name with the actual name of the new Control.
Douglas Currie