virtualx-engine/scene/3d/listener.cpp

148 lines
2.8 KiB
C++
Raw Normal View History

2016-03-20 03:10:04 +01:00
#include "listener.h"
#include "scene/resources/mesh.h"
void Listener::_update_audio_listener_state() {
}
void Listener::_request_listener_update() {
_update_listener();
}
bool Listener::_set(const StringName &p_name, const Variant &p_value) {
2016-03-20 03:10:04 +01:00
if (p_name == "current") {
if (p_value.operator bool()) {
make_current();
} else {
2016-03-20 03:10:04 +01:00
clear_current();
}
} else
2016-03-20 03:10:04 +01:00
return false;
return true;
}
bool Listener::_get(const StringName &p_name, Variant &r_ret) const {
2016-03-20 03:10:04 +01:00
if (p_name == "current") {
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
r_ret = current;
} else {
2016-03-20 03:10:04 +01:00
r_ret = is_current();
}
} else
2016-03-20 03:10:04 +01:00
return false;
return true;
}
void Listener::_get_property_list(List<PropertyInfo> *p_list) const {
2016-03-20 03:10:04 +01:00
p_list->push_back(PropertyInfo(Variant::BOOL, "current"));
2016-03-20 03:10:04 +01:00
}
void Listener::_update_listener() {
if (is_inside_tree() && is_current()) {
get_viewport()->_listener_transform_changed_notify();
}
}
void Listener::_notification(int p_what) {
switch (p_what) {
2016-03-20 03:10:04 +01:00
case NOTIFICATION_ENTER_WORLD: {
bool first_listener = get_viewport()->_listener_add(this);
if (!get_tree()->is_node_being_edited(this) && (current || first_listener))
make_current();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
_request_listener_update();
} break;
case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
clear_current();
current = true; //keep it true
2016-03-20 03:10:04 +01:00
} else {
current = false;
2016-03-20 03:10:04 +01:00
}
}
get_viewport()->_listener_remove(this);
} break;
}
}
Transform Listener::get_listener_transform() const {
return get_global_transform().orthonormalized();
}
void Listener::make_current() {
current = true;
2016-03-20 03:10:04 +01:00
if (!is_inside_tree())
return;
get_viewport()->_listener_set(this);
}
void Listener::clear_current() {
current = false;
2016-03-20 03:10:04 +01:00
if (!is_inside_tree())
return;
if (get_viewport()->get_listener() == this) {
2016-03-20 03:10:04 +01:00
get_viewport()->_listener_set(NULL);
get_viewport()->_listener_make_next_current(this);
}
}
bool Listener::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
return get_viewport()->get_listener() == this;
2016-03-20 03:10:04 +01:00
} else
return current;
return false;
}
bool Listener::_can_gizmo_scale() const {
return false;
}
RES Listener::_get_gizmo_geometry() const {
Ref<Mesh> mesh = memnew(Mesh);
return mesh;
}
void Listener::_bind_methods() {
ObjectTypeDB::bind_method(_MD("make_current"), &Listener::make_current);
ObjectTypeDB::bind_method(_MD("clear_current"), &Listener::clear_current);
ObjectTypeDB::bind_method(_MD("is_current"), &Listener::is_current);
ObjectTypeDB::bind_method(_MD("get_listener_transform"), &Listener::get_listener_transform);
2016-03-20 03:10:04 +01:00
}
Listener::Listener() {
current = false;
force_change = false;
2016-03-20 03:10:04 +01:00
//active=false;
}
Listener::~Listener() {
}