gutil.h File Reference

gutil.h File Reference
#include "GeomExport.h"
#include <WTypes.h>
#include "point2.h"
#include "point3.h"

Functions

Point3 BaryCoords (Point3 p0, Point3 p1, Point3 p2, Point3 p)
 Calculates the barycentric coordinates of the point p in 3-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2. More...
 
Point3 BaryCoords (Point2 p0, Point2 p1, Point2 p2, Point2 p)
 Calculates the barycentric coordinates of the point p in 2-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2. More...
 
BOOL RayHitsBox (Ray &ray, Box3 &b)
 Checks if the given ray intersects a three-dimensional box. More...
 
float DistPtToLine (Point2 *p0, Point2 *p1, Point2 *q)
 Calculates the distance of a given point from a line in two dimensions. More...
 
float Dist3DPtToLine (Point3 *p0, Point3 *p1, Point3 *q)
 Calculates the distance of a given point from a line in three dimensions. More...
 
void ComputeBumpVectors (const Point3 tv[3], const Point3 v[3], Point3 bvec[3])
 
void ComputeBumpVec2D (int axis, const Point3 tv[3], const Point3 v[3], Point3 bvec[2])
 Computes the 2 Bump basis vectors from the UV, VW, or WU at a triangle. More...
 
Point3 ComputeTangent (const Point3 tv[3], const Point3 v[3])
 returns the bump basis vector for the U texture channel (called the tangent) More...
 
void ComputeTangentAndBinormal (const Point3 tv[3], const Point3 v[3], Point3 bvec[2])
 Computes the bump basis vector for the U texture channel (called the tangent), and the cross product of the surface normal with the tangent (called the binormal). More...
 
ULONG CompressNormal (Point3 p)
 Low precision compression of a vector from 12 bytes to 4 bytes. More...
 
Point3 DeCompressNormal (ULONG n)
 Decompresses a vector that was compressed using CompressNormal(). More...
 
void ArbAxis (const Point3 &zAxis, Matrix3 &matrix)
 Creates an arbitrary axis system given an up vector that conforms to the AutoCAD algorithm. More...
 

Function Documentation

Point3 BaryCoords ( Point3  p0,
Point3  p1,
Point3  p2,
Point3  p 
)

Calculates the barycentric coordinates of the point p in 3-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2.

Parameters
p0,p1,p2The three vertices of the reference triangle in 3-dimensional space.
pThe point for which the barycentric coordinates should be calculated.
Returns
Barycentric coordinates of point p.
See Also
BaryCoords(Point2, Point2, Point2, Point2)
Point3 BaryCoords ( Point2  p0,
Point2  p1,
Point2  p2,
Point2  p 
)

Calculates the barycentric coordinates of the point p in 2-dimensional space according to a reference triangle indicated by its three vertices p0, p1 and p2.

Parameters
p0,p1,p2The three vertices of the reference triangle in 2-dimensional space.
pThe point for which the barycentric coordinates should be calculated.
Returns
Barycentric coordinates of point p.
See Also
BaryCoords(Point3, Point3, Point3, Point3)
BOOL RayHitsBox ( Ray ray,
Box3 b 
)

Checks if the given ray intersects a three-dimensional box.

Parameters
rayThe ray
bThe box
Returns
true if the ray intersects the box, false otherwise.
float DistPtToLine ( Point2 p0,
Point2 p1,
Point2 q 
)

Calculates the distance of a given point from a line in two dimensions.

Parameters
p0,p1Pointers to the two 2-dimensional points with which the line is defined.
qPointer to the 2-dimensional point whose distance from the line should be calculated.
Returns
The distance of the point from the line.
float Dist3DPtToLine ( Point3 p0,
Point3 p1,
Point3 q 
)

Calculates the distance of a given point from a line in three dimensions.

Parameters
p0,p1Pointers to the two 3-dimensional points with which the line is defined.
qPointer to the 3-dimensional point whose distance from the line should be calculated.
Returns
The distance of the point from the line.
void ComputeBumpVectors ( const Point3  tv[3],
const Point3  v[3],
Point3  bvec[3] 
)
Deprecated:
Do not use this function. Use ComputeBumpVec2D() instead. This is here for compatibility only.

Computes the 3 bump basis vectors from the UVW coordinates of the triangle.

Parameters
tvTexture coordinates at 3 triangle vertices
vCoordinates of triangle vertices (usually in camera space).
[out]bvecThe 3 bump basis vectors (normalized) corresponding to the U,V,and W axes.
void ComputeBumpVec2D ( int  axis,
const Point3  tv[3],
const Point3  v[3],
Point3  bvec[2] 
)

Computes the 2 Bump basis vectors from the UV, VW, or WU at a triangle.

Parameters
axisEither AXIS_UV, AXIS_VW, or AXIS_WU .
tvTexture coordinates at 3 triangle vertices.
vCoordinates of triangle vertices (usually in camera space)
[out]bvecThe 2 normalized bump basis vectors corresponding to the specified axes.
Note
This is the recommended way to compute bump vectors instead of ComputeBumpVectors() which can give erroneous results.
Point3 ComputeTangent ( const Point3  tv[3],
const Point3  v[3] 
)

returns the bump basis vector for the U texture channel (called the tangent)

Parameters
tvTexture coordinates at 3 triangle vertices.
vCoordinates of triangle vertices (usually in camera space)
Returns
The 2 normalized bump basis vectors corresponding to the specified axes.
void ComputeTangentAndBinormal ( const Point3  tv[3],
const Point3  v[3],
Point3  bvec[2] 
)

Computes the bump basis vector for the U texture channel (called the tangent), and the cross product of the surface normal with the tangent (called the binormal).

These along with the surface normal are used as the basis vectors for normal mapping.

Parameters
tvTexture coordinates at 3 triangle vertices.
vCoordinates of triangle vertices (usually in camera space)
[out]bvecThe 2 normalized bump basis vectors corresponding to the specified axes.
ULONG CompressNormal ( Point3  p)

Low precision compression of a vector from 12 bytes to 4 bytes.

Only accurate to 1 part in 512. This is commonly used to compress normals. The vector has to be <= 1.0 in length.

Parameters
pThe decompressed vector.
Returns
The 4-byte long compressed value of p
See Also
DeCompressNormal(), BMM_CHAN_NORMAL
Point3 DeCompressNormal ( ULONG  n)

Decompresses a vector that was compressed using CompressNormal().

This function may also be used to decompress a surface normal from the G-Buffer using the BMM_CHAN_NORMAL channel. The decompressed vector has absolute error <.001 in each component.

Parameters
nA vector compressed using CompressNormal()
Returns
A normalized decompressed normal vector
See Also
CompressNormal()
void ArbAxis ( const Point3 zAxis,
Matrix3 matrix 
)

Creates an arbitrary axis system given an up vector that conforms to the AutoCAD algorithm.

Parameters
zAxisThe up vector.
[out]matrixThe new axis system.