VR-Engage  2.2
Loading...
Searching...
No Matches
DtSceneObjectMimicUpdater.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file DtSceneObjectMimicUpdater.h
7//! \brief Defines the DtSceneObjectMimicUpdater class that allows one scene object to mimic another's position.
8//!
9//! This updater allows a scene object to follow the position and orientation of another scene object
10//! with an optional offset. This is particularly useful for implementing first-person views,
11//! attached equipment, or any other entity that needs to follow another entity's movements.
12//!
13//! \ingroup vreCommonComponents
14
15#pragma once
16
18
19#include <vrvCore/DtSceneObjectUpdater.h>
20
21namespace makVrv
22{
23//! \brief Forward declaration of the model instance class
24class DtModelInstance;
25
26//! \brief Forward declaration of the OSG model instance class
27class DtOsgModelInstance;
28} // namespace makVrv
29
30namespace osg
31{
32//! \brief Forward declaration of the OSG node class
33class Node;
34} // namespace osg
35
36using namespace makVrv;
37
38namespace makVre
39{
40//! \brief Scene object updater that mimics the position and orientation of another scene object
41//!
42//! The DtSceneObjectMimicUpdater allows one scene object to follow another's position and orientation
43//! with an optional offset. This updater is responsible for connecting to the parent scene object,
44//! tracking its position, and updating the child scene object accordingly. It also handles special
45//! cases like DiGuy character models and configures the child object's rendering properties.
46//!
47//! Common use cases include:
48//! - First-person view models (cockpit interiors, weapon models)
49//! - Attached equipment (backpacks, tools, accessories)
50//! - Character models that need to follow another entity
51class VRECOMMONCOMPONENTS_DLL DtSceneObjectMimicUpdater : public DtSceneObjectUpdater
52{
53public:
54 //! \brief Constructor for DtSceneObjectMimicUpdater
55 //!
56 //! Initializes the updater with default values (no parent object, null model instance,
57 //! and zero speeds).
58 //!
59 //! \param de Reference to the dynamic environment
60 //! \param id Unique identifier for this updater
61 DtSceneObjectMimicUpdater(DtDe& de, DtUniqueID id);
62
63 //! \brief Virtual destructor for DtSceneObjectMimicUpdater
64 //!
65 //! Clears the parent scene object reference to avoid dangling pointers.
66 virtual ~DtSceneObjectMimicUpdater() override;
67
68 //! \brief Updates the scene object's position and orientation
69 //!
70 //! Called each frame to update the scene object's position and orientation based on
71 //! the parent scene object. Performs model checking and position updating.
72 //!
73 //! \param tNow Current simulation time
74 virtual void update(DtTime tNow) override;
75
76 //! \brief Sets the parent scene object to copy position from
77 //!
78 //! Establishes a connection to the specified scene object and sets up a signal/slot
79 //! to handle parent object deletion. If a previous parent was set, disconnects from it.
80 //!
81 //! \param id Unique identifier of the parent scene object
82 virtual void setParentSceneObject(DtUniqueID id);
83
84 //! \brief Sets the offset from the parent object
85 //!
86 //! Defines a local offset vector to apply when positioning this object relative to
87 //! the parent. The offset is applied in the parent's local coordinate system.
88 //!
89 //! \param offset Vector offset to apply (typically in meters)
90 virtual void setModelOffset(const DtVector& offset);
91
92protected:
93 //! \brief Checks if the model instance has changed
94 //!
95 //! Verifies if the current scene object's model instance has changed since the last update.
96 //! If it has, initializes the new model instance by calling initModel().
97 virtual void checkModel();
98
99 //! \brief Initializes a new model instance
100 //!
101 //! Sets up a new model instance, detecting if it's an OSG model instance and configuring it accordingly.
102 //!
103 //! \param modelInstance Pointer to the model instance to initialize
104 virtual void initModel(DtModelInstance* modelInstance);
105
106 //! \brief Sets up OSG nodes for an OSG model instance
107 //!
108 //! Retrieves the root node from the OSG model instance and sets it up.
109 //!
110 //! \param osgModelInstance Pointer to the OSG model instance to configure
111 virtual void setupOsgNodes(DtOsgModelInstance* osgModelInstance);
112
113 //! \brief Configures an OSG node
114 //!
115 //! Sets up rendering properties for the node, including:
116 //! - Disabling intersection testing (making the model not selectable)
117 //! - Disabling shadow casting
118 //! - Setting the render bin to ensure proper rendering order
119 //!
120 //! \param node Pointer to the OSG node to configure
121 virtual void setupOsgNode(osg::Node* node);
122
123 //! \brief Updates the position and orientation
124 //!
125 //! Calculates and applies the position and orientation based on the parent object.
126 //! Handles special cases like DiGuy character models.
127 //!
128 //! \param tNow Current simulation time
129 virtual void updatePosition(DtTime tNow);
130
131 //! \brief Signal handler for parent scene object deletion
132 //!
133 //! Called when the parent scene object is about to be deleted.
134 //! Clears the reference to avoid dangling pointers.
135 //!
136 //! \param id The unique ID of the scene object being deleted
137 virtual void slot_parentSceneObjectToBeDeleted(const DtUniqueID& id);
138
139 //! \brief Pointer to the parent scene object being mimicked
140 //!
141 //! This is the scene object whose position and orientation are being copied.
142 DtSceneObject* myParentSceneObject;
143
144 //! \brief Pointer to the current model instance
145 //!
146 //! The model instance for the scene object being updated.
147 DtModelInstance* myModelInstance;
148
149 //! \brief Offset vector to apply when positioning
150 //!
151 //! Local offset to apply from the parent object's position.
153
154 //! \brief Smoothed linear speed
155 //!
156 //! Cached and smoothed linear speed value for animation purposes.
158
159 //! \brief Smoothed yaw rotation speed
160 //!
161 //! Cached and smoothed yaw rotation speed value for animation purposes.
163};
164} // namespace makVre
double myYawSpeed
Smoothed yaw rotation speed.
Definition DtSceneObjectMimicUpdater.h:162
double myLinearSpeed
Smoothed linear speed.
Definition DtSceneObjectMimicUpdater.h:157
virtual void updatePosition(DtTime tNow)
Updates the position and orientation.
DtSceneObjectMimicUpdater(DtDe &de, DtUniqueID id)
Constructor for DtSceneObjectMimicUpdater.
virtual void setModelOffset(const DtVector &offset)
Sets the offset from the parent object.
DtModelInstance * myModelInstance
Pointer to the current model instance.
Definition DtSceneObjectMimicUpdater.h:147
virtual void checkModel()
Checks if the model instance has changed.
DtVector myModelOffset
Offset vector to apply when positioning.
Definition DtSceneObjectMimicUpdater.h:152
virtual void setParentSceneObject(DtUniqueID id)
Sets the parent scene object to copy position from.
virtual void setupOsgNodes(DtOsgModelInstance *osgModelInstance)
Sets up OSG nodes for an OSG model instance.
DtSceneObject * myParentSceneObject
Pointer to the parent scene object being mimicked.
Definition DtSceneObjectMimicUpdater.h:142
virtual ~DtSceneObjectMimicUpdater() override
Virtual destructor for DtSceneObjectMimicUpdater.
virtual void initModel(DtModelInstance *modelInstance)
Initializes a new model instance.
virtual void slot_parentSceneObjectToBeDeleted(const DtUniqueID &id)
Signal handler for parent scene object deletion.
virtual void update(DtTime tNow) override
Updates the scene object's position and orientation.
virtual void setupOsgNode(osg::Node *node)
Configures an OSG node.
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Definition appLauncherComponent.h:28
Definition DtSceneObjectMimicUpdater.h:31
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.