Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Geom.h
1// trax track library
2// AD 2014
3//
4// "Now I'm ready
5// to rise again"
6//
7// Gabrielle
8//
9//
10// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
11// Copyright (c) 2019 Marc-Michael Horstmann
12//
13// Permission is hereby granted to any person obtaining a copy of this software
14// and associated source code (the "Software"), to use, view, and study the
15// Software for personal or internal business purposes, subject to the following
16// conditions:
17//
18// 1. Redistribution, modification, sublicensing, or commercial use of the
19// Software is NOT permitted without prior written consent from the copyright
20// holder.
21//
22// 2. The Software is provided "AS IS", without warranty of any kind, express
23// or implied.
24//
25// 3. All copies of the Software must retain this license notice.
26//
27// For further information, please contact: horstmann.marc@trendverlag.de
28
29#pragma once
30
31#include "trax/Configuration.h"
32#include "trax/Units.h"
33//#include "GeomType.h"
34
35#include "spat/Frame.h"
36#include "spat/Box.h"
37#include "spat/Position2D.h"
38
39#include <memory>
40#include <vector>
41
42namespace trax{
43
44 struct Material;
45 enum class GeomType : char;
46
50 struct Geom{
51
53 virtual const char* TypeName() const noexcept = 0;
54
55
61 virtual std::unique_ptr<Geom> Instance() const noexcept = 0;
62
63
64 // Geom's name:
65
70 virtual void SetName( const char* name ) noexcept = 0;
71
72
74 virtual const char* GetName() const noexcept = 0;
75
76
77
82 virtual void SetFrame( const spat::Frame<Length,One>& frame ) noexcept = 0;
83
84
86 virtual void GetFrame( spat::Frame<Length,One>& frame ) const noexcept = 0;
87
88
91 virtual spat::Box<Length> GetExtent() const noexcept = 0;
92
93
95 virtual void SetMaterial( const Material& material ) noexcept = 0;
96
97
99 virtual const Material& GetMaterial() const noexcept = 0;
100
101
103 virtual GeomType GetGeomType() const noexcept = 0;
104
105
110 enum Filters : unsigned int{
111 none = 0,
112 fBogie = 0x00000001,
113 fChildBogie = 0x00000002,
114 fWheelset = 0x00000004,
115 fCargo = 0x00000008,
116 fTerrain = 0x00000010,
117 fBogieSpace = 0x00000020,
118 fCrane = 0x00000040,
119 fConstruction = 0x00000080,
120
121 fHook = 0x00000100,
122 fHookFixed = 0x00000200,
123 fCouplingNorth = 0x00000400,
124 fCouplingSouth = 0x00000800,
125
126 fTriggerShape = 0x00001000,
127 fCabin = 0x00002000,
128 fBogieNoCabin = 0x00004000,
129 fBuffer = 0x00008000,
130 fTrack = 0x00010000,
131 fMovableTrack = 0x00020000,
132
133 fAll = 0x2fffffff
134 };
135
136
141 virtual void TypeFilter( Filters type ) noexcept = 0;
142
143
145 virtual Filters TypeFilter() const noexcept = 0;
146
147
159 virtual void CollisionFilter( unsigned int collideWith ) noexcept = 0;
160
161
163 virtual unsigned int CollisionFilter() const noexcept = 0;
164
165
166 virtual ~Geom() = default;
167 };
168
169
170 dclspc std::string ToString( Geom::Filters filter );
171
172 dclspc Geom::Filters GeomFilter( const std::string& filter );
173
174 dclspc unsigned int CollisionFilterFor( Geom::Filters filter ) noexcept;
175
176 constexpr bool IsTrigger( unsigned int filter ) noexcept{
177 return (filter & (Geom::fHook | Geom::fHookFixed | Geom::fCouplingNorth | Geom::fCouplingSouth)) ? true : false;
178 }
179
180
182 struct GeomCuboid : virtual Geom{
183
185 virtual void Diagonal( const spat::Vector<Length>& diagonal ) = 0;
186
187
189 virtual const spat::Vector<Length>& Diagonal() const = 0;
190
191
193 virtual void SetFromBox( const spat::Box<Length>& box ) = 0;
194 };
195
196
201 struct GeomCylinder : virtual Geom{
202
203 virtual void Radius( Length radius ) = 0;
204
205 virtual Length Radius() const = 0;
206
207 virtual void SetLength( Length length ) = 0;
208
209 virtual Length GetLength() const = 0;
210 };
211
212
220 struct GeomCapsule : virtual Geom{
221
223 virtual void Radius( Length radius ) = 0;
224
225
227 virtual Length Radius() const = 0;
228
229
231 virtual void SetLength( Length length ) = 0;
232
233
235 virtual Length GetLength() const = 0;
236 };
237
238
240 struct GeomSphere : virtual Geom{
241
242 virtual void Radius( Length radius ) = 0;
243
244 virtual Length Radius() const = 0;
245 };
246
247
248 struct GeomHeightField : virtual Geom{
249
261 virtual bool Create( const short* pSamples, const bool* pbHoles, int nRows, int nCols, Real vertScale, Real horzScale ) = 0;
262
263
268 virtual bool CreateEEPStyle( const short* pSamples, const bool* pbHoles, int nRows, int nCols, Real vertScale, Real horzScale ) = 0;
269
270
271 virtual Length Height( const spat::Position2D<Length>& parameter ) const = 0;
272
273
274 virtual void Get( const spat::Position2D<Length>& parameter, spat::Position<Length>& pos ) const= 0;
275
276
277 virtual void Get( const spat::Position2D<Length>& parameter, spat::Frame<Length,One>& frame ) const = 0;
278 };
279
280
281 struct GeomMesh : virtual Geom{
282
283 virtual bool Create( const std::vector<spat::Position<Length>>& points ) = 0;
284
285 virtual bool Create( const std::vector<spat::Position<Length>>& points, const std::vector<int>& indices ) = 0;
286
287
288 };
289}
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
float Real
Underlying floating point type to be used with the dim library.
Definition DimensionedValues.h:190
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
GeomType
Type of a geom.
Definition GeomType.h:33
Axis aligned box.
Definition Box.h:41
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Implements a 2D - position in cartesian coordinates.
Definition Position2D.h:45
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Implements a 3D - vector in cartesian coordinates.
Definition Vector.h:48
A Capsule is a Cylinder with round caps.
Definition Geom.h:220
virtual Length Radius() const =0
Gets the radius aof the cylinder part and the caps.
virtual void Radius(Length radius)=0
Sets the radius aof the cylinder part and the caps.
virtual Length GetLength() const =0
Gets the length of the capsule without the caps.
virtual void SetLength(Length length)=0
Sets the length of the capsule without the caps.
Rectangular cuboid shape.
Definition Geom.h:182
virtual const spat::Vector< Length > & Diagonal() const =0
Get the edge lengthes of the cuboid.
virtual void Diagonal(const spat::Vector< Length > &diagonal)=0
Set the edge lengthes of the cuboid shape.
virtual void SetFromBox(const spat::Box< Length > &box)=0
Set the dimensions and the frame of the cuboid to represent an axis aligned box.
Cylinder shaped Geom.
Definition Geom.h:201
Definition Geom.h:248
virtual bool Create(const short *pSamples, const bool *pbHoles, int nRows, int nCols, Real vertScale, Real horzScale)=0
Creates a heightfield from data.
virtual bool CreateEEPStyle(const short *pSamples, const bool *pbHoles, int nRows, int nCols, Real vertScale, Real horzScale)=0
creates a heightfield from data in the EEP style.
A Geom is used for collision detection. It differs from a Shape in that it defines the most simple el...
Definition Geom.h:50
virtual GeomType GetGeomType() const noexcept=0
virtual void SetFrame(const spat::Frame< Length, One > &frame) noexcept=0
Sets position and orientation (pose) relative to a Body's frame.
virtual void GetFrame(spat::Frame< Length, One > &frame) const noexcept=0
Gets the pose relative to a Body's frame.
virtual void SetName(const char *name) noexcept=0
Sets the name of the Geom.
virtual void TypeFilter(Filters type) noexcept=0
Specify a flag for the type of this Geom.
virtual spat::Box< Length > GetExtent() const noexcept=0
Gets the minimum axis aligned box that includes the the Geom completely.
virtual const char * GetName() const noexcept=0
virtual const Material & GetMaterial() const noexcept=0
virtual Filters TypeFilter() const noexcept=0
virtual void CollisionFilter(unsigned int collideWith) noexcept=0
Specify the collision bitfield.
virtual void SetMaterial(const Material &material) noexcept=0
Sets the material to be applied with the Geom.
virtual const char * TypeName() const noexcept=0
virtual std::unique_ptr< Geom > Instance() const noexcept=0
Creates a new geom that will share shape data with the existing one.
Filters
Filter flags that will serve in fast collision testing.
Definition Geom.h:110
Definition Geom.h:281
A sphere shaped Geom.
Definition Geom.h:240
Definition Material.h:34