00001 /* 00002 File: Draw.cc 00003 00004 Function: 00005 00006 Author: Andrew Willmott 00007 00008 Notes: 00009 */ 00010 00011 #include "gcl/Draw.h" 00012 #include "gcl/VecUtil.h" 00013 #include "gcl/Scene.h" 00014 00015 Int scRenderSteps = 10; 00016 00017 Void DrawCircle(Renderer &r, const Point &p, const Vector &n, GCLReal rad) 00018 { 00019 const GCLReal slice = 2 * vl_pi / GCLReal(scRenderSteps); 00020 GCLReal theta; 00021 Vector a0, a1; 00022 Int i; 00023 00024 a0 = norm(FindOrthoVector(n)) * rad; 00025 a1 = cross(n, a0); 00026 theta = 0.0; 00027 00028 r.Begin(scPrimitive::sRenderStyle); 00029 00030 for (i = 0; i < scRenderSteps; i++) 00031 { 00032 r.P(p + a0 * cos(theta) + a1 * sin(theta)); 00033 theta += slice; 00034 } 00035 00036 r.End(); 00037 } 00038 00039 Void MakeBoxCorners(const Point &min, const Point &max, Point corners[8]) 00059 { 00060 corners[0] = Point(min[0], min[1], min[2]); 00061 corners[1] = Point(max[0], min[1], min[2]); 00062 corners[2] = Point(max[0], max[1], min[2]); 00063 corners[3] = Point(min[0], max[1], min[2]); 00064 00065 corners[4] = Point(min[0], min[1], max[2]); 00066 corners[5] = Point(max[0], min[1], max[2]); 00067 corners[6] = Point(max[0], max[1], max[2]); 00068 corners[7] = Point(min[0], max[1], max[2]); 00069 } 00070 00071 Void PaintBox(Renderer &r, const Point &min, const Point &max) 00072 { 00073 Point corners[8]; 00074 00075 MakeBoxCorners(min, max, corners); 00076 PaintBox(r, corners); 00077 } 00078 00079 Void FrameBox(Renderer &r, const Point &min, const Point &max) 00080 { 00081 Point corners[8]; 00082 00083 MakeBoxCorners(min, max, corners); 00084 FrameBox(r, corners); 00085 } 00086 00087 Void PaintRect(Renderer &r, const Coord &min, const Coord &max) 00088 { 00089 r.Begin(scPrimitive::sRenderStyle) 00090 .P(min).P(Coord(max[0], min[1])) 00091 .P(max).P(Coord(min[0], max[1])) 00092 .P(min) 00093 .End(); 00094 } 00095 00096 Void FrameRect(Renderer &r, const Coord &min, const Coord &max) 00097 { 00098 r.Begin(renLineLoop) 00099 .P(min).P(Coord(max[0], min[1])) 00100 .P(max).P(Coord(min[0], max[1])) 00101 .P(min) 00102 .End(); 00103 } 00104 00105 Void PaintBox(Renderer &r, Point c[8]) 00106 { 00107 r.N(-Vector(vl_z)); 00108 r.Begin(scPrimitive::sRenderStyle).P(c[3]).P(c[2]).P(c[1]).P(c[0]).End(); 00109 r.N(Vector(vl_z)); 00110 r.Begin(scPrimitive::sRenderStyle).P(c[4]).P(c[5]).P(c[6]).P(c[7]).End(); 00111 00112 r.N(-Vector(vl_y)); 00113 r.Begin(scPrimitive::sRenderStyle).P(c[0]).P(c[1]).P(c[5]).P(c[4]).End(); 00114 r.N(Vector(vl_x)); 00115 r.Begin(scPrimitive::sRenderStyle).P(c[1]).P(c[2]).P(c[6]).P(c[5]).End(); 00116 r.N(Vector(vl_y)); 00117 r.Begin(scPrimitive::sRenderStyle).P(c[2]).P(c[3]).P(c[7]).P(c[6]).End(); 00118 r.N(-Vector(vl_x)); 00119 r.Begin(scPrimitive::sRenderStyle).P(c[3]).P(c[0]).P(c[4]).P(c[7]).End(); 00120 } 00121 00122 Void FrameBox(Renderer &r, Point c[8]) 00123 { 00124 r.Begin(renLineLoop).P(c[0]).P(c[1]).P(c[2]).P(c[3]).End(); 00125 r.Begin(renLineLoop).P(c[4]).P(c[5]).P(c[6]).P(c[7]).End(); 00126 00127 r.Begin(renLines) 00128 .P(c[0]).P(c[4]) 00129 .P(c[1]).P(c[5]) 00130 .P(c[2]).P(c[6]) 00131 .P(c[3]).P(c[7]) 00132 .End(); 00133 } 00134