WTK Geometry Properties

 

All geometric entities (of type WTgeometry) have properties that can be Set and retrieved. This properties include the name, material table, material table index, and rendering style. Other properties such as midpoint, radius, and extents can only be retrieved. Geometries can also be prebuilt for optimization. The geometry can also be retrieved from its node using the function WTnode_getgeometry.

WTnode_getgeometry

This function returns a pointer to the geometry contained with in a node the node passed in can be a regular node or movable node. This function is useful if you need to retrieve the geometry form a node and haven’t kept a pointer to the original geometry around. It is also the function used to retrieve the WTgeometry form a node the was created by reading a file such as nff, bff, or 3ds. Once the geometry is retrieved it can be edited if it hasn’t been prebuilt and can be unoptimized (its prebuild deleted) so that it may be edited.

SYNTAX:

WTgeometry *WTnode_getgeometry(WTnode *node);

ARGUMENTS:

node -- The node to retrieve the geometry form.

RETRUN TYPE:

The function returns NULL if an invalid node was passed in otherwise it returns a pointer to the WTgeometry contained in that node.

 

Naming Geometry

Like nodes geometries can also be given names. A name is a string assigned to the geometry and can be useful when identifying the geometry when it is retrieve (as an error check to make sure you retrieved the proper geometry). There are two function that work with geometry names getname and setname.

WTgeometry_setname

This functions set the name string property of a WTgeometry. The default name for a custom geometry is "untitled", for primitives it is the primitive name i.e. block, and for geometries read form a file are assigned the corresponding name that it was given in the file.

SYNTAX:

void WTgeometry_setname(WTgeometry *geom, char *name);

ARGUMENTS:

geom -- The geometry whose name field is being set.
Name
-- a string containing the desired name. It is recommended that if you name geometries that each is given a unique name.

RETURN TYPE:

void

 

WTgeometry_getname

Use this function to retrieve the name of a geometry.

SYNTAX:

char *WTgeometry_getname(WTgeometry *geom);

ARGUMENTS:

geom -- The WTgeometry in question.

RETURN TYPE:

A pointer to a character string containing the name

 

Geometric Properties

Properties, like nodes, have geometric properties such as the midpoint, extents, and radius. These properties CAN NOT be set during runtime.

WTgeometry_getmidpoint

This function returns the midpoint of the geometries bounding box in local (object) coordinates.

SYNTAX:

void WTgeometry_getmidpoint(WTgeometry *geom, WTp3 midpoint);

ARGUMENTS:

geom -- The geometry in question
midpoint --
A WTp3 that will hold the result of the function.

RETURN TYPE:

void

 

WTgeometry_getextents

This function returns the geometry’s axis aligned bounding box. The bounding box contains the longest X, Y and Z extents of the geometry

SYNTAX:

void WTgeometry_getextents(WTgeometry *geom, WTp3 extents);

ARGUMENTS:

geom -- The WTgeometry in question.
extents --
a WTp3 that will hold the bounding box extents.

RETURN TYPE:

void

WTgeometry_getradius

Like a node the radius of a WTgeometry is the magnitude of a vector from the objects midpoint to one of the corners of its bounding box.

SYNTAX:

float WTgeometry_getradius(WTgeometry *geom);

ARGUMENTS:

geom -- The geometry in question

RETURN TYPE:

a float containing the radius.

 

 

Geometry Materials

Every geometry gets assigned a material table upon creation, uses a default material table, or uses a material specific to that geometry.

WTK allows the user to tell the geometry what material table and index into it to use. It also provides a function that allows the user to set the color (universally) of a geometry using RGB color values. The material table access function will be discussed when we talk about material tables they are listed here for you convenience.

void WTgeometry_setmtable(WTgeometry *geom, WTmtable *mtable);

WTmtable *WTgeometry_getmtable(WTgeometry *geom);

FLAG WTgeometry_setmatid(WTgeometry *geom, in id);

 

The function well look at here is WTgeometry_setrgb

WTgeometry_setrgb

Set the 24-bit color value of a geometry where red, green , and blue are color components in the range of 0 - 255. Although WTK allows the user to specify an RGB color for a geometry, internally WTK makes use of a material table by finding the color in the material table or creating a new entry that matches the specified color.

SYNTAX:

void WTgeometry_setrgb(WTgeometry *geom, unsigned char red, unsigned char green, unsigned char blue);

ARGUMENTS:

geom -- The WTgeometry in question.
red --
The red component
green --
The green component
blue --
The blue component

RETURN TYPE:

void

 

Setting the geometries rendering style

WTK allows the user to set and retrieve a geometries geometry rendering style, This allows the user to mix and match rendering styles in the simulation. Some geometries can be rendered in wireframe while others can be fully perspective textured or gouraud shaded. By default all geometries are rendered according to the style set with WTuniverse_setrendering.

 

WTgeometry_setrenderingstyle

Sets the rendering style for a particular geometry.

SYNTAX:

FLAG WTgeometry_setrenderingstyle(WTgeometry *geom, int flags, int style);

ARGUMENTS:

geom -- The WTgeometry in question
flags --
a bitmask of the rendering flags to change valid arguments are

FLAG MEANING

WTRENDER_GOURAUD to enable gouraud shading
WTRENDER_TEXTURED to enable texturing
WTRENDER_PERSPECTIVE to enable perspective texturing
WTRENDER_ANTIALIAS to enable anti-aliasing
WTRENDER_BEST to enable all of the above
WTRENDER_WIREFRAME to enable wireframe
WTRENDER_NOSHADE to enable noshading

style -- set TRUE to enable the flags, FALSE to disable the flags

RETURN TYPE:

FLAG indicating the success of failure of the function.

 

Geometry Optimization

The prebuild function optimizes a specific geometry for maximum rendering speed. This optimization takes place BEFORE rendering to convert the polys in a geometry into triangle strips which are rendered more efficiently by OpenGL. In order to make use to the function, it is important to understand what the function can do to efficiently. Here’s what must be true of two adjacent polys in order to take advantage of this option

 

The polys MUST share an edge

If the polys are textured, they must have the same texture, and the uv coords at their common vertices MUST BE the same.

If texturing is off and vertices have material properties, material properties at their common vertices must be the same. If the vertices do not have material properties then the polygons material ID’s must match.

If lighting is on, Polys must have the same vertex normals or polygon normals.

 

There is a limit to the number of polys that an individual geometry can have for optimization to be effective. This depends on your hardware platform, but in general, geometries composed of more the 32K vertices will make excessive demands on memory. This means that you are better off organizing you geometries into logical, localized units (like pieces of furniture in a room) rather than creating massive geometries that are difficult to optimize.

Once You have optimized a geometry it CAN NOT be edited, stretched, or scaled. Colors cannot be changed nor can textures. It can, however, be translated and rotated as desired.

If editing of the geometry is required it must be unoptimized using WTgeometry_deleteprebuild, edited, it can then be re optimized using the prebuild function.

WTgeometry_prebuild

Optimizes a geometry as discussed above

SYNTAX:

FLAG WTgeometry_prebuild(WTgeometry *geom);

ARGUMENTS:

geom -- The WTgeometry in question

RETURN TYPE:

FLAG indicating the success or failure of the function

 

WTgeometry_deleteprebuild

Deletes the optimized data structure created with the prebuild function

SYNTAX:

FLAG WTgeometry_deleteprebuild(WTgeometry *geom);

ARGUMENTS:

geom -- The WTgeometry in question

RETURN TYPE:

FLAG indicating the success or failure of the function.

 

Assignment 9

project definition:

Hint: Use WTp3_print to print the values returned in the WTp3’s
Use WTmessage to print other values
WTp3_print(WTp3 p3, char *message);
WTmessage works just like ANSI C printf function