2017-04-23 14:10:41 +02:00
|
|
|
/*************************************************************************/
|
2020-04-08 16:47:36 +02:00
|
|
|
/* xr_nodes.h */
|
2017-04-23 14:10:41 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-04-23 14:10:41 +02:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-04-23 14:10:41 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-04-08 16:47:36 +02:00
|
|
|
#ifndef XR_NODES_H
|
|
|
|
#define XR_NODES_H
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/camera_3d.h"
|
|
|
|
#include "scene/3d/node_3d.h"
|
2019-02-05 11:02:13 +01:00
|
|
|
#include "scene/resources/mesh.h"
|
2020-04-08 16:47:36 +02:00
|
|
|
#include "servers/xr/xr_positional_tracker.h"
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
@author Bastiaan Olij <mux213@gmail.com>
|
|
|
|
**/
|
|
|
|
|
|
|
|
/*
|
2020-04-08 16:47:36 +02:00
|
|
|
XRCamera is a subclass of camera which will register itself with its parent XROrigin and as a result is automatically positioned
|
2017-04-23 14:10:41 +02:00
|
|
|
*/
|
2020-04-08 16:47:36 +02:00
|
|
|
class XRCamera3D : public Camera3D {
|
|
|
|
GDCLASS(XRCamera3D, Camera3D);
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
2020-10-29 11:01:28 +01:00
|
|
|
TypedArray<String> get_configuration_warnings() const override;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const override;
|
|
|
|
virtual Point2 unproject_position(const Vector3 &p_pos) const override;
|
2021-01-30 01:55:54 +01:00
|
|
|
virtual Vector3 project_position(const Point2 &p_point, real_t p_z_depth) const override;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Vector<Plane> get_frustum() const override;
|
2017-09-29 13:36:27 +02:00
|
|
|
|
2020-05-19 11:24:58 +02:00
|
|
|
XRCamera3D() {}
|
|
|
|
~XRCamera3D() {}
|
2017-04-23 14:10:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2020-04-08 16:47:36 +02:00
|
|
|
XRController3D is a helper node that automatically updates its position based on tracker data.
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-04-08 16:47:36 +02:00
|
|
|
It must be a child node of our XROrigin node
|
2017-04-23 14:10:41 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-08 16:47:36 +02:00
|
|
|
class XRController3D : public Node3D {
|
|
|
|
GDCLASS(XRController3D, Node3D);
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
private:
|
2020-05-19 11:24:58 +02:00
|
|
|
int controller_id = 1;
|
|
|
|
bool is_active = true;
|
|
|
|
int button_states = 0;
|
2019-02-05 11:02:13 +01:00
|
|
|
Ref<Mesh> mesh;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_controller_id(int p_controller_id);
|
2020-05-14 11:11:27 +02:00
|
|
|
int get_controller_id() const;
|
|
|
|
String get_controller_name() const;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
int get_joystick_id() const;
|
2020-03-07 02:22:18 +01:00
|
|
|
bool is_button_pressed(int p_button) const;
|
2017-04-23 14:10:41 +02:00
|
|
|
float get_joystick_axis(int p_axis) const;
|
|
|
|
|
2017-11-01 11:46:37 +01:00
|
|
|
real_t get_rumble() const;
|
|
|
|
void set_rumble(real_t p_rumble);
|
|
|
|
|
2017-04-23 14:10:41 +02:00
|
|
|
bool get_is_active() const;
|
2020-12-10 12:16:14 +01:00
|
|
|
XRPositionalTracker::TrackerHand get_tracker_hand() const;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
Ref<Mesh> get_mesh() const;
|
2019-02-05 11:02:13 +01:00
|
|
|
|
2020-10-29 11:01:28 +01:00
|
|
|
TypedArray<String> get_configuration_warnings() const override;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-05-19 11:24:58 +02:00
|
|
|
XRController3D() {}
|
|
|
|
~XRController3D() {}
|
2017-04-23 14:10:41 +02:00
|
|
|
};
|
|
|
|
|
2017-08-03 10:58:05 +02:00
|
|
|
/*
|
2020-04-08 16:47:36 +02:00
|
|
|
XRAnchor3D is a helper node that automatically updates its position based on anchor data, it represents a real world location.
|
|
|
|
It must be a child node of our XROrigin3D node
|
2017-08-03 10:58:05 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-08 16:47:36 +02:00
|
|
|
class XRAnchor3D : public Node3D {
|
|
|
|
GDCLASS(XRAnchor3D, Node3D);
|
2017-08-03 10:58:05 +02:00
|
|
|
|
|
|
|
private:
|
2020-05-19 11:24:58 +02:00
|
|
|
int anchor_id = 1;
|
|
|
|
bool is_active = true;
|
2017-08-03 10:58:05 +02:00
|
|
|
Vector3 size;
|
2019-02-05 11:02:13 +01:00
|
|
|
Ref<Mesh> mesh;
|
2017-08-03 10:58:05 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_anchor_id(int p_anchor_id);
|
2020-05-14 11:11:27 +02:00
|
|
|
int get_anchor_id() const;
|
|
|
|
String get_anchor_name() const;
|
2017-08-03 10:58:05 +02:00
|
|
|
|
|
|
|
bool get_is_active() const;
|
|
|
|
Vector3 get_size() const;
|
|
|
|
|
2017-09-29 13:36:27 +02:00
|
|
|
Plane get_plane() const;
|
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
Ref<Mesh> get_mesh() const;
|
2019-02-05 11:02:13 +01:00
|
|
|
|
2020-10-29 11:01:28 +01:00
|
|
|
TypedArray<String> get_configuration_warnings() const override;
|
2017-08-03 10:58:05 +02:00
|
|
|
|
2020-05-19 11:24:58 +02:00
|
|
|
XRAnchor3D() {}
|
|
|
|
~XRAnchor3D() {}
|
2017-08-03 10:58:05 +02:00
|
|
|
};
|
|
|
|
|
2017-04-23 14:10:41 +02:00
|
|
|
/*
|
2020-04-08 16:47:36 +02:00
|
|
|
XROrigin3D is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world.
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
It is this point that you will move around the world as the player 'moves while standing still', i.e. the player moves through teleporting or controller inputs as opposed to physically moving.
|
|
|
|
|
|
|
|
Our camera and controllers will always be child nodes and thus place relative to this origin point.
|
2020-04-08 16:47:36 +02:00
|
|
|
This node will automatically locate any camera child nodes and update its position while our XRController3D node will handle tracked controllers.
|
2017-04-23 14:10:41 +02:00
|
|
|
*/
|
2020-04-08 16:47:36 +02:00
|
|
|
class XROrigin3D : public Node3D {
|
|
|
|
GDCLASS(XROrigin3D, Node3D);
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
private:
|
2020-05-19 11:24:58 +02:00
|
|
|
XRCamera3D *tracked_camera = nullptr;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2020-10-29 11:01:28 +01:00
|
|
|
TypedArray<String> get_configuration_warnings() const override;
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-04-08 16:47:36 +02:00
|
|
|
void set_tracked_camera(XRCamera3D *p_tracked_camera);
|
|
|
|
void clear_tracked_camera_if(XRCamera3D *p_tracked_camera);
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2021-01-30 01:55:54 +01:00
|
|
|
real_t get_world_scale() const;
|
|
|
|
void set_world_scale(real_t p_world_scale);
|
2017-04-23 14:10:41 +02:00
|
|
|
|
2020-05-19 11:24:58 +02:00
|
|
|
XROrigin3D() {}
|
|
|
|
~XROrigin3D() {}
|
2017-04-23 14:10:41 +02:00
|
|
|
};
|
|
|
|
|
2020-04-08 16:47:36 +02:00
|
|
|
#endif /* XR_NODES_H */
|