This time, we will explain the basic usage of a plugin developed to visualize EXODUS analysis results using UC-win/Road, using sample code. It is designed to control UC-win/Road's human character objects by replaying previously saved analysis results.
|
|
3D character functionality and control |
|
■ Specifications for Character Objects in UC-win/Road
The character object functions in UC-win/Road are applicable to objects that move and perform complex actions, such as people or animals. To save these movements, the md3 file format is used. A single character model stores multiple animation data to reproduce various movements, allowing for the expression of any desired movement. However, for example, if you set the walking animation speed to 30 kilometers per hour, it would appear unnatural for a human, so it's more appropriate to set it within a range of 1 to 10 kilometers per hour.
Therefore, UC-win/Road provides a settings screen that allows users to set appropriate movement speeds for each animation. This enables the animation to be played at a speed proportional to the model's movement speed during playback.
By using the UC-win/Road SDK, you can implement the above-mentioned processing by controlling the movement of character models.
■ Objects related to characters
To animate and draw characters in UC-win/Road, 2 objects are used. 1 object contains the polygon information necessary for drawing the character, which includes animation data. This is called a "QuakeIII" object, originally developed as a character data format for the QuakeIII game.
Another object is called CharacterInstance, which is used to place and move characters within the UC-win/Road VR space. This object manages positional information, movement calculations, and animation states. A single CharacterInstance refers to 1 QuakeIII object. It is also possible for multiple CharacterInstances to refer to the same QuakeIII object. To put it in terms of cars, several people can drive the same type of car, but this "type" represents a single set of common data.
In the data structure, information about character shapes is stored in one location (as in QuakeIII) and applied to multiple instances (CharacterInstance). Therefore, when controlling character movement in UC-win/Road, it is necessary to load the QuakeIII object beforehand. The class structure for MD3 characters is shown in Figure 1.
■ Sample program source code
The following source code creates an instance of a character in UC-win/Road and sets its initial position. In this example, the character is created as a temporary object.
function CreateNewInstance(project: IF8ProjectForRoad):
IF8CharacterInstance;
var
startPosition : GLPointType;
begin
// Check if the project exists
// Checks whether there is 1 or more MD3 character models.
if Assigned(project) and (project.numberOfCharacters > 0) then
begin
//Using the first MD3 character, and the character's..
// Creates an instance.
result := project.CreateCharacterInstance
(project.character[1], true);
// Set the initial position to a temporary variable
// Assigns the value to the properties of the character instance.
startPosition[_x] := 5000;
startPosition[_y] := 0;
startPosition[_z] := 5000;
startPosition[_z] := 0;
newInstance.instancePosition := startPosition;
end;
end; |
|
Control character movement |
|
■Synchronization with UC-win/Road simulations
Normally, character movement is calculated as part of the UC-win/Road traffic simulation. When controlling character instances using a plugin, it is necessary to synchronize the control with the main program's calculations. In the traffic simulation calculation, the position of each vehicle and the position of the characters are calculated before being displayed on the screen. The calculation is performed once for each frame to be displayed, but the frame update rate varies depending on the complexity of the 3D data in the VR space. Therefore, it is necessary to perform calculations that can handle variable time delays.
The calculation of movement itself can be done in various ways, depending on the object being moved and the mathematical models used. In virtual reality simulations, the system calculates the next pose based on the current pose of an object. During this process, the time difference between poses is used to calculate the amount of movement. The following example shows a linear movement at a constant speed. This method can also be used even when the time difference is variable.
procedure CalculatePosition(dtInSeconds : double; const CurrentX,
CurrentY : double; out X, Y : double);
const
SPEED = 10; // meters per second
DirectionX = 1.41421;
// Movement direction vector, X coordinate
DirectionY = 1.41421;
// Movement direction vector, Y coordinate
// Make the direction vector a unit vector.
begin
// Calculates the new X coordinate after dt seconds.
X := CurrentX + SPEED * dtInSeconds * DirectionX;
// Calculates the new Y coordinate after dt seconds.
Y := CurrentY + SPEED * dtInSeconds * DirectionY;
end; |
■ Character Position Control
Here, we will explain the process of reproducing pre-saved movement settings in real time. First, it is necessary to determine the format for saving the information. Considering versatility, we will save pose (position and orientation) information as a function of time. The variable types are declared as follows:
type
// Record for saving location information, direction, and time
// At the time specified by "time," a character or moving object will..
It seems to be displayed based on the position and orientation.
RoutePointType = record
time: double; // Time
position: array[1..3] of double; // 3D coordinates
orientation: array[1..3] of double; // 3D vector
end;
// This describes the route that a character or moving object takes
It is defined as an array of RoutePointType.
RouteType = array of RoutePointType; |
 |
| ■ Figure 1: Class structure of the MD3 character |
This type stores pose information at specific times. To represent this movement, the character is displayed using the stored poses, and the appropriate position is calculated based on the actual elapsed time. By updating the displayed pose according to the time, it is possible to express the movement.
However, it is necessary to calculate the orientation information in sync with the time at which drawing is performed using UC-win/Road. In such cases, there may be a difference between the drawing time of UC-win/Road and the time of the orientation data stored in the route, so smooth movement can be achieved by interpolating the orientation information (the most recent and subsequent) that is closest to the drawing time of UC-win/Road.
■ Road Alignment (Planar Geometry)
Each TurningPoint located below a Road object defines an Intersection Point (IP) on a plane line. This is the point where the extension of a straight road segment intersects. The planar linear segments are defined by an array of TurningPoints, and this array can be accessed through the turningPoint property of the Road object.
 |
| ■ Figure 2: Mechanism for reproducing character movement |
The UC-win/Road software will inform the application about the timing for updating character poses using a callback function. When a function is assigned to the OnMove event property of a generated character, that function is called when the character's pose needs to be updated. Within this function, the movement of the character is calculated, and the pose information is updated accordingly.
So far, we have been able to update the pose of the generated character. However, it is necessary to associate the UC-win/Road character instance with a pre-saved route. Several methods are possible, but here, we will use a new class to associate the route and the character instance. Specifically, this class will store information about the route, and a method of this class will be assigned to the character's OnMove event.
When a character instance is removed from the UC-win/Road core, using the OnDestroy event allows plugins to release related information. Additionally, implementing features such as reading root information from text files within this class can be convenient. Ultimately, the class declaration will look something like the following.
unit Move;
interface
uses
Classes,
F8OpenGL,
PluginCore;
type
// This record saves 1 node on a route
// This is declared using F8OpenGL here
// Using point-based system.
RoutePointType = record
time: double; // Time
position: GLPointType; // 3D coordinates
orientation: GLPointType; // 3D vector
end;
// This class associates character instances with root information
MoveClass = class
private
// Interface for the currently managed character instance
p_Instance: IF8MovingObjectInstance;
// This variable holds the current pose information index within the route
currentPointIndex: integer;
// This variable holds the current time within the route
time: double;
// Variable to hold the contents of the route
route: array of RoutePointType;
// This function is called when allocating a character instance.
// This function is declared with the MyInstance property
// This method is automatically called during assignment.
procedure SetInstance
(const Value: IF8MovingObjectInstance);
public
// Object creation
constructor Create(source: TStrings);
// Object release
destructor Destroy; override;
// When the main UC-win/Road program requests movement calculations
// Function to be called.
procedure Move(dTimeInSeconds: double; Instance:
IF8MovingObjectInstance);
// On the UC-win/Road main program side, character instances are
// Function called when an object is being deleted.
procedure InstanceDestroy(Instance: IF8DBObject);
// This function is used for initialization and resets to the starting position.
function GetFirstPosition: GLPointType;
// This provides access to the character instance currently being handled
// Properties.
property MyInstance
: IF8MovingObjectInstance read p_Instance
write SetInstance;
|
The implementation of the methods for this class is as follows.
implementation
uses
SysUtils;
{ MoveClass }
// ===================================================
// Object creation and initialization
// During initialization, time and pose information is read from a CSV file
// This variable stores data related to the route.
// The format of the CSV file is as follows.
// Time, X coordinate of position, Y coordinate of position, Z coordinate of position, Yaw angle,
Pitch angle, roll angle
// Example:
// 0,5000,2,5000,1.5707963267948966192313216916398,0,0
// 5,5005,3,5000,0,0,0
// 10,5005,4,5005,0.78539816339744830961566084581988,0,0
// 15,5010,5,5010,-2.3561944901923449288469825374596,0,0
//20,5000,2,5000,1.5707963267948966192313216916398,0,0
// ==================================================
constructor MoveClass.Create(source: TStrings);
var
i: integer;
node: RoutePointType;
begin
// Member initialization
time := 0;
currentPointIndex := 0;
p_Instance := nil;
// Reading the contents of the CSV file
source.CommaText := source.Text;
SetLength(route, source.Count div 7);
i := 0;
while i < source.Count do
begin
node.time := StrToFloat(source[i]);
Inc(i);
node.position[_x] := StrToFloat(source[i]);
Inc(i);
node.position[_y] := StrToFloat(source[i]);
Inc(i);
node.position[_z] := StrToFloat(source[i]);
Inc(i);
node.orientation[_x] := StrToFloat(source[i]);
Inc(i);
node.orientation[_y] := StrToFloat(source[i]);
Inc(i);
node.orientation[_z] := StrToFloat(source[i]);
Inc(i);
route[i div 7 - 1] := node;
end;
end;
// ==================================================
// Object deallocation
// ==================================================
destructor MoveClass.Destroy;
begin
MyInstance := nil;
end;
// ==================================================
// This function is used for initialization and resets the position to the beginning.
// ==================================================
function MoveClass.GetFirstPosition: GLPointType;
begin
if High(route) >= 0 then
result := route[0].position;
end;
// ==================================================
// On the UC-win/Road main program side, character instances are
This function is called when an object is deleted.
// Releases the character instance's interface.
// ==================================================
procedure MoveClass.InstanceDestroy
(Instance: IF8DBObject);
begin
p_Instance := nil;
end;
// ==================================================
This function is called when the UC-win/Road core requests calculation of movement.
// Calculate the position based on pre-loaded route data
// This reflects the changes on the character instance.
// ==================================================
procedure MoveClass.Move(dTimeInSeconds: double;
Instance: IF8MovingObjectInstance);
function LookForNode: boolean;
var
i: integer;
begin
result := false;
// Search for the corresponding position within the route from the current location.
If found, update the current location.
for i := currentPointIndex to High(route) - 1 do
begin
if (route[i].time <= time) and (route[i + 1].time >
time) then
begin
currentPointIndex := i;
result := true;
Break;
end;
end;
end;
var
// Variables used for position calculation.
position: GLPointType;
p1: GLPointType;
p2: GLPointType;
(The following has been omitted) |
The above describes the situation.
Ultimately, the plugin being developed will require programs to manage character instance creation and deletion, but we will omit those details here.
Announcement of experiential seminars
| UC-win/Road SDK seminar |
| • Date and time |
July 20, 2012 (Friday), 1:30 PM to 5:00 PM |
| • Course fees |
¥15,750 (including tax) |
| • This venue |
FORUM8 Tokyo headquarters, GT Tower seminar room
※TV conferencing systemThe event will be held simultaneously in Tokyo, Osaka, Nagoya, Fukuoka, and Sendai |
|
|
| Up&Coming '12, featured in the summer issue |
 |
|







>> Product comprehensive catalog

>> Premium membership services
>> Financial support
| Recently released products |
|
|
|