{
OrientedPoint result;
- Transform dir_trans = Transform::rotation(dir, Vector(0, 0, 1));
if(radius)
{
Angle a = Angle::from_radians(d/radius);
- Vector r = dir_trans.transform(Vector(0, -radius, 0));
- result.position = pos-r+Transform::rotation(a, Vector(0, 0, 1)).transform(r);
+ result.position = transform.transform(Vector(sin(a)*abs(radius), radius-cos(a)*radius, 0));
result.rotation = dir+a;
}
else
{
- result.position = pos+dir_trans.transform(Vector(d, 0, 0));
+ result.position = transform.transform(Vector(d, 0, 0));
result.rotation = dir;
}
OrientedPoint TrackPart::get_nearest_point(const Vector &p) const
{
OrientedPoint result;
- Transform dir_trans = Transform::rotation(dir, Vector(0, 0, 1));
if(radius)
{
- Vector r = dir_trans.transform(Vector(0, -radius, 0));
- Vector v = p-pos+r;
+ Vector v = p-transform.transform(Vector(0, radius, 0));
Angle a = Geometry::atan2(v.y, v.x)+Angle::quarter_turn()-dir;
if(radius<0)
a = Angle::half_turn()-a;
a = min(max(a, Angle::zero()), Angle::from_radians(length));
if(radius<0)
a = -a;
- result.position = pos-r+Transform::rotation(a, Vector(0, 0, 1)).transform(r);
+ result.position = transform.transform(Vector(sin(a)*abs(radius), radius-cos(a)*radius, 0));
result.rotation = dir+a;
}
else
{
Vector v = p-pos;
- Vector dir_vec = dir_trans.transform(Vector(1, 0, 0));
+ Vector dir_vec = transform.transform_linear(Vector(1, 0, 0));
float d = min(max(dot(dir_vec, v), 0.0f), length);
result.position = pos+dir_vec*d;
result.rotation = dir;
void TrackPart::create_shape()
{
- Transform trans = Transform::translation(pos)*
- Transform::rotation(dir, LinAl::Vector<float, 3>(0, 0, 1));
if(radius)
{
Geometry::ExtrudedShape<float, 3> ring(
shapes.push_back(&bounds);
shape = new Geometry::TransformedShape<float, 3>(
Geometry::Intersection<float, 3>::from_iterator_range(shapes.begin(), shapes.end()),
- trans*Transform::translation(Vector(0, radius, 0.005)));
+ transform*Transform::translation(Vector(0, radius, 0.005)));
}
else
{
// TODO Get the track profile dimensions from somewhere
shape = new Geometry::TransformedShape<float, 3>(
Geometry::Box<float>(length, 0.04, 0.01),
- trans*Transform::translation(Vector(length/2, 0, 0.005)));
+ transform*Transform::translation(Vector(length/2, 0, 0.005)));
}
}
obj.length /= 1000;
obj.pos /= 1000;
+
+ obj.transform = Transform::translation(obj.pos)*
+ Transform::rotation(obj.dir, Vector(0, 0, 1));
}
void TrackPart::Loader::start(float x, float y, float d)