|
|
7 |
| Practical exercise sample code explanation (2) |
|
|
Following the previous session, we will provide explanations of the sample programs included in the UC-win/Road SDK, using source code. This time, we will cover topics such as importing models, interaction during simulation, custom event actions, and editing the main input screen.
|
|
Model import: ModelImportPlugin |
|
This example explains how to create a 3D model using UC-win/Road. It reads positional information, normal vectors, and texture coordinates for each vertex of the model from a text file, creates the model based on this information, places it in the scene, and finally provides an aerial view of it.
Selecting "Import Simple Model..." from the Tools menu will import a model without textures. Conversely, selecting "Import Textures Model..." will load a model with its associated textures.
■ 1: Structure of the 3D Model
3D models are composed of polygons (planar data consisting of multiple sides).
A 3D model is composed of a set of 3D coordinates for each vertex of the triangular polygons. In UC-win/Road, the polygon coordinates are defined in a counter-clockwise direction.
■ 2: If it includes textures
If textures are included, for each vertex of the triangular polygon, in addition to the three-dimensional coordinates, a normal vector and texture coordinates are set.
In the figure, (1) represents the vertex coordinates, (2) represents the normal vector [Note 7], and (3) represents the texture coordinates [Note 8].
■ 3: Loading the Model
To load a 3D model into UC-win/Road, first create a new 3D model object within the project, and then add polygon information.
The relevant interfaces are as follows:
// Object generation for 3D models
function IF8ProjectForRoad.CreateThreeDModel :
IF8ThreeDeeStudio;
// Add group (used as a group when adding polygon information)
function IF8ThreeDeeStudio.AddGroup : integer;
// Add polygon information (in cases where there is no texture)
procedure IF8ThreeDeeStudio.AddTrianglesGroup
(groupIndex : integer; triangles :
F8TriangleArrayType{*});
groupIndex: The group (component, layer) to which the polygon being added belongs
triangles: polygon coordinate information
// Add polygon information (if textures exist)
procedure IF8ThreeDeeStudio.AddTexturedTrianglesGroup
(groupIndex : integer;triangles :
F8TexturedTriangleArrayType{*});
groupIndex: The group (component, layer) to which the polygon being added belongs
triangles: polygon coordinate information
F8TriangleArrayType
F8TriangleArrayType = arrau of F8TriangleType;
F8TriangleType = array[1..3] of GLPointType;
F8TexturedTriangleArrayType
F8TexturedTriangleArrayType = array of F8TexturedTriangle;
F8TexturedTriangle = record
vertex: F8TriangleType;
normal: F8TriangleType;
textureUV: F8TriangleType;
end; |
■ 4: Placement of the added 3D models
To deploy a model registered in UC-win/Road, you need to generate an instance of the model and set its coordinate information.
The interfaces used are as follows:
function IF8ProjectForRoad.MakeModel(currentModel :
IF8ThreeDeeStudio;
xx: double; yy : double) : IF8ModelInstance;
currentModel: This refers to the model that will be deployed going forward
xx: The X coordinate (east-west direction, positive for east) of the model to be placed
yy: The Z coordinate (north-south direction, positive for south) of the model to be placed |
|
Interaction Sample Plugin |
|
This sample demonstrates examples of simulations and user interactions. By selecting "Display Logs..." from the tool menu, you can obtain logs from the operation. Selecting "Display user inputs..." allows you to capture events from the mouse, keyboard, and game controller on the main screen.
First, add vertical alignment to the road using the following interface.
• 1: Registering callback functions for models and road clicks
Register callback functions to be executed when a model or road is clicked on the main screen. When a model is clicked, its instance is returned through the callback function; when a road is clicked, information about the road and the click location is returned through the callback function.
var
method : Tmethod;
ApplicationService : IF8ApplicationService;
begin
// Registering callback functions for model clicks
FormMainModelClickFunc(method) := ModelClick;
ApplicationService.RegisterEventHandler
( _plgFormMainModelClick, method);
// Registering callback functions for road clicks
FormMainRoadClickFunc(method) := RoadClick;
ApplicationService.RegisterEventHandler
( _plgFormMainRoadClick, method);
end;
// Callback function when a model is clicked
function ModelClick
(modelInstance: IF8Instance): boolean;
modelInstance: The instance of the clicked model
// Callback function for when a road is clicked
function RoadClick
( c o n s t r o a d : I F 8 R o a d ; c o n s t d i s t a n c e , offset:
double;const leftSide,carriageway: boolean): boolean;
road: The clicked road
distance: The distance from the starting point on the line
offset: Offset from the end edge in the cross-sectional direction
leftSide: True indicates driving on the left side of the road; False indicates driving on the right side of the road
carriageway: True: Click on "carriageway" to select it; False: Select anything other than "carriageway"
Click |
■2: Log Output
To enable logging, you need to access the LogServer, which controls the logging functionality.
Register a callback function for retrieving log data with the obtained `logServer` object. This `OnLog` function is called every frame.
var
applicationSerive : IF8ApplicationServices;
logServer : IF8LogServer;
begin
logServer := applicationService.GetLogServer;
end; |
OnLogServerPushLogProc(method) := OnLog;
logServer.RegisterOnLogProcedure(method);
// Callback function
procedure OnLog(dTimeInSeconds: double; instance:
IF8DBObject; group: TlogExportOption);
dTimeInSeconds: Frame interval
instance: log object
group: object type
leoUsersVehicle: User-operated vehicles
leoDriverInFront: A vehicle traveling in the same lane as the user's vehicle and located ahead of them
leoSurroundingMovingObjects: Vehicles within a certain range of the user-operated vehicle
leoOtherMovingObjects: Vehicles belonging to log targets located outside the specified range |
OnTimeStep
This event occurs just before the frame is drawn. This callback function allows you to determine the current time when OnLog is called.
TimeStepProc(method) := OnTimeStep;
ApplicationService.RegisterEventHandler( _plgTimeStep, method);
procedure OnTimeStep(dTimeInSeconds: double);
var
t : TLargeInteger;
begin
if logging then
begin
QueryPerformanceCounter(t);
currentTime := (t - startTime) / frequency;
end;
end; |
Log start, log end
The interface for starting and stopping log output is as follows:
var
logServer : IF8LogServer;
begin
//Log output start
logServer.StartLogs;
//End of log output
logServer.StopLogs;
end; |
Actual log acquisition process
The following examples illustrate how to obtain logs.
procedure TFormLogDisplay.OnLog(dTimeInSeconds:
double; instance: IF8DBObject; group: TLogExportOption);
var
vehicleLogs : IF8VehicleLogs;
movingModel : IF8InstanceLogs;
logRecord : PLogRecordType;
begin
logRecord := nil;
// When the instance is of type IF8VehicleLogs (vehicle logs), access the log information using the vehicleLogs variable
if Supports(instance, IF8VehicleLogs, vehicleLogs)
then
begin
logRecord := NewLogRecord;
logRecord.time := currentTime;
// The frame interval obtained using OnTimeStep()
..
logRecord.yawAngle := vehicleLogs.yawAngle;
logRecord.pitchAngle := vehicleLogs.pitchAngle;
logRecord.rollAngle := vehicleLogs.rollAngle;
logRecord.direction := vehicleLogs.direction;
...
After log acquisition is complete, output the data to an external file or other destination
...
end;
end; |
|
Custom Waypoints, custom event actions |
|
This sample demonstrates driving simulation log output and examples of custom waypoints, as well as custom event actions within scenarios. Here, we will focus on explaining waypoints in detail.
■ 1: What is a Waypoint (operational control point)?
A waypoint refers to a location that, when passed by a vehicle during driving or operation, triggers the execution of specified commands for that vehicle or movable model.
Change the vehicle's speed or perform any desired action.
■2: Adding commands
~ TwaypointCommandAttribute structure
To add custom commands, define the required fields in a structure of type TWaypointCommandAttribute and register it with UC-win/Road using the specified procedure. This structure allows you to set permissions for accessing each field other than the command itself when selecting an added command on the "Edit Waypoint Control Points" screen.
| Command name |
Explanation |
| isDirectionEditable |
True: Accessible via "direction."
False: "Direction" is inaccessible |
| isLaneEditable |
True: Accessible from the "lane."
False: "Lane" is inaccessible |
| isInstanceEditable |
True: Accessible to the "target."
False: "Target" is inaccessible |
| isActivateEditable |
True: "Function" is accessible.
False: "Function" is inaccessible |
| isArg1Editable |
True: Accessible via "Note 1."
False: "Note 1" is inaccessible |
| isArg2Editable |
True: Accessible via "Note 2."
False: "Remarks 2" is inaccessible |
| Arg1Min |
Note 1: Minimum value |
| Arg1Max |
Note 1: Maximum value |
| Arg2Min |
Note 2: Minimum value |
| Arg2Max |
Note 2: Maximum value |
Methods for adding commands
Command additions use the following Application Service interfaces.
procedure IF8ApplicationService.AddCommandForWaypo
intEditor(Item : PWaypointCommandAttribute);
Here,
PwaypointCommandAttribute = ^TwaypointCommandAttribute; |
■ 3: Adding a Callback Function
This function registers a callback that will be executed when the added Waypoint command is selected in the editing screen for control points.
The registered event handler must be released when the plugin terminates.
// This event handler responds to commands when adding a new motion control point in the editing screen
procedure ActivateWayPointCommand(waypointCommands
Info : WaypointCommandInfoArray※12);
//Registration method
var
method : Tmethod;
begin
...
// Registering event handlers
ActivateWayPointCommandProc(method) :
= ActivateWayPointCommand;
ApplicationSerivice.RegisterEventHandler(_plgWayPo
intDoOneCommand,method);
...
end;
// Unregistering event handlers
ActivateWayPointCommandProc(method) :
= ActivateWayPointCommand;
ApplicationSerivice.UnRegisterEventHandler(_plgWay
PointDoOneCommand,method); |
WaypointCommandInfoArray
WaypointCommandInfoArray
= array of WaypointCommandInfoType;
WaypointCommandInfoType = record
// Roads to which waypoints will be added
curve: IF8DBObject;
// Command enablement instance type ID
instanceID: Integer;
// Distance from the starting point to the waypoint
distance: double;
// Command name
command: WideString;
// Pointer to the actual object where the command is enabled
recipient: ISupportWaypointCommands;
end; |
|
Main input screen editor: StationPointEditorPlugin |
|
This sample demonstrates screen editing using UC-win/Road.
■ 1: Add any desired controls to the screen
You can add custom controls to the screen by using callback functions that are triggered when the editing screen is displayed.
To add an arbitrary control, locate the base control on the target screen and then configure settings such as the display position of the control you want to add.
| Explore the controls attached to the TForm |

Based on the Left, Top, Width, and Height properties of the target control, determine the necessary size
Expand the Width and Height of the TForm |

| Attach the control to the expanded area |
|
■ 2: Exploring Controls
The exploration of control strategies can be broadly described as follows:
procedure FormRoadSideSignEditorShow( form :
TForm; theObject : IF8Sign );
var
i : integer;
ctrl : TControl;
pageControl: TPageControl;
tabSheet : TTabSheet;
begin
Assert(form.name = 'FormSignEditor');
pageControl := nil;
// Searches for controls directly placed on the TForm
for i := 0 to form.ControlCount - 1 do
begin
ctrl := form.Controls[i]; // If the element being searched is a TPageControl
Obtain the pointer and exit the search.
if (ctrl is TPageControl) and (ctrl.Name =
'PageControl') then
begin
pageControl := ctrl as TPageControl;
break;
end;
end;
tabSheet := nil;
if Assigned(pageControl) then
begin
// Explore the target page
for i := 0 to pageControl.PageCount - 1 do
begin
If it's the target page, retrieve the corresponding sheet.
end;
...//Repeat this process sequentially until you reach the control for the desired purpose.
...When you reach the control, expand the Width and Height of the TForm by the necessary amount.
...// Paste the control you want to add and set the necessary properties and event handlers. |
This sample also covers topics such as road alignment changes, cross-sections, and the placement of road infrastructure. For more details, please refer to "Programming Introduction for Civil Engineering and Architectural Engineers" (available for purchase on Amazon).
Announcement of experiential seminars
| UC-win/Road SDK introductory seminar |
| • Date and time |
March 2, 2012 (Friday), 1:30 PM to 5:00 PM |
| • Course fees |
Free of charge |
| • This venue |
FORUM8 Tokyo headquarters, GT Tower seminar room
※TV conferencing systemThe event will be held simultaneously in Tokyo, Osaka, Nagoya, Fukuoka, and Sendai |
|
|
| (Featured in the New Year issue of Up&Coming '12) |
 |
|







>> Product comprehensive catalog

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