VR-Engage  2.2
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
17namespace makVrv
18{
19class DtVirtualRealityDriver;
20}
21
22namespace makVre
23{
25{
26//! \ingroup RoleConfigParams
27//! \defgroup ScopeSimLogicRoleParams Scope Sim Logic Role Parameters
28//! \roleInherits{PlayerComponentRoleParams}
29//! Configuration Options for scope simulation logic role.
30//! @{
31
32//! \vreRoleParam{hmdSmoothingAlpha,double,0.8,scopeSimLogic,Alpha value for HMD orientation smoothing when using scopes in VR mode.}
33constexpr const char* hmdSmoothingAlpha = "hmdSmoothingAlpha";
34
35//! \vreRoleParam{hmdSmoothingEnabled,bool,true,scopeSimLogic,Whether to enable HMD orientation smoothing when using scopes in VR mode.}
36constexpr const char* hmdSmoothingEnabled = "hmdSmoothingEnabled";
37
38//! \vreRoleParam{hmdSmoothingThreshold,double,60.0,scopeSimLogic,Threshold angle in degrees for triggering HMD orientation smoothing.}
39constexpr const char* hmdSmoothingThreshold = "hmdSmoothingThreshold";
40
41//! @}
42} // namespace ScopeSimLogicConfig
43
44//! \brief Type identifier for DtScopeSimLogic component
45constexpr const char* DtScopeSimLogicType = "DtScopeSimLogic";
46
47//! \brief Component for managing weapon scope simulation and zoom controls
48//!
49//! DtScopeSimLogic manages zoom functionality for weapon scopes, handling both
50//! discrete zoom level changes and observer view mode adjustments when aiming.
51//! The component responds to zoom increase/decrease messages and automatically
52//! configures VR-specific settings such as head orientation smoothing when in VR mode.
53//! It also enforces first-person view when aiming through a scope and manages the
54//! transition between aiming and non-aiming states.
56{
57public:
58 //! \brief Constructor for DtScopeSimLogic
59 //! \param className Class name for identification, defaults to "DtScopeSimLogic"
60 //!
61 //! Initializes the component with default zoom and smoothing settings
63
64 //! \brief Virtual destructor for DtScopeSimLogic
65 virtual ~DtScopeSimLogic() override;
66
67 //! \brief Initializes the scope simulation logic component
68 //! \param player Pointer to the player station this component belongs to
69 //! \param config Configuration table containing scope settings
70 //! \return True if initialization succeeded, false otherwise
71 //!
72 //! Reads configuration values for HMD smoothing settings, registers message handlers
73 //! for scope zoom messages, and sets up attribute callbacks for aiming state and
74 //! view magnification changes
76
77 //! \brief Performs post-initialization after all components are initialized
78 //! \return True if post-initialization succeeded, false otherwise
79 //!
80 //! Sets up VR-specific configurations if applicable, including
81 //! configuring the VR driver's orientation smoothing settings
82 virtual bool postInitialize() override;
83
84 //! \brief Called every frame to update the component state
85 //! \param dt Delta time since the last frame in seconds
86 //!
87 //! Current implementation is empty as updates occur through message handlers
88 //! and attribute change callbacks
89 virtual void tick(double dt) override;
90
91 //! \brief Shuts down the scope simulation logic component
92 //!
93 //! Removes message handlers and attribute change callbacks
94 virtual void shutdown() override;
95
96 //! \brief Returns the type identifier for this component
97 //! \return The type string for DtScopeSimLogic
98 virtual const char* type() const override;
99
100 //! \brief Handles messages to increase scope zoom level
101 //! \param msg The scope increase zoom message
102 //! \return Message handling result indicating the message was handled
103 //!
104 //! Increases the zoom index and updates the view magnification to the next
105 //! higher zoom level from the configured scopeZoomLevels array
107
108 //! \brief Handles messages to decrease scope zoom level
109 //! \param msg The scope decrease zoom message
110 //! \return Message handling result indicating the message was handled
111 //!
112 //! Decreases the zoom index and updates the view magnification to the next
113 //! lower zoom level from the configured scopeZoomLevels array
115
116 //! \brief Callback for when the aiming state changes
117 //! \param aiming New aiming state (true when aiming, false otherwise)
118 //!
119 //! When entering aiming state, sets initial zoom level, disables third person view,
120 //! and forces first person observer mode. When exiting aiming state, restores the
121 //! previous observer attach mode.
122 virtual void onAimingChanged(bool aiming);
123
124 //! \brief Callback for view magnification attribute changes
125 //! \param mag New magnification value
126 //!
127 //! Current implementation is empty
128 virtual void onViewMagnificationChanged(double mag);
129
130protected:
131 //! \brief Maximum allowed view magnification value
133
134 //! \brief Pointer to the VR driver if available
135 makVrv::DtVirtualRealityDriver* myVrDriver;
136
137 //! \brief Flag indicating if mixed reality was active before entering aiming mode
139
140 //! \brief The observer attach mode used before entering aiming mode
141 //!
142 //! Stored when entering aiming mode so it can be restored when exiting
144
145 //! \brief Flag indicating if HMD orientation smoothing is enabled
147
148 //! \brief Smoothing alpha parameter for HMD orientation smoothing
149 //! \note Higher values (closer to 1.0) produce more smoothing
151
152 //! \brief Threshold parameter for HMD orientation smoothing in degrees per second
153 //! \note Rotation speeds below this threshold will be smoothed
155};
156} // namespace makVre
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:135
DtScopeSimLogic()
Constructor for DtScopeSimLogic.
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:143
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:138
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:154
double myHmdSmoothingAlpha
Smoothing alpha parameter for HMD orientation smoothing.
Definition vreScopeSimLogic.h:150
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:146
double myMaxViewMagnification
Maximum allowed view magnification value.
Definition vreScopeSimLogic.h:132
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:36
constexpr const char * hmdSmoothingAlpha
Definition vreScopeSimLogic.h:33
constexpr const char * hmdSmoothingThreshold
Definition vreScopeSimLogic.h:39
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:25
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
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:45
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.