summaryrefslogtreecommitdiff
path: root/scene/2d/skeleton_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/skeleton_2d.cpp')
-rw-r--r--scene/2d/skeleton_2d.cpp76
1 files changed, 52 insertions, 24 deletions
diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp
index 2363c791fa..8ceffb3c27 100644
--- a/scene/2d/skeleton_2d.cpp
+++ b/scene/2d/skeleton_2d.cpp
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* skeleton_2d.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* 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 */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#include "skeleton_2d.h"
void Bone2D::_notification(int p_what) {
@@ -59,8 +89,8 @@ void Bone2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_default_length", "default_length"), &Bone2D::set_default_length);
ClassDB::bind_method(D_METHOD("get_default_length"), &Bone2D::get_default_length);
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D,"rest"),"set_rest","get_rest");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"default_length",PROPERTY_HINT_RANGE,"1,1024,1"),"set_default_length","get_default_length");
+ ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "rest"), "set_rest", "get_rest");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "default_length", PROPERTY_HINT_RANGE, "1,1024,1"), "set_default_length", "get_default_length");
}
void Bone2D::set_rest(const Transform2D &p_rest) {
@@ -90,8 +120,7 @@ void Bone2D::apply_rest() {
void Bone2D::set_default_length(float p_length) {
- default_length=p_length;
-
+ default_length = p_length;
}
float Bone2D::get_default_length() const {
@@ -99,7 +128,7 @@ float Bone2D::get_default_length() const {
}
int Bone2D::get_index_in_skeleton() const {
- ERR_FAIL_COND_V(!skeleton,-1);
+ ERR_FAIL_COND_V(!skeleton, -1);
skeleton->_update_bone_setup();
return skeleton_index;
}
@@ -107,22 +136,21 @@ String Bone2D::get_configuration_warning() const {
String warning = Node2D::get_configuration_warning();
if (!skeleton) {
- if (warning!=String()) {
- warning+="\n";
+ if (warning != String()) {
+ warning += "\n";
}
if (parent_bone) {
- warning+=TTR("This Bone2D chain should end at a Skeleton2D node.");
+ warning += TTR("This Bone2D chain should end at a Skeleton2D node.");
} else {
- warning+=TTR("A Bone2D only works with a Skeleton2D or another Bone2D as parent node.");
+ warning += TTR("A Bone2D only works with a Skeleton2D or another Bone2D as parent node.");
}
}
- if (rest==Transform2D(0,0,0,0,0,0)) {
- if (warning!=String()) {
- warning+="\n";
+ if (rest == Transform2D(0, 0, 0, 0, 0, 0)) {
+ if (warning != String()) {
+ warning += "\n";
}
- warning+=TTR("This bone lacks a proper REST pose. Go to the Skeleton2D node and set one.");
-
+ warning += TTR("This bone lacks a proper REST pose. Go to the Skeleton2D node and set one.");
}
return warning;
@@ -131,12 +159,12 @@ String Bone2D::get_configuration_warning() const {
Bone2D::Bone2D() {
skeleton = NULL;
parent_bone = NULL;
- skeleton_index=-1;
- default_length=16;
+ skeleton_index = -1;
+ default_length = 16;
set_notify_local_transform(true);
//this is a clever hack so the bone knows no rest has been set yet, allowing to show an error.
- for(int i=0;i<3;i++) {
- rest[i]=Vector2(0,0);
+ for (int i = 0; i < 3; i++) {
+ rest[i] = Vector2(0, 0);
}
}
@@ -164,12 +192,12 @@ void Skeleton2D::_update_bone_setup() {
for (int i = 0; i < bones.size(); i++) {
bones[i].rest_inverse = bones[i].bone->get_skeleton_rest().affine_inverse(); //bind pose
- bones[i].bone->skeleton_index=i;
+ bones[i].bone->skeleton_index = i;
Bone2D *parent_bone = Object::cast_to<Bone2D>(bones[i].bone->get_parent());
if (parent_bone) {
- bones[i].parent_index=parent_bone->skeleton_index;
+ bones[i].parent_index = parent_bone->skeleton_index;
} else {
- bones[i].parent_index=-1;
+ bones[i].parent_index = -1;
}
}
@@ -200,8 +228,8 @@ void Skeleton2D::_update_transform() {
for (int i = 0; i < bones.size(); i++) {
- ERR_CONTINUE(bones[i].parent_index>=i);
- if (bones[i].parent_index>=0) {
+ ERR_CONTINUE(bones[i].parent_index >= i);
+ if (bones[i].parent_index >= 0) {
bones[i].accum_transform = bones[bones[i].parent_index].accum_transform * bones[i].bone->get_transform();
} else {
bones[i].accum_transform = bones[i].bone->get_transform();
@@ -247,7 +275,7 @@ void Skeleton2D::_notification(int p_what) {
}
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- VS::get_singleton()->skeleton_set_base_transform_2d(skeleton,get_global_transform());
+ VS::get_singleton()->skeleton_set_base_transform_2d(skeleton, get_global_transform());
}
}