mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
Apply reference frame transform to OpenXRCompositionLayer nodes
This commit is contained in:
parent
b7feebefab
commit
6a8f2f00ac
@ -135,6 +135,11 @@
|
||||
Emitted when an interface is removed.
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="reference_frame_changed">
|
||||
<description>
|
||||
Emitted when the reference frame transform changes.
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="tracker_added">
|
||||
<param index="0" name="tracker_name" type="StringName" />
|
||||
<param index="1" name="type" type="int" />
|
||||
|
@ -151,6 +151,16 @@ void OpenXRCompositionLayer::update_fallback_mesh() {
|
||||
should_update_fallback_mesh = true;
|
||||
}
|
||||
|
||||
XrPosef OpenXRCompositionLayer::get_openxr_pose() {
|
||||
Transform3D reference_frame = XRServer::get_singleton()->get_reference_frame();
|
||||
Transform3D transform = reference_frame.inverse() * get_transform();
|
||||
Quaternion quat(transform.basis.orthonormalized());
|
||||
return {
|
||||
{ (float)quat.x, (float)quat.y, (float)quat.z, (float)quat.w },
|
||||
{ (float)transform.origin.x, (float)transform.origin.y, (float)transform.origin.z }
|
||||
};
|
||||
}
|
||||
|
||||
bool OpenXRCompositionLayer::is_viewport_in_use(SubViewport *p_viewport) {
|
||||
for (const OpenXRCompositionLayer *other_composition_layer : composition_layer_nodes) {
|
||||
if (other_composition_layer != this && other_composition_layer->is_inside_tree() && other_composition_layer->get_layer_viewport() == p_viewport) {
|
||||
|
@ -77,6 +77,8 @@ protected:
|
||||
|
||||
void update_fallback_mesh();
|
||||
|
||||
XrPosef get_openxr_pose();
|
||||
|
||||
static Vector<OpenXRCompositionLayer *> composition_layer_nodes;
|
||||
bool is_viewport_in_use(SubViewport *p_viewport);
|
||||
|
||||
|
@ -52,6 +52,7 @@ OpenXRCompositionLayerCylinder::OpenXRCompositionLayerCylinder() {
|
||||
aspect_ratio, // aspectRatio
|
||||
};
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider((XrCompositionLayerBaseHeader *)&composition_layer));
|
||||
XRServer::get_singleton()->connect("reference_frame_changed", callable_mp(this, &OpenXRCompositionLayerCylinder::update_transform));
|
||||
}
|
||||
|
||||
OpenXRCompositionLayerCylinder::~OpenXRCompositionLayerCylinder() {
|
||||
@ -131,14 +132,15 @@ Ref<Mesh> OpenXRCompositionLayerCylinder::_create_fallback_mesh() {
|
||||
void OpenXRCompositionLayerCylinder::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
|
||||
Transform3D transform = get_transform();
|
||||
Quaternion quat(transform.basis.orthonormalized());
|
||||
composition_layer.pose.orientation = { (float)quat.x, (float)quat.y, (float)quat.z, (float)quat.w };
|
||||
composition_layer.pose.position = { (float)transform.origin.x, (float)transform.origin.y, (float)transform.origin.z };
|
||||
update_transform();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayerCylinder::update_transform() {
|
||||
composition_layer.pose = get_openxr_pose();
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayerCylinder::set_radius(float p_radius) {
|
||||
ERR_FAIL_COND(p_radius <= 0);
|
||||
radius = p_radius;
|
||||
|
@ -50,6 +50,8 @@ protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
void update_transform();
|
||||
|
||||
virtual Ref<Mesh> _create_fallback_mesh() override;
|
||||
|
||||
public:
|
||||
|
@ -53,6 +53,7 @@ OpenXRCompositionLayerEquirect::OpenXRCompositionLayerEquirect() {
|
||||
-lower_vertical_angle, // lowerVerticalAngle
|
||||
};
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider((XrCompositionLayerBaseHeader *)&composition_layer));
|
||||
XRServer::get_singleton()->connect("reference_frame_changed", callable_mp(this, &OpenXRCompositionLayerEquirect::update_transform));
|
||||
}
|
||||
|
||||
OpenXRCompositionLayerEquirect::~OpenXRCompositionLayerEquirect() {
|
||||
@ -139,14 +140,15 @@ Ref<Mesh> OpenXRCompositionLayerEquirect::_create_fallback_mesh() {
|
||||
void OpenXRCompositionLayerEquirect::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
|
||||
Transform3D transform = get_transform();
|
||||
Quaternion quat(transform.basis.orthonormalized());
|
||||
composition_layer.pose.orientation = { (float)quat.x, (float)quat.y, (float)quat.z, (float)quat.w };
|
||||
composition_layer.pose.position = { (float)transform.origin.x, (float)transform.origin.y, (float)transform.origin.z };
|
||||
update_transform();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayerEquirect::update_transform() {
|
||||
composition_layer.pose = get_openxr_pose();
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayerEquirect::set_radius(float p_radius) {
|
||||
ERR_FAIL_COND(p_radius <= 0);
|
||||
radius = p_radius;
|
||||
|
@ -51,6 +51,8 @@ protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
void update_transform();
|
||||
|
||||
virtual Ref<Mesh> _create_fallback_mesh() override;
|
||||
|
||||
public:
|
||||
|
@ -50,6 +50,7 @@ OpenXRCompositionLayerQuad::OpenXRCompositionLayerQuad() {
|
||||
{ (float)quad_size.x, (float)quad_size.y }, // size
|
||||
};
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider((XrCompositionLayerBaseHeader *)&composition_layer));
|
||||
XRServer::get_singleton()->connect("reference_frame_changed", callable_mp(this, &OpenXRCompositionLayerQuad::update_transform));
|
||||
}
|
||||
|
||||
OpenXRCompositionLayerQuad::~OpenXRCompositionLayerQuad() {
|
||||
@ -72,14 +73,15 @@ Ref<Mesh> OpenXRCompositionLayerQuad::_create_fallback_mesh() {
|
||||
void OpenXRCompositionLayerQuad::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
|
||||
Transform3D transform = get_transform();
|
||||
Quaternion quat(transform.basis.orthonormalized());
|
||||
composition_layer.pose.orientation = { (float)quat.x, (float)quat.y, (float)quat.z, (float)quat.w };
|
||||
composition_layer.pose.position = { (float)transform.origin.x, (float)transform.origin.y, (float)transform.origin.z };
|
||||
update_transform();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayerQuad::update_transform() {
|
||||
composition_layer.pose = get_openxr_pose();
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayerQuad::set_quad_size(const Size2 &p_size) {
|
||||
quad_size = p_size;
|
||||
composition_layer.size = { (float)quad_size.x, (float)quad_size.y };
|
||||
|
@ -47,6 +47,8 @@ protected:
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
void update_transform();
|
||||
|
||||
virtual Ref<Mesh> _create_fallback_mesh() override;
|
||||
|
||||
public:
|
||||
|
@ -98,6 +98,8 @@ void XRServer::_bind_methods() {
|
||||
BIND_ENUM_CONSTANT(RESET_BUT_KEEP_TILT);
|
||||
BIND_ENUM_CONSTANT(DONT_RESET_ROTATION);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("reference_frame_changed"));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("interface_added", PropertyInfo(Variant::STRING_NAME, "interface_name")));
|
||||
ADD_SIGNAL(MethodInfo("interface_removed", PropertyInfo(Variant::STRING_NAME, "interface_name")));
|
||||
|
||||
@ -213,11 +215,13 @@ void XRServer::center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height) {
|
||||
|
||||
reference_frame = new_reference_frame.inverse();
|
||||
set_render_reference_frame(reference_frame);
|
||||
emit_signal(SNAME("reference_frame_changed"));
|
||||
}
|
||||
|
||||
void XRServer::clear_reference_frame() {
|
||||
reference_frame = Transform3D();
|
||||
set_render_reference_frame(reference_frame);
|
||||
emit_signal(SNAME("reference_frame_changed"));
|
||||
}
|
||||
|
||||
void XRServer::_set_render_reference_frame(const Transform3D &p_reference_frame) {
|
||||
|
Loading…
Reference in New Issue
Block a user