RigsofRods
Soft-body Physics Simulation
ProceduralRoad.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #pragma once
22 
23 #include <Ogre.h>
24 
25 #include "Application.h"
26 #include "RefCountingObject.h"
27 
28 namespace RoR {
29 
32 
33 enum class RoadType
34 {
36  ROAD_FLAT,
37  ROAD_LEFT,
38  ROAD_RIGHT,
39  ROAD_BOTH,
42 };
43 
44 enum class TextureFit
45 {
57 };
58 
59 // dynamic roads
60 class ProceduralRoad : public RefCountingObject<ProceduralRoad>
61 {
62 public:
63 
65  virtual ~ProceduralRoad() override;
66 
67  void addBlock(Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight, int pillartype = 1);
72  void addQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, TextureFit texfit, Ogre::Vector3 pos, Ogre::Vector3 lastpos, float width, bool flip = false);
73  void addCollisionQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, ground_model_t* gm, bool flip = false);
74  void addCollisionQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, std::string const& gm_name, bool flip = false);
75  void createMesh();
76  void finish(Ogre::SceneNode* snode);
77  void setCollisionEnabled(bool v) { collision = v; }
78 
79  static const unsigned int MAX_VERTEX = 50000;
80  static const unsigned int MAX_TRIS = 50000;
81 
82 private:
83 
84  inline Ogre::Vector3 baseOf(Ogre::Vector3 p);
85  void computePoints(Ogre::Vector3* pts, Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight);
86  void textureFit(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, TextureFit texfit, Ogre::Vector2* texc, Ogre::Vector3 pos, Ogre::Vector3 lastpos, float width);
87 
88  struct CoVertice_t
89  {
90  Ogre::Vector3 vertex;
91  Ogre::Vector3 normal;
92  Ogre::Vector2 texcoord;
93  };
94 
95  Ogre::MeshPtr msh;
96  Ogre::SubMesh* mainsub = nullptr;
97 
98  Ogre::Vector2 tex[MAX_VERTEX] = {};
99  Ogre::Vector3 vertex[MAX_VERTEX] = {};
100  int tricount = 0;
101  int vertexcount = 0;
102  uint16_t tris[MAX_TRIS * 3] = {};
103 
104  Ogre::Quaternion lastrot;
105  Ogre::SceneNode* snode = nullptr;
106  Ogre::Vector3 lastpos;
107  bool first = true;
108  float lastbheight = 0.f;
109  float lastbwidth = 0.f;
110  float lastwidth = 0.f;
112  int mid = 0;
113  bool collision = true;
114  std::vector<int> registeredCollTris;
115 };
116 
118 
119 } // namespace RoR
120 
RoR::ProceduralRoad::collision
bool collision
Register collision triangles?
Definition: ProceduralRoad.h:113
RoR::ProceduralRoad::MAX_TRIS
static const unsigned int MAX_TRIS
Definition: ProceduralRoad.h:80
RoR::RoadType::ROAD_BOTH
@ ROAD_BOTH
RoR::ProceduralRoad::snode
Ogre::SceneNode * snode
Definition: ProceduralRoad.h:105
RoR::TextureFit::TEXFIT_CONCRETEUNDER
@ TEXFIT_CONCRETEUNDER
RoR::RoadType::ROAD_AUTOMATIC
@ ROAD_AUTOMATIC
RoR::ProceduralRoad::lasttype
RoadType lasttype
Definition: ProceduralRoad.h:111
RoR::ProceduralRoad::mid
int mid
Definition: ProceduralRoad.h:112
RoR::ProceduralRoad::addQuad
void addQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, TextureFit texfit, Ogre::Vector3 pos, Ogre::Vector3 lastpos, float width, bool flip=false)
Definition: ProceduralRoad.cpp:358
RoR::ProceduralRoad::CoVertice_t::vertex
Ogre::Vector3 vertex
Definition: ProceduralRoad.h:90
RoR::ProceduralRoad::msh
Ogre::MeshPtr msh
Definition: ProceduralRoad.h:95
RoR::ProceduralRoad::tris
uint16_t tris[MAX_TRIS *3]
Definition: ProceduralRoad.h:102
RoR::ProceduralRoad::lastwidth
float lastwidth
Definition: ProceduralRoad.h:110
RoR::TextureFit::TEXFIT_CONCRETEWALL
@ TEXFIT_CONCRETEWALL
RoR::ProceduralRoad::~ProceduralRoad
virtual ~ProceduralRoad() override
Definition: ProceduralRoad.cpp:43
RoR::ProceduralRoad::setCollisionEnabled
void setCollisionEnabled(bool v)
Definition: ProceduralRoad.h:77
RoR::ProceduralRoad::CoVertice_t::texcoord
Ogre::Vector2 texcoord
Definition: ProceduralRoad.h:92
RoR::ProceduralRoad::mainsub
Ogre::SubMesh * mainsub
Definition: ProceduralRoad.h:96
RoR::ProceduralRoad::finish
void finish(Ogre::SceneNode *snode)
Definition: ProceduralRoad.cpp:61
RoR::ProceduralRoad::vertex
Ogre::Vector3 vertex[MAX_VERTEX]
Definition: ProceduralRoad.h:99
RoR::TextureFit::TEXFIT_ROADS1
@ TEXFIT_ROADS1
RoR::TextureFit
TextureFit
Definition: ProceduralRoad.h:44
RoR::TextureFit::TEXFIT_BRICKWALL
@ TEXFIT_BRICKWALL
RoR::ProceduralRoad::textureFit
void textureFit(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, TextureFit texfit, Ogre::Vector2 *texc, Ogre::Vector3 pos, Ogre::Vector3 lastpos, float width)
Definition: ProceduralRoad.cpp:403
RoR::ProceduralRoad::tricount
int tricount
Definition: ProceduralRoad.h:100
RoR::TextureFit::TEXFIT_CONCRETEWALLI
@ TEXFIT_CONCRETEWALLI
RoR::RoadType
RoadType
Definition: ProceduralRoad.h:33
RoR::ProceduralRoad::addBlock
void addBlock(Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight, int pillartype=1)
Definition: ProceduralRoad.cpp:81
RoR::ProceduralRoad::MAX_VERTEX
static const unsigned int MAX_VERTEX
Definition: ProceduralRoad.h:79
RoR::ProceduralRoad::registeredCollTris
std::vector< int > registeredCollTris
Definition: ProceduralRoad.h:114
RoR::RoadType::ROAD_BRIDGE
@ ROAD_BRIDGE
RoR::TextureFit::TEXFIT_ROADS2
@ TEXFIT_ROADS2
RoR::ProceduralRoad::lastpos
Ogre::Vector3 lastpos
Definition: ProceduralRoad.h:106
RefCountingObject.h
Application.h
Central state/object manager and communications hub.
RoR::ProceduralRoad::tex
Ogre::Vector2 tex[MAX_VERTEX]
Definition: ProceduralRoad.h:98
RoR::TextureFit::TEXFIT_ROAD
@ TEXFIT_ROAD
RoR::ProceduralRoad::vertexcount
int vertexcount
Definition: ProceduralRoad.h:101
RoR::ProceduralRoad::lastrot
Ogre::Quaternion lastrot
Definition: ProceduralRoad.h:104
RoR::RoadType::ROAD_FLAT
@ ROAD_FLAT
RoR::ProceduralRoad::baseOf
Ogre::Vector3 baseOf(Ogre::Vector3 p)
Definition: ProceduralRoad.cpp:346
RoR::RoadType::ROAD_MONORAIL
@ ROAD_MONORAIL
RoR::RoadType::ROAD_RIGHT
@ ROAD_RIGHT
RoR::ProceduralRoad::lastbheight
float lastbheight
Definition: ProceduralRoad.h:108
RoR::ProceduralRoad
Definition: ProceduralRoad.h:60
RoR::TextureFit::TEXFIT_NONE
@ TEXFIT_NONE
RoR::ProceduralRoad::first
bool first
Definition: ProceduralRoad.h:107
RoR::ProceduralRoad::CoVertice_t::normal
Ogre::Vector3 normal
Definition: ProceduralRoad.h:91
RoR::RoadType::ROAD_LEFT
@ ROAD_LEFT
RoR::TextureFit::TEXFIT_CONCRETETOP
@ TEXFIT_CONCRETETOP
RoR::ground_model_t
Surface friction properties.
Definition: SimData.h:739
RoR::ProceduralRoad::lastbwidth
float lastbwidth
Definition: ProceduralRoad.h:109
RoR::TextureFit::TEXFIT_ROADS3
@ TEXFIT_ROADS3
RoR::ProceduralRoad::computePoints
void computePoints(Ogre::Vector3 *pts, Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight)
Definition: ProceduralRoad.cpp:276
RoR::TextureFit::TEXFIT_ROADS4
@ TEXFIT_ROADS4
RoR::ProceduralRoad::addCollisionQuad
void addCollisionQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, ground_model_t *gm, bool flip=false)
RoR::ProceduralRoad::ProceduralRoad
ProceduralRoad()
Definition: ProceduralRoad.cpp:38
RefCountingObject
Self reference-counting objects, as requred by AngelScript garbage collector.
Definition: RefCountingObject.h:26
RoR::ProceduralRoad::CoVertice_t
Definition: ProceduralRoad.h:88
RoR
Definition: AppContext.h:36
RoR::ProceduralRoad::createMesh
void createMesh()
Definition: ProceduralRoad.cpp:577