DI-Guy SDK Documentation  13.7.1
1.1 - DI-Guy SDK Use Cases

This chapter provides three detailed examples of how you can use the DI-Guy SDK to simulate entity behavior:

  • Create a scenario using DI-Guy Scenario (with DI-Guy AI) and then load the scenario into your DI-Guy-enabled simulation and play it. The high-level construction is performed off-line in DI-Guy Scenario, a tool designed to quickly and efficiently generate compelling human behavior. This is the recommended use case.
  • Create and control DI-Guy characters directly in your simulation using low-level calls to the DI-Guy Action API. In this use case, you code all the high-level construction.
  • Drive DI-Guy characters from a network. Examples include being at the end of a DIS/HLA pipe or being in a Host-IG environment. Here the high-level construction is performed somewhere else and piped in.

The DI-Guy SDK includes programming examples. The examples assume a Windows operating system using OpenGL. Source code for the examples is provided with the DI-Guy distribution. They are in ./programming_examples/. In addition to OpenGL, examples are provided for DirectX and OpenSceneGraph (OSG) in the DI-Guy Graphics API, featuring open source implementation details. DI-Guy can render on just about any Windows or Linux rendering system imaginable.

All the OpenGL Windows examples should be looked at by all users, not just OpenGL users. Although the rendering environments can be very different, almost all your DI-Guy code will look the same.

1.1.1 Embed Scenarios Created with DI-Guy Scenario

The DI-Guy SDK can load and play scenarios created using DI-Guy Scenario. The .dss scenario file describes the scenario, the characters, behaviors, AI, decisions, and logic that play out over time. The characters are still accessible using the DI-Guy API, so you can both monitor and alter their behavior at runtime.

dig_sdk_usdediguyinanapplication.png
Using a DI-Guy Scenario in an Application

We think this is the most productive way to work with DI-Guy, because DI-Guy Scenario and DI-Guy AI are designed to let you quickly and efficiently create compelling human performances whether you are a programmer or not. The high-level process is as follows:

  1. Use DI-Guy Scenario to create a scenario.
  2. Load the scenario into your application through the DI-Guy API.
  3. Play the scenario.

This method of adding humans is shown in the simple_playback example. This example is in ./programming_examples/diguy_ogl/simple_playback.

(Details about programming examples can be found in 10 - Programming Examples.)

The following DI-Guy OpenGL example loads and then plays back a scenario file created with DI-Guy Scenario.

  1. Initialize DI-Guy. This particular initialization works for OpenGL, but diguy_graphics_api_initialize() should be used for the DI-Guy Graphics API implementations.

  2. Create a DI-Guy scenario.

  3. Load the .dss file into the scenario.

    scenario->load(arg_dss_filename);

  4. In your update loop, update the scenario with the current time in seconds.

    scenario->update(t);

  5. In your draw loop, draw the scenario. In scene graph style renderers, this step is not necessary.

    scenario->draw();

  6. 6. When finished, clean up the scenario and DI-Guy.

1.1.2 Create and Control Characters in Real-time Using the DI-Guy API

Another straight-forward way to use DI-Guy is to add DI-Guy characters to your application and then command their behaviors directly in real time using the DI-Guy API.

The "simple" example, creates a soldier character and then commands the character to perform a sequence of movements starting from a standing position. The source code for this example is in ./programming_examples/diguy_ogl/simple. You can run the compiled example by executing simple.exe (Windows) or simple (Linux).

  1. Initialize DI-Guy. In this example, we used the OpenGL version of DI-Guy.

  2. Create a DI-Guy scenario. You need at least one scenario to run DI-Guy.

  3. Create a DI-Guy character of type soldier. You must specify the name, character type, and appearance of your character. You can specify body appearance, head appearance, and hand item. If you do not specify one of these, default values are used.

    "Character 1", // name
    "soldier_07", // character type soldier
    NULL); // default appearance

  4. Set the initial position, orientation, and action for the character:

    character1->set_position(0.0f, -3.0f, 0.0f);
    character1->set_orientation(90.0f, 0.0f, 0.0f);
    character1->force_action("kneel_ready");

  5. You will update the scenario periodically using scenario_update(). Before calling scenario_update() in the update loop, make any calls to change the behavior of your character. Here prev_t is the value of t the last time through the loop. At 2 seconds the character is commanded to walk, at 8 seconds the characters walks in a crouch, at 14 seconds he gets on the ground and aims the weapon, and at 18 seconds he fires the gun in 1 second intervals. All transitions are handled automatically by the DI-Guy motion engine.

    if ((t >= 2.0) && (t_prev <= 2.0))
    character1->set_desired_action("walk");
    if ((t >= 8.0) && (t_prev <= 8.0))
    character1->set_desired_action("walk_lo");
    if ((t >= 14.0) && (t_prev <= 14.0))
    character1->set_desired_action("prone_aim");
    if ((t >= 18.0) && (t_prev <= 18.0))
    character1->fire_weapon_n_times(4, 1.0f);

  6. In your update loop, update the scenario with the current time, in seconds:

    scenario->update(t);

  7. In your draw loop, draw your DI-Guy characters. (In scene graph style renderers, this step is not necessary.)

    scenario->draw();

  8. When finished, clean up the character, the scenario, and DI-Guy:

    scenario->destroy_character(character1);

1.1.3 Network with Other Simulators (DIS or HLA)

A common mode of operation for DI-Guy SDK is to visualize human characters simulated by a remote application. A typical case is when you connect your simulation to a DIS or HLA network. (DI-Guy support HLA 1.3, HLA 1516 (SISO DLC), and HLA Evolved.)

Another common case is where your simulator is a HOST-IG style simulator, often connected using a CIGI pipe. DI-Guy provides support for broadcasting, receiving, displaying, and controlling characters in networked simulations. In addition to functions that deal with standard DIS and HLA lifeform functions, DI-Guy provides custom PDUs for DIS and the DI-Guy FOMs for HLA, that extend these protocols to take full advantage of DI-Guy’s capabilities. (DI-Guy has a custom FOM for HLA 1.3 and HLA 1516 and FOM modules for HLA Evolved.)

dig_sdk_useinnetworkedsimulation.png
Using DI-Guy in a Networked Simulation

The following example shows how to network your DI-Guy characters to a DIS network. It is in ./programming_examples/diguy_networking/DIS. This example uses VR-Link (sold separately) to provide the networking layer. DI-Guy is designed to interface easily with whatever networking layer you use, so if you want to hook up your own networking middleware to DI-Guy, you can do so.

  1. Initialize DI-Guy:

  2. Initialize DIS:

  3. Create a DI-Guy scenario:

  4. Call networking functions to specify that we are receiving. Set the network host ID and go online:

    diguy_net_module->set_publish_local_chars(0);
    diguy_net_module->set_host(2);
    diguy_net_module->go_online(scenario);

  5. In your update loop, get updates from DIS and update the scenario with the current time in seconds:

    diguy_net_module->update();
    scenario->update(t);

  6. In your draw loop, draw the scenario. Scene graph style renderers do not require this step.

    scenario->draw();

  7. When you shut down, do it in the proper order.

    diguy_net_module->go_offline();
    diguy_net_module->update(); // don't forget this update

The SDK also has the following examples of networking using HLA:

  • For HLA 1.3: ./programming_examples/diguy_networking/HLA.
  • For HLA 1516: ./programming_examples/diguy_networking/HLA1516.
  • For HLA Evolved: ./programming_examples/diguy_networking/HLA1516e.

[Home] [Top of Page] [Querying and Setting Actions in a Pipeline Setting >>]