summaryrefslogtreecommitdiff
path: root/servers/xr/xr_positional_tracker.h
blob: 895bcab215e7e39876a9da18ea5ea907d3668229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*************************************************************************/
/*  xr_positional_tracker.h                                              */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                      https://godotengine.org                          */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/

#ifndef XR_POSITIONAL_TRACKER_H
#define XR_POSITIONAL_TRACKER_H

#include "core/os/thread_safe.h"
#include "scene/resources/mesh.h"
#include "servers/xr/xr_pose.h"
#include "servers/xr_server.h"

/**
	@author Bastiaan Olij <mux213@gmail.com>

	The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset.
	An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation.
	This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
*/

class XRPositionalTracker : public RefCounted {
	GDCLASS(XRPositionalTracker, RefCounted);
	_THREAD_SAFE_CLASS_

public:
	enum TrackerHand {
		TRACKER_HAND_UNKNOWN, /* unknown or not applicable */
		TRACKER_HAND_LEFT, /* controller is the left hand controller */
		TRACKER_HAND_RIGHT /* controller is the right hand controller */
	};

private:
	XRServer::TrackerType type; // type of tracker
	StringName name; // (unique) name of the tracker
	String description; // description of the tracker, this is interface dependent, for OpenXR this will be the interaction profile bound for to the tracker
	TrackerHand hand; // if known, the hand this tracker is held in

	Map<StringName, Ref<XRPose>> poses;
	Map<StringName, Variant> inputs;

	int joy_id; // if we also have a related joystick entity, the id of the joystick
	Ref<Mesh> mesh; // when available, a mesh that can be used to render this tracker
	real_t rumble; // rumble strength, 0.0 is off, 1.0 is maximum, note that we only record here, xr_interface is responsible for execution

protected:
	static void _bind_methods();

public:
	void set_tracker_type(XRServer::TrackerType p_type);
	XRServer::TrackerType get_tracker_type() const;
	void set_tracker_name(const StringName &p_name);
	StringName get_tracker_name() const;
	void set_tracker_desc(const String &p_desc);
	String get_tracker_desc() const;
	XRPositionalTracker::TrackerHand get_tracker_hand() const;
	void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand);

	bool has_pose(const StringName &p_action_name) const;
	Ref<XRPose> get_pose(const StringName &p_action_name) const;
	void invalidate_pose(const StringName &p_action_name);
	void set_pose(const StringName &p_action_name, const Transform3D &p_transform, const Vector3 &p_linear_velocity, const Vector3 &p_angular_velocity);

	Variant get_input(const StringName &p_action_name) const;
	void set_input(const StringName &p_action_name, const Variant &p_value);

	// TODO replace by new implementation
	real_t get_rumble() const;
	void set_rumble(real_t p_rumble);

	XRPositionalTracker();
	~XRPositionalTracker() {}
};

VARIANT_ENUM_CAST(XRPositionalTracker::TrackerHand);

#endif