summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-05-12 08:17:09 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-05-12 08:17:09 -0300
commit3936ed882c6f39c74a3b124a95d5adc5e61ab3c5 (patch)
treea88b80dc67f3ca4bb6bb62b5173001f850178ca6 /scene/2d
parent436379860855fe2d1b073a74f4bfa4e7acc96c5b (diff)
-Added lookat/get_angle_to functions in 2D, and a demo, closes #1843
-Added get_viewport().get_mouse_pos() to replace Input.get_mouse_pos(), closes #1838
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/node_2d.cpp14
-rw-r--r--scene/2d/node_2d.h3
2 files changed, 17 insertions, 0 deletions
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index fc5be255ce..99c33c787d 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -346,6 +346,17 @@ Matrix32 Node2D::get_relative_transform(const Node *p_parent) const {
return parent_2d->get_relative_transform(p_parent) * get_transform();
}
+
+void Node2D::look_at(const Vector2& p_pos) {
+
+ rotate(get_angle_to(p_pos));
+}
+
+float Node2D::get_angle_to(const Vector2& p_pos) const {
+
+ return (get_global_transform().affine_inverse().xform(p_pos)).atan2();
+}
+
void Node2D::_bind_methods() {
@@ -374,6 +385,9 @@ void Node2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform);
ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform);
+ ObjectTypeDB::bind_method(_MD("look_at","point"),&Node2D::look_at);
+ ObjectTypeDB::bind_method(_MD("get_angle_to","point"),&Node2D::get_angle_to);
+
ObjectTypeDB::bind_method(_MD("set_z","z"),&Node2D::set_z);
ObjectTypeDB::bind_method(_MD("get_z"),&Node2D::get_z);
diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h
index 74612b3c6d..8efce33cda 100644
--- a/scene/2d/node_2d.h
+++ b/scene/2d/node_2d.h
@@ -93,6 +93,9 @@ public:
void set_z(int p_z);
int get_z() const;
+ void look_at(const Vector2& p_pos);
+ float get_angle_to(const Vector2& p_pos) const;
+
void set_z_as_relative(bool p_enabled);
bool is_z_relative() const;