| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
| <title>FTGL: FTContour.cpp Source File</title> |
| <link href="doxygen.css" rel="stylesheet" type="text/css"> |
| </head><body> |
| <!-- Generated by Doxygen 1.3.6 --> |
| <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div> |
| <h1>FTContour.cpp</h1><a href="FTContour_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#include "<a class="code" href="FTContour_8h.html">FTContour.h</a>"</span> |
| 00002 |
| <a name="l00003"></a><a class="code" href="FTContour_8cpp.html#a0">00003</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="FTContour_8cpp.html#a0">BEZIER_STEP_SIZE</a> = 0.2f; |
| 00004 |
| 00005 |
| 00006 <span class="keywordtype">void</span> FTContour::AddPoint( <a class="code" href="classFTPoint.html">FTPoint</a> point) |
| 00007 { |
| 00008 <span class="keywordflow">if</span>( pointList.<a class="code" href="classFTVector.html#a9">empty</a>() || point != pointList[pointList.<a class="code" href="classFTVector.html#a3">size</a>() - 1]) |
| 00009 { |
| 00010 pointList.<a class="code" href="classFTVector.html#a14">push_back</a>( point); |
| 00011 } |
| 00012 } |
| 00013 |
| 00014 |
| 00015 <span class="keywordtype">void</span> FTContour::AddPoint( <span class="keywordtype">float</span> x, <span class="keywordtype">float</span> y) |
| 00016 { |
| 00017 AddPoint( <a class="code" href="classFTPoint.html">FTPoint</a>( x, y, 0.0f)); |
| 00018 } |
| 00019 |
| 00020 |
| 00021 <span class="keywordtype">void</span> FTContour::evaluateQuadraticCurve() |
| 00022 { |
| 00023 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i <= ( 1.0f / <a class="code" href="FTContour_8cpp.html#a0">BEZIER_STEP_SIZE</a>); i++) |
| 00024 { |
| 00025 <span class="keywordtype">float</span> bezierValues[2][2]; |
| 00026 |
| 00027 <span class="keywordtype">float</span> t = static_cast<float>(i) * <a class="code" href="FTContour_8cpp.html#a0">BEZIER_STEP_SIZE</a>; |
| 00028 |
| 00029 bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0]; |
| 00030 bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1]; |
| 00031 |
| 00032 bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0]; |
| 00033 bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1]; |
| 00034 |
| 00035 bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0]; |
| 00036 bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1]; |
| 00037 |
| 00038 AddPoint( bezierValues[0][0], bezierValues[0][1]); |
| 00039 } |
| 00040 } |
| 00041 |
| 00042 <span class="keywordtype">void</span> FTContour::evaluateCubicCurve() |
| 00043 { |
| 00044 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i <= ( 1.0f / <a class="code" href="FTContour_8cpp.html#a0">BEZIER_STEP_SIZE</a>); i++) |
| 00045 { |
| 00046 <span class="keywordtype">float</span> bezierValues[3][2]; |
| 00047 |
| 00048 <span class="keywordtype">float</span> t = static_cast<float>(i) * <a class="code" href="FTContour_8cpp.html#a0">BEZIER_STEP_SIZE</a>; |
| 00049 |
| 00050 bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0]; |
| 00051 bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1]; |
| 00052 |
| 00053 bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0]; |
| 00054 bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1]; |
| 00055 |
| 00056 bezierValues[2][0] = (1.0f - t) * controlPoints[2][0] + t * controlPoints[3][0]; |
| 00057 bezierValues[2][1] = (1.0f - t) * controlPoints[2][1] + t * controlPoints[3][1]; |
| 00058 |
| 00059 bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0]; |
| 00060 bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1]; |
| 00061 |
| 00062 bezierValues[1][0] = (1.0f - t) * bezierValues[1][0] + t * bezierValues[2][0]; |
| 00063 bezierValues[1][1] = (1.0f - t) * bezierValues[1][1] + t * bezierValues[2][1]; |
| 00064 |
| 00065 bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0]; |
| 00066 bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1]; |
| 00067 |
| 00068 AddPoint( bezierValues[0][0], bezierValues[0][1]); |
| 00069 } |
| 00070 } |
| 00071 |
| 00072 |
| <a name="l00073"></a><a class="code" href="classFTContour.html#a0">00073</a> <a class="code" href="classFTContour.html#a0">FTContour::FTContour</a>( FT_Vector* contour, <span class="keywordtype">char</span>* pointTags, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numberOfPoints) |
| 00074 { |
| 00075 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointIndex = 0; pointIndex < numberOfPoints; ++ pointIndex) |
| 00076 { |
| 00077 <span class="keywordtype">char</span> pointTag = pointTags[pointIndex]; |
| 00078 |
| 00079 <span class="keywordflow">if</span>( pointTag == FT_Curve_Tag_On || numberOfPoints < 2) |
| 00080 { |
| 00081 AddPoint( contour[pointIndex].x, contour[pointIndex].y); |
| 00082 <span class="keywordflow">continue</span>; |
| 00083 } |
| 00084 |
| 00085 <a class="code" href="classFTPoint.html">FTPoint</a> controlPoint( contour[pointIndex]); |
| 00086 <a class="code" href="classFTPoint.html">FTPoint</a> previousPoint = ( 0 == pointIndex) |
| 00087 ? <a class="code" href="classFTPoint.html">FTPoint</a>( contour[numberOfPoints - 1]) |
| 00088 : pointList[pointList.<a class="code" href="classFTVector.html#a3">size</a>() - 1]; |
| 00089 |
| 00090 <a class="code" href="classFTPoint.html">FTPoint</a> nextPoint = ( pointIndex == numberOfPoints - 1) |
| 00091 ? pointList[0] |
| 00092 : <a class="code" href="classFTPoint.html">FTPoint</a>( contour[pointIndex + 1]); |
| 00093 |
| 00094 <span class="keywordflow">if</span>( pointTag == FT_Curve_Tag_Conic) |
| 00095 { |
| 00096 <span class="keywordtype">char</span> nextPointTag = ( pointIndex == numberOfPoints - 1) |
| 00097 ? pointTags[0] |
| 00098 : pointTags[pointIndex + 1]; |
| 00099 |
| 00100 <span class="keywordflow">while</span>( nextPointTag == FT_Curve_Tag_Conic) |
| 00101 { |
| 00102 nextPoint = ( controlPoint + nextPoint) * 0.5f; |
| 00103 |
| 00104 controlPoints[0][0] = previousPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[0][1] = previousPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00105 controlPoints[1][0] = controlPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[1][1] = controlPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00106 controlPoints[2][0] = nextPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[2][1] = nextPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00107 |
| 00108 evaluateQuadraticCurve(); |
| 00109 ++pointIndex; |
| 00110 |
| 00111 previousPoint = nextPoint; |
| 00112 controlPoint = <a class="code" href="classFTPoint.html">FTPoint</a>( contour[pointIndex]); |
| 00113 nextPoint = ( pointIndex == numberOfPoints - 1) |
| 00114 ? pointList[0] |
| 00115 : FTPoint( contour[pointIndex + 1]); |
| 00116 nextPointTag = ( pointIndex == numberOfPoints - 1) |
| 00117 ? pointTags[0] |
| 00118 : pointTags[pointIndex + 1]; |
| 00119 } |
| 00120 |
| 00121 controlPoints[0][0] = previousPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[0][1] = previousPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00122 controlPoints[1][0] = controlPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[1][1] = controlPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00123 controlPoints[2][0] = nextPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[2][1] = nextPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00124 |
| 00125 evaluateQuadraticCurve(); |
| 00126 <span class="keywordflow">continue</span>; |
| 00127 } |
| 00128 |
| 00129 <span class="keywordflow">if</span>( pointTag == FT_Curve_Tag_Cubic) |
| 00130 { |
| 00131 <a class="code" href="classFTPoint.html">FTPoint</a> controlPoint2 = nextPoint; |
| 00132 |
| 00133 <a class="code" href="classFTPoint.html">FTPoint</a> nextPoint = ( pointIndex == numberOfPoints - 2) |
| 00134 ? pointList[0] |
| 00135 : <a class="code" href="classFTPoint.html">FTPoint</a>( contour[pointIndex + 2]); |
| 00136 |
| 00137 controlPoints[0][0] = previousPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[0][1] = previousPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00138 controlPoints[1][0] = controlPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[1][1] = controlPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00139 controlPoints[2][0] = controlPoint2.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[2][1] = controlPoint2.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00140 controlPoints[3][0] = nextPoint.<a class="code" href="classFTPoint.html#a7">X</a>(); controlPoints[3][1] = nextPoint.<a class="code" href="classFTPoint.html#a8">Y</a>(); |
| 00141 |
| 00142 evaluateCubicCurve(); |
| 00143 ++pointIndex; |
| 00144 <span class="keywordflow">continue</span>; |
| 00145 } |
| 00146 } |
| 00147 } |
| </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Dec 5 22:24:05 2004 for FTGL by |
| <a href="http://www.doxygen.org/index.html"> |
| <img src="doxygen.png" alt="doxygen" align="middle" border=0 > |
| </a>1.3.6 </small></address> |
| </body> |
| </html> |