DI-Guy SDK Documentation  13.1
2.2 - Working with the diguyScenario and diguyCharacter Classes

Table of Contents

The diguyScenario and diguyCharacter classes are the two most powerful classes in DI-Guy.

Most of your development will center on working with these two classes. The following sections describe some of the key functions and concepts of each class.

2.2.1 The diguyScenario Class

The following sections describe important types of functions in the diguyScenario class.

2.2.1.1 Update and Draw Functions for diguyScenario

The update() and draw() functions are key functions used in even the simplest DI-Guy application.

The update() function advances time forward to time t and new position and joint values are calculated for all the characters. No rendering happens in update().

On immediate mode rendering systems, rendering is performed in the draw() function. The draw function calls two sub-functions, draw_pass1(), which draws the opaque objects in the scene, and draw_pass2(), which draws the transparent objects. You can call the subfunctions directly if you need that level of control.

Functions are provided for enabling and disabling culling of characters that are outside the view frustum. Characters are surrounded by bounding spheres.

2.2.1.2 Working with .dss Files

If you save a scenario created with DI-Guy Scenario, it creates a .dss file. You can use the load() function to load a diguyScenario from the .dss file.

2.2.1.3 Time Control and Playback Functions

The reset() function rewinds the scenario back to the start time (t-in) and resets a number of features such as signals. Reset is almost always the preferred way to restart a scenario, as opposed to just setting t to zero.

Use get_t() if you want to know what time the scenario thinks it is. Accessor functions such as get/set_tout(), get/set_playback_loop(), and get_tick_dt() allow users to set and get various values associated with time control of a DI-Guy scenario.

The concept of associating a clock time-of-day to t-in is available in DI-Guy and can be accessed through the tin_time_of_day family of functions.

2.2.1.4 Performance Functions for diguyScenario

The following functions improve loading performance.

These functions let you avoid problems at runtime that can occur if new character data is loaded when a character or gesture is called for the first time. These functions load the data during startup, when delay is less important.

You can also improve performance when updating DI-Guy. You can use a multi-threaded control API in diguyApp. For details, please see diguyApp:set_num_threads(). The get/set_ticks_can_be_dropped() and get/set_max_ticks_behind_till_dropped() functions let you tune scenarios that have trouble running in real time. For more information about improving performance, please see 4 - Maximizing DI-Guy Performance.

2.2.1.5 General Query Functions

The diguyScenario class has functions that let you get the following information about DI-Guy characters and their capabilities:

  • Number of different character types available.
  • The number of appearances or actions available for a given character type.
  • The speed, distance, direction, or facing angle of a particular action.
  • The number of gestures available.

When a number of items are available, there are functions for getting those items by index.

2.2.1.6 Character Functions

Perhaps the most important function of the diguyScenario class is to act as a container for DI-Guy characters.

  • get_num_characters(). Reports how many characters are in the scenario. Functions are then available to retrieve these characters either by name or by index.
  • create_character(). Creates a new character.
  • destroy_character(). Destroys a character.
  • set_iguy_character(). Designates a character as being driven by a joystick. We call a DI-Guy character that is controlled by a joystick an I-Guy.

2.2.1.7 Path Shape and Waypoint Functions

Path shapes are the splines that underlie paths in DI-Guy. The diguyScenario class has functions for creating, indexing, copying, and destroying path shapes. Once a path shape has been defined, DI-Guy characters can follow them. The path shapes are in turn composed of waypoints, which can also be manipulated through the diguyScenario interface.

2.2.1.8 Signal Functions

Signals are useful as a means to call event handlers. You can create and destroy signals, retrieve the number of signals, retrieve a signal using its index, or retrieve a signal using its name. All of the signals can be reset using reset_signals().

2.2.1.9 Sound Functions for diguyScenario

You can create and destroy sounds, retrieve the number of sounds, retrieve a sound using its index, or retrieve a sound using its name. All sounds can be reset using stop_all_sounds().

    \note Sounds are not played directly. They are used as templates for sound instances. Please see diguyCharacter::play_sound() and diguyCharacter::create_sound_instance() for more details.

2.2.1.10 Group Functions

Groups are subsets of the characters belonging to the scenario. They can be very useful as a way to organize characters. For example, when networking, combatants are classified as belonging to groups net_friendly, net_opposing, or net_neutral. You can create and destroy groups, retrieve the number of groups, retrieve a group using its index, or retrieve a group using its name.

2.2.1.11 Sensor Region Functions

Sensor regions are user-definable cubic regions that sense when characters enter and leave them, and also know how many characters are in them. You can retrieve the number of sensor regions and retrieve a sensor region using its index. Sensor regions can have callbacks associated with them for when characters enter or leave.

DI-Guy AI supports arbitrarily shaped regions.

2.2.1.12 Scene Object Functions

Scene objects are stationary objects (usually terrains) to which waypoints can be ground clamped.

You can create and destroy scene objects, retrieve the number of scene objects, retrieve a scene object using its index, or retrieve a scene object using its name. Scene objects can be enabled or disabled (that is, rendered).

2.2.1.13 View Functions

Views are windows in which rendering occurs. You can find a view by name, retrieve the primary view, or retrieve a secondary view by index.

2.2.1.14 Camera Functions

Each view has a camera associated with it that defines how the 3D scene is viewed in the window. Multiple camera settings can be contained in a scenario, and the camera can be set to the values in any of those camera settings. Functions are available to query the number of camera settings, or get a camera setting by index or name. The function load_camera_settings() sets the primary view’s camera parameters from the specified camera setting.

There is also a set of functions for setting or querying the relationship of script events to the camera.

2.2.1.15 Fog and Light Functions

diguyScenario has functions for managing fog and light settings, including querying the number of settings, retrieving a setting by index or name, and manipulating the values of the settings. These functions are relevant only if you want to program while running inside of DI-Guy Scenario.

2.2.1.16 Information Popup Functions

Information popups are boxes with text that appear when running a scenario inside of DI-Guy Scenario. An API is available to manage the popups.

2.2.1.17 Variable Functions

You can declare user variables that are attached to the diguyScenario class. An API is available to manage the variables, including declaring, setting, naming, finding, and using the variables.

2.2.1.18 Facial Expression Functions

You can create, delete, and manage the facial expressions associated with Expressive Faces software.

2.2.1.19 Callback Functions

You can use the add_callback() function to have a function called when any of the following scenario-level events occur. Some of the events are specific to DI-Guy Scenario.

  • CALLBACK_ID_CREATE
  • CALLBACK_ID_DESTROY
  • CALLBACK_ID_RESET
  • CALLBACK_ID_WAIT_CURSOR_SHOW
  • CALLBACK_ID_WAIT_CURSOR_HIDE
  • CALLBACK_ID_LOAD
  • CALLBACK_ID_SAVE
  • CALLBACK_ID_LOAD_SCENARIO_FILE.

For additional callbacks see diguyScenario.h.

2.2.1.20 Default Character Callbacks, Altitude Functions, and other Default Callbacks

The function add_default_character_callback() lets you assign particular character level callbacks to all subsequent characters added to the scenario. Similarly, set_default_character_altitude_function() lets you assign a particular altitude function to any character subsequently added to the scenario. There are similar methods for assigning callbacks to paths, sensor regions, signals, views, cameras, fog, and lights.

2.2.1.21 Event Handler Functions

DI-Guy event handlers are similar to callbacks, but have a name with which they can be referenced. map_event_handler_to_callback_id() maps an event handler function to a particular callback ID. The API provides functions for registering various event handlers tied to signals, sensor regions, character events, and scenario events.

2.2.1.22 History and Review Functions

You can save and load history for after action review of your scenario. Call set_history_type() to DIGUY_HISTORY_TYPE_COMPLETE, since this is a DI-Guy SDK application. When playing back scenarios, other calls made to DI-Guy API functions may be ignored, unless you are at a point in the scenario for which no data had been recorded.

2.2.1.23 LOD Functions

DI-Guy supports levels-of-detail for graphics (where characters are drawn with various numbers of polygons), motion (where characters can limit which joints are updated), and shaders. Activation, ranges, and other methods of parameterizing the LODs are available in the API.

2.2.1.24 Meta−Action Functions

The basic concept of meta-actions is that you should be able to query a character for his "closest action" without knowing exactly what actions or their names are available by describing the direction-of-travel, speed, posture, and variant of the action he would like to use. For example, you might ask for a moving forward motion that goes four MPH in an upright posture. For a soldier, the "jog" action might be returned, while for the female_pedestrian, perhaps "powerwalk" would be returned. Variant can mean different things, for example, "funky" versus "stiff" might be a way of differentiating between two different types of walking.

2.2.2 The diguyCharacter Class

The following sections describe important types of functions in the diguyCharacter class.

2.2.2.1 General Accessor Functions

  • get/set_name(). Gets or sets the name of the character.
  • get/set_type_name(). Gets or sets the character type of a character.
  • get_scenario(). Gets the scenario the character belongs to.
  • get/set_enabled(). Gets or sets a character's enabled status.
  • get/set_drawn_by_scenario_flag(). Determines whether the character gets drawn when its parent scenario gets drawn.
  • get/set_current_tin(), get/set_current_tout(). Gets or sets the time range during which the character will be active.
  • get/set_position() and get/set_orientation(). Gets or sets geographic position or orientation of the character.
  • get/set_position_double(). Gets or sets position when the character needs to be far away from the origin.
  • set_position_relative_to_parent() and set_orientation_relative_to_parent(). Used when parenting the character to another character.
  • set_initial_position() and set_initial_orientation(). Sets the position of a character when a reset occurs. This is for free position mode only. In path position mode, the start of the path is where the character will go on a reset.
  • get/set_scale(). Gets or sets the scale of the character along the three major axes.
  • is_group_member(). Returns whether the character belongs to a particular group.

2.2.2.2 Update and Draw Functions

  • update() advances time forward to time t and new position and joint values are calculated for the characters. No rendering happens in update().
  • get/set_t_controlled_by_scenario_t() checks to see if your character has its time controlled by the scenario (this is the default).
  • Rendering is performed in the draw() function on immediate mode rendering machines. The draw function calls two sub-functions, draw_pass1(), which draws the opaque objects in the scene, and draw_pass2(), which draws the transparent objects. You can call the subfunctions directly if you need that level of control.

2.2.2.3 Appearance Functions

  • get/set_appearance() and get/set_current_appearance() let you get and set a character's appearance. Current appearance (as returned by get_current_appearance()) may be different than the base appearance. This base appearance is the starting appearance of the character before any calls to set_current_appearance() have been made. This means that if the scenario is reset, the appearance will revert to the base appearance.

    \note DI-Guy currently prohibits changing the appearance of a character to a new appearance associated with a different actor once a scenario is underway. This is due to DI-Guy methods for reducing foot slippage. It is therefore important to use set_appearance() before advancing time. Choose an appearance associated with the actor with whom all anticipated future appearances are also associated.
    

  • get/set_current_head_appearance() allows you to swap heads on the character.
  • get_current_hand_item(), set_hand_item(). These functions let you get and set the character's hand item.

2.2.2.4 Dying

  • die_now(). Tells a character to die as soon as possible. Characters execute their dead action. All aiming, gazing, pointing, head nodding, gestures, and sounds stop.
  • get_dead(). Gets the dead state of a character.
  • revive_now(). Resuscitates a character.

2.2.2.5 Performance Functions

Use of shader LODs can improve performance. Use the get/set_graphics_lod() and get/set_shader_lod() functions.

Characters can be culled in or out of the scene. You can set or view a character’s bounding radius with get/set_bounding_radius() and get/set_default_bounding_radius(). DI-Guy Character Viewer can also display them. Please see the culling examples for how to use these functions inside your application.

2.2.2.6 The "Up" Vector

Normally "Z" is up for a character, but occasionally you may want to alter the up vector. A good example would be a vehicle like an airplane banking as it made a turn. Use the get/set_up_vector() to access this value.

2.2.2.7 Action and Speed Functions

  • set_speed(). Sets a goal velocity after calling set_desired_action(). You can undo the speed setting by calling set_speed() with DIGUY_DEFAULT_FLOAT or by subsequently calling set_desired_action() or force_action().
  • get_speed() retrieves the current speed of the character.
  • set_t_scale_factor(). Dilates time around the character. Use unset_t_scale_factor() to turn it off.
  • get/set_desired_action(). Puts the character into free action mode. A character that was in path action mode will now ignore subsequent action beads on his path. Characters that are in path position mode should use the retain_path_shape argument to determine whether they will leave path position mode for free position mode.
  • force_action(). Forces a new action to be executed immediately. By contrast, set_desired_action() allows the current action to complete its cycle before transitioning.
  • force_action_duration(). Used when the character is in path position mode. It forces the character to perform an action for a certain period and then revert to the path.
  • force_action_and_path_shape(). Forces the action and puts the character on the designated path shape.
  • get_time_to_transition(). Returns the time till a desired action begins.
  • get_action_mode(). Returns the action mode of the character.

The following function support animation blend tree functionality:

  • get/set_animation_velocity() and get/set_animation_local_velocity(). Sets a generic parameter in world/local space that can be mapped to a blend tree driver. The locomotion actions are driven by these values allowing one action to go many different directions.
  • get/set_animation_angular_velocity(). Sets a generic parameter that can be mapped to a blend tree driver to control rate of turning in locomotion actions

For more information about animation blend trees, please see 3.1.1.1 Animation Blend Trees. For more information about these functions, see the Animation Blend Tree Parameters section in diguyCharacter.h.

2.2.2.8 Parenting Functions

set/unset_parent() allows you to parent a character to another character. Characters move relative to the parent character, not global space.

2.2.2.9 Link Functions

  • get_link_position(). Gets the location and orientation of a particular link of a character. get_link_position_double() returns a double precision answer when the character is far from the origin. The get_link_position_with_offset() and get_link_position_with_offset_double() functions allow you to get an offset into that link.
  • get_link_relative_position(). Gets the position and orientation of the link relative to the parent link. There is also a with_offset version.
  • get_base_link(), find_link(), and get_link_at_index(). These functions get particular links.

2.2.2.10 LOD Functions

  • Call get/set_lod_ranges() to access the graphics LOD ranges of the character. You can use set_graphics_lod() to manually set the graphics LOD of the character. You should turn off automatic LOD switching at the scenario level when you do this. Use the DI-Guy Character Viewer to visually and textually review the LODs of the character. DI-Guy characters have up to 7 LODs, with individual meshes having up to 4 LODs, typically decimated according to the 50-30-30 rule (LOD 2 has 50% of the polygons of LOD 1, and so on).
  • get/set_motion_lod() Gets or sets the motion LOD state of the character. Coordinate use of the set function with the Load Manager.

2.2.2.11 User Data

get/set_user_data(). Lets you attach your own classes or structures to a DI-Guy character and access them.

2.2.2.12 Path Functions

  • set_distance_along_path(). Positions a character at a particular distance along a path when in path position mode. leave_path() makes a character change from path position mode to free position mode.
  • get_position_mode(). Tells you whether the character is in free or path position mode.
  • diguyCharacter has functions for determining how many paths are associated with the character and you can retrieve them by name or index.
  • push_path(). Appends a path to a list of paths the character will follow.
  • force_path(). Takes a character off the current path and puts it on the input path.
  • force_partial_path(). Designates a start position on the input path.
  • resume_interrupted_path(). Allows you to get back to a path after a set_desired_action() or force_action() removed you from the path and the retain_path_shape argument was set for those functions.
  • create_and_force_bridge_path(). Creates a temporary path from your character's current position on a path and switches the character onto it. This temporary bridge path then transitions the character onto the new path.
  • create_path() and create_simple_path(). Allow runtime generation of a path. The former creates an empty path, the latter a two waypoint path.
  • jump_to_action_bead(). Causes the character to jump forward along its current path to the named action bead.

2.2.2.13 Sound Functions

Call play_3d_sound() to have your character play a sound that "follows" your character. play_sound() plays an "ambient" (positionless) sound.

2.2.2.14 Sound Instance Functions

A sound instance is, roughly speaking, a playing copy of a sound. A single sound can be layered on top of itself many times. Each of these layers is a sound instance. For example, a single gunshot sound might be used for every soldier's gun. Since these guns might be fired nearly simultaneously, each gun, when it fires, has its own instance of the gunshot sound. Any time a sound is played, a sound instance is being used. Generally, these sound instances are managed internally to DI-Guy and you need not worry about them if you use only play_sound() or play_3d_sound(). But if you need finer control over sound, you will have to work with sound instances.

Sound instances are generally most useful for longer sounds, such as the engine sound of a vehicle. With such sounds, you may want to play them for a shorter time than their natural duration. You need to be able to stop them before they play out naturally. You also might want to repeat a relatively short sound so that it will fill up a desired amount of time. You can do both of these things with sound instances.

Please see the SDK reference for details on using sound instances.

2.2.2.15 Perception Functions

Use is_within_distance_n_of_character() to query whether any other characters are near your character. is_within_distance_n_of_member_of_group() queries whether any characters that belong to a particular group are near your character.

Other functions for detecting characters include:

  • get_nearest_character()
  • is_character_visible()
  • get_nearest_active_character()
  • get_nearest_active_character_in_group()
  • check_character_visibility()
  • check_point_visibility().

For details, see diguyCharacter.h.

2.2.2.16 Callback Functions

Use the add_callback() function to have a function called in response to character-level events. Please refer to the SDK Reference Manual for a list of callbacks. Types of callbacks include upon create, upon destroy, and pre and post weapon fire.

2.2.2.17 Event Handler Functions

map_event_handler_to_callback_id() maps an event handler function to a particular callback ID. DI-Guy event handlers are similar to callbacks, but have a name with which they can be referenced. The API has functions for registering various event handlers tied to signals, sensor regions, character events, and scenario events.

2.2.2.18 Aim, Gaze, Pointing, and Nodding Functions

Characters can aim, gaze, or point by being directly commanded or by reaching a bead on the path they are traveling.

Aim, gaze, and point have many functions for specifying how to aim, gaze, and point, whether it is at a point in space, a local direction, or at another character or link. Functions are also available for determining the status or duration of the aim, gaze, or point, and to terminate these actions. Query functions allow you to determine a character’s particular ability to aim, gaze, and point.

A smaller API is available for nodding and head shaking for default, non-animated heads. The Expressive Faces module offers dynamic facial animation.

2.2.2.19 Altitude Functions

While a character is in path position mode, its altitude (position in Z direction) is most often determined by the path. Characters in free position mode often need their altitude to be determined by another method. This can be done by setting the position manually (using the set_position()) call, or semi−automatically by registering an altitude function. An altitude function is a callback function that gets called once per character update. Based on the character's updated X and Y position, the callback can calculate and return an appropriate Z position. This is commonly done using some type of graphics intersection testing.

2.2.2.20 Weapon Functions

DI-Guy characters that have weapons can fire them. The SDK has functions for determining the muzzle flash and sound to play when firing. Use set_weapon_fires_live_rounds() to determine whether the character might hit or kill other characters. The kill zone has a near, far, and weapon spread that is programmable.

Characters can fire a weapon using the fire_weapon() or fire_weapon_n_times() function.

By default, when a character get’s shot, it dies. However, you can use the CALLBACK_ID_IMPACT and CALLBACK_ID_CROWD_MEMBER_IMPACT callbacks to override this behavior and create custom damage models. These callbacks are called when a character has been hit. diguyCharacter::get_last_impact_record() contains a pointer to the impact information. If a character has this callback the standard behavior (killing the character) is skipped and the system assumes the end user has handled the impact.

The diguyImpact class contains detailed information for the result of a weapon fire. Consult this class for more information for supporting advanced weapon effects.

2.2.2.21 Gesture Functions

A gesture is a motion a character can do that temporarily overrides a subset of the character's joints. Gestures are designed to supplement the stock set of character motions. Most gestures are available to all characters.

gestures.png
Gestures

DI-Guy Scenario has an interactive mode that allows gestures to be easily previewed, right click on any character and do show Gesture Previewer. For more information about gestures, please see 3.1.5 Gestures.

2.2.2.22 DIS Functions

DI-Guy characters support setting and querying information about how they are broadcast or received from a DIS networking session. Attributes such as whether a character should be published, its lifeform state, weapon state, network marking, and entity number can all be set or queried.

2.2.2.23 Working with Guides

A guide is a mechanism for controlling the position, orientation, or action of a character that is in free position mode and free action mode. Guides are most often used by networking software, where you only get intermittent information about a character’s position and actions, or formations. In either case, there is usually a current state and a goal state, and the guide is used to try to minimize the difference in the two in a believable manner. Most guides look at the desired position, velocity, and orientation of the character and do what is necessary to get the character there (or at least closer). How a guide accomplishes this depends on:

  • The guide algorithm being used.
  • The parameters set for that algorithm.
  • The difference between current and desired settings.

The desired position and orientation for a character can be set by set_desired_position() and set_desired_orientation(). They may also be implicitly set if that character is in a formation. Guides can be explicitly added to a character by calling add_guide() or create_guide(). They can also be implicitly added to a character if that character is called into a formation. Guide parameters are set by calls to diguyCharacterGuide::set_guide_algorithm_float_parameter().

The set_desired_velocity() function lets you do dead-reckoning.

Once a guide has been added to a character it can affect the position, orientation, and/or action of a character until the guide has been removed. Guides can be explicitly removed from a character by calling remove_guide() or remove_all_guides(). They can be implicitly removed by the break-up of a formation, or by an automatic removal guide acquiring the target destination.

Currently the following algorithms are offered as guides:

  • Exact
  • Follow1
  • Follow2
  • Drift1
  • Adaptive (*this is typically the best choice for your guide).

Please see the SDK reference for more information on particular guide algorithms and functions to activate and manage guides.

2.2.2.24 Variable Functions

Just like scenarios, characters can have user variables associated with them. A set of functions is available for querying, creating, setting, and using user variables. Variables can be integers, strings, or floats.

[<< How DI-Guy Works] [Home] [Top of Page] [The DI-Guy Graphics API >>]