diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/arvr/arvr_positional_tracker.cpp | 33 | ||||
-rw-r--r-- | servers/arvr/arvr_positional_tracker.h | 8 |
2 files changed, 36 insertions, 5 deletions
diff --git a/servers/arvr/arvr_positional_tracker.cpp b/servers/arvr/arvr_positional_tracker.cpp index 4215363d16..9f3d01267b 100644 --- a/servers/arvr/arvr_positional_tracker.cpp +++ b/servers/arvr/arvr_positional_tracker.cpp @@ -40,6 +40,13 @@ void ARVRPositionalTracker::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tracks_position"), &ARVRPositionalTracker::get_tracks_position); ClassDB::bind_method(D_METHOD("get_position"), &ARVRPositionalTracker::get_position); ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &ARVRPositionalTracker::get_transform); + + // these functions we don't want to expose to normal users but do need to be callable from GDNative + ClassDB::bind_method(D_METHOD("_set_type", "type"), &ARVRPositionalTracker::set_type); + ClassDB::bind_method(D_METHOD("_set_name", "name"), &ARVRPositionalTracker::set_name); + ClassDB::bind_method(D_METHOD("_set_joy_id", "joy_id"), &ARVRPositionalTracker::set_joy_id); + ClassDB::bind_method(D_METHOD("_set_orientation", "orientation"), &ARVRPositionalTracker::set_orientation); + ClassDB::bind_method(D_METHOD("_set_rw_position", "rw_position"), &ARVRPositionalTracker::set_rw_position); }; void ARVRPositionalTracker::set_type(ARVRServer::TrackerType p_type) { @@ -102,14 +109,36 @@ bool ARVRPositionalTracker::get_tracks_position() const { void ARVRPositionalTracker::set_position(const Vector3 &p_position) { _THREAD_SAFE_METHOD_ + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL(arvr_server); + real_t world_scale = arvr_server->get_world_scale(); + ERR_FAIL_COND(world_scale == 0); + tracks_position = true; // obviously we have this - position = p_position; + rw_position = p_position / world_scale; }; Vector3 ARVRPositionalTracker::get_position() const { _THREAD_SAFE_METHOD_ - return position; + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL_V(arvr_server, rw_position); + real_t world_scale = arvr_server->get_world_scale(); + + return rw_position * world_scale; +}; + +void ARVRPositionalTracker::set_rw_position(const Vector3 &p_rw_position) { + _THREAD_SAFE_METHOD_ + + tracks_position = true; // obviously we have this + rw_position = p_rw_position; +}; + +Vector3 ARVRPositionalTracker::get_rw_position() const { + _THREAD_SAFE_METHOD_ + + return rw_position; }; Transform ARVRPositionalTracker::get_transform(bool p_adjust_by_reference_frame) const { diff --git a/servers/arvr/arvr_positional_tracker.h b/servers/arvr/arvr_positional_tracker.h index e8c613b29d..dba203b73c 100644 --- a/servers/arvr/arvr_positional_tracker.h +++ b/servers/arvr/arvr_positional_tracker.h @@ -56,7 +56,7 @@ private: bool tracks_orientation; // do we track orientation? Basis orientation; // our orientation bool tracks_position; // do we track position? - Vector3 position; // our position + Vector3 rw_position; // our position "in the real world, so without world_scale applied" protected: static void _bind_methods(); @@ -73,8 +73,10 @@ public: void set_orientation(const Basis &p_orientation); Basis get_orientation() const; bool get_tracks_position() const; - void set_position(const Vector3 &p_position); - Vector3 get_position() const; + void set_position(const Vector3 &p_position); // set position with world_scale applied + Vector3 get_position() const; // get position with world_scale applied + void set_rw_position(const Vector3 &p_rw_position); + Vector3 get_rw_position() const; Transform get_transform(bool p_adjust_by_reference_frame) const; |