Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Camera.h
1// Copyright (c) 2021 Marc-Michael Horstmann. All Rights Reserved.
2//
3// trax track library
4// AD 2016
5//
6// "the resolution of all the fruitless searches"
7//
8// Peter Gabriel
9
10#pragma once
11
12#include "trax/Configuration.h"
13#include "CameraType.h"
14#include "trax/Identified.h"
15#include "trax/Units.h"
16#include "trax/collections/Collection.h"
17
18#include "spat/Frame.h"
19//#include "TriggerShape.h"
20
21namespace common{
22 template<typename> struct Interval;
23}
24
25namespace spat{
26 template<typename> class Transformation;
27}
28
29namespace trax{
30
31 struct Body;
32 struct GeomList;
33 struct Module;
34
35 class Location;
36
38 struct Frustum{
39 static const Angle default_fovy;
40 static const One default_aspect;
41 static const Length default_nearPlane;
42 static const Length default_farPlane;
43
44 virtual void SetFromFofy( Angle fovy = default_fovy, One aspect = default_aspect, Length zn = default_nearPlane, Length zf = default_farPlane ) = 0;
45
46 virtual void SetFromDimensions( Length width, Length height, Length zn = default_nearPlane, Length zf = default_farPlane ) = 0;
47
48 virtual void PlaneDistances( const common::Interval<Length>& planes ) = 0;
49
50 virtual Length NearPlaneDistance() const = 0;
51
52 virtual Length FarPlaneDistance() const = 0;
53
54 virtual void Width( Length width ) = 0;
55
56 virtual Length Width() const = 0;
57
58 virtual void Height( Length height ) = 0;
59
60 virtual Length Height() const = 0;
61
63 virtual void Fovy( Angle fovy ) = 0;
64
66 virtual Angle Fovy() const = 0;
67
69 virtual void AspectRatio( One aspect ) = 0;
70
72 virtual One AspectRatio() const = 0;
73
74 virtual void ProjectionMatrix( const spat::Transformation<Real>& projection ) = 0;
75
76 virtual const spat::Transformation<Real>& ProjectionMatrix() const = 0;
77
78 virtual spat::Transformation<Real>& ProjectionMatrix() = 0;
79
80 virtual ~Frustum() = default;
81 Frustum( const Frustum& ) = delete;
82 Frustum( Frustum&& ) = delete;
83 Frustum& operator=( const Frustum& ) = delete;
84 Frustum& operator=( Frustum&& ) = delete;
85 protected:
86 Frustum() = default;
87 };
88
90 struct Camera : Frustum,
91 Identified<Camera>
92 {
94 static dclspc std::unique_ptr<Camera> Make( CameraType type = CameraType::cam_basic ) noexcept;
95
96
98 virtual const char* TypeName() const noexcept = 0;
99
100
101 virtual Camera& operator=( const Camera& camera ) = 0;
102
103
105 virtual CameraType GetType() const = 0;
106
107
108 // Object's pose:
109
113 virtual void SetFrame( const spat::Frame<Length,One>& frame ) = 0;
114
115
119 virtual const spat::Frame<Length,One>& GetFrame() const = 0;
120
121 virtual spat::Frame<Length,One>& GetFrame() = 0;
123
124
128 virtual spat::Vector<Velocity> GetVelocity() const = 0;
129
131 virtual void EyePoint( const spat::Position<Length>& eyePoint ) = 0;
132
133 virtual spat::Position<Length> EyePoint() const = 0;
134
135 virtual void Up( const spat::Vector<One>& up ) = 0;
136
137 virtual spat::Vector<One> Up() const = 0;
138
139 virtual void LookAt( const spat::Position<Length>& lookAtPoint ) = 0;
140
141 virtual spat::Position<Length> LookAt() const = 0;
142
143
145 virtual bool InFrustum( const spat::Position<Length>& position ) const = 0;
146 };
147
149 struct AnimatedCamera : virtual Camera{
150
151 using Camera::operator=;
152
155 virtual void AttachTo( std::shared_ptr<Module> pModule ) = 0;
156
157
159 virtual std::shared_ptr<Module> GetModule() const = 0;
160
161
162 virtual std::vector<GeomList*> OverlapQuery( unsigned int filterflags ) const = 0;
163
164 virtual GeomList* OverlapQueryAny( unsigned int filterflags ) const = 0;
165
166
170 virtual void Update() = 0;
171
172
174 virtual void StepBack() = 0;
175
176
178 virtual void Stop() = 0;
179
180
182 virtual void Reset() = 0;
183
184
188 virtual void MaximumLinearVelocity( Velocity maxVelocity ) = 0;
189
190 virtual Velocity MaximumLinearVelocity() const = 0;
191
192
194 virtual void SetVelocity( const spat::Vector<Velocity>& velocity ) = 0;
195
196 virtual void SetVelocity( const spat::Vector<Velocity>& linearVelocity, const spat::Vector<AngularVelocity>& rotationalVelocity ) = 0;
197
199 virtual void RotationalVelocity( const spat::Vector<AngularVelocity>& rotvel ) = 0;
200
209
210 virtual void ControllerTranslateX( Velocity dx ) = 0;
211
212 virtual void ControllerTranslateY( Velocity dy ) = 0;
213
214 virtual void ControllerTranslateZ( Velocity dz ) = 0;
215
216 virtual void ControllerRotateX( AngularVelocity dx ) = 0;
217
218 virtual void ControllerRotateY( AngularVelocity dy ) = 0;
219
220 virtual void ControllerRotateZ( AngularVelocity dz ) = 0;
222
226
227 virtual void DampingTranslate( Real damping ) = 0;
228
229 virtual Real DampingTranslate() const = 0;
230
231 virtual void DampingRotate( Real damping ) = 0;
232
233 virtual Real DampingRotate() const = 0;
235 };
236
238 struct BodyCam : virtual AnimatedCamera{
239
240 using Camera::operator=;
241
243
246 virtual void AttachTo( std::shared_ptr<Body> pBody ) = 0;
247
248
250 virtual std::shared_ptr<Body> GetBody() const = 0;
251
252
257
258 virtual void Center( const spat::Frame<Length,One>& center ) = 0;
259
260 virtual const spat::Frame<Length,One>& Center() const = 0;
262
263
266 virtual bool GetLoose() const = 0;
267
268
271 virtual bool BodyRealtiveRotations() const = 0;
272
273 virtual void PhiLimits( const common::Interval<Angle>& limits ) = 0;
274
275 virtual const common::Interval<Angle>& PhiLimits() const = 0;
276
277 virtual void PhiResetValue( Angle phi ) = 0;
278
279 virtual Angle PhiResetValue() const = 0;
280
281 virtual void Phi( Angle phi ) = 0;
282
283 virtual Angle Phi() const = 0;
284
285
286 virtual void ThetaLimits( const common::Interval<Angle>& limits ) = 0;
287
288 virtual const common::Interval<Angle>& ThetaLimits() const = 0;
289
290 virtual void ThetaResetValue( Angle theta ) = 0;
291
292 virtual Angle ThetaResetValue() const = 0;
293
294 virtual void Theta( Angle theta ) = 0;
295
296 virtual Angle Theta() const = 0;
297
298
299 virtual void RadiusLimits( const common::Interval<Length>& limits ) = 0;
300
301 virtual const common::Interval<Length>& RadiusLimits() const = 0;
302
303 virtual void RadiusResetValue( Length radius ) = 0;
304
305 virtual Length RadiusResetValue() const = 0;
306
307 virtual void Radius( Length radius ) = 0;
308
309 virtual Length Radius() const = 0;
310 };
311
312
314 struct DollyCam : Camera{
315
316 using Camera::operator=;
317
318 virtual const Location& GetLocation() const = 0;
319 };
320
322 struct CameraCollection : Collection<CameraCollection,Camera>/*,
323 virtual TriggerShapeCollection*/
324 {
326 static dclspc std::unique_ptr<CameraCollection> Make() noexcept;
327
328
329 virtual void UserCameraType( CameraType type ) = 0;
330
331 virtual CameraType UserCameraType() const = 0;
332
333 virtual void UserStartCameraID( IDType id ) = 0;
334
335 virtual IDType UserStartCameraID() const = 0;
336
337 //virtual void Update( const Simulator& simulator ) = 0;
338
339 //using TriggerShapeCollection::Update;
340 };
341
342 struct Fleet;
343 struct Train;
344
345
347 //dclspc std::vector<std::shared_ptr<Train>> GetVisibleTrains( const Fleet& fleet, const Camera& camera );
348}
Homogenous transformation matrix.
Definition Matrix.h:387
A Location specifies a position on a track system by referencing a track and a TrackLocation on it.
Definition Location.h:110
Namespace of common utility classes and methods.
Definition Helpers.h:43
Value< Dimension< 0, 0, -1 > > AngularVelocity
Angular velocity.
Definition DimensionedValues.h:323
Value< Dimension< 1, 0, -1 > > Velocity
Velocity.
Definition DimensionedValues.h:331
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
Value< Dimension< 0, 0, 0 > > Angle
Angle in radians.
Definition DimensionedValues.h:320
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
CameraType
Type of the camera.
Definition CameraType.h:19
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Implements a 3D - vector in cartesian coordinates.
Definition Vector.h:48
Interface for movable cameras.
Definition Camera.h:149
virtual std::shared_ptr< Module > GetModule() const =0
virtual void Reset()=0
Resets the position of the camera.
virtual void Stop()=0
Stops any animated inertial movement of the camera.
virtual void StepBack()=0
Reverts the last positional change done by Update().
virtual void SetVelocity(const spat::Vector< Velocity > &velocity)=0
Set the camera velocity directly.
virtual void MaximumLinearVelocity(Velocity maxVelocity)=0
Sets a maximum velocity that will not be exceeded.
virtual void RotationalVelocity(const spat::Vector< AngularVelocity > &rotvel)=0
Set the rotational velocity directly.
virtual void Update()=0
Updates the camera by the fixed time step.
virtual void AttachTo(std::shared_ptr< Module > pModule)=0
If attached to a module, the camera will stay on top of the terrain and will not penetrate geoms in t...
Interface for cameras that can get attached to a Body.
Definition Camera.h:238
virtual void Theta(Angle theta)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual const common::Interval< Length > & RadiusLimits() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void ThetaResetValue(Angle theta)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual const common::Interval< Angle > & ThetaLimits() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual Angle Phi() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual bool BodyRealtiveRotations() const =0
virtual const spat::Frame< Length, One > & Center() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual const common::Interval< Angle > & PhiLimits() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void PhiResetValue(Angle phi)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual Length Radius() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual std::shared_ptr< Body > GetBody() const =0
virtual Length RadiusResetValue() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void Phi(Angle phi)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void PhiLimits(const common::Interval< Angle > &limits)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual Angle ThetaResetValue() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void RadiusLimits(const common::Interval< Length > &limits)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual bool GetLoose() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void RadiusResetValue(Length radius)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void Center(const spat::Frame< Length, One > &center)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual Angle Theta() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual Angle PhiResetValue() const =0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void ThetaLimits(const common::Interval< Angle > &limits)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
virtual void Radius(Length radius)=0
Signals that the user put the camera into a state that might signal to cut loose from the body.
A dynamic object in physical space.
Definition Body.h:44
Collection to store cameras.
Definition Camera.h:324
static dclspc std::unique_ptr< CameraCollection > Make() noexcept
Makes a CameraCollection object.
Base Camera interface.
Definition Camera.h:92
static dclspc std::unique_ptr< Camera > Make(CameraType type=CameraType::cam_basic) noexcept
Makes a Camera object.
virtual spat::Vector< Velocity > GetVelocity() const =0
Gets the current velocity.
virtual void EyePoint(const spat::Position< Length > &eyePoint)=0
Sets the camera to look at eyePoint.
virtual bool InFrustum(const spat::Position< Length > &position) const =0
virtual const char * TypeName() const noexcept=0
virtual CameraType GetType() const =0
virtual void SetFrame(const spat::Frame< Length, One > &frame)=0
Sets position and orientation (pose) in global coordinates.
Interface for Cameras movable along tracks.
Definition Camera.h:314
A Fleet holds Trains and (topmost) Bogies via their common interface RailRunner.
Definition Fleet.h:48
virtual One AspectRatio() const =0
virtual void Fovy(Angle fovy)=0
The Field Of View angle in radiants.
virtual Angle Fovy() const =0
virtual void AspectRatio(One aspect)=0
Type used for IDs in the trax library.
Definition IDType.h:43
A module is a chunck of railroad stuff that is all located in one rectangular volume.
Definition Module.h:60
A Train is a collection of TrainComponents that are coupled in a row.
Definition Train.h:43