|
//
// Vector3.h
//
// Copyright (c) Paul Higinbotham
//
#ifndef __VECTOR3_H_
#define __VECTOR3_H_
#include "Math.h"
#include <cassert>
namespace ZGraphics
{
template <typename TR>
class Vector3
{
public:
Vector3();
Vector3(TR fX, TR fY, TR fZ);
Vector3(const TR fVector[3]);
Vector3(const Vector3<TR> & rCopy);
~Vector3() {}
// Data access
const TR & operator[] (size_t tIndex) const;
TR & operator[] (size_t tIndex);
const TR * GetPtr() const;
TR * GetPtr();
TR X() const;
TR Y() const;
TR Z() const;
// assignment
Vector3 & operator= (const Vector3 & rhs);
Vector3 & operator= (const float fVector[3]);
// arithmetic
Vector3 operator* (const Vector3 &rhs) const;
Vector3 operator* (TR fScalar) const;
Vector3 operator/ (TR fScalar) const;
Vector3 operator+ (const Vector3 &rhs) const;
Vector3 operator- (const Vector3 &rhs) const;
Vector3 operator- () const;
//
Vector3 & operator*= (TR fScalar);
Vector3 & operator/= (TR fScalar);
Vector3 & operator+= (const Vector3 & rhs);
Vector3 & operator-= (const Vector3 & rhs);
// compare
bool operator== (const Vector3 & rhs) const;
bool operator!= (const Vector3 & rhs) const;
// Other operations
TR Dot(const Vector3& rVector)const;
Vector3 Cross(const Vector3 & rVector) const;
Vector3 CrossN(const Vector3 & rVector) const;
TR Normalize();
TR Mag() const;
TR MagSquared() const;
Vector3 & ABS();
Vector3 & Invert();
// Class constants
static const Vector3 cZero;
static const Vector3 cUnitX;
static const Vector3 cUnitY;
static const Vector3 cUnitZ;
private:
TR m_vData[3];
};
// Include the implementation file
#include "Vector3.inl"
typedef Vector3<float> Vector3f;
typedef Vector3<double> Vector3d;
} /* namespace ZGraphics */
#endif /* __VECTOR3_H_ */
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a senior software developer currently doing contract work for Microsoft. My educational background is in electrical engineering and I hold a masters degree from the University of Washington. I have experience in hardware and systems design but have done primarily software development for the last two decades. I have worked for various small companies as well as start-up companies, and have worked as a full time employee SDE at Microsoft Corporation.