Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Triangle.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2016 Fabian Killus
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 <OgreVector3.h>
23
26
29
36{
37public:
39 explicit Triangle(const Ogre::Vector3& a, const Ogre::Vector3& b, const Ogre::Vector3& c)
40 : a{a}, b{b}, c{c}, u{a - c}, v{b - c}, m_initialized{false}
41 {
42 }
43
48 Ogre::Vector3 normal() const
49 {
50 if (!m_initialized)
51 {
52 m_normal = u.crossProduct(v);
53 m_normal.normalise();
54 m_initialized = true;
55 }
56 return m_normal;
57 }
58
59 const Ogre::Vector3 a,
60 b,
61 c;
62
63 const Ogre::Vector3 u,
64 v;
65
66private:
67 mutable bool m_initialized;
68 mutable Ogre::Vector3 m_normal;
69};
70
Represents a triangle in three-dimensional space.
Definition Triangle.h:36
const Ogre::Vector3 u
Span vector u.
Definition Triangle.h:63
Triangle(const Ogre::Vector3 &a, const Ogre::Vector3 &b, const Ogre::Vector3 &c)
Construct triangle from three given vertices.
Definition Triangle.h:39
const Ogre::Vector3 v
Span vector v.
Definition Triangle.h:64
const Ogre::Vector3 b
Vertex b.
Definition Triangle.h:60
bool m_initialized
Definition Triangle.h:67
Ogre::Vector3 m_normal
Cached normal vector.
Definition Triangle.h:68
const Ogre::Vector3 a
Vertex a.
Definition Triangle.h:59
const Ogre::Vector3 c
Vertex c.
Definition Triangle.h:61
Ogre::Vector3 normal() const
Return normal vector of the triangle.
Definition Triangle.h:48