[SESI logo]

Prisms Development Toolkit Documentation

Side Effects Software Inc. 1997

Programmers Reference Section

Macros

List Traversal Macros

For each of these, Npt, Npoly, Nvtx and Npd must be previously declared as type int, and ppt, ppoly, pvtx and pdp must be previously declared as the appropriates pointer.

FOR_ALL_POINTS(head, ppt, Npt) 
FOR_ALL_POLYS(head, ppoly, Npoly)
FOR_ALL_VERTICES(head, pvtx, Nvtx)
FOR_ALL_PDPS(head, pdp, Npd)
ppt starts at head, follows the ->next pointer until it comes back to head. Npt is initialized to 0, incremented for each visited point. Similarly for polys, vertices and pdps. For example:
	int		count;
	PolyPoint	*ppt;

	FOR_ALL_POINTS(inputPdp->ppt, ppt, count)
	{
		ppt->pos.x += 3.5;
	}

would add 3.5 to the x value of all the points in the PolyDetail called inputPdp.

There are also macros for traversing two lists simultaneously:

FOR_PAIR_POINTS(head, head2, ppt, ppt2, Npt)
FOR_PAIR_POLYS(head, head2, pp, pp2, Npoly)
FOR_PAIR_VERTICES(head, head2, pvtx, pvtx2, Nvtx)
Work as before, but on two lists at once. The loop will end at the end of the first list, if they are not the same length. This is used for doing combinations of geometry, for example, blending shapes.

Vector Macros

Inputs are of type Vector, eg: Vector a, b, c;

DOT(a, b)			Vector dot product
    a.x*b.x + a.y*b.y + a.z*b.z
NORM(a)				Normalize vector
    a.x /= length
    a.y /= length
    a.z /= length
CROSS(a, b, c)			Vector cross product (c = a x b)
    c.x = a.y*b.z - a.z*b.y
    c.y = a.z*b.x - a.x*b.z
    c.z = a.x*b.y - a.y*b.x
VADD(a, b, c)			Vector addition (c = a + b)
    c.x = a.x + b.x
    c.y = a.y + b.y
    c.z = a.z + b.z
VSUB(a, b, c)			Vector subtraction (c = a - b)
    c.x = a.x - b.x
    c.y = a.y - b.y
    c.z = a.z - b.z
For example:
	int		count;
	PolyPoint	*ppt;
	Vector		inpos, center, dist;
	float		d;

	center.x = 0;
	center.y = 0;
	center.z = 0;
	FOR_ALL_POINTS(inputPdp->ppt, ppt, count)
	{
		inpos.x = ppt->pos.x;
		inpos.y = ppt->pos.y;
		inpos.z = ppt->pos.z;
		VSUB(inpos, center, dist);
		d = sqrt(dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
	}

computes the distance between a point and a pre-defined center point.

Other Macros

DEGTORAD(deg)   		convert degrees to radians
RADTODEG(rad)   		convert radians to degrees
SQR(x)				square the input
MAX(i,j)        		max of i and j
MIN(i,j)        		min of i and j
ABS(x)          		absolute value of x
BOUND(lo,x,hi)  		the middle value of 3
APX_EQ(x,y,eps)         	True if absolute value of distance 
				between x and y is within eps
REL_EQ(x,y,eps)			True if absolute value of distance
				between x and y is within eps
SWAP(type,x,y)			swap two values of given type
				(eg, int, float, etc)

Constants


PI		3.1415926535897932
TRUE		1
FALSE		0

Tookit Overview
Expression Functions | User Functions | Custom SOPs
Prisms Internal Format | Programmer's Reference
Compiling SOPs | Using sopbuild | SOP Routine Reference
Dynamic SOPs | Prisms Types | Macros
Math Routines | Data Routines | Polygon Routines | Winged-edge Routines

Copyright © 1997 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7