Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
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
28namespace RoR {
29
32
43
58
59static constexpr const char* PROROAD_DEFAULT_MATERIAL = "road2";
60
61// dynamic roads
62class ProceduralRoad : public RefCountingObject<ProceduralRoad>
63{
64public:
65
66 ProceduralRoad(const std::string& _groundmodelName = "");
67 virtual ~ProceduralRoad() override;
68
69 void addBlock(Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight, int pillartype = 1);
74 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);
75 void addCollisionQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, ground_model_t* gm, bool flip = false);
76 void addCollisionQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, std::string const& gm_name, bool flip = false);
77 void finish(Ogre::SceneNode* snode, const std::string& materialName = "");
78 void setCollisionEnabled(bool v) { collision = v; }
79
80 static const unsigned int MAX_VERTEX = 50000;
81 static const unsigned int MAX_TRIS = 50000;
82
83private:
84
85 inline Ogre::Vector3 baseOf(Ogre::Vector3 p);
86 void computePoints(Ogre::Vector3* pts, Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight);
87 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);
88 void createMesh(const std::string& materialName = "");
89
91 {
92 Ogre::Vector3 vertex;
93 Ogre::Vector3 normal;
94 Ogre::Vector2 texcoord;
95 };
96
97 Ogre::MeshPtr msh;
98 Ogre::SubMesh* mainsub = nullptr;
99
100 Ogre::Vector2 tex[MAX_VERTEX] = {};
101 Ogre::Vector3 vertex[MAX_VERTEX] = {};
102 int tricount = 0;
103 int vertexcount = 0;
104 uint16_t tris[MAX_TRIS * 3] = {};
105
106 Ogre::Quaternion lastrot;
107 Ogre::SceneNode* snode = nullptr;
108 Ogre::Vector3 lastpos;
109 bool first = true;
110 float lastbheight = 0.f;
111 float lastbwidth = 0.f;
112 float lastwidth = 0.f;
114 int mid = 0;
115 bool collision = true;
117 std::vector<int> registeredCollTris;
118};
119
121
122} // namespace RoR
123
Central state/object manager and communications hub.
Self reference-counting objects, as requred by AngelScript garbage collector.
static const unsigned int MAX_TRIS
static const unsigned int MAX_VERTEX
Ogre::SceneNode * snode
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)
uint16_t tris[MAX_TRIS *3]
void setCollisionEnabled(bool v)
Must be set before any quads are added. Default: true.
void finish(Ogre::SceneNode *snode, const std::string &materialName="")
If materialName is empty, the default material will be used.
Ogre::Vector2 tex[MAX_VERTEX]
virtual ~ProceduralRoad() override
void addCollisionQuad(Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, ground_model_t *gm, bool flip=false)
std::vector< int > registeredCollTris
void addBlock(Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight, int pillartype=1)
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)
bool collision
Register collision triangles?
Ogre::Vector3 vertex[MAX_VERTEX]
Ogre::Vector3 baseOf(Ogre::Vector3 p)
void createMesh(const std::string &materialName="")
If materialName is empty, the default material will be used.
Ogre::Vector3 lastpos
Ogre::SubMesh * mainsub
ground_model_t * m_customGroundmodel
Ogre::Quaternion lastrot
void computePoints(Ogre::Vector3 *pts, Ogre::Vector3 pos, Ogre::Quaternion rot, RoadType type, float width, float bwidth, float bheight)
static constexpr const char * PROROAD_DEFAULT_MATERIAL
Surface friction properties.
Definition SimData.h:704