Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Scene.h
1// trax track library
2// AD 2025
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8//
9// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
10// Copyright (c) 2019 Marc-Michael Horstmann
11//
12// Permission is hereby granted to any person obtaining a copy of this software
13// and associated source code (the "Software"), to use, view, and study the
14// Software for personal or internal business purposes, subject to the following
15// conditions:
16//
17// 1. Redistribution, modification, sublicensing, or commercial use of the
18// Software is NOT permitted without prior written consent from the copyright
19// holder.
20//
21// 2. The Software is provided "AS IS", without warranty of any kind, express
22// or implied.
23//
24// 3. All copies of the Software must retain this license notice.
25//
26// For further information, please contact: horstmann.marc@trendverlag.de
27
28#pragma once
29
30#include "trax/Configuration.h"
31#include "trax/Identified.h"
32#include "trax/Units.h"
33
34#include "spat/Frame.h"
35#include "spat/Box.h"
36
37#include <memory>
38
39namespace trax{
40
41 struct BallAndSocketJoint;
42 struct Body;
43 struct DistanceJoint;
44 struct Geom;
45 struct GeomCuboid;
46 struct GeomCylinder;
47 struct GeomCapsule;
48 struct GeomSphere;
49 struct GeomHeightField;
50 struct GeomMesh;
51 struct Gestalt;
52 struct HingeJoint;
53 struct Shape;
54 struct Simulated;
55 struct Simulator;
56 struct SliderJoint;
57 enum class GeomType : char;
58 class TrackJointFeeder;
60
61
71 struct Scene : Identified<Scene>
72 {
74 static dclspc std::unique_ptr<Scene> Make( const Simulator& simulator ) noexcept;
75
76
78 virtual const char* TypeName() const noexcept = 0;
79
80
84 virtual bool IsValid( bool bSilent = true ) const noexcept = 0;
85
86
89 virtual void Up( const spat::Vector<One>& up ) = 0;
90
91
93 virtual spat::Vector<One> Up() const = 0;
94
95
100 virtual void Gravity( const spat::Vector<Acceleration>& gravityAccelerarion ) = 0;
101
102
104 virtual spat::Vector<Acceleration> Gravity() const = 0;
105
106
112 virtual void Register( Simulated& simulated ) = 0;
113
114
116 virtual void Unregister( const Simulated& simulated ) = 0;
117
118
120 virtual void UnregisterAllSimulated() = 0;
121
122
134 virtual void Simulate() = 0;
135
136 virtual void Simulate( Time forTimePeriod ) = 0;
138
139
141 virtual bool IsSimulationRunning() const noexcept = 0;
142
143
145 virtual Time SimulationTime() const noexcept = 0;
146
147
153 virtual void BeginSimulation() noexcept = 0;
154
155
162 virtual void Loop( Time forTimePeriod ) = 0;
163
164
166 virtual void Step( Time dt = fixed_timestep ) = 0;
167
168
174 virtual void EndSimulation() noexcept = 0;
175
176
178 virtual void Pause() noexcept = 0;
179
180
182 virtual void Resume() noexcept = 0;
183
184
186 virtual void Stop() noexcept = 0;
187
188
189 virtual std::unique_ptr<Body> CreateBody() const = 0;
190
191 virtual std::unique_ptr<Shape> CreateShape() const = 0;
192
193 virtual std::unique_ptr<Gestalt> CreateGestalt() const = 0;
194
195 virtual std::unique_ptr<Gestalt> CreateGestalt( spat::Box<Length> box, Mass mass ) const noexcept = 0;
196
197 virtual std::unique_ptr<Geom> CreateGeom( GeomType type ) const = 0;
198
199 virtual std::unique_ptr<GeomCuboid> CreateGeomCuboid() const = 0;
200
201 virtual std::unique_ptr<GeomCylinder> CreateGeomCylinder() const = 0;
202
203 virtual std::unique_ptr<GeomCapsule> CreateGeomCapsule() const = 0;
204
205 virtual std::unique_ptr<GeomSphere> CreateGeomSphere() const = 0;
206
207 virtual std::unique_ptr<GeomHeightField> CreateGeomHeightField() const = 0;
208
209 virtual std::unique_ptr<GeomMesh> CreateGeomConvexMesh() const = 0;
210
211 virtual std::unique_ptr<GeomMesh> CreateGeomTriangleMesh() const = 0;
212
213
214 virtual std::unique_ptr<HingeJoint> CreateHingeJoint(
215 Body* pBodyA,
216 const spat::Frame<Length,One>& localAnchorA,
217 Body* pBodyB,
218 const spat::Frame<Length,One>& localAnchorB ) const = 0;
219
220 virtual std::unique_ptr<SliderJoint> CreateSliderJoint(
221 Body* pBodyA,
222 const spat::Frame<Length,One>& localAnchorA,
223 Body* pBodyB,
224 const spat::Frame<Length, One>& localAnchorB ) const = 0;
225
226 virtual std::unique_ptr<BallAndSocketJoint> CreateBallAndSocketJoint(
227 Body* pBodyA,
228 const spat::Frame<Length,One>& localAnchorA,
229 Body* pBodyB,
230 const spat::Frame<Length, One>& localAnchorB ) const = 0;
231
232 virtual std::unique_ptr<DistanceJoint> CreateDistanceJoint(
233 Body* pBodyA,
234 const spat::Frame<Length,One>& localAnchorA,
235 Body* pBodyB,
236 const spat::Frame<Length,One>& localAnchorB ) const = 0;
237
238 virtual std::shared_ptr<TrackJointFeeder> CreateTrackJointFeeder(
239 const Body& bodyMoving,
240 const spat::Frame<Length,One>& localAnchor ) noexcept = 0;
241
242 virtual std::shared_ptr<TrackJointFeeder> CreateTrackJointFeeder(
243 const Body& bodyMoving,
244 const spat::Frame<Length,One>& localAnchor,
245 const Body& bodyTrack ) noexcept = 0;
246
247 virtual std::shared_ptr<TrackJointFeederMotorModel> CreateTrackJointFeederMotorModel(
248 const Body& bodyMoving,
249 const spat::Frame<Length,One>& localAnchor ) noexcept = 0;
250
251 virtual std::shared_ptr<TrackJointFeederMotorModel> CreateTrackJointFeederMotorModel(
252 const Body& bodyMoving,
253 const spat::Frame<Length,One>& localAnchor,
254 const Body& bodyTrack ) noexcept = 0;
255
256 virtual void Release( TrackJointFeeder& feeder ) noexcept = 0;
257
258
260 virtual void DumpTasksTo( std::ostream& stream ) const noexcept = 0;
261
262
266 virtual struct Jack& JackOnSimulationStep() noexcept = 0;
267
268
270 virtual struct MultiPlug& PlugToStop() noexcept = 0;
271
272
273 virtual ~Scene() = default;
274 };
275
276}
Class with minimal functionality to support a track joint on a track system.
Definition TrackJointFeeder.h:43
Class with functionality to support a track joint on a track system. Provides a model for friction,...
Definition TrackJointFeeder.h:198
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
Value< Dimension< 0, 1, 0 > > Mass
Mass.
Definition DimensionedValues.h:327
Value< Dimension< 0, 0, 1 > > Time
Time.
Definition DimensionedValues.h:329
Value< Dimension< 1, 0, -2 > > Acceleration
Acceleration.
Definition DimensionedValues.h:332
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
constexpr Time fixed_timestep
The fixed timestep to use with the simulation.
Definition Units.h:136
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 3D - vector in cartesian coordinates.
Definition Vector.h:48
Definition Joint.h:125
A dynamic object in physical space.
Definition Body.h:44
Definition Joint.h:132
A Capsule is a Cylinder with round caps.
Definition Geom.h:220
Rectangular cuboid shape.
Definition Geom.h:182
Cylinder shaped Geom.
Definition Geom.h:201
Definition Geom.h:248
A Geom is used for collision detection. It differs from a Shape in that it defines the most simple el...
Definition Geom.h:50
Definition Geom.h:281
A sphere shaped Geom.
Definition Geom.h:240
A Gestalt is a Body with a Shape.
Definition Gestalt.h:100
Definition Joint.h:97
A jack a plug can get connected with.
Definition Jack.h:83
A MultiPlug provides a variable number of actual Plugs to one input slot.
Definition Plug.h:307
A physical simulation scene for running a simulation and creating physical objects in the scene.
Definition Scene.h:72
virtual void Resume() noexcept=0
Resumes the simulation.
static dclspc std::unique_ptr< Scene > Make(const Simulator &simulator) noexcept
Makes a Scene object.
virtual void Gravity(const spat::Vector< Acceleration > &gravityAccelerarion)=0
Sets the vector of gravity acceleration.
virtual void Step(Time dt=fixed_timestep)=0
Completes one simulation step.
virtual void Register(Simulated &simulated)=0
Registers a Simulated object for simulation.
virtual void Stop() noexcept=0
Stops the simulation loop.
virtual struct Jack & JackOnSimulationStep() noexcept=0
A Jack that triggers a pulse once a simulation step.
virtual void Up(const spat::Vector< One > &up)=0
Sets the up direction for this simulator.
virtual void BeginSimulation() noexcept=0
Prepares the simulation to start.
virtual void Unregister(const Simulated &simulated)=0
Unregisters a Simulated object from simulation.
virtual bool IsValid(bool bSilent=true) const noexcept=0
Checks whether the scene is valid.
virtual struct MultiPlug & PlugToStop() noexcept=0
A Plug that stops a running simulation.
virtual Time SimulationTime() const noexcept=0
virtual void DumpTasksTo(std::ostream &stream) const noexcept=0
Dumps information about all tasks to the given stream.
virtual void EndSimulation() noexcept=0
Cleans up after the simulation ends.
virtual void Loop(Time forTimePeriod)=0
Steps the simulation by fixed_timestep until forTimePeriod expires.
virtual const char * TypeName() const noexcept=0
virtual void UnregisterAllSimulated()=0
Unregisters all Simulated objects from simulation.
virtual void Pause() noexcept=0
Pauses the simulation.
virtual bool IsSimulationRunning() const noexcept=0
A Shape is a collection of Geoms.
Definition Shape.h:41
A simulated object. Register the object with a scene to get called back for Update,...
Definition Simulated.h:39
Interface for the physics simulator.
Definition Simulator.h:59
Definition Joint.h:116