Introduction to Object/Property/Event Architecture

Capabilities

1.  Treat most WTK object types as generic (or base) objects, which can be stroed, manipulated, and retrived in a uniform manner using certain WTbase functions.

2.  Create you own properties for objects. in which to easily store user-defined data.  This provides a convenient alternative to the setdata and getdata functions for each object type.

3.  Trigger reactions to property changes for both user-defined properties and pre-defined properties.  A property change is known as an event, and the optional reaction that is triggered in response to an event is controlled by the property's event handles(s)

4.  Share properties, allowing you to create multi-user simulations to be used with World2World.

 

Advantages of OPE Architecture

1.  Easier to create user-defined data with objects

2.  The event-basse architecture corresponds more closely with other modern event-based programming paradigms

3. Easy integration with World2World.

 

Object Types Supported by OPE Architecture

WTnode
WTviewpoint
WTwindow
WTsensor
WTpath
WTbase

Properties

Objects supported by the OPE architecture are distinguished from one another by their properties. 

Properties describe characteristics of an object.

Additional user-defined properties can be added to an object of any of the supported types.

Events occur when a property is set (even if it is set to the same value it had previously)

Properties are specified by their porperty name.  Each property MUST have a unique name

Each property is of a specified data type.

The following table lists the predefined WTK data types and their actual C data type.

WTdatatype Actual Data Type
WTINT int
WTUINT unsigned int
WTFLOAT float
WTDOUBLE double
WTP2 float[2]
WTP3 float[3]
WTQ float[4]
WTSTRING char *
WTPOINTER void *


The following tables lists the perdefined properties of the WTK OPE supported data types (WTnode, WTviewpoint, WTwindow, WTsensor, WTpath, and WTbase).

WTanchornode Properties Data Type Description
WTANCHOR_LOCATION WTSTRING  

 

WTfognode Properties Data Type Description
WTFOG_COLOR WTQ (R,G,B,A)
WTFOG_LINEARSTART WTFLOAT  
WTFOG_MODE WTINT  
WTFOG_RANGE WTFLOAT  

 

WTinlinenode Properties Data Type Description
WTINLINE_LOCATION WTSTRING  

 

WTlightnode Properties Data Type Description
WTLIGHT_AMBIENT WTP3 Ambient Color (R,G,B)
WTLIGHT_ANGLE WTFLOAT  
WTLIGHT_ATTENUATION WTP3  
WTLIGHT_DIFFUSE WTP3 Diffuse Color (R,G,B)
WTLIGHT_DIRECTION WTP3 Direction Vector (normalized)
WTLIGHT_EXPONENT WTFLOAT  
WTLIGHT_INTENSITY WTFLOAT Intensity of the light
WTLIGHT_POSITION WTP3 Position of the light
WTLIGHT_SPECULAR WTP3 Specular color of the light

 

WTlodnode Properties Data Type Description
WTLOD_CENTER WTP3  
WTLOD_RANGE WTSTRING ("range;range;range")  

 

WTmovnode Properties Data Type Description
WTMOVNODE_ATTACHMENTS WTSTRING ("name,name,name") list of the name of the attached nodes

 

WTnode Properties Data Type Description
WTNODE_BOUNDINGBOX WTINT Bounding box ON or OFF
WTNODE_CHILDREN WTSTRING (name;name;name) List of the names of the child nodes
WTNODE_ENABLED WTINT Is the node ON or OFF
WTNODE_ROTATION WTQ The rotation of the node in parent frame
WTNODE_TRANSLATION WTP3 The translation of the node in parent frame

 

WTsepnode Properties Data Type Description
WTSEP_CULLMODE WTINT Culling ON or OFF

 

WTswitchnode Properties Data Type Description
WTSWITCH_WHICHCHILD WTINT The current active child of the switch

 

WTviewpoint Properties Data Type Description
WTVIEWPOINT_ASPECT WTFLOAT  
WTVIEWPOINT_CONVDISTANCE WTFLOAT Convergence Distance
WTVIEWPOINT_CONVERGENCE WTINT  
WTVIEWPOINT_ORIENTATION WTQ The orientation of the viewpoint
WTVIEWPOINT_PARALLAX WTFLOAT  
WTVIEWPOINT_POSITION WTP3 The position of the viewpoint

 

WTwindow Properties Data Type Description
WTWINDOW_BGRGB WTP3 Window background color
WTWINDOW_BOTTOMRIGHT WTP2 Bottom right coroner of the window
WTWINDOW_ENABLED WTNT Window ON or OFF
WTWINDOW_EYE WTINT The eye (left or right) the window is being rendered from
WTWINDOW_HITHER WTFLOAT Position of hither clipping plane
WTWINDOW_KEY WTINT ASCII value of a key press when window has focus
WTWINDOW_LBUTTON WTINT Left mouse button clicked in window
WTWINDOW_LBUTTONDBLCLICK WTINT Left mouse button double clicked in the window
WTWINDOW_RBUTTON WTINT Right mouse button clicked in window
WTWINDOW_RBUTTONDBLCLICK WTINT Right mouse button double clicked in window
WTWINDOW_MBUTTON WTINT Middle mouse button clicked in window
WTWINDOW_MBUTTONDBLCLICK WTINT Middle mouse button dowble clicked in the window
WTWINDOW_POSITION WTPT Position of the window
WTWINDOW_PROJECTION WTINT Projection type
WTWINDOW_ROOTNODE WTSTRING Name of the root node for this window
WTWINDOW_SIZE WTP2  
WTWINDOW_TOPLEFT WTP2 Position of the top left corner of the window
WTWINDOW_VIEWANGLE WTFLOAT The view angle of the window
WTWINDOW_VIEWPOINT WTSTRING The viewpoint in the window
WTWINDOW_VIEWPOINT2 WTSTRING  
WTWINDOW_YON WTFLOAT The position of the Yon (far) clipping plane

 

WTsensor Properties Data Type Description
WTSENSOR_ANGULARRATE WTFLOAT The angular rate of the sensor
WTSENSOR_LASTROTATION WTQ The last (previous) rotation record from the sensor
WTSENSOR_LASTTRANSLATION WTP3 The last (previous) translation record from the sensor
WTSENSOR_MISCDATA WTINT The misc data structure from the sensor
WTSENSOR_RAWDATA WTPOINTER Pointer to the raw data structure for the sensor
WTSENSOR_ROTATION WTQ The current rotation record from the sensor
WTSENSOR_ROTATIONALOFFSET WTQ  
WTSENSOR_SENSITIVITY WTFLOAT The sensitivity of the sensor (translational)
WTSENSOR_TRANSLATION WTP3 The current translation record from the sensor
WTSENSOR_UPDATEFN WTPOINTER Pointer to the Update function of the sensor

 

WTpath Properties Data Type Description
WTPATH_CONSTRAINTS WTINT  
WTPATH_DIRECTION WTINT Play direction of the path
WTPATH_MARKER WTPOINTER Pointer to the geometry used as a marker
WTPATH_MODE WTINT Play mode for the path
WTPATH_PLAYING WTINT Play state of the path
WTPATH_PLAYSPEED WTINT Play speed of the path
WTPATH_ROTATION WTQ  
WTPATH_RECORDING WTINT Recording state of the path
WTPATH_RECORDLINK WTPOINTER Pointer the the motionlink to use for recording
WTPATH_SAMPLES WTINT  
WTPATH_TRANSLATION WTP3  
WTPATH_VISIBILITY WTNT  

 

 

Getting the value of a property

WTK provides 3 ways to obtain the value of a property.  One generic fuction, type-specific fucnctions, and "getasstring" function.

Generic Function

SYNTAX:
FLAG WTproperty_get(void *object, const char *propname, void *value);

ARGUMENTS:
object -- A pointer to the object
propname  --  a string containing the property name
(void *) value -- a pointer to the varaible that will receive the value of the property.   Type casting is necessary.

RETURN TYPE:
FLAG --  returns TRUE  if the function was successful.

Example:

        WTviewpoint *vp;
        WTp3 pos;
        vp = WTuniverse_getviewpoints();


        /* get the POSITION property of the viewpoint */
        WTproperty_get(vp, WTVIEWPOINT_POSITION, (void *)pos);

/* print the position */
        WTp3_print(pos , "Position = ");

NOTE:
The char* reusult of retrieving a WTSTRING property value is a pointer to the actual string stored in WTK.  DO NOT modify this directly with calls to WTfree, WTrealloc, strcat, strcpy, etc. If you need to modify the string value, make a local copy of the string before modifying it.

 

Type Specific Functions

Each WTK data type has its own type specific utility function for getting the property value.  The able below describes each function.

Function Name WTK data type Syntax Description
WTproperty_geti WTINT int
WTproperty_geti(
void *object,
const char*propname);
Returns a property with a WTINT data type.
WTproperty_getui WTUINT unsigned int WTpropert_getui(
void *object,
const char*propname);
Retuns a propery with a WTUINT data type.
WTproperty_getf WTFLOAT float
WTpropert_getf(
void *object,
const char*propname);
Returns a property with a WTFLOAT data type.
WTproperty_getd WTDOUBLE double
WTpropert_getd(
void *object,
const char*propname);
Returns a property with a WTDOUBLE data type.
WTproperty_getp2 WTP2 FLAG
WTpropert_getp2(
void *object,
const char*propname
WTp2 value);
Places the value of the property in its value argument.
WTproperty_getp3 WTP3 FLAG
WTpropert_getp3(
void *object,
const char*propname
WTp3 value);
Places the value of the property in its value argument.
WTproperty_getq WTQ FLAG
WTpropert_getq(
void *object,
const char*propname
WTQ value);
Places the value of the property in its value argument.

WTproperty_gets


WTSTRING char *
WTpropert_getsi(
void *object,
const char*propname);
Returns a property with a WTDOUBLE data type.
NOTE:
The char* reusult of retrieving a WTSTRING property value
is a pointer to the actual string stored in WTK.  DO NOT modify this directly with calls to WTfree, WTrealloc, strcat, strcpy, etc. If you need to modify the string value, make a local copy of the string before modifying it.

WTproperty_getp WTPOINTER void *
WTpropert_getp(
void *object);
Returns the property with a WTPOINTER data type.

 

WTproperty_getasstring function

Returns the specified objects specified property value as a string.  (Strings returned are only good until another call th WTproperty_getasstring is executed.

SYNTAX:
char * WTproperty_getasstring(void *object, const char *propname);

ARGUMENTS:
object  --  a pointer to the object in question
propname -- string containing the property name

RETURN TYPE
char *  -- The property value as a string.

 

 

Assignment 8

project definition:

 

 

Setting an objects property value


WTK provides 3 ways to set the value of a property.  One generic fuction, type-specific fucnctions, and the WTproperty_setat function.

Generic Function: (WTproperty_set)

WTproperty_set function sets the value of the spercified property for the specified object.

SYNTAX:
FLAG WTproperty_set(void *object, const char *propname, void *value);

ARGUMENTS:
object -- a pointer to the object whose property you want to set
propname -- a string containing the name of the property
value -- the new value NOTE: typcasting of the newvalue is required.

RETURN TYPE:
FLAG is TRUE if the function was successful.

Example:  /* translating the viewpoint in world coordinates in the positive X direction*/

        WTp3 vpPos;
        WTviewpoint *vp;
        vp = WTuniverse_getviewpoints();
        WTproperty_getp3(vp, WTVIEWPOINT_POSITION, vpPos);
        vpPos[X] = vpPos[X] + 1.0f;
        WTproperty_set(vp, WTVIEWPOINT_POSITION,(void *)vpPos);

 

Type Specific Functions

Each WTK data type has its own type specific utility function for setting the property value.  The able below describes each function.

 

 

Function Name

WTK data type Syntax Description
WTproperty_seti WTINT WTproperty_seti(
void *object,
const char *propname,
int value);
Sets specified properties WTINT value
WTproperty_setui WTUINT WTproperty_setui(
void *object,
const char *propname,
unsigned int value);
Sets specified properties WTUINT value
WTproperty_setf WTFLOAT WTproperty_setf(
void *object,
const char *propname,
unsigned int value);
Sets specified properties WTFLOAT value
WTproperty_setd WTDOUBLE WTproperty_setd(
void *object,
const char *propname,
double value);
Sets specified properties WTDOUBLE value
WTproperty_setp2 WTP2 WTproperty_setp2(
void *object,
const char *propname,
WTp2 value);
Sets specified properties WTP2 value
WTproperty_setp3 WTP3 WTproperty_setp3(
void *object,
const char *propname,
WTp3 value);
Sets specified properties WTP3 value
WTproperty_setq WTQ WTproperty_setq(
void *object,
const char *propname,
WTq value);
Sets specified properties WTQ value

WTproperty_sets

WTSTRING WTproperty_setd(
void *object,
const char *propname,
condy vhst *value);
Sets specified properties WTSTRING value
WTproperty_setp WTPOINTER WTproperty_setp(
void *object,
const char *propname,
void *value);
Sets specified properties WTPOINTER value

 

 

WTproperty_setat function

This function sets the specified object's property value at a specified time.   Time values are measured in seconds from January 1st, 1970 and includes fractions of a second.

SYNTAX:
FLAG WTproperty_setat(void *object, const char* propname, void *value, double time);

ARGUMENTS:
object --  pointer to the object whose property to set.
propname  --  a string value containing the name of the property to set.
value  --  pointer to the new value
time  -- time to set the property.

RETURN TYPE:
FLAG is TRUE is the function was successful.

 

 

Assignment 9

project definition:

 

 

 

Adding user-defined properties to an object

Use the WTproperty_new function to add user-defined properties to an object.

SYNTAX:
FLAG WTproperty_new( void *object, const char* propname, WTdatatype *dtype);

ARGUMENTS:
object -- the object to add the user-defined property value to.
propname --  A string containing the name of the property
dtype  --  WTK Data Type of the property.

RETURN TYPE:
FLAG is TRUE if the function was successful.

 

 

Assignment 10

project definition:

 

Other Property functions

Function Description
FLAG WTproperty_delete(void *object, const char* propname); Deletes the specified property from the object
FLAG WTproperty_exists(void *object, const char* propname); Returns true if the specifed proptery for the specified object exists
void WTproperty_setdata(void *object, const char*propname, void *data); Sets the user-defined data field for a property.
void *WTproperty_getddata(void *object, const char *propname); Returns the user-defined data field for a property.
WTdatattype WTproperty_getdatatype(void *object,
const char *propname);
Returns the datatype of the specified objects propname
unisgnhed int WTproperty_getsizeofdata(void *object,
const char *propname);
Returns the number of bytes used by the specified objects property name value.
char * WTvalue_tostring(WTdatatype dtype, void *value); Returns the value of the dtype argument as a string.  Strings returned  are only good until another call to WTvalue_tostring is executed.


Events

Events occur what the value of a property is set, even if it is set to its current value.

The value of the propety change generates an event that can be acted upon by creating an event handler for that objects property.

Events are fired right before the universe's action function is called

If the universe simulation loop is not running event;s can be executed by calling the WTuniverse_processevents function

One property can have numberous events

Event handlers are give a pointer to the object, the property taht generated the event, the new value of the property, the source from which teh property cange event was generated, and the time the event was generated. 

 

Creating an event function:

There is a two step process for creating event handlers and associating them with a property.

1.  Create the event handler.
2.  Call WTproperty_add handler function to associate the event handler function with the object and property.

The following example executes the MyEventHandler function when the viewpoint changes position.

Example:

void MyEventHandler(void *object, const char *propname, void *value, double time, WTeventsource src);

void MyEventHandler(void *object, const char *propname, void *value, double time, WTeventsource src)
{
/*code  to execute when the event occurs */
}

WTproperty_addhandler(WTuniverse_getviewpoints(), WTVIEWPOINT_POSITION, MyEventHandler);

 

Event Handler Arguments

object -- pointer to the object whos property generated the event
propname -- string value containing he name of the property
value -- pointer to the new value coming into the function
time  -- time the event was generated
src  --  the source of the event can be on of the following constant values
WTLOCAL -- events generated from the local computer
WTNETWORK  -- event generated another computer in a W2W simulation
WTLOCAL_TIMER  and WTNETWORKTIMER --  event generated from a value set by WTproperty_setat function

WTproperty_addhandler:

SYNTAX:
FLAG WTproperty_addhandler(void *object, const char*propname, WTeventhandler eh);

ARGUMENTS:
object -- the object to add the event handler to
propname --  The property to generate the event
WTeventhandler  --  The name of the event handler function.

RETURN TYPE:
FLAG is TRUE if the function was successful.


Assignment 11

project definition:

 

Creating new user-defined Objects (WTbase Objects)

WTbase object type allows you to create generic, empty objects, distinguished only by the properties that you add to them.  Just like the other object types supported by the WTK OPE architecture, you can add properties, event handlers, and share those properties across a network.

WTK object types that are not supported by the OPE architecture cannot contain properties and thus, do not genetrat events or allow the sharing of data over a network

To extend the OPE paradigm, create WTbase objects and user-defined properties to represent the desired attributes of the unsupported objects.