Class Point3
See Also: Class IPoint3, Class DPoint3, Class Matrix3.
class Point3
Description:
This class describes a 3D point using float x, y and z coordinates. Methods are provided to add and subtract points, multiply and divide by scalars, and element by element multiply and divide two points.
This class is also frequently used to simply store three floating point values that may not represent a point. For example, a color value where x=red, y=green, and z=blue. For color, the range of values is 0.0 to 1.0, where 0 is 0 and 1.0 is 255. All methods are implemented by the system.
Note: In 3ds max, all vectors are assumed to be row vectors. Under this assumption, multiplication of a vector with a matrix can be written either way (Matrix*Vector or Vector*Matrix), for ease of use, and the result is the same -- the (row) vector transformed by the matrix.
Data Members:
public:
float x, y, z;
The x, y and z components of the point.
static const Point3 Origin;
This data member is available in release 3.0 and later only.
This is equivalent to Point3(0.0f, 0.0f, 0.0f);
static const Point3 XAxis;
This data member is available in release 3.0 and later only.
This is equivalent to Point3(1.0f, 0.0f, 0.0f);
static const Point3 YAxis;
This data member is available in release 3.0 and later only.
This is equivalent to Point3(0.0f, 1.0f, 0.0f);
static const Point3 ZAxis;
This data member is available in release 3.0 and later only.
This is equivalent to Point3(0.0f, 0.0f, 1.0f);
Methods:
Prototype:
Point3()
Remarks:
Constructor. No initialization is performed.
Prototype:
Point3(float X, float Y, float Z)
Remarks:
Constructor. x, y, and z are initialized to the values specified.
Prototype:
Point3(double X, double Y, double Z)
Remarks:
Constructor. x, y, and z are initialized to the specified values (cast as floats).
Prototype:
Point3(int X, int Y, int Z)
Remarks:
Constructor. x, y, and z are initialized to the specified values (cast as floats).
Prototype:
Point3(const Point3& a)
Remarks:
Constructor. x, y, and z are initialized to the specified Point3.
Prototype:
Point3(float af[3])
Remarks:
Constructor. x, y, and z are initialized to af[0], af[1], and af[2] respectively.
Operators:
Prototype:
float& operator[](int i)
const float& operator[](int i) const
Remarks:
Allows access to x, y and z using the subscript operator.
Return Value:
An value for i of 0 will return x, 1 will return y, 2 will return z.
Prototype:
operator float*()
Remarks:
Conversion function. Returns the address of the Point3.x
Prototype:
Point3 operator-() const
Remarks:
Unary - operator. Negates x, y and z.
Prototype:
Point3 operator+() const
Remarks:
Unary +. Returns the Point3.
Prototype:
inline Point3& operator-=(const Point3&);
Remarks:
Subtracts a Point3 from this Point3.
Prototype:
inline Point3& operator+=(const Point3&);
Remarks:
Adds a Point3 to this Point3.
Prototype:
inline Point3& operator*=(float);
Remarks:
Multiplies this Point3 by a floating point value.
Prototype:
inline Point3& operator/=(float);
Remarks:
Divides this Point3 by a floating point value.
Prototype:
inline Point3& operator*=(const Point3&);
Remarks:
Element-by-element multiplication of two Point3s:
(x*x, y*y, z*z).
Prototype:
int operator==(const Point3& p) const
Remarks:
Equality operator. Test for equality between two Point3's.
Return Value:
Nonzero if the Point3's are equal; otherwise 0.
Prototype:
inline Point3 operator-(const Point3&) const;
Remarks:
Subtracts a Point3 from a Point3.
Prototype:
inline Point3 operator+(const Point3&) const;
Remarks:
Adds a Point3 to a Point3.
Prototype:
inline Point3 operator/(const Point3&) const;
Remarks:
Divides a Point3 by a Point3 element by element.
Prototype:
inline Point3 operator*(const Point3&) const;
Remarks:
Multiplies a Point3 by a Point3 element by element.
(x*x, y*y, z*z).
Prototype:
Point3 operator^(const Point3&) const;
Remarks:
The cross product of two Point3's (vectors).
Return Value:
The cross product of two Point3's.
The following functions are not methods of Point3 but are available for use:
Prototype:
inline float Length(const Point3& v)
Remarks:
Returns the 'Length' of the point (vector). This is:
sqrt(v.x*v.x+v.y*v.y+v.z*v.z)
Prototype:
inline float FLength(const Point3& v)
Remarks:
Returns the 'Length' of the point (vector) using a faster assembly language implementation for square root. This is:
Sqrt(v.x*v.x+v.y*v.y+v.z*v.z)
Prototype:
inline float LengthSquared(const Point3& v)
Remarks:
The 'Length' squared of the point. This is v.x*v.x+v.y*v.y+v.z*v.z.
Prototype:
int MaxComponent(const Point3&);
Remarks:
Returns the component with the maximum absolute value. 0=x, 1=y, 2=z.
Prototype:
int MinComponent(const Point3&);
Remarks:
Returns the component with the minimum absolute value. 0=x, 1=y, 2=z.
Prototype:
Point3 Normalize(const Point3&);
Remarks:
Returns a normalized unit vector. This is a Point3 with each component divided by the point Length().
Prototype:
Point3 FNormalize(const Point3&);
Remarks:
Returns a normalized unit vector using faster assembly language code than that used by Normalize(). This is a Point3 with each component divided by the point Length().
Prototype:
inline Point3 operator*(float f, const Point3& a)
Remarks:
Returns a Point3 that is the specified Point3 multiplied by the specified float.
Prototype:
inline Point3 operator*(const Point3& a, float f)
Remarks:
Returns a Point3 that is the specified Point3 multiplied by the specified float.
Prototype:
inline Point3 operator/(const Point3& a, float f)
Remarks:
Returns a Point3 that is the specified Point3 divided by the specified float.
Prototype:
inline Point3 operator+(const Point3& a, float f)
Remarks:
Returns a Point3 that is the specified Point3 with the specified floating point valued added to each component x, y, and z.
Prototype:
inline float DotProd(const Point3& a, const Point3& b);
Remarks:
Returns the dot product of two Point3s. This is the sum of each of the components multiplied together, element by element a.x*b.x+a.y*b.y+a.z*b.z
The dot product has the property of equaling the product of the magnitude (length) of the two vector times the cosine of the angle between them.
Prototype:
Point3 CrossProd(const Point3& a, const Point3& b);
Remarks:
This returns the cross product of the specified Point3's (vectors). The cross product of two vectors is a third vector, perpendicular to the plane formed by the two vectors.
Prototype:
ULONG CompressNormal(Point3 p);
Remarks:
This function will compress a normal vector from 12 bytes to 4 bytes. The vector has to be <= 1.0 in length.
Prototype:
Point3 DeCompressNormal(ULONG n);
Remarks:
This function may be used to decompress a surface normal from the G-Buffer (ie the BMM_CHAN_NORMAL channel). The Point3 returned is normalized. The decompressed vector has absolute error <.001 in each component.