]> Shamusworld >> Repos - architektonas/commitdiff
Added 'Fixed Angle' functionality to Line.
authorShamus Hammons <jlhamm@acm.org>
Fri, 16 Sep 2011 21:21:18 +0000 (21:21 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 16 Sep 2011 21:21:18 +0000 (21:21 +0000)
README
src/line.cpp
src/line.h

diff --git a/README b/README
index dec1d8024ab51b49350e33ecec2ed6e9fd43b513..e749f3f3fc855a5100a8261fba8343b6443a2183 100644 (file)
--- a/README
+++ b/README
@@ -70,8 +70,8 @@ love to hear from you so that we can improve!
 
 @-~ Installation ~-@
 
-Architektonas is built on the Qt 4 framework; it requires version 4.7.1 or
-later. We build it using gcc v4.4.5; we can't guarantee that it will compile on
+Architektonas is built on the Qt 4 framework; it requires version 4.7.4 or
+later. We build it using gcc v4.4.6; we can't guarantee that it will compile on
 lesser versions but you never know. Building Architektonas should be as easy as
 typing:
 
index 60e5ab0c1095ff67856aa5b333bf72a0d46afbcf..d6169d64a0a593649171c83348a1a2a6341b6047 100644 (file)
@@ -23,7 +23,8 @@
 
 Line::Line(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2),
        draggingLine(false), draggingHandle1(false), draggingHandle2(false), //needUpdate(false),
-       length(Vector::Magnitude(p2, p1)), hitPoint1(false), hitPoint2(false), hitLine(false)
+       length(Vector::Magnitude(p2, p1)), angle(Vector(endpoint - position).Unit()),
+       hitPoint1(false), hitPoint2(false), hitLine(false)
 {
 }
 
@@ -97,7 +98,7 @@ We solve this by allowing only *one* Dimension object to be attached to the Line
 Arc, etc. and by giving the Dimension object a pointer to our endpoints.
 
 Problem still arises when we delete this object; The attached Dimension object will
-then have bad pointers! What is *should* do is delete the object if and only if this
+then have bad pointers! What it *should* do is delete the object if and only if this
 line is not attached to any other object. If it is, then one of those attachment
 points should be sent to the dimension object (done for position & endpoint).
 
@@ -257,6 +258,7 @@ software currently out there: the GUI will try to do the right thing, most of th
                Vector point1 = (draggingHandle1 ? endpoint : position);
                Vector point2 = (draggingHandle1 ? position : endpoint);
 
+#if 0
                Vector current(point2, point1);
                Vector v = current.Unit() * length;
                Vector v2 = point1 + v;
@@ -264,6 +266,22 @@ software currently out there: the GUI will try to do the right thing, most of th
                //bleh
                if (!Object::fixedLength)
                        v2 = point2;
+#endif
+
+               if (Object::fixedAngle)
+               {
+                       // Here we calculate the component of the current vector along the fixed angle.
+                       // A_compB = (A . Bu) * Bu
+                       double magnitudeAlongB = Vector::Dot(Vector(point2 - point1), angle);
+
+                       if (draggingHandle1)
+                               position = endpoint + (angle * magnitudeAlongB);
+
+                       if (draggingHandle2)
+                               endpoint = position + (angle * magnitudeAlongB);
+               }
+//             else
+//                     v2 = point2;
 
 //If we tell the dimension to flip sides, this is no longer a valid
 //assumption. !!! FIX !!!
@@ -307,6 +325,13 @@ software currently out there: the GUI will try to do the right thing, most of th
                        // it turns out to have a fixed length. :-)
                        length = Vector(endpoint - position).Magnitude();
                }
+
+               if (!Object::fixedAngle)
+               {
+                       // Calculate the new angle, just in case on the next move it turns out to
+                       // be fixed. :-)
+                       angle = Vector(endpoint - position).Unit();
+               }
        }
 
        draggingLine = false;
index 8fd1ed9229f5895d21c50956dda2bba865aa5eb1..ab262254583885d5545f20b35b297492042d3abc 100644 (file)
@@ -35,6 +35,7 @@ class Line: public Object
                bool draggingHandle2;
                bool objectWasDragged;
                double length;
+               Vector angle;
                bool hitPoint1, hitPoint2, hitLine;
                bool oldHitPoint1, oldHitPoint2, oldHitLine;
 };