2017-04-23 12:10:41 +00:00
/*************************************************************************/
2020-04-08 14:47:36 +00:00
/* xr_interface.h */
2017-04-23 12:10:41 +00:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:16:55 +00:00
/* https://godotengine.org */
2017-04-23 12:10:41 +00:00
/*************************************************************************/
2021-01-01 19:13:46 +00:00
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2017-04-23 12:10:41 +00: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. */
/*************************************************************************/
2018-01-04 23:50:27 +00:00
2020-04-08 14:47:36 +00:00
# ifndef XR_INTERFACE_H
# define XR_INTERFACE_H
2017-04-23 12:10:41 +00:00
# include "core/math/camera_matrix.h"
2018-09-11 16:13:45 +00:00
# include "core/os/thread_safe.h"
2020-04-08 14:47:36 +00:00
# include "servers/xr_server.h"
2017-04-23 12:10:41 +00:00
2021-05-07 13:19:04 +00:00
// forward declaration
struct BlitToScreen ;
2017-04-23 12:10:41 +00:00
/**
@ author Bastiaan Olij < mux213 @ gmail . com >
Fix various typos with codespell
Found via `codespell -q 3 -S ./thirdparty,*.po,./DONORS.md -L ackward,ang,ans,ba,beng,cas,childs,childrens,dof,doubleclick,fave,findn,hist,inout,leapyear,lod,nd,numer,ois,ony,paket,seeked,sinc,switchs,te,uint`
2021-07-07 15:17:32 +00:00
The XR interface is a template class on top of which we build interface to different AR , VR and tracking SDKs .
2017-04-23 12:10:41 +00:00
The idea is that we subclass this class , implement the logic , and then instantiate a singleton of each interface
when Godot starts . These instances do not initialize themselves but register themselves with the AR / VR server .
If the user wants to enable AR / VR the choose the interface they want to use and initialize it .
Note that we may make this into a fully instantiable class for GDNative support .
*/
2021-06-04 16:03:15 +00:00
class XRInterface : public RefCounted {
GDCLASS ( XRInterface , RefCounted ) ;
2017-04-23 12:10:41 +00:00
public :
2017-09-29 11:36:27 +00:00
enum Capabilities { /* purely meta data, provides some info about what this interface supports */
2020-04-08 14:47:36 +00:00
XR_NONE = 0 , /* no capabilities */
XR_MONO = 1 , /* can be used with mono output */
XR_STEREO = 2 , /* can be used with stereo output */
XR_AR = 4 , /* offers a camera feed for AR */
XR_EXTERNAL = 8 /* renders to external device */
2017-09-29 11:36:27 +00:00
} ;
2017-04-23 12:10:41 +00:00
enum Eyes {
EYE_MONO , /* my son says we should call this EYE_CYCLOPS */
EYE_LEFT ,
EYE_RIGHT
} ;
2021-08-23 05:23:16 +00:00
enum TrackingStatus { /* tracking status currently based on AR but we can start doing more with this for VR as well */
2020-04-08 14:47:36 +00:00
XR_NORMAL_TRACKING ,
XR_EXCESSIVE_MOTION ,
XR_INSUFFICIENT_FEATURES ,
XR_UNKNOWN_TRACKING ,
XR_NOT_TRACKING
2017-09-29 11:36:27 +00:00
} ;
2021-08-23 05:23:16 +00:00
private :
2017-09-29 11:36:27 +00:00
protected :
_THREAD_SAFE_CLASS_
static void _bind_methods ( ) ;
public :
/** general interface information **/
2021-08-23 05:23:16 +00:00
virtual StringName get_name ( ) const = 0 ;
virtual uint32_t get_capabilities ( ) const = 0 ;
2017-04-23 12:10:41 +00:00
bool is_primary ( ) ;
2021-08-23 05:23:16 +00:00
void set_primary ( bool p_is_primary ) ;
2017-04-23 12:10:41 +00:00
2018-07-25 01:11:03 +00:00
virtual bool is_initialized ( ) const = 0 ; /* returns true if we've initialized this interface */
2017-04-23 12:10:41 +00:00
virtual bool initialize ( ) = 0 ; /* initialize this interface, if this has an HMD it becomes the primary interface */
virtual void uninitialize ( ) = 0 ; /* deinitialize this interface */
2021-08-23 05:23:16 +00:00
virtual TrackingStatus get_tracking_status ( ) const ; /* get the status of our current tracking */
2017-09-29 11:36:27 +00:00
/** specific to VR **/
// nothing yet
/** specific to AR **/
virtual bool get_anchor_detection_is_enabled ( ) const ;
virtual void set_anchor_detection_is_enabled ( bool p_enable ) ;
2017-08-20 14:17:24 +00:00
virtual int get_camera_feed_id ( ) ;
2017-09-29 11:36:27 +00:00
/** rendering and internal **/
2021-08-23 05:23:16 +00:00
virtual Size2 get_render_target_size ( ) = 0 ; /* returns the recommended render target size per eye for this device */
2021-05-07 13:19:04 +00:00
virtual uint32_t get_view_count ( ) = 0 ; /* returns the view count we need (1 is monoscopic, 2 is stereoscopic but can be more) */
virtual Transform3D get_camera_transform ( ) = 0 ; /* returns the position of our camera for updating our camera node. For monoscopic this is equal to the views transform, for stereoscopic this should be an average */
virtual Transform3D get_transform_for_view ( uint32_t p_view , const Transform3D & p_cam_transform ) = 0 ; /* get each views transform */
virtual CameraMatrix get_projection_for_view ( uint32_t p_view , real_t p_aspect , real_t p_z_near , real_t p_z_far ) = 0 ; /* get each view projection matrix */
2021-08-23 05:23:16 +00:00
// note, external color/depth/vrs texture support will be added here soon.
2021-05-07 13:19:04 +00:00
virtual Vector < BlitToScreen > commit_views ( RID p_render_target , const Rect2 & p_screen_rect ) = 0 ; /* commit rendered views to the XR interface */
2017-04-23 12:10:41 +00:00
virtual void process ( ) = 0 ;
2021-08-23 05:23:16 +00:00
virtual void notification ( int p_what ) ;
2017-09-29 11:36:27 +00:00
2020-04-08 14:47:36 +00:00
XRInterface ( ) ;
~ XRInterface ( ) ;
2017-04-23 12:10:41 +00:00
} ;
2020-04-08 14:47:36 +00:00
VARIANT_ENUM_CAST ( XRInterface : : Capabilities ) ;
VARIANT_ENUM_CAST ( XRInterface : : Eyes ) ;
2021-08-23 05:23:16 +00:00
VARIANT_ENUM_CAST ( XRInterface : : TrackingStatus ) ;
2017-04-23 12:10:41 +00:00
2021-08-23 05:23:16 +00:00
# endif // !XR_INTERFACE_H