summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/arvr_nodes.cpp110
-rw-r--r--scene/3d/arvr_nodes.h7
-rw-r--r--scene/3d/camera.h8
3 files changed, 121 insertions, 4 deletions
diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/arvr_nodes.cpp
index 147d3bf115..c6b6c02129 100644
--- a/scene/3d/arvr_nodes.cpp
+++ b/scene/3d/arvr_nodes.cpp
@@ -67,6 +67,105 @@ String ARVRCamera::get_configuration_warning() const {
return String();
};
+Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const {
+ // get our ARVRServer
+ ARVRServer *arvr_server = ARVRServer::get_singleton();
+ ERR_FAIL_NULL_V(arvr_server, Vector3());
+
+ Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
+ ERR_FAIL_COND_V(arvr_interface.is_null(), Vector3());
+
+ if (!is_inside_tree()) {
+ ERR_EXPLAIN("Camera is not inside scene.");
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
+ };
+
+ Size2 viewport_size = get_viewport()->get_camera_rect_size();
+ Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
+ Vector3 ray;
+
+ CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
+ float screen_w, screen_h;
+ cm.get_viewport_size(screen_w, screen_h);
+ ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_w, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_h, -get_znear()).normalized();
+
+ return ray;
+};
+
+Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const {
+ // get our ARVRServer
+ ARVRServer *arvr_server = ARVRServer::get_singleton();
+ ERR_FAIL_NULL_V(arvr_server, Vector2());
+
+ Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
+ ERR_FAIL_COND_V(arvr_interface.is_null(), Vector2());
+
+ if (!is_inside_tree()) {
+ ERR_EXPLAIN("Camera is not inside scene.");
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector2());
+ };
+
+ Size2 viewport_size = get_viewport()->get_visible_rect().size;
+
+ CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
+
+ Plane p(get_camera_transform().xform_inv(p_pos), 1.0);
+
+ p = cm.xform4(p);
+ p.normal /= p.d;
+
+ Point2 res;
+ res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x;
+ res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y;
+
+ return res;
+};
+
+Vector3 ARVRCamera::project_position(const Point2 &p_point) const {
+ // get our ARVRServer
+ ARVRServer *arvr_server = ARVRServer::get_singleton();
+ ERR_FAIL_NULL_V(arvr_server, Vector3());
+
+ Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
+ ERR_FAIL_COND_V(arvr_interface.is_null(), Vector3());
+
+ if (!is_inside_tree()) {
+ ERR_EXPLAIN("Camera is not inside scene.");
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
+ };
+
+ Size2 viewport_size = get_viewport()->get_visible_rect().size;
+
+ CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
+
+ Size2 vp_size;
+ cm.get_viewport_size(vp_size.x, vp_size.y);
+
+ Vector2 point;
+ point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0;
+ point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0;
+ point *= vp_size;
+
+ Vector3 p(point.x, point.y, -get_znear());
+
+ return get_camera_transform().xform(p);
+};
+
+Vector<Plane> ARVRCamera::get_frustum() const {
+ // get our ARVRServer
+ ARVRServer *arvr_server = ARVRServer::get_singleton();
+ ERR_FAIL_NULL_V(arvr_server, Vector<Plane>());
+
+ Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
+ ERR_FAIL_COND_V(arvr_interface.is_null(), Vector<Plane>());
+
+ ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());
+
+ Size2 viewport_size = get_viewport()->get_visible_rect().size;
+ CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
+ return cm.get_projection_planes(get_camera_transform());
+};
+
ARVRCamera::ARVRCamera(){
// nothing to do here yet for now..
};
@@ -297,6 +396,8 @@ void ARVRAnchor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRAnchor::get_is_active);
ClassDB::bind_method(D_METHOD("get_size"), &ARVRAnchor::get_size);
+
+ ClassDB::bind_method(D_METHOD("get_plane"), &ARVRAnchor::get_plane);
};
void ARVRAnchor::set_anchor_id(int p_anchor_id) {
@@ -346,6 +447,15 @@ String ARVRAnchor::get_configuration_warning() const {
return String();
};
+Plane ARVRAnchor::get_plane() const {
+ Vector3 location = get_translation();
+ Basis orientation = get_transform().basis;
+
+ Plane plane(location, orientation.get_axis(1).normalized());
+
+ return plane;
+};
+
ARVRAnchor::ARVRAnchor() {
anchor_id = 0;
is_active = true;
diff --git a/scene/3d/arvr_nodes.h b/scene/3d/arvr_nodes.h
index 5269ec0248..e0ccfab58b 100644
--- a/scene/3d/arvr_nodes.h
+++ b/scene/3d/arvr_nodes.h
@@ -52,6 +52,11 @@ protected:
public:
String get_configuration_warning() const;
+ virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const;
+ virtual Point2 unproject_position(const Vector3 &p_pos) const;
+ virtual Vector3 project_position(const Point2 &p_point) const;
+ virtual Vector<Plane> get_frustum() const;
+
ARVRCamera();
~ARVRCamera();
};
@@ -118,6 +123,8 @@ public:
bool get_is_active() const;
Vector3 get_size() const;
+ Plane get_plane() const;
+
String get_configuration_warning() const;
ARVRAnchor();
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index 3a725eaf66..73c6844c1a 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -127,16 +127,16 @@ public:
virtual Transform get_camera_transform() const;
Vector3 project_ray_normal(const Point2 &p_pos) const;
- Vector3 project_ray_origin(const Point2 &p_pos) const;
+ virtual Vector3 project_ray_origin(const Point2 &p_pos) const;
Vector3 project_local_ray_normal(const Point2 &p_pos) const;
- Point2 unproject_position(const Vector3 &p_pos) const;
+ virtual Point2 unproject_position(const Vector3 &p_pos) const;
bool is_position_behind(const Vector3 &p_pos) const;
- Vector3 project_position(const Point2 &p_point) const;
+ virtual Vector3 project_position(const Point2 &p_point) const;
void set_cull_mask(uint32_t p_layers);
uint32_t get_cull_mask() const;
- Vector<Plane> get_frustum() const;
+ virtual Vector<Plane> get_frustum() const;
void set_environment(const Ref<Environment> &p_environment);
Ref<Environment> get_environment() const;