X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_blinecalctangent.cpp;h=3a3c2cc209797ddde008cc78e3d6d5d287b80b1b;hb=ecff046513a5c0bd64db58b69fdd2fb42736bca7;hp=36eced51826c25695355ce1a9c1ccc3c784eeab3;hpb=b37086823c5bfee9c76f6b265584a414100963ef;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp index 36eced5..3a3c2cc 100644 --- a/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_blinecalctangent.cpp @@ -6,7 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** Copyright (c) 2007 Chris Moore +** Copyright (c) 2007, 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -58,13 +58,16 @@ using namespace synfig; ValueNode_BLineCalcTangent::ValueNode_BLineCalcTangent(const ValueBase::Type &x): LinkableValueNode(x) { - if(x!=ValueBase::TYPE_ANGLE && x!=ValueBase::TYPE_VECTOR) - throw Exception::BadType(ValueBase::type_name(x)); + if(x!=ValueBase::TYPE_ANGLE && x!=ValueBase::TYPE_REAL && x!=ValueBase::TYPE_VECTOR) + throw Exception::BadType(ValueBase::type_local_name(x)); ValueNode_BLine* value_node(new ValueNode_BLine()); set_link("bline",value_node); set_link("loop",ValueNode_Const::create(bool(false))); set_link("amount",ValueNode_Const::create(Real(0.5))); + set_link("offset",ValueNode_Const::create(Angle::deg(0))); + set_link("scale",ValueNode_Const::create(Real(1.0))); + set_link("fixed_length",ValueNode_Const::create(bool(false))); } LinkableValueNode* @@ -85,14 +88,19 @@ ValueNode_BLineCalcTangent::~ValueNode_BLineCalcTangent() } ValueBase -ValueNode_BLineCalcTangent::operator()(Time t)const +ValueNode_BLineCalcTangent::operator()(Time t, Real amount)const { - const std::vector bline((*bline_)(t)); + if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS")) + printf("%s:%d operator()\n", __FILE__, __LINE__); + + const std::vector bline((*bline_)(t).get_list()); handle bline_value_node(bline_); const bool looped(bline_value_node->get_loop()); int size = bline.size(), from_vertex; bool loop((*loop_)(t).get(bool())); - Real amount((*amount_)(t).get(Real())); + Angle offset((*offset_)(t).get(Angle())); + Real scale((*scale_)(t).get(Real())); + bool fixed_length((*fixed_length_)(t).get(bool())); BLinePoint blinepoint0, blinepoint1; if (!looped) size--; @@ -100,6 +108,7 @@ ValueNode_BLineCalcTangent::operator()(Time t)const switch (get_type()) { case ValueBase::TYPE_ANGLE: return Angle(); + case ValueBase::TYPE_REAL: return Real(); case ValueBase::TYPE_VECTOR: return Vector(); default: assert(0); return ValueBase(); } @@ -127,21 +136,31 @@ ValueNode_BLineCalcTangent::operator()(Time t)const blinepoint0.get_tangent2(), blinepoint1.get_tangent1()); etl::derivative< etl::hermite > deriv(curve); -#ifdef ETL_FIXED_DERIVATIVE - 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 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); + case ValueBase::TYPE_ANGLE: return deriv(amount-from_vertex).angle() + offset; + case ValueBase::TYPE_REAL: + { + if (fixed_length) return scale; + return deriv(amount-from_vertex).mag() * scale; + } + case ValueBase::TYPE_VECTOR: + { + Vector tangent(deriv(amount-from_vertex)); + Angle angle(tangent.angle() + offset); + Real mag = fixed_length ? scale : (tangent.mag() * scale); + return Vector(Angle::cos(angle).get()*mag, + Angle::sin(angle).get()*mag); + } default: assert(0); return ValueBase(); } -#endif +} + +ValueBase +ValueNode_BLineCalcTangent::operator()(Time t)const +{ + Real amount((*amount_)(t).get(Real())); + return (*this)(t, amount); } String @@ -157,23 +176,18 @@ ValueNode_BLineCalcTangent::get_local_name()const } bool -ValueNode_BLineCalcTangent::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_BLineCalcTangent::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && i=0 && i=0 && i