return 0;
}
+Point Track::get_endpoint_position(const Endpoint &ep) const
+{
+ float c=cos(rot);
+ float s=sin(rot);
+ return Point(pos.x+c*ep.pos.x-s*ep.pos.y, pos.y+s*ep.pos.x+c*ep.pos.y, pos.z+ep.pos.z);
+}
+
float Track::get_length() const
{
float len=parts.front().length;
float limit=(link && !flex) ? 1e-6 : 1e-4;
for(EndpointSeq::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
{
- float x=pos.x+i->pos.x*cos(rot)-i->pos.y*sin(rot);
- float y=pos.y+i->pos.y*cos(rot)+i->pos.x*sin(rot);
+ Point epp=get_endpoint_position(*i);
for(EndpointSeq::iterator j=other.endpoints.begin(); j!=other.endpoints.end(); ++j)
{
if(j->link)
continue;
- float x2=other.pos.x+j->pos.x*cos(other.rot)-j->pos.y*sin(other.rot);
- float y2=other.pos.y+j->pos.y*cos(other.rot)+j->pos.x*sin(other.rot);
- float dx=x2-x;
- float dy=y2-y;
+ Point epp2=other.get_endpoint_position(*j);
+ float dx=epp2.x-epp.x;
+ float dy=epp2.y-epp.y;
if(dx*dx+dy*dy<limit)
{
set_rotation(other.rot+j->rot-i->rot+M_PI);
- set_position(Point(x2-(i->pos.x*cos(rot)-i->pos.y*sin(rot)), y2-(i->pos.y*cos(rot)+i->pos.x*sin(rot)), other.pos.z+j->pos.z-i->pos.z));
+ set_position(Point(epp2.x-(i->pos.x*cos(rot)-i->pos.y*sin(rot)), epp2.y-(i->pos.y*cos(rot)+i->pos.x*sin(rot)), other.pos.z+j->pos.z-i->pos.z));
if(link)
{
if(i->link)
{
for(EndpointSeq::const_iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
{
- float x=pos.x+i->pos.x*cos(rot)-i->pos.y*sin(rot);
- float y=pos.y+i->pos.y*cos(rot)+i->pos.x*sin(rot);
- float dx=pt.x-x;
- float dy=pt.y-y;
+ Point epp=get_endpoint_position(*i);
+ float dx=pt.x-epp.x;
+ float dy=pt.y-epp.y;
if(dx*dx+dy*dy<1e-4)
{
- pt.x=x;
- pt.y=y;
+ pt=epp;
d=rot+i->rot;
return true;
}