X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Ftrack.cpp;h=9797c4a67369c90a7e6d05b07495171fd7afdcfe;hb=1c072afdb1866ba397ee8e6155f5f68c6c7ab4da;hp=72973f3a9b4bc03501af1777d004a275f14cc5b6;hpb=51779f52d3f1fe23e2bdb8864c88b5edd49c57ed;p=r2c2.git diff --git a/source/3d/track.cpp b/source/3d/track.cpp index 72973f3..9797c4a 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -47,50 +47,20 @@ Track3D::~Track3D() delete *i; } -void Track3D::get_bounds(float angle, Vector &minp, Vector &maxp) const -{ - type.get_bounds(angle-track.get_rotation(), minp, maxp); - - float c = cos(-angle); - float s = sin(-angle); - - const Vector &pos = track.get_position(); - minp.x += c*pos.x-s*pos.y; - maxp.x += c*pos.x-s*pos.y; - minp.y += s*pos.x+c*pos.y; - maxp.y += s*pos.x+c*pos.y; - minp.z += pos.z; - maxp.z += pos.z; - - float slope = track.get_slope(); - if(slope>0) - maxp.z += slope; - else - minp.z += slope; -} - Vector Track3D::get_node() const { - const Vector &pos = track.get_position(); - Vector minp; - Vector maxp; - type.get_bounds(0, minp, maxp); - float rot = track.get_rotation(); - float c = cos(rot); - float s = sin(rot); + Geometry::BoundingBox bbox = track.get_type().get_shape()->get_axis_aligned_bounding_box(); + const Vector &minp = bbox.get_minimum_point(); + const Vector &maxp = bbox.get_maximum_point(); - Vector center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0); - return Vector(pos.x+c*center.x-s*center.y, pos.y+s*center.x+c*center.y, pos.z+0.02); + return track.get_position()+rotated_vector((minp+maxp)/2.0f, track.get_rotation())+Vector(0, 0, 0.02); } GL::Matrix Track3D::create_matrix() const { - const Vector &pos = track.get_position(); - float rot = track.get_rotation(); - GL::Matrix matrix; - matrix.translate(pos.x, pos.y, pos.z); - matrix.rotate(rot, 0, 0, 1); + matrix.translate(track.get_position()); + matrix.rotate(track.get_rotation(), 0, 0, 1); matrix.rotate(track.get_slope()/track.get_type().get_total_length(), 0, -1, 0); return matrix;