RigsofRods  2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Vec3.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2025 Petr Ohlidal
4 
5  For more information, see http://www.rigsofrods.org/
6 
7  Rigs of Rods is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License version 3, as
9  published by the Free Software Foundation.
10 
11  Rigs of Rods is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <math.h> // sqrtf()
23 #include <Ogre.h> // Ogre::Vector3
24 
25 namespace RoR {
26 
28  struct Vec3
29  {
30  float x, y, z;
31 
32  Vec3() : x(0), y(0), z(0) {}
33  Vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
34  Vec3(const Ogre::Vector3& v) { x = v.x; y = v.y; z = v.z; }
35 
36  Vec3 operator+(const Vec3& b) const { return Vec3(x + b.x, y + b.y, z + b.z); }
37  Vec3 operator-(const Vec3& b) const { return Vec3(x - b.x, y - b.y, z - b.z); }
38  Vec3 operator*(float f) const { return Vec3(x * f, y * f, z * f); }
39  Vec3 operator/(float f) const { return Vec3(x / f, y / f, z / f); }
40 
41  Vec3& operator+=(const Vec3& b) { x += b.x; y += b.y; z += b.z; return *this; }
42  Vec3& operator-=(const Vec3& b) { x -= b.x; y -= b.y; z -= b.z; return *this; }
43  Vec3& operator*=(float f) { x *= f; y *= f; z *= f; return *this; }
44  Vec3& operator/=(float f) { x /= f; y /= f; z /= f; return *this; }
45 
46  operator Ogre::Vector3() const { return Ogre::Vector3(x, y, z); }
47 
48  Vec3 operator-() const { return Vec3(-x, -y, -z); }
49 
50  float dotProduct(const Vec3& b) const { return x * b.x + y * b.y + z * b.z; }
51  Vec3 crossProduct(const Vec3& b) const { return Vec3(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); }
52  float length() const { return sqrtf(x * x + y * y + z * z); }
53  float squaredLength() const { return x * x + y * y + z * z; }
54  };
55 
56  inline Vec3 operator*(float f, const Vec3& v) { return Vec3(v.x * f, v.y * f, v.z * f); }
57 
58 } // namespace RoR
RoR::Vec3::operator/=
Vec3 & operator/=(float f)
Definition: Vec3.h:44
RoR::Vec3::operator/
Vec3 operator/(float f) const
Definition: Vec3.h:39
RoR::Vec3::squaredLength
float squaredLength() const
Definition: Vec3.h:53
RoR::Vec3::dotProduct
float dotProduct(const Vec3 &b) const
Definition: Vec3.h:50
RoR::Vec3::crossProduct
Vec3 crossProduct(const Vec3 &b) const
Definition: Vec3.h:51
RoR::Vec3::z
float z
Definition: Vec3.h:30
RoR::Vec3::operator*=
Vec3 & operator*=(float f)
Definition: Vec3.h:43
RoR::Vec3
Designed to work smoothly with optimizations disabled.
Definition: Vec3.h:28
RoR::Vec3::operator-
Vec3 operator-(const Vec3 &b) const
Definition: Vec3.h:37
RoR::Vec3::operator-=
Vec3 & operator-=(const Vec3 &b)
Definition: Vec3.h:42
RoR::Vec3::operator-
Vec3 operator-() const
Definition: Vec3.h:48
RoR::Vec3::Vec3
Vec3(float _x, float _y, float _z)
Definition: Vec3.h:33
RoR::Vec3::operator*
Vec3 operator*(float f) const
Definition: Vec3.h:38
RoR::operator*
Vec3 operator*(float f, const Vec3 &v)
Definition: Vec3.h:56
RoR::Vec3::length
float length() const
Definition: Vec3.h:52
RoR::Vec3::x
float x
Definition: Vec3.h:30
RoR::Vec3::Vec3
Vec3()
Definition: Vec3.h:32
RoR::Vec3::y
float y
Definition: Vec3.h:30
RoR::Vec3::Vec3
Vec3(const Ogre::Vector3 &v)
Definition: Vec3.h:34
RoR::Vec3::operator+=
Vec3 & operator+=(const Vec3 &b)
Definition: Vec3.h:41
RoR
Definition: AppContext.h:36
RoR::Vec3::operator+
Vec3 operator+(const Vec3 &b) const
Definition: Vec3.h:36