VR-Engage  2.3
Loading...
Searching...
No Matches
vreScopeSimLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreScopeSimLogic.h
7//! \brief Component for managing weapon scope zoom functionality
8//! \ingroup vreCommonComponents
9
10#pragma once
11
16
18
19namespace makVrv
20{
21class DtVirtualRealityDriver;
22}
23
24namespace makVre
25{
27{
28//! \ingroup RoleConfigParams
29//! \defgroup ScopeSimLogicRoleParams Scope Sim Logic Role Parameters
30//! \roleInherits{PlayerComponentRoleParams}
31//! Configuration Options for scope simulation logic role.
32//! @{
33
34//! \vreRoleParam{hmdSmoothingAlpha,double,0.8,scopeSimLogic,Alpha value for HMD orientation smoothing when using scopes in VR mode.}
35constexpr const char* hmdSmoothingAlpha = "hmdSmoothingAlpha";
36
37//! \vreRoleParam{hmdSmoothingEnabled,bool,true,scopeSimLogic,Whether to enable HMD orientation smoothing when using scopes in VR mode.}
38constexpr const char* hmdSmoothingEnabled = "hmdSmoothingEnabled";
39
40//! \vreRoleParam{hmdSmoothingThreshold,double,60.0,scopeSimLogic,Threshold angle in degrees for triggering HMD orientation smoothing.}
41constexpr const char* hmdSmoothingThreshold = "hmdSmoothingThreshold";
42
43//! @}
44} // namespace ScopeSimLogicConfig
45
46//! \brief Type identifier for DtScopeSimLogic component
47constexpr const char* DtScopeSimLogicType = "DtScopeSimLogic";
48
49//! \brief Component for managing weapon scope simulation and zoom controls
50//!
51//! DtScopeSimLogic manages zoom functionality for weapon scopes, handling both
52//! discrete zoom level changes and observer view mode adjustments when aiming.
53//! The component responds to zoom increase/decrease messages and automatically
54//! configures VR-specific settings such as head orientation smoothing when in VR mode.
55//! It also enforces first-person view when aiming through a scope and manages the
56//! transition between aiming and non-aiming states.
58{
59public:
60 //! \brief Constructor for DtScopeSimLogic
61 //! \param className Class name for identification, defaults to "DtScopeSimLogic"
62 //!
63 //! Initializes the component with default zoom and smoothing settings
65
66 //! \brief Virtual destructor for DtScopeSimLogic
67 virtual ~DtScopeSimLogic() override;
68
69 //! \brief Initializes the scope simulation logic component
70 //! \param player Pointer to the player station this component belongs to
71 //! \param config Configuration table containing scope settings
72 //! \return True if initialization succeeded, false otherwise
73 //!
74 //! Reads configuration values for HMD smoothing settings, registers message handlers
75 //! for scope zoom messages, and sets up attribute callbacks for aiming state and
76 //! view magnification changes
78
79 //! \brief Performs post-initialization after all components are initialized
80 //! \return True if post-initialization succeeded, false otherwise
81 //!
82 //! Sets up VR-specific configurations if applicable, including
83 //! configuring the VR driver's orientation smoothing settings
84 virtual bool postInitialize() override;
85
86 //! \brief Called every frame to update the component state
87 //! \param dt Delta time since the last frame in seconds
88 //!
89 //! Current implementation is empty as updates occur through message handlers
90 //! and attribute change callbacks
91 virtual void tick(double dt) override;
92
93 //! \brief Shuts down the scope simulation logic component
94 //!
95 //! Removes message handlers and attribute change callbacks
96 virtual void shutdown() override;
97
98 //! \brief Returns the type identifier for this component
99 //! \return The type string for DtScopeSimLogic
100 virtual const char* type() const override;
101
102 //! \brief Handles messages to increase scope zoom level
103 //! \param msg The scope increase zoom message
104 //! \return Message handling result indicating the message was handled
105 //!
106 //! Increases the zoom index and updates the view magnification to the next
107 //! higher zoom level from the configured scopeZoomLevels array
109
110 //! \brief Handles messages to decrease scope zoom level
111 //! \param msg The scope decrease zoom message
112 //! \return Message handling result indicating the message was handled
113 //!
114 //! Decreases the zoom index and updates the view magnification to the next
115 //! lower zoom level from the configured scopeZoomLevels array
117
118 //! \brief Callback for when the aiming state changes
119 //! \param aiming New aiming state (true when aiming, false otherwise)
120 //!
121 //! When entering aiming state, sets initial zoom level, disables third person view,
122 //! and forces first person observer mode. When exiting aiming state, restores the
123 //! previous observer attach mode.
124 virtual void onAimingChanged(bool aiming);
125
126 //! \brief Callback for view magnification attribute changes
127 //! \param mag New magnification value
128 //!
129 //! Current implementation is empty
130 virtual void onViewMagnificationChanged(double mag);
131
132protected:
133 //! \brief Maximum allowed view magnification value
135
136 //! \brief Pointer to the VR driver if available
137 makVrv::DtVirtualRealityDriver* myVrDriver;
138
139 //! \brief Flag indicating if mixed reality was active before entering aiming mode
141
142 //! \brief The observer attach mode used before entering aiming mode
143 //!
144 //! Stored when entering aiming mode so it can be restored when exiting
146
147 //! \brief Flag indicating if HMD orientation smoothing is enabled
149
150 //! \brief Smoothing alpha parameter for HMD orientation smoothing
151 //! \note Higher values (closer to 1.0) produce more smoothing
153
154 //! \brief Threshold parameter for HMD orientation smoothing in degrees per second
155 //! \note Rotation speeds below this threshold will be smoothed
157
158 //! \brief Handle for available scope zoom levels.
159 //! \vreAttrKey{scopeZoomLevels}
161 //! \brief Handle for current scoped view magnification.
162 //! \vreAttrKey{viewMagnification}
164 //! \brief Handle for current scope zoom level index.
165 //! \vreAttrKey{scopeZoomIndex}
167};
168} // namespace makVre
Provides handle classes for safe access to attributes.
Type-specific handle class for attributes.
Definition attributeHandle.h:229
Table-based access to Lua state for configuration data.
Definition initializer.h:38
virtual DtPlayerStation & player()
Gets the player station.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
makVrv::DtVirtualRealityDriver * myVrDriver
Pointer to the VR driver if available.
Definition vreScopeSimLogic.h:137
DtAttributeHandleType< double > myViewMagnificationAttr
Handle for current scoped view magnification.
Definition vreScopeSimLogic.h:163
DtScopeSimLogic()
Constructor for DtScopeSimLogic.
DtAttributeHandleType< int > myScopeZoomIndexAttr
Handle for current scope zoom level index.
Definition vreScopeSimLogic.h:166
virtual void shutdown() override
Shuts down the scope simulation logic component.
virtual const char * type() const override
Returns the type identifier for this component.
ObserverAttachMode myLastObserverAttachMode
The observer attach mode used before entering aiming mode.
Definition vreScopeSimLogic.h:145
virtual void onViewMagnificationChanged(double mag)
Callback for view magnification attribute changes.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the scope simulation logic component.
bool myMrWasActive
Flag indicating if mixed reality was active before entering aiming mode.
Definition vreScopeSimLogic.h:140
virtual makVre::DtVreMessageResult handleScopeIncreaseZoom(makVre::DtVreMessage *msg)
Handles messages to increase scope zoom level.
virtual void onAimingChanged(bool aiming)
Callback for when the aiming state changes.
double myHmdSmoothingThreshold
Threshold parameter for HMD orientation smoothing in degrees per second.
Definition vreScopeSimLogic.h:156
double myHmdSmoothingAlpha
Smoothing alpha parameter for HMD orientation smoothing.
Definition vreScopeSimLogic.h:152
DtAttributeHandleType< std::vector< double > > myScopeZoomLevelsAttr
Handle for available scope zoom levels.
Definition vreScopeSimLogic.h:160
virtual ~DtScopeSimLogic() override
Virtual destructor for DtScopeSimLogic.
virtual void tick(double dt) override
Called every frame to update the component state.
bool myHmdSmoothingEnabled
Flag indicating if HMD orientation smoothing is enabled.
Definition vreScopeSimLogic.h:148
double myMaxViewMagnification
Maximum allowed view magnification value.
Definition vreScopeSimLogic.h:134
virtual makVre::DtVreMessageResult handleScopeDecreaseZoom(makVre::DtVreMessage *msg)
Handles messages to decrease scope zoom level.
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
constexpr const char * hmdSmoothingEnabled
Definition vreScopeSimLogic.h:38
constexpr const char * hmdSmoothingAlpha
Definition vreScopeSimLogic.h:35
constexpr const char * hmdSmoothingThreshold
Definition vreScopeSimLogic.h:41
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition vreScopeSimLogic.h:27
!
Definition glsVreMessageUtil.h:50
ObserverAttachMode
Enumeration of camera/observer attachment offsets.
Definition stateDefines.h:44
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtScopeSimLogicType
Type identifier for DtScopeSimLogic component.
Definition vreScopeSimLogic.h:47
Definition appLauncherComponent.h:28
Defines the DtPlayerComponent base class for VR-Engage role components.
Common enumeration definitions used throughout the VREngage system.
Defines the base class for all VREngage messages.