| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /*
- * PolyVector3.h
- * TAU
- *
- * Created by Ivan Safrin on 3/14/08.
- * Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
-
- // @package Math
- #pragma once
- #include "PolyString.h"
- #include "PolyGlobals.h"
- #include <math.h>
- //#ifdef _WINDOWS
- #include <assert.h>
- //#endif
- namespace Polycode {
- class _PolyExport Vector3 {
- public:
-
- Vector3();
- Vector3(float x,float y,float z);
- ~Vector3();
- void set(float x, float y, float z);
- inline Vector3 operator - ( const Vector3& v2 ) const {
- return Vector3(x - v2.x, y - v2.y, z - v2.z);
- }
- inline float distance(const Vector3& rhs) const {
- return (*this - rhs).length();
- }
- inline Vector3& operator * (const float val) {
- x *= val;
- y *= val;
- z *= val;
- return *this;
- }
- inline Vector3& operator / (const float val) {
- assert( val != 0.0 );
- x /= val;
- y /= val;
- z /= val;
- return *this;
- }
- inline Vector3& operator = ( const Vector3& v2) {
- x = v2.x;
- y = v2.y;
- z = v2.z;
- return *this;
- }
- inline Vector3& operator += ( const Vector3& v2) {
- x += v2.x;
- y += v2.y;
- z += v2.z;
- return *this;
- }
- inline Vector3& operator -= ( const Vector3& v2) {
- x -= v2.x;
- y -= v2.y;
- z -= v2.z;
- return *this;
- }
-
- inline Vector3 operator + ( const Vector3& v2 ) const {
- return Vector3(x + v2.x, y + v2.y, z + v2.z);
- }
- inline float length () const {
- return sqrtf( x * x + y * y + z * z );
- }
-
- inline float dot(Vector3 &u) {
- return x * u.x + y * u.y + z * u.z;
- }
- inline Vector3 crossProduct( const Vector3& rkVector ) const {
- return Vector3(
- y * rkVector.z - z * rkVector.y,
- z * rkVector.x - x * rkVector.z,
- x * rkVector.y - y * rkVector.x);
- }
- void Normalize();
-
- float x;
- float y;
- float z;
-
- private:
- };
- }
|