From: dooglus Date: Sun, 23 Sep 2007 20:25:41 +0000 (+0000) Subject: Allow the 'BLine Tangent' to be used to convert angles. The resulting value is the... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=bfcc4388320d55a365d6bc427d58f47f359d2ac3;p=synfig.git Allow the 'BLine Tangent' to be used to convert angles. The resulting value is the angle of the tangent to the bline at the given point to the horizontal. git-svn-id: http://svn.voria.com/code@745 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index 778fb42..b7bf0d4 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp @@ -57,7 +57,7 @@ using namespace synfig; ValueNode_BLineCalcTangent::ValueNode_BLineCalcTangent(const ValueBase::Type &x): LinkableValueNode(x) { - if(x!=ValueBase::TYPE_VECTOR) + if(x!=ValueBase::TYPE_ANGLE && x!=ValueBase::TYPE_VECTOR) throw Exception::BadType(ValueBase::type_name(x)); ValueNode_BLine* value_node(new ValueNode_BLine()); @@ -69,7 +69,7 @@ ValueNode_BLineCalcTangent::ValueNode_BLineCalcTangent(const ValueBase::Type &x) LinkableValueNode* ValueNode_BLineCalcTangent::create_new()const { - return new ValueNode_BLineCalcTangent(ValueBase::TYPE_VECTOR); + return new ValueNode_BLineCalcTangent(get_type()); } ValueNode_BLineCalcTangent* @@ -95,7 +95,13 @@ ValueNode_BLineCalcTangent::operator()(Time t)const BLinePoint blinepoint0, blinepoint1; if (!looped) size--; - if (size < 1) return Vector(); + if (size < 1) + switch (get_type()) + { + case ValueBase::TYPE_ANGLE: return Angle(); + case ValueBase::TYPE_VECTOR: return Vector(); + default: assert(0); return ValueBase(); + } if (loop) { amount = amount - int(amount); @@ -121,9 +127,19 @@ ValueNode_BLineCalcTangent::operator()(Time t)const etl::derivative< etl::hermite > deriv(curve); #ifdef ETL_FIXED_DERIVATIVE - return deriv(amount-from_vertex)*(0.5); + switch (get_type()) + { + case ValueBase::TYPE_ANGLE: return (deriv(amount-from_vertex)*(0.5)).angle(); + case ValueBase::TYPE_VECTOR: return deriv(amount-from_vertex)*(0.5); + default: assert(0); return ValueBase(); + } #else - return deriv(amount-from_vertex)*(-0.5); + switch (get_type()) + { + case ValueBase::TYPE_ANGLE: return (deriv(amount-from_vertex)*(-0.5)).angle(); + case ValueBase::TYPE_VECTOR: return deriv(amount-from_vertex)*(-0.5); + default: assert(0); return ValueBase(); + } #endif } @@ -219,5 +235,6 @@ ValueNode_BLineCalcTangent::get_link_index_from_name(const String &name)const bool ValueNode_BLineCalcTangent::check_type(ValueBase::Type type) { - return type==ValueBase::TYPE_VECTOR; + return (type==ValueBase::TYPE_ANGLE || + type==ValueBase::TYPE_VECTOR); } diff --git a/synfig-core/trunk/src/synfig/vector.h b/synfig-core/trunk/src/synfig/vector.h index c509c3c..61314f1 100644 --- a/synfig-core/trunk/src/synfig/vector.h +++ b/synfig-core/trunk/src/synfig/vector.h @@ -27,6 +27,7 @@ /* === H E A D E R S ======================================================= */ +#include "angle.h" #include "real.h" #include @@ -169,6 +170,9 @@ public: Vector perp()const { return Vector(_y,-_x); } + Angle angle()const + { return Angle::rad(atan2(_y, _x)); } + bool is_equal_to(const Vector& rhs)const { static const value_type epsilon(0.0000000000001);