From e179208d1c8370f87ce6ec87f649e5e99eb5724f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 21 Dec 2009 08:00:11 +0000 Subject: [PATCH] Compute Z bounds for Track3D Set Z coordinates for TrackWraps --- source/3d/track.cpp | 3 +++ source/designer/manipulator.cpp | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/3d/track.cpp b/source/3d/track.cpp index b2ee4fa..1df93a2 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -40,12 +40,15 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const { const Point &pos = track.get_position(); float rot = track.get_rotation(); + float slope = track.get_slope(); float c = cos(-angle); float s = sin(-angle); minp.x = maxp.x = c*pos.x-s*pos.y; minp.y = maxp.y = s*pos.x+c*pos.y; + minp.z = pos.z+min(slope, 0.0f); + maxp.z = pos.z+0.01+max(slope, 0.0f); float c2 = cos(rot-angle); float s2 = sin(rot-angle); diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index f4e75e7..09d32fd 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -387,6 +387,7 @@ void Manipulator::update_wrap() wrap.clear(); float min_x = 0, max_x = 0; float min_y = 0, max_y = 0; + float min_z = 0; for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { Track3D &t3d = designer.get_layout_3d()->get_track(*i->track); @@ -404,7 +405,7 @@ void Manipulator::update_wrap() float s = sin(a); float x = (minp.x+maxp.x)/2; float y = (minp.y+maxp.y)/2; - tw.pos = Point(c*x-s*y, s*x+c*y, (minp.z+maxp.z)/2); + tw.pos = Point(c*x-s*y, s*x+c*y, minp.z); tw.rot = a; tw.width = maxp.x-minp.x+0.01; tw.height = maxp.y-minp.y+0.01; @@ -417,6 +418,7 @@ void Manipulator::update_wrap() { min_x = max_x = tw.pos.x; min_y = max_y = tw.pos.y; + min_z = tw.pos.z; } else { @@ -424,22 +426,24 @@ void Manipulator::update_wrap() max_x = max(max_x, tw.pos.x); min_y = min(min_y, tw.pos.y); max_y = max(max_y, tw.pos.y); + min_z = min(min_z, tw.pos.z); } wrap.push_back(tw); } - center = Point((min_x+max_x)/2, (min_y+max_y)/2, 0); + center = Point((min_x+max_x)/2, (min_y+max_y)/2, min_z); wrap_pos = center; wrap_rot = 0; for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { const Point &tp = i->track->get_position(); - i->pos = Point(tp.x-center.x, tp.y-center.y, tp.z); + i->pos = Point(tp.x-center.x, tp.y-center.y, tp.z-center.z); } for(list::iterator i=wrap.begin(); i!=wrap.end(); ++i) { i->pos.x -= center.x; i->pos.y -= center.y; + i->pos.z -= center.z; } } -- 2.43.0