X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fline.hh;h=60a0b34eb89402ed23f1c1c2d9e3a63a41887fe7;hp=b40e7cf8c7c8190c9bb59ef5c8d566cda17edc65;hb=HEAD;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/moof/line.hh b/src/moof/line.hh index b40e7cf..60a0b34 100644 --- a/src/moof/line.hh +++ b/src/moof/line.hh @@ -1,33 +1,31 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #ifndef _MOOF_LINE_HH_ #define _MOOF_LINE_HH_ -/** - * \file line.hh - * Classes related to line segments. - */ - #include #include +#include #include #include #include #include #include #include -#include +/** + * \file line.hh + * Classes related to line segments. + */ + namespace moof { @@ -36,18 +34,15 @@ struct line : public drawable, public shape { typedef moof::vector< scalar, fixed > vector; - vector a; vector b; - line() {} line(const vector& point1, const vector& point2) : a(point1), b(point2) {} - vector direction() const { return b - a; @@ -58,31 +53,31 @@ struct line : public drawable, public shape return direction().length(); } - bool intersect(const line& other, contact& hit) const { scalar d = (other.b[1] - other.a[1]) * (b[0] - a[0]) - - (other.b[0] - other.a[0]) * (b[1] - a[1]); + (other.b[0] - other.a[0]) * (b[1] - a[1]); - if (d == SCALAR(0.0)) return false; // lines are parallel + if (d == SCALAR(0.0)) return false; // lines are parallel // ignoring the (somewhat remote) possibility of coincidence - scalar m = ((other.b[0] - other.a[0]) * (a[1] - other.a[1]) - - (other.b[1] - other.a[1]) * (a[0] - other.a[0])) / d; + scalar m = ((other.b[0] - other.a[0]) * + (a[1] - other.a[1]) - + (other.b[1] - other.a[1]) * + (a[0] - other.a[0])) / d; scalar n = ((b[0] - a[0]) * (b[1] - other.a[1]) - - (b[1] - a[1]) * (b[0] - other.a[0])) / d; + (b[1] - a[1]) * (b[0] - other.a[0])) / d; if (m < SCALAR(0.0) || m > SCALAR(1.0) || // not intersecting - n < SCALAR(0.0) || n > SCALAR(1.0)) return false; + n < SCALAR(0.0) || n > SCALAR(1.0)) + return false; vector2 tangent = b - a; vector2 normal = perp(tangent).normalize(); if (dot(normal, other.a - other.b) < SCALAR(0.0)) - { normal = -normal; - } hit.point = a + m * tangent; hit.normal = normal; @@ -104,7 +99,6 @@ struct line : public drawable, public shape if (projection < SCALAR(0.0) || projection > surfaceLength) { // try endpoints - if (other.intersect(a, hit)) { hit.normal = -hit.normal; @@ -117,7 +111,6 @@ struct line : public drawable, public shape hit.point = b; return true; } - return false; } @@ -126,7 +119,7 @@ struct line : public drawable, public shape scalar distance = normal.length(); - if (distance > other.radius) false; // not intersecting + if (distance > other.radius) false; // not intersecting normal.normalize(); @@ -137,8 +130,8 @@ struct line : public drawable, public shape return true; } - - bool intersect_ray(const ray<2>& ray, ray<2>::contact& hit) const + bool + intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const { vector2 v1 = a - ray.point; scalar a1 = signed_angle_2D(v1, b - ray.point); @@ -170,7 +163,6 @@ struct line : public drawable, public shape hit.normal = perp(a - b); return true; - /* // solve: Cx + r*Dx = Ax + s(Bx - Ax) // Cy + r*Dy = Ay + s(By - Ay) @@ -222,10 +214,9 @@ struct line : public drawable, public shape */ } - void draw(scalar alpha = 0.0) const { - texture::reset_binding(); + image::reset_binding(); glBegin(GL_LINES); glVertex(a); glVertex(b); @@ -233,7 +224,6 @@ struct line : public drawable, public shape } }; - typedef line<2> line2; typedef line<3> line3; @@ -247,31 +237,27 @@ struct polygon : public drawable, public shape polygon() {} - bool intersect_ray(const ray& ray, typename ray::contact& hit) + bool intersect_ray(const ray& ray, + typename moof::ray::contact& hit) { return false; } void draw(scalar alpha = 0.0) const { - texture::reset_binding(); + image::reset_binding(); glBegin(GL_POLYGON); - for (int i = 0; i < D; ++i) - { - glVertex(points[0]); - } + for (int i = 0; i < D; ++i) glVertex(points[0]); glEnd(); } }; - typedef polygon<2,3> triangle2; typedef polygon<3,3> triangle3; template -bool intersect(const line& line, const sphere& sphere, - contact& hit) +bool intersect(const line& line, const sphere& sphere, contact& hit) { return false; }