absence_thelab

annotate src/common/n3dmath.inl @ 0:1cffe3409164

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 01:46:07 +0300
parents
children
rev   line source
nuclear@0 1 float Vector3::DotProduct(const Vector3 &vec) const {
nuclear@0 2 return x * vec.x + y * vec.y + z * vec.z;
nuclear@0 3 }
nuclear@0 4
nuclear@0 5 float DotProduct(const Vector3 &vec1, const Vector3 &vec2) {
nuclear@0 6 return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z;
nuclear@0 7 }
nuclear@0 8
nuclear@0 9 Vector3 Vector3::CrossProduct(const Vector3 &vec) const {
nuclear@0 10 return Vector3(y * vec.z - z * vec.y, z * vec.x - x * vec.z, x * vec.y - y * vec.x);
nuclear@0 11 }
nuclear@0 12
nuclear@0 13 Vector3 CrossProduct(const Vector3 &vec1, const Vector3 &vec2) {
nuclear@0 14 return Vector3(vec1.y * vec2.z - vec1.z * vec2.y, vec1.z * vec2.x - vec1.x * vec2.z, vec1.x * vec2.y - vec1.y * vec2.x);
nuclear@0 15 }
nuclear@0 16
nuclear@0 17 Vector3 Vector3::operator +(const Vector3 &vec) const {
nuclear@0 18 return Vector3(x + vec.x, y + vec.y, z + vec.z);
nuclear@0 19 }
nuclear@0 20
nuclear@0 21 Vector3 Vector3::operator -(const Vector3 &vec) const {
nuclear@0 22 return Vector3(x - vec.x, y - vec.y, z - vec.z);
nuclear@0 23 }
nuclear@0 24
nuclear@0 25 Vector3 Vector3::operator *(float scalar) const {
nuclear@0 26 return Vector3(x * scalar, y * scalar, z * scalar);
nuclear@0 27 }
nuclear@0 28
nuclear@0 29 Vector3 Vector3::operator /(float scalar) const {
nuclear@0 30 return Vector3(x / scalar, y / scalar, z / scalar);
nuclear@0 31 }
nuclear@0 32
nuclear@0 33 void Vector3::operator +=(const Vector3 &vec) {
nuclear@0 34 x += vec.x;
nuclear@0 35 y += vec.y;
nuclear@0 36 z += vec.z;
nuclear@0 37 }
nuclear@0 38
nuclear@0 39 void Vector3::operator -=(const Vector3 &vec) {
nuclear@0 40 x -= vec.x;
nuclear@0 41 y -= vec.y;
nuclear@0 42 z -= vec.z;
nuclear@0 43 }
nuclear@0 44
nuclear@0 45 void Vector3::operator *=(float scalar) {
nuclear@0 46 x *= scalar;
nuclear@0 47 y *= scalar;
nuclear@0 48 z *= scalar;
nuclear@0 49 }
nuclear@0 50
nuclear@0 51 void Vector3::operator /=(float scalar) {
nuclear@0 52 x /= scalar;
nuclear@0 53 y /= scalar;
nuclear@0 54 z /= scalar;
nuclear@0 55 }
nuclear@0 56
nuclear@0 57 Vector3 Vector3::operator -() const {
nuclear@0 58 return Vector3(-x, -y, -z);
nuclear@0 59 }
nuclear@0 60
nuclear@0 61 bool Vector3::operator >(const Vector3 &vec) const {
nuclear@0 62 return LengthSq() > vec.LengthSq();
nuclear@0 63 }
nuclear@0 64
nuclear@0 65 bool Vector3::operator <(const Vector3 &vec) const {
nuclear@0 66 return LengthSq() < vec.LengthSq();
nuclear@0 67 }
nuclear@0 68
nuclear@0 69 bool Vector3::operator >(float len) const {
nuclear@0 70 return LengthSq() > len;
nuclear@0 71 }
nuclear@0 72
nuclear@0 73 bool Vector3::operator <(float len) const {
nuclear@0 74 return LengthSq() < len;
nuclear@0 75 }
nuclear@0 76
nuclear@0 77 bool Vector3::operator ==(const Vector3 &vec) const {
nuclear@0 78 return ((*this - vec).Length() < XSmallNumber);
nuclear@0 79 }
nuclear@0 80
nuclear@0 81 bool Vector3::operator ==(float len) const {
nuclear@0 82 return ((this->Length() - len) < XSmallNumber);
nuclear@0 83 }
nuclear@0 84
nuclear@0 85 Vector3::operator Vector2() const {
nuclear@0 86 return Vector2(x, y);
nuclear@0 87 }
nuclear@0 88
nuclear@0 89 Vector3::operator Vector4() const {
nuclear@0 90 return Vector4(x, y, z, 1.0f);
nuclear@0 91 }
nuclear@0 92
nuclear@0 93
nuclear@0 94 float Vector3::Length() const {
nuclear@0 95 return (float)sqrt(x*x + y*y + z*z);
nuclear@0 96 }
nuclear@0 97
nuclear@0 98 float Vector3::LengthSq() const {
nuclear@0 99 return x*x + y*y + z*z;
nuclear@0 100 }
nuclear@0 101
nuclear@0 102 void Vector3::Normalize() {
nuclear@0 103 float len = (float)sqrt(x*x + y*y + z*z);
nuclear@0 104 x /= len;
nuclear@0 105 y /= len;
nuclear@0 106 z /= len;
nuclear@0 107 }
nuclear@0 108
nuclear@0 109 Vector3 Vector3::Normalized() const {
nuclear@0 110 float len = (float)sqrt(x*x + y*y + z*z);
nuclear@0 111 return Vector3(x / len, y / len, z / len);
nuclear@0 112 }
nuclear@0 113
nuclear@0 114 Vector3 Vector3::Reflection(const Vector3 &normal) const {
nuclear@0 115 return normal * this->DotProduct(normal) * 2.0f - *this;
nuclear@0 116 }