INTRODUCTION TO NODEPATHS

A nodepath is a mathematical entity that allows you to distinguish between multiple occurrences of the same node due to instancing. This allows you to indicate a specific occurrence of a node in the scene graph. There are two things you can do with nodepaths:

figure 19

 

In figure 19 two nodepaths can be generated so that when picking you can pick the spheres.

 

 

Creating Nodepaths

 

WTnodepath_new

Use this function to create a new nodepath. A nodepath is fully specified by giving the bottom-most node in interest, the ancestor node, and the occurrence number.

SYNTAX:

WTnodepath_new(WTnode *node, WTnode *ancestor, int which);

ARGUMENTS:

node -- bottom-most node
ancestor -- The ancestor
which --
The occurrence of the node.

RETURN TYPE:

Returns a pointer to a new WTnodepath

 

Picking

WTK provides functions to allow the user to pick a geometry in the render window using a pointing device such as the mouse. The WTwindow_pickpoly function allows the user to specify a 2d screen coordinate and will pick the front-most polygon the appears beneath that point.. You can obtain the 2d screen point by using the mouse raw data structure and miscellaneous data structure.

 

Getting the Mouse Data

All sensors have miscellaneous and raw data structures that information returned by the sensor. In the case of the mouse, the miscellaneous data structure contains information about which button has been pressed on the mouse, and the raw data structure will contain the 2d screen coordinate of where the mouse is currently in the window. Use the functions WTsensor_getrawdata and WTsensor_getmiscdata to obtain this information

 

WTsensor_getmiscdata

Use this function to obtain the miscellaneous information associated with a sensor. In the case of the mouse button press information is contained in the miscellaneous data structure.

SYNTAX:

int WTsensor_getmiscdata(WTsensor *sensor);

ARGUMENTS:

sensor -- A pointer to a type WTsensor to get the misc. data from.

RETURN TYPE:

integer containing the miscellaneous data. In the case of the mouse it will be one of the predefined constants

WTMOUSE_LEFTBUTTON

WTMOUSE_LEFTDOWN

WTMOUSE_LEFTUP

WTMOUSE_RIGHTBUTTON

WTMOUSE_RIGHTDOWN

WTMOUSE_RIGHTUP

WTMOUS_MIDDLEBUTTON

WTMOUSE_MIDDLEDOWN

WTMOUSE_MIDDLEUP

EXAMPLE: -- Getting mouse clicks. This example assumes that you have a sensor object called mouse that has been initialized with the WTmouse_new function.

…..

 

if(WTsensor_getmiscdata(mouse) & WTMOUSE_LEFTBUTTON)

WTmessage("Left button pressed");

 

…..

 

Notice the we use a bitwise and operator (&) to test for the comparison.

 

 

WTsensor_getrawdata

Use this function to obtain the rawdata structure associated with a sensor. For the mouse the current 2d screen coordinate will be contained in the rawdata structure.

SYNTAX:

void *WTsensor_getrawdata(WTsensor *sensor);

ARGUMENTS:

sensor -- A pointer to the sensor in question

RETURN TYPE:

The sensor specific raw data structure. The return needs to be typecast appropriately before the contents of the structure can be accessed.

 

EXAMPLE -- Getting 2D mouse points. This example assumes that you have a sensor object called mouse that has been initialized with the WTmouse_new function.

 

….

WTmouse_rawdata *rawdata;

if(WTsensor_getmiscdata(mouse) & WTMOUSE_LEFTBUTTON)

rawdata = (WTmouse_rawdata)WTsenosr_getrawdata(mouse);

….

 

Assignment 17

project definition:

 

Picking graphical objects

WTK allows the user to get the polygon that is the front-most polygon under a 2ds screen point.

 

WTwindow_pickpoly

Use this function to get a pointer to a WTpoly that is the front-most polygon under the 2d coordinate passed in.

SYNTAX:

WTpoly *WTwindow_pickpoly(WTwindow *win, WTp2 screenpoint, WTnodepath *nodepath, WTp3 point3d);

ARGUMENTS:

window -- A pointer to a type WTwindow that the poly is in
screenpoint --
A WTp2 containing the 2d screen coordinate
nodepath --
A pointer to a nodepath that will receive the information concerning what node was picked. You can pass NULL to this argument and WTK will not figure out the nodepath for you.
Point3d --
A 3d point in world coordinates at which the selected poly was intersected.

RETURN TYPE:

A pointer to the WTpoly that was picked

 

Getting the graphical object from the nodepath

WTnodepath_getnode

Use this function to access the nodes of a nodepath.

SYNTAX:

WTnode *WTnodepath_getnode(int num);

ARGUMENTS:

num -- the number of the node in the nodepath. To get the bottommost node pass in WTnodepath_numnodes() - 1;

RETURN TYPE

A pointer to a type WTnode containing the node information.

 

EXAMPLE:

….

WTmouse_raw *rawdata;

WTnodepath *nodepath[1];

WTp3 point3d;

WTnode *pickednode;

if(WTsensor_getmiscdata(mouse) & WTMOUSE_LEFTBUTTON)

rawdata = (WTmouse_rawdata)WTsenosr_getrawdata(mouse);

WTwindow_pickpoly(WTuniverse_getcurrwindow(), rawdata, nodepath, point3d);

pickednode = WTnodepath_getnode(nodepath[0], WTnodepath_numnodes(nodepath[0]) - 1);

WTnode_boundingbox(pickednode, TRUE);

….

Assignment 18

project definition: