NODE CONSTRUCTION
WTnode_print(WTnode *node);
Node Type | Creation functions |
ROOT | WTnode *WTrootnode_new(void); |
SEPARATOR | WTnode *WTsepnode_new(WTnode *parent); |
SWITCH | WTnode *WTswitchnode_new(WTnode *parent); |
TRANSFORM | WTnode *WTxformnode_new(WTnode *parent); |
TRANSFORM SEPARATOR | WTnode *WTxformsepnode_new(WTnode *parent); |
DIRECTED LIGHTS | WTnode *WTlightnode_newdirected(WTnode *parent); |
POINT LIGHTS | WTnode *WTlightnode_newpoint(WTnode *parent); |
GEOMETRY | WTnode *WTgeometrynode_new(WTnode *parent, WTgeometry *geom); |
Loading a file into the Scene Graph
SYNTAX:
WTnode *WTnode_load(WTnode *parent, char *filename, float scale);
ARGUMENTS:
RETURN TYPE:
SYNTAX:
WTnode *WTgeometrynode_load(WTnode *parent, char *filename, float scale);
ARGUMENTS:
parent -- The parent to insert beneath. If the argument is NULL the nodes become "orphan nodes" that can later be inserted using addchild or insertchild function.
filename -- The name of the file to that contains the geometric data. Supported types include NFF, BFF, DXF, 3DS, OBJ, GEO, SLP. These file types may contain more than one geometry in which case all the geometry is loaded in a single geometry. You CANNOT use this function to load FLT, or WRL files since these files can contain non-geometric information.
Scale -- The amount to scale the geometry on all axes. If no scaling is desired you should specify 1.0f as this argument.
Extra Zooming the Window
The function WTwindow_zoomviewpoint( WTwindow *window) will zoom the window so that all the geometry contained in that window is in view.
Assignment 2
Project definition: Write an application that performs the following functionality:
Creating geometry "on the fly"
Creating Primitives
When creating primitives it is important to note that all primitives are constructed using their local coordinate system (0,0,0) being the center or midpoint of the geometry. Therefore when the geometry is inserted into the scene graph it is inserted about the World (0,0,0). Refer back to the Understanding coordinate system sections for more information on coordinate systems. WTK provides functions for creating the following primitive types:
Type of Primitive | Function | Explanation |
BLOCKS | WTgeometry_newblock | creates a rectangular box |
CYLINDERS | WTgeometry_newcylinder | creates a cylinder |
CONES | WTgeometry_newcone | creates a cone |
SPHERES | WTgeometry_newsphere | creates a sphere |
HEMISPHERES | WTgeometry_newhemisphere | creates the top half of a sphere |
RECTANGLES | WTgeometry_newrectangle | creates a single rectangle |
TRUNCATED CONES | WTgeometry_newtruncone | creates a truncated cone |
EXTRUSIONS | WTgeometry_newextrusion | extrudes a contour into a geometry |
TEXT3D | WTgeometry_newtext3d | creates a 3dfont from a file and character string |
NOTE: When a primitive is create it is assigned a default material of matte white.
WTgeometry_newblock
SYNTAX:
WTgeometry *WTgeometry_newblock(float lx, float ly, float lz, FLAG bothsides);
ARGUMENTS:
lx -- length in the x direction
ly -- length in the y direction
lz -- length in the z direction
bothsides -- indicates whether polygons backfaces are visible.
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL if unsuccessful.
WTgeometry_newcylinder
SYNTAX:
WTgeometry *WTgeometry_newcylinder(float height, float radius, int tess, FLAG bothsides, FLAG gouraud);
ARGUMENTS:
height -- height along the world y axis
radius -- radius of the cylinder
tess -- the number of lines used to define the curved surface of the cylinder (the sides)
bothsides -- indicates whether polygons backfaces are visible.
Gouraud -- outward pointing vertex normals parallel to the cylinder base are defined. (on systems that support gouraud shading)
RETURN TYPE:
A pointer to a type WTgeometry if successful NULL if unsuccessful.
WTgeometry_newcone
SYNTAX:
WTgeometry *WTgeometry_newcone(float height, float radius, int tess, FLAG bothsides);
ARGUMENTS:
height -- the height of the cone along the world Y axis
radius -- the radius of the cone
tess -- the number of lines used to represent the curved surface of the cone
bothsides -- indicates whether polygons backfaces are visible.
RETURN TYPE:
A pointer to a type WTgeometry if successful NULL if unsuccessful
WTgeometry_newsphere
SYNTAX:
WTgeometry *WTgeometry_newsphere(float radius, int nlat, int nlong, FLAG bothsides, FLAG gouraud);
ARGUMENTS:
radius -- the radius of the sphere
nlat -- the number of lines used to represent the curved surface along the latitude of the sphere
nlong -- the number of lines used to represent the curved surface along the longitude of the sphere
bothsides -- indicates whether polygons backfaces are visible.
Gouraud -- define outward pointing vertex normals
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL in unsuccessful
WTgeometry_newhemisphere
SYNTAX:
WTgeometry *WTgeometry_newhemisphere(float radius, int nlat, int nlong, FLAG bothsides, FLAG gouraud);
ARGUMENTS:
radius -- the radius of the sphere
nlat -- the number of lines used to represent the curved surface along the latitude of the sphere
nlong -- the number of lines used to represent the curved surface along the longitude of the sphere
bothsides -- indicates whether polygons backfaces are visible.
Gouraud -- define outward pointing vertex normals
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL in unsuccessful
WTgeometry_newrectangle
SYNTAX:
WTgeometry *WTgeometry_newrectangle(float height, float width, FLAG bothsides);
ARGUMENTS:
height -- length along the world y axis
width -- length along the world x axis
bothsides -- indicates whether polygons backfaces are visible.
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL if unsuccessful
WTgeometry_newtruncone
SYNTAX:
WTgeometry *WTgeometry_newtruncone(float height, float toprad, float baserad, int tess, FLAG bothsides, FLAG gouraud);
ARGUMENTS:
height -- height of the cone along the world Y axis
toprad -- the radius of the top of the cone
baserad -- the radius of the base of the cone
tess -- the number of lines used to represent the curved surface of the cone
bothsides -- indicates whether polygons backfaces are visible.
gouraud -- outward pointing normals for the side polygons are defined
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL if unsuccessful
WTgeometry_newextrusion
SYNTAX:
WTgeometry *WTgeometry_newextrusion(WTp2 points[], int numpts, float height, FLAG bothsides, FLAG gouraud);
ARGUMENTS:
points[] -- an array of points that is assumed to be NON-SELF INTERSECTING contour in the x-z plane of the world coordinate system. The number of points must be between 3 and 256 and are 2 dimensional (WTp2)
numpts -- the number of points in the points array
height -- the height to extrude along the world y axis
bothsides -- indicates whether polygons backfaces are visible.
gouraud -- outward pointing normals for the side polygons are defined
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL if unsuccessful.
WTgeometry_new3dtext
SYNTAX:
WTgeometry *WTgeometry_new3dtext(WTfont3d *font, char *string);
ARGUMENTS:
font -- A pointer to a type WTfont3d (obtained for the WTfont3d_load function)
string -- the string to print such as "Hello"
RETURN TYPE:
A pointer to a type WTgeometry if successful, NULL is unsuccessful
Associating the geometry with a node
Once the geometry is created it is not visible on the screen because it has not been associated with a node in the scene graph. There are two functions that will do this WTgeometrynode_new and WTmovgoemetrynode_new. The second function deals with movables so that well learn about later. For now we will use WTgeometrynode_new.
WTgeometrynode_new
SYNTAX:
WTnode *WTgeometrynode_new(WTnode *parent, WTgeometry *geom);
ARGUMENTS:
parent -- the new node is inserted as the last child of the parent specified. If the parent argument is NULL then the node is an orphan and can be inserted or added later.
geom -- A pointer to a type WTgeometry obtained with one of the primitive construction functions.
RETURN TYPE:
A pointer to a type WTnode.
Assignment 3
Project definition: Write an application that performs the following functionality:
Node instances
figure 9
WTnode_addchild
Add a node as the last child of the parent specified
SYNTAX:
FLAG *WTnode_addchild(WTnode *parent, WTnode *child);
ARGUMENTS:
parent -- The parent node for the node
child -- The child node to add
RETURN TYPE:
FLAG tells if the function was successful.
WTnode_insertchild
Adds a node as the numth child of the parent node specified
SYNTAX:
FLAG WTnode_insertchild(WTnode *parent, WTnode *child, int childnum);
ARGUMENTS:
parent -- The parent node to insert beneath
child -- The node to insert
childnum -- the number child to insert
RETURN TYPE:
FLAG indicating success of failure.
Assignment 4
Project definition:
Creating transform and separator nodes
In order to move objects in the simulation you must first create a transform node that will apply a transformation to the graphical object, but these functions only work on transform or movable nodes. First a transform node must be created.
WTxformnode_new
SYNTAX:
WTnode *WTxformnode_new(WTnode *parent);
ARGUMENTS:
parent -- The node will be inserted as the last child of the parent specified. If NULL is specific as the parent argument then the node is created as an "orphan" and can be added or inserted later.
RETURN TYPE:
A pointer to a type WTnode containing the new transform node.
Setting the contents of the transform node
Once the transform node is created its contents must be set. Transformations in WTK are stored in 4x4 matrices the specify the rotation and translation the will be applied to the state of the scene graph. There are functions that allow the user to set the absolute contents of transform nodes. The following chart lists these function and gives a brief explanation of their use
FUNCTION | EXPLANATION |
WTnode_settranslation | Sets only the absolute translation value of the transformation matrix. |
WTnode_setrotation | Sets only the absolute rotation values of the transformation matrix. The rotation is specified in a 3x3 matrix |
WTnode_setorientation | Sets the orientation (rotation) of the transformation matrix. The orientation is specified as a quaternion. |
WTnode_settransform | Sets the translation and rotation of the transformation matrix. Values are specified in a 4x4 matrix. |
WTnode_settranslation
Replaces the translation component or the transformation matrix of the specified node.
SYNTAX:
FLAG WTnode_settranslation(WTnode *node, WTp3 txvector);
ARGUMENTS:
node -- The node to operate on. This can only be a transform or movable node.
txvector -- the vector specifying the magnitude of the translation.
RETURN TYPE:
FLAG indicating the success of the function.
WTnode_setrotation
Replaces the rotational component of the specified nodes transformation matrix.
SYNTAX:
FLAG WTnode_setrotation(WTnode *node, WTm3 rotation);
ARGUMENTS:
node -- The node to operate upon.
rotation -- a 3x3 matrix specifying the rotation to apply
RETURN TYPE:
FLAG indication the success of the function
WTnode_setorientation
Replaces the rotational component of the specified nodes transformation matrix
SYNTAX:
FLAG WTnode_setorientation(WTnode *node, WTq orientation);\
ARGUMENTS:
node -- The node to operate upon
orientation -- a WTq specifying the rotation as a quaternion
RETURN TYPE:
FLAG indicating the success of the function.
WTnode_settransform
Replaces the entire transformation matrix of the specified node.
SYNTAX:
FLAG WTnode_settransform(WTnode *node, WTm4 matrix);
ARGUMENTS:
node -- the node to operate upon.
matrix -- The 4x4 matrix specifying the transform (translation and rotation) information.
RETURN TYPE:
FLAG indicating the success of the function
Assignment 5
project definition:
Using a separator
In the previous assignment (assignment 5) both spheres were translated by the transform node. This is not the desired results. Only the first sphere should be translated. Using a separator node will allow the user to move graphical objects individually and not have the state set by the transform node affect other objects in the scene graph. As you recall there are two types of separator nodes separators and transform separators.
WTsepnode_new
Creates a new separator node and adds it as the last child of the parent specified. If NULL is specified as the parent argument then the node is created as an orphan that can be added or inserted later.
SYNTAX:
WTnode *WTsepnode_new(WTnode *parent)
ARGUMENTS:
parent -- The parent node
RETURN TYPE:
A pointer to a type WTnode that hold the separator node.
WTxformsepnode_new
Creates a new transform separator and adds it as the last child of the parent specified. If NULL is specified as the parent argument then the node is created as an orphan that can added or inserted later.
SYNTAX:
WTnode *WTxformsepnode_new(WTnode *parent);
ARGUMENTS:
parent -- The parent node
RETURN TYPE:
A pointer to a type WTnode holding the transform separator.
Assignment 6
project definition: