summaryrefslogtreecommitdiff
path: root/scene/3d/spatial.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/spatial.cpp')
-rw-r--r--scene/3d/spatial.cpp96
1 files changed, 66 insertions, 30 deletions
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index e890533ab7..a55c4a2cc5 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -555,30 +555,36 @@ bool Spatial::is_visible() const {
return data.visible;
}
-void Spatial::rotate(const Vector3 &p_normal, float p_radians) {
+void Spatial::rotate_object_local(const Vector3 &p_axis, float p_angle) {
+ Transform t = get_transform();
+ t.basis.rotate_local(p_axis, p_angle);
+ set_transform(t);
+}
+
+void Spatial::rotate(const Vector3 &p_axis, float p_angle) {
Transform t = get_transform();
- t.basis.rotate_local(p_normal, p_radians); //use local rotation here, as it makes more sense here in tree hierarchy
+ t.basis.rotate(p_axis, p_angle);
set_transform(t);
}
-void Spatial::rotate_x(float p_radians) {
+void Spatial::rotate_x(float p_angle) {
Transform t = get_transform();
- t.basis.rotate_local(Vector3(1, 0, 0), p_radians);
+ t.basis.rotate(Vector3(1, 0, 0), p_angle);
set_transform(t);
}
-void Spatial::rotate_y(float p_radians) {
+void Spatial::rotate_y(float p_angle) {
Transform t = get_transform();
- t.basis.rotate_local(Vector3(0, 1, 0), p_radians);
+ t.basis.rotate(Vector3(0, 1, 0), p_angle);
set_transform(t);
}
-void Spatial::rotate_z(float p_radians) {
+void Spatial::rotate_z(float p_angle) {
Transform t = get_transform();
- t.basis.rotate_local(Vector3(0, 0, 1), p_radians);
+ t.basis.rotate(Vector3(0, 0, 1), p_angle);
set_transform(t);
}
@@ -589,19 +595,45 @@ void Spatial::translate(const Vector3 &p_offset) {
set_transform(t);
}
+void Spatial::translate_object_local(const Vector3 &p_offset) {
+ Transform t = get_transform();
+
+ Transform s;
+ s.translate(p_offset);
+ set_transform(t * s);
+}
+
void Spatial::scale(const Vector3 &p_ratio) {
Transform t = get_transform();
t.basis.scale(p_ratio);
set_transform(t);
}
-void Spatial::global_rotate(const Vector3 &p_normal, float p_radians) {
- Basis rotation(p_normal, p_radians);
+void Spatial::scale_object_local(const Vector3 &p_scale) {
+ Transform t = get_transform();
+ t.basis.scale_local(p_scale);
+ set_transform(t);
+}
+
+void Spatial::global_rotate(const Vector3 &p_axis, float p_angle) {
+
+ Basis rotation(p_axis, p_angle);
Transform t = get_global_transform();
t.basis = rotation * t.basis;
set_global_transform(t);
}
+
+void Spatial::global_scale(const Vector3 &p_scale) {
+
+ Basis s;
+ s.set_scale(p_scale);
+
+ Transform t = get_global_transform();
+ t.basis = s * t.basis;
+ set_global_transform(t);
+}
+
void Spatial::global_translate(const Vector3 &p_offset) {
Transform t = get_global_transform();
t.origin += p_offset;
@@ -620,7 +652,7 @@ void Spatial::set_identity() {
set_transform(Transform());
}
-void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up_normal) {
+void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) {
Transform lookat;
lookat.origin = get_global_transform().origin;
@@ -629,19 +661,19 @@ void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up_normal) {
ERR_FAIL();
}
- if (p_up_normal.cross(p_target - lookat.origin) == Vector3()) {
+ if (p_up.cross(p_target - lookat.origin) == Vector3()) {
ERR_EXPLAIN("Up vector and direction between node origin and target are aligned, look_at() failed");
ERR_FAIL();
}
- lookat = lookat.looking_at(p_target, p_up_normal);
+ lookat = lookat.looking_at(p_target, p_up);
set_global_transform(lookat);
}
-void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up_normal) {
+void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) {
Transform lookat;
lookat.origin = p_pos;
- lookat = lookat.looking_at(p_target, p_up_normal);
+ lookat = lookat.looking_at(p_target, p_up);
set_global_transform(lookat);
}
@@ -677,9 +709,9 @@ void Spatial::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_transform"), &Spatial::get_transform);
ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Spatial::set_translation);
ClassDB::bind_method(D_METHOD("get_translation"), &Spatial::get_translation);
- ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Spatial::set_rotation);
+ ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Spatial::set_rotation);
ClassDB::bind_method(D_METHOD("get_rotation"), &Spatial::get_rotation);
- ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Spatial::set_rotation_degrees);
+ ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Spatial::set_rotation_degrees);
ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Spatial::get_rotation_degrees);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Spatial::set_scale);
ClassDB::bind_method(D_METHOD("get_scale"), &Spatial::get_scale);
@@ -711,22 +743,26 @@ void Spatial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform);
ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled);
- void rotate(const Vector3 &p_normal, float p_radians);
- void rotate_x(float p_radians);
- void rotate_y(float p_radians);
- void rotate_z(float p_radians);
+ void rotate(const Vector3 &p_axis, float p_angle);
+ void rotate_x(float p_angle);
+ void rotate_y(float p_angle);
+ void rotate_z(float p_angle);
void translate(const Vector3 &p_offset);
void scale(const Vector3 &p_ratio);
- void global_rotate(const Vector3 &p_normal, float p_radians);
+ void global_rotate(const Vector3 &p_axis, float p_angle);
void global_translate(const Vector3 &p_offset);
- ClassDB::bind_method(D_METHOD("rotate", "normal", "radians"), &Spatial::rotate);
- ClassDB::bind_method(D_METHOD("global_rotate", "normal", "radians"), &Spatial::global_rotate);
- ClassDB::bind_method(D_METHOD("rotate_x", "radians"), &Spatial::rotate_x);
- ClassDB::bind_method(D_METHOD("rotate_y", "radians"), &Spatial::rotate_y);
- ClassDB::bind_method(D_METHOD("rotate_z", "radians"), &Spatial::rotate_z);
- ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate);
+ ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Spatial::rotate);
+ ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Spatial::global_rotate);
+ ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Spatial::global_scale);
ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Spatial::global_translate);
+ ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Spatial::rotate_object_local);
+ ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Spatial::scale_object_local);
+ ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Spatial::translate_object_local);
+ ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Spatial::rotate_x);
+ ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Spatial::rotate_y);
+ ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Spatial::rotate_z);
+ ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate);
ClassDB::bind_method(D_METHOD("orthonormalize"), &Spatial::orthonormalize);
ClassDB::bind_method(D_METHOD("set_identity"), &Spatial::set_identity);