## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# csVector3 Class Reference
[Geometry utilities]

A 3D vector. More...

`#include <csgeom/vector3.h>`

List of all members.

## Public Member Functions

void | Cross (const csVector3 &px, const csVector3 &py)
| Take cross product of two vectors and put result in this vector.
| csVector3 (const csDVector3 &)
| Conversion from double precision vector to single.
| csVector3 (const csVector3 &v)
| Copy Constructor.
| csVector3 (float ix, float iy, float iz=0)
| Make a new vector and initialize with the given values.
| csVector3 (float m)
| Make a new initialized vector.
| csVector3 ()
| Make a new vector.
csString | Description () const
| Return a textual representation of the vector in the form "x,y,z".
void | Get (float *v)
| Get the value of this vector.
bool | IsZero (float precision=SMALL_EPSILON) const
| Query if the vector is zero.
float | Norm () const
| Returns the norm of this vector.
void | Normalize ()
| Scale this vector to length = 1.0;.
csVector3 & | operator *= (float f)
| Multiply this vector by a scalar.
csVector3 | operator+ () const
| Unary + operator.
csVector3 & | operator+= (const csVector3 &v)
| Add another vector to this vector.
csVector3 | operator- () const
| Unary - operator.
csVector3 & | operator-= (const csVector3 &v)
| Subtract another vector from this vector.
csVector3 & | operator/= (float f)
| Divide this vector by a scalar.
float & | operator[] (int n)
| Returns n-th component of the vector.
float | operator[] (int n) const
| Returns n-th component of the vector.
void | Set (float v)
| Set the value of this vector so that all components are the same.
void | Set (float const *v)
| Set the value of this vector.
void | Set (csVector3 const &v)
| Set the value of this vector.
void | Set (float sx, float sy, float sz)
| Set the value of this vector.
float | SquaredNorm () const
| Return the squared norm (magnitude) of this vector.
csVector3 | Unit () const
| Returns the unit vector in the direction of this vector.

## Static Public Member Functions

static float | Norm (const csVector3 &v)
| Returns the norm (magnitude) of a vector.
static csVector3 | Unit (const csVector3 &v)
| Normalizes a vector to a unit vector.

## Friends

csVector3 | operator * (int f, const csVector3 &v)
| Multiply a vector and a scalar int.
csVector3 | operator * (const csVector3 &v, int f)
| Multiply a vector and a scalar int.
csDVector3 | operator * (double f, const csVector3 &v)
| Multiply a vector and a scalar double. Upgrade v to DVector.
csDVector3 | operator * (const csVector3 &v, double f)
| Multiply a vector and a scalar double. Upgrade v to DVector.
csVector3 | operator * (float f, const csVector3 &v)
| Multiply a vector and a scalar.
csVector3 | operator * (const csVector3 &v, float f)
| Multiply a vector and a scalar.
float | operator * (const csVector3 &v1, const csVector3 &v2)
| Take the dot product of two vectors.
bool | operator!= (const csVector3 &v1, const csVector3 &v2)
| Check if two vectors are not equal.
csVector3 | operator% (const csVector3 &v1, const csVector3 &v2)
| Take the cross product of two vectors.
csDVector3 | operator+ (const csVector3 &v1, const csDVector3 &v2)
| Add two vectors of differing type, raise the csVector3 to DVector3.
csDVector3 | operator+ (const csDVector3 &v1, const csVector3 &v2)
| Add two vectors of differing type, raise the csVector3 to DVector3.
csVector3 | operator+ (const csVector3 &v1, const csVector3 &v2)
| Add two vectors.
csDVector3 | operator- (const csDVector3 &v1, const csVector3 &v2)
| Subtract two vectors of differing type, cast to double.
csDVector3 | operator- (const csVector3 &v1, const csDVector3 &v2)
| Subtract two vectors of differing type, cast to double.
csVector3 | operator- (const csVector3 &v1, const csVector3 &v2)
| Subtract two vectors.
csVector3 | operator/ (const csVector3 &v, int f)
| Divide a vector by a scalar int.
csDVector3 | operator/ (const csVector3 &v, double f)
| Divide a vector by a scalar double. Upgrade v to DVector.
csVector3 | operator/ (const csVector3 &v, float f)
| Divide a vector by a scalar.
bool | operator< (const csVector3 &v, float f)
| Test if each component of a vector is less than a small epsilon value.
csVector3 | operator<< (const csVector3 &v1, const csVector3 &v2)
| Project one vector onto another.
bool | operator== (const csVector3 &v1, const csVector3 &v2)
| Check if two vectors are equal.
bool | operator> (float f, const csVector3 &v)
| Test if each component of a vector is less than a small epsilon value.
csVector3 | operator>> (const csVector3 &v1, const csVector3 &v2)
| Project one vector onto another.

## Detailed Description

A 3D vector.

Definition at line 56 of file vector3.h.

## Constructor & Destructor Documentation

csVector3::csVector3 | ( |  | ) | `[inline]`

Make a new vector.

Warning:
  The vector is not initialized. This makes the code slightly faster as csVector3 objects are used a lot.

Definition at line 84 of file vector3.h.

csVector3::csVector3 | ( | float | m | ) | `[inline]`

| Make a new initialized vector. Creates a new vector and initializes it to m*<1,1,1>. To create a vector initialized to the zero vector, use csVector3(0) Definition at line 91 of file vector3.h.

csVector3::csVector3 | ( | float | ix,
|  | float | iy,
|  | float | iz = `0`
| ) | `[inline]`

| Make a new vector and initialize with the given values. Definition at line 94 of file vector3.h.

csVector3::csVector3 | ( | const csVector3 & | v | ) | `[inline]`

| Copy Constructor. Definition at line 97 of file vector3.h.

csVector3::csVector3 | ( | const csDVector3 & |  | ) |

| Conversion from double precision vector to single.

## Member Function Documentation

void csVector3::Cross | ( | const csVector3 & | px,
|  | const csVector3 & | py
| ) | `[inline]`

| Take cross product of two vectors and put result in this vector. Definition at line 142 of file vector3.h. References x, y, and z.

csString csVector3::Description | ( |  | ) | const

| Return a textual representation of the vector in the form "x,y,z".

void csVector3::Get | ( | float * | v | ) | `[inline]`

| Get the value of this vector. Definition at line 270 of file vector3.h.

bool csVector3::IsZero | ( | float | precision = `SMALL_EPSILON` | ) | const`[inline]`

| Query if the vector is zero. Definition at line 296 of file vector3.h. References ABS.

static float csVector3::Norm | ( | const csVector3 & | v | ) | `[inline, static]`

| Returns the norm (magnitude) of a vector. Definition at line 287 of file vector3.h. References Norm().

float csVector3::Norm | ( |  | ) | const

| Returns the norm of this vector. Referenced by csMath3::DoubleArea3(), and Norm().

void csVector3::Normalize | ( |  | ) |

| Scale this vector to length = 1.0;.

csVector3& csVector3::operator *= | ( | float | f | ) | `[inline]`

| Multiply this vector by a scalar. Definition at line 244 of file vector3.h.

csVector3 csVector3::operator+ | ( |  | ) | const`[inline]`

| Unary + operator. Definition at line 252 of file vector3.h.

csVector3& csVector3::operator+= | ( | const csVector3 & | v | ) | `[inline]`

| Add another vector to this vector. Definition at line 224 of file vector3.h. References x, y, and z.

csVector3 csVector3::operator- | ( |  | ) | const`[inline]`

| Unary - operator. Definition at line 255 of file vector3.h.

csVector3& csVector3::operator-= | ( | const csVector3 & | v | ) | `[inline]`

| Subtract another vector from this vector. Definition at line 234 of file vector3.h. References x, y, and z.

csVector3& csVector3::operator/= | ( | float | f | ) | `[inline]`

| Divide this vector by a scalar. Definition at line 248 of file vector3.h.

float& csVector3::operator[] | ( | int | n | ) | `[inline]`

| Returns n-th component of the vector. Definition at line 220 of file vector3.h.

float csVector3::operator[] | ( | int | n | ) | const`[inline]`

| Returns n-th component of the vector. Definition at line 213 of file vector3.h.

void csVector3::Set | ( | float | v | ) | `[inline]`

| Set the value of this vector so that all components are the same. Definition at line 267 of file vector3.h.

void csVector3::Set | ( | float const * | v | ) | `[inline]`

| Set the value of this vector. Definition at line 264 of file vector3.h.

void csVector3::Set | ( | csVector3 const & | v | ) | `[inline]`

| Set the value of this vector. Definition at line 261 of file vector3.h. References x, y, and z.

void csVector3::Set | ( | float | sx,
|  | float | sy,
|  | float | sz
| ) | `[inline]`

| Set the value of this vector. Definition at line 258 of file vector3.h. Referenced by csShaderVariable::GetValue().

float csVector3::SquaredNorm | ( |  | ) | const`[inline]`

| Return the squared norm (magnitude) of this vector. Definition at line 276 of file vector3.h. Referenced by csSpotLightProc< AttenuationProc >::ProcessVertex(), csDirectionalLightProc< AttenuationProc >::ProcessVertex(), and csPointLightProc< AttenuationProc >::ProcessVertex().

static csVector3 csVector3::Unit | ( | const csVector3 & | v | ) | `[inline, static]`

| Normalizes a vector to a unit vector. Definition at line 290 of file vector3.h. References Unit().

csVector3 csVector3::Unit | ( |  | ) | const`[inline]`

| Returns the unit vector in the direction of this vector. Attempting to normalize a zero-vector will result in a divide by zero error. This is as it should be... fix the calling code. Definition at line 284 of file vector3.h. Referenced by Unit().

## Friends And Related Function Documentation

csVector3 operator * | ( | int | f,
|  | const csVector3 & | v
| ) | `[friend]`

| Multiply a vector and a scalar int. Definition at line 170 of file vector3.h.

csVector3 operator * | ( | const csVector3 & | v,
|  | int | f
| ) | `[friend]`

| Multiply a vector and a scalar int. Definition at line 166 of file vector3.h.

csDVector3 operator * | ( | double | f,
|  | const csVector3 & | v
| ) | `[friend]`

| Multiply a vector and a scalar double. Upgrade v to DVector. Definition at line 162 of file vector3.h.

csDVector3 operator * | ( | const csVector3 & | v,
|  | double | f
| ) | `[friend]`

| Multiply a vector and a scalar double. Upgrade v to DVector. Definition at line 158 of file vector3.h.

csVector3 operator * | ( | float | f,
|  | const csVector3 & | v
| ) | `[friend]`

| Multiply a vector and a scalar. Definition at line 154 of file vector3.h.

csVector3 operator * | ( | const csVector3 & | v,
|  | float | f
| ) | `[friend]`

| Multiply a vector and a scalar. Definition at line 150 of file vector3.h.

float operator * | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Take the dot product of two vectors. Definition at line 130 of file vector3.h.

bool operator!= | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Check if two vectors are not equal. Definition at line 190 of file vector3.h.

csVector3 operator% | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Take the cross product of two vectors. Definition at line 134 of file vector3.h.

csDVector3 operator+ | ( | const csVector3 & | v1,
|  | const csDVector3 & | v2
| ) | `[friend]`

| Add two vectors of differing type, raise the csVector3 to DVector3. Definition at line 114 of file vector3.h.

csDVector3 operator+ | ( | const csDVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Add two vectors of differing type, raise the csVector3 to DVector3. Definition at line 110 of file vector3.h.

csVector3 operator+ | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Add two vectors. Definition at line 106 of file vector3.h.

csDVector3 operator- | ( | const csDVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Subtract two vectors of differing type, cast to double. Definition at line 126 of file vector3.h.

csDVector3 operator- | ( | const csVector3 & | v1,
|  | const csDVector3 & | v2
| ) | `[friend]`

| Subtract two vectors of differing type, cast to double. Definition at line 122 of file vector3.h.

csVector3 operator- | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Subtract two vectors. Definition at line 118 of file vector3.h.

csVector3 operator/ | ( | const csVector3 & | v,
|  | int | f
| ) | `[friend]`

| Divide a vector by a scalar int. Definition at line 182 of file vector3.h.

csDVector3 operator/ | ( | const csVector3 & | v,
|  | double | f
| ) | `[friend]`

| Divide a vector by a scalar double. Upgrade v to DVector. Definition at line 178 of file vector3.h.

csVector3 operator/ | ( | const csVector3 & | v,
|  | float | f
| ) | `[friend]`

| Divide a vector by a scalar. Definition at line 174 of file vector3.h.

bool operator< | ( | const csVector3 & | v,
|  | float | f
| ) | `[friend]`

| Test if each component of a vector is less than a small epsilon value. Definition at line 202 of file vector3.h.

csVector3 operator<< | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Project one vector onto another. Definition at line 198 of file vector3.h.

bool operator== | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Check if two vectors are equal. Definition at line 186 of file vector3.h.

bool operator> | ( | float | f,
|  | const csVector3 & | v
| ) | `[friend]`

| Test if each component of a vector is less than a small epsilon value. Definition at line 206 of file vector3.h.

csVector3 operator>> | ( | const csVector3 & | v1,
|  | const csVector3 & | v2
| ) | `[friend]`

| Project one vector onto another. Definition at line 194 of file vector3.h.

## Member Data Documentation

float csVector3::m[3]

| All components. Definition at line 75 of file vector3.h.

float csVector3::x

The X component of the vector.

Definition at line 67 of file vector3.h.

Referenced by csPlane3::A(), csBox3::AddBoundingVertex(), csBox3::AddBoundingVertexSmart(), csBox3::AddBoundingVertexSmartTest(), csBox3::AddBoundingVertexTest(), csPoly3D::AddVertex(), csVector3Array::AddVertexSmart(), csPlane3::Classify(), csBox3::Contains(), Cross(), csLinearAttenuation::csLinearAttenuation(), csQuaternion::csQuaternion(), csMath3::Direction3(), csPath::GetForwardVector(), csPath::GetInterpolatedForward(), csPath::GetInterpolatedPosition(), csPath::GetInterpolatedUp(), csPath::GetPositionVector(), csPath::GetUpVector(), csBox3::In(), makeGLMatrix(), operator+=(), operator-=(), csVector4::operator=(), csBox3::Overlap(), csQuaternion::PrepRotation(), Set(), csPath::SetForwardVector(), csMath3::SetMinMax(), csPath::SetPositionVector(), CrystalSpace::SoftShader::InterpolateEdgePersp::Setup(), csPath::SetUpVector(), csShaderVariable::SetValue(), and csMath3::WhichSide3D().

float csVector3::y

The Y component of the vector.

Definition at line 69 of file vector3.h.

Referenced by csBox3::AddBoundingVertex(), csBox3::AddBoundingVertexSmart(), csBox3::AddBoundingVertexSmartTest(), csBox3::AddBoundingVertexTest(), csPoly3D::AddVertex(), csVector3Array::AddVertexSmart(), csPlane3::Classify(), csBox3::Contains(), Cross(), csQuaternion::csQuaternion(), csMath3::Direction3(), csPath::GetForwardVector(), csPath::GetInterpolatedForward(), csPath::GetInterpolatedPosition(), csPath::GetInterpolatedUp(), csPath::GetPositionVector(), csPath::GetUpVector(), csBox3::In(), makeGLMatrix(), operator+=(), operator-=(), csVector4::operator=(), csBox3::Overlap(), csQuaternion::PrepRotation(), Set(), csPath::SetForwardVector(), csMath3::SetMinMax(), csPath::SetPositionVector(), CrystalSpace::SoftShader::InterpolateEdgePersp::Setup(), csPath::SetUpVector(), csShaderVariable::SetValue(), and csMath3::WhichSide3D().

float csVector3::z

The Z component of the vector.

Definition at line 71 of file vector3.h.

Referenced by csBox3::AddBoundingVertex(), csBox3::AddBoundingVertexSmart(), csBox3::AddBoundingVertexSmartTest(), csBox3::AddBoundingVertexTest(), csPoly3D::AddVertex(), csVector3Array::AddVertexSmart(), csPlane3::Classify(), csBox3::Contains(), Cross(), csQuaternion::csQuaternion(), csMath3::Direction3(), csPath::GetForwardVector(), csPath::GetInterpolatedForward(), csPath::GetInterpolatedPosition(), csPath::GetInterpolatedUp(), csPath::GetPositionVector(), csPath::GetUpVector(), csBox3::In(), makeGLMatrix(), operator+=(), operator-=(), csVector4::operator=(), csBox3::Overlap(), csQuaternion::PrepRotation(), Set(), csPath::SetForwardVector(), csMath3::SetMinMax(), csPath::SetPositionVector(), CrystalSpace::SoftShader::InterpolateEdgePersp::Setup(), csPath::SetUpVector(), csShaderVariable::SetValue(), and csMath3::WhichSide3D().

The documentation for this class was generated from the following file:

- csgeom/vector3.h