#include <bezier_patch.h>
0 ---s---> 3
A---> ad ---- da <---D | | | | | | v v | ab ia id dc t | | | | | | v ba ib ic cd ^ ^ | | | | B---> bc ---- cb <---C 1 2
Nevrax France
Definition at line 73 of file bezier_patch.h.
Public Member Functions | |
void | applyMatrix (const CMatrix &m) |
Do the matrix transformation m*patch. | |
CBezierPatch () | |
Constructor: undefined Bezier patch!! | |
CVector | eval (float s, float t) const |
Evaluate. | |
CVectorD | evalDouble (double s, double t) const |
Evaluate, but return a vector double. | |
CVector | evalNormal (float s, float t) const |
Evaluate the normal at (s,t). returned vector is normalized. | |
CVector | evalTangentS (float s, float t) const |
Evaluate the tangentS at (s,t). returned vector is normalized. | |
CVector | evalTangentT (float s, float t) const |
Evaluate the tangentT at (s,t). returned vector is normalized. | |
void | make (CVector vertices[4], CVector normals[4]) |
complete computation of Vertices, Tangents, and Interiors, provinding the vertices and vertex normals. | |
void | makeInteriors () |
make default Interiors, according to Vertices and Tangents. | |
Subdivision. | |
void | subdivideS (CBezierPatch &left, CBezierPatch &right, float s=0.5f) const |
void | subdivideT (CBezierPatch &top, CBezierPatch &bottom, float t=0.5f) const |
Data Fields | |
CVector | Interiors [4] |
The interiors, ia,ib,ic,id. NB: interiors are points, not vectors. | |
CVector | Tangents [8] |
The tangents ab, ba, bc, cb, cd, dc, da, ad. NB: tangents are points, not vectors. | |
CVector | Vertices [4] |
The vertices a,b,c,d of the quad patch. |
|
Constructor: undefined Bezier patch!!
Definition at line 86 of file bezier_patch.h.
00086 {} |
|
Do the matrix transformation m*patch.
Definition at line 73 of file bezier_patch.cpp. References Interiors, sint, Tangents, and Vertices.
|
|
Evaluate.
Definition at line 105 of file bezier_patch.cpp. References Interiors, NL3D::mulAdd(), NLMISC::CVector::set(), Tangents, and Vertices. Referenced by NL3D::CPatch::appendTileMaterialToRenderList(), NL3D::CPatch::computeVertex(), NL3D::CPatch::createVegetableBlock(), NL3D::CPatchDLMContext::generate(), NL3D::CPatch::generateTileVegetable(), and NL3D::CLandscapeVegetableBlock::init().
00106 { 00107 CVector p; 00108 00109 float ps2 = ps * ps; 00110 float ps1 = 1.0f - ps; 00111 float ps12 = ps1 * ps1; 00112 float s0 = ps12 * ps1; 00113 float s1 = 3.0f * ps * ps12; 00114 float s2 = 3.0f * ps2 * ps1; 00115 float s3 = ps2 * ps; 00116 float pt2 = pt * pt; 00117 float pt1 = 1.0f - pt; 00118 float pt12 = pt1 * pt1; 00119 float t0 = pt12 * pt1; 00120 float t1 = 3.0f * pt * pt12; 00121 float t2 = 3.0f * pt2 * pt1; 00122 float t3 = pt2 * pt; 00123 00124 p.set(0,0,0); 00125 mulAdd(p, Vertices[0] , s0 * t0); 00126 mulAdd(p, Tangents[7] , s1 * t0); 00127 mulAdd(p, Tangents[6] , s2 * t0); 00128 mulAdd(p, Vertices[3] , s3 * t0); 00129 mulAdd(p, Tangents[0] , s0 * t1); 00130 mulAdd(p, Interiors[0], s1 * t1); 00131 mulAdd(p, Interiors[3], s2 * t1); 00132 mulAdd(p, Tangents[5] , s3 * t1); 00133 mulAdd(p, Tangents[1] , s0 * t2); 00134 mulAdd(p, Interiors[1], s1 * t2); 00135 mulAdd(p, Interiors[2], s2 * t2); 00136 mulAdd(p, Tangents[4] , s3 * t2); 00137 mulAdd(p, Vertices[1] , s0 * t3); 00138 mulAdd(p, Tangents[2] , s1 * t3); 00139 mulAdd(p, Tangents[3] , s2 * t3); 00140 mulAdd(p, Vertices[2] , s3 * t3); 00141 00142 return p; 00143 } |
|
Evaluate, but return a vector double.
Definition at line 145 of file bezier_patch.cpp. References Interiors, NL3D::mulAddD(), NLMISC::CVectorD::set(), Tangents, and Vertices.
00146 { 00147 CVectorD p; 00148 00149 double ps2 = ps * ps; 00150 double ps1 = 1.0f - ps; 00151 double ps12 = ps1 * ps1; 00152 double s0 = ps12 * ps1; 00153 double s1 = 3.0f * ps * ps12; 00154 double s2 = 3.0f * ps2 * ps1; 00155 double s3 = ps2 * ps; 00156 double pt2 = pt * pt; 00157 double pt1 = 1.0f - pt; 00158 double pt12 = pt1 * pt1; 00159 double t0 = pt12 * pt1; 00160 double t1 = 3.0f * pt * pt12; 00161 double t2 = 3.0f * pt2 * pt1; 00162 double t3 = pt2 * pt; 00163 00164 p.set(0,0,0); 00165 mulAddD(p, Vertices[0] , s0 * t0); 00166 mulAddD(p, Tangents[7] , s1 * t0); 00167 mulAddD(p, Tangents[6] , s2 * t0); 00168 mulAddD(p, Vertices[3] , s3 * t0); 00169 mulAddD(p, Tangents[0] , s0 * t1); 00170 mulAddD(p, Interiors[0], s1 * t1); 00171 mulAddD(p, Interiors[3], s2 * t1); 00172 mulAddD(p, Tangents[5] , s3 * t1); 00173 mulAddD(p, Tangents[1] , s0 * t2); 00174 mulAddD(p, Interiors[1], s1 * t2); 00175 mulAddD(p, Interiors[2], s2 * t2); 00176 mulAddD(p, Tangents[4] , s3 * t2); 00177 mulAddD(p, Vertices[1] , s0 * t3); 00178 mulAddD(p, Tangents[2] , s1 * t3); 00179 mulAddD(p, Tangents[3] , s2 * t3); 00180 mulAddD(p, Vertices[2] , s3 * t3); 00181 00182 return p; 00183 } |
|
Evaluate the normal at (s,t). returned vector is normalized.
Definition at line 187 of file bezier_patch.cpp. References Interiors, NL3D::mulAdd(), NLMISC::CVector::normalize(), NLMISC::CVector::set(), Tangents, and Vertices. Referenced by NL3D::CPatch::appendTileMaterialToRenderList(), NL3D::CZoneLighter::buildZoneInformation(), NL3D::CPatch::computeNoise(), NL3D::CPatch::computeNormalCornerSmooth(), NL3D::CPatch::computeNormalEdgeSmooth(), NL3D::CPatch::computeNormalOnNeighbor(), NL3D::CPatchDLMContext::generate(), NL3D::CPatch::generateTileVegetable(), NL3D::CZoneLighter::getNormal(), and NL3D::CZoneLighter::processZonePointLightRT().
00188 { 00189 CVector tgtS, tgtT; 00190 00191 float s0,s1,s2,s3; 00192 float t0,t1,t2,t3; 00193 float ps2 = ps * ps; 00194 float ps1 = 1.0f - ps; 00195 float ps12 = ps1 * ps1; 00196 float pt2 = pt * pt; 00197 float pt1 = 1.0f - pt; 00198 float pt12 = pt1 * pt1; 00199 00200 // Compute tangentS 00201 //================= 00202 // s/ds. 00203 s0 = -3* ps12; 00204 s1 = 9*ps2 + 3 -12*ps; 00205 s2 =-9*ps2 + 6*ps ; 00206 s3 = 3* ps2; 00207 // t/dt. 00208 t0 = pt12 * pt1; 00209 t1 = 3.0f * pt * pt12; 00210 t2 = 3.0f * pt2 * pt1; 00211 t3 = pt2 * pt; 00212 00213 tgtS.set(0,0,0); 00214 mulAdd(tgtS, Vertices[0] , s0 * t0); 00215 mulAdd(tgtS, Tangents[7] , s1 * t0); 00216 mulAdd(tgtS, Tangents[6] , s2 * t0); 00217 mulAdd(tgtS, Vertices[3] , s3 * t0); 00218 mulAdd(tgtS, Tangents[0] , s0 * t1); 00219 mulAdd(tgtS, Interiors[0], s1 * t1); 00220 mulAdd(tgtS, Interiors[3], s2 * t1); 00221 mulAdd(tgtS, Tangents[5] , s3 * t1); 00222 mulAdd(tgtS, Tangents[1] , s0 * t2); 00223 mulAdd(tgtS, Interiors[1], s1 * t2); 00224 mulAdd(tgtS, Interiors[2], s2 * t2); 00225 mulAdd(tgtS, Tangents[4] , s3 * t2); 00226 mulAdd(tgtS, Vertices[1] , s0 * t3); 00227 mulAdd(tgtS, Tangents[2] , s1 * t3); 00228 mulAdd(tgtS, Tangents[3] , s2 * t3); 00229 mulAdd(tgtS, Vertices[2] , s3 * t3); 00230 00231 // Compute tangentT 00232 //================= 00233 // s/ds. 00234 s0 = ps12 * ps1; 00235 s1 = 3.0f * ps * ps12; 00236 s2 = 3.0f * ps2 * ps1; 00237 s3 = ps2 * ps; 00238 // t/dt. 00239 t0 = -3* pt12; 00240 t1 = 9*pt2 + 3 -12*pt; 00241 t2 =-9*pt2 + 6*pt ; 00242 t3 = 3* pt2; 00243 00244 tgtT.set(0,0,0); 00245 mulAdd(tgtT, Vertices[0] , s0 * t0); 00246 mulAdd(tgtT, Tangents[7] , s1 * t0); 00247 mulAdd(tgtT, Tangents[6] , s2 * t0); 00248 mulAdd(tgtT, Vertices[3] , s3 * t0); 00249 mulAdd(tgtT, Tangents[0] , s0 * t1); 00250 mulAdd(tgtT, Interiors[0], s1 * t1); 00251 mulAdd(tgtT, Interiors[3], s2 * t1); 00252 mulAdd(tgtT, Tangents[5] , s3 * t1); 00253 mulAdd(tgtT, Tangents[1] , s0 * t2); 00254 mulAdd(tgtT, Interiors[1], s1 * t2); 00255 mulAdd(tgtT, Interiors[2], s2 * t2); 00256 mulAdd(tgtT, Tangents[4] , s3 * t2); 00257 mulAdd(tgtT, Vertices[1] , s0 * t3); 00258 mulAdd(tgtT, Tangents[2] , s1 * t3); 00259 mulAdd(tgtT, Tangents[3] , s2 * t3); 00260 mulAdd(tgtT, Vertices[2] , s3 * t3); 00261 00262 00263 // Return the normal. 00264 CVector norm= tgtT^tgtS; 00265 norm.normalize(); 00266 return norm; 00267 } |
|
Evaluate the tangentS at (s,t). returned vector is normalized.
Definition at line 271 of file bezier_patch.cpp. References Interiors, NL3D::mulAdd(), NLMISC::CVector::normed(), NLMISC::CVector::set(), Tangents, and Vertices.
00272 { 00273 CVector tgtS; 00274 00275 float s0,s1,s2,s3; 00276 float t0,t1,t2,t3; 00277 float ps2 = ps * ps; 00278 float ps1 = 1.0f - ps; 00279 float ps12 = ps1 * ps1; 00280 float pt2 = pt * pt; 00281 float pt1 = 1.0f - pt; 00282 float pt12 = pt1 * pt1; 00283 00284 // Compute tangentS 00285 //================= 00286 // s/ds. 00287 s0 = -3* ps12; 00288 s1 = 9*ps2 + 3 -12*ps; 00289 s2 =-9*ps2 + 6*ps ; 00290 s3 = 3* ps2; 00291 // t/dt. 00292 t0 = pt12 * pt1; 00293 t1 = 3.0f * pt * pt12; 00294 t2 = 3.0f * pt2 * pt1; 00295 t3 = pt2 * pt; 00296 00297 tgtS.set(0,0,0); 00298 mulAdd(tgtS, Vertices[0] , s0 * t0); 00299 mulAdd(tgtS, Tangents[7] , s1 * t0); 00300 mulAdd(tgtS, Tangents[6] , s2 * t0); 00301 mulAdd(tgtS, Vertices[3] , s3 * t0); 00302 mulAdd(tgtS, Tangents[0] , s0 * t1); 00303 mulAdd(tgtS, Interiors[0], s1 * t1); 00304 mulAdd(tgtS, Interiors[3], s2 * t1); 00305 mulAdd(tgtS, Tangents[5] , s3 * t1); 00306 mulAdd(tgtS, Tangents[1] , s0 * t2); 00307 mulAdd(tgtS, Interiors[1], s1 * t2); 00308 mulAdd(tgtS, Interiors[2], s2 * t2); 00309 mulAdd(tgtS, Tangents[4] , s3 * t2); 00310 mulAdd(tgtS, Vertices[1] , s0 * t3); 00311 mulAdd(tgtS, Tangents[2] , s1 * t3); 00312 mulAdd(tgtS, Tangents[3] , s2 * t3); 00313 mulAdd(tgtS, Vertices[2] , s3 * t3); 00314 00315 // Return the tgt normalized 00316 return tgtS.normed(); 00317 } |
|
Evaluate the tangentT at (s,t). returned vector is normalized.
Definition at line 321 of file bezier_patch.cpp. References Interiors, NL3D::mulAdd(), NLMISC::CVector::normed(), NLMISC::CVector::set(), Tangents, and Vertices.
00322 { 00323 CVector tgtT; 00324 00325 float s0,s1,s2,s3; 00326 float t0,t1,t2,t3; 00327 float ps2 = ps * ps; 00328 float ps1 = 1.0f - ps; 00329 float ps12 = ps1 * ps1; 00330 float pt2 = pt * pt; 00331 float pt1 = 1.0f - pt; 00332 float pt12 = pt1 * pt1; 00333 00334 // Compute tangentT 00335 //================= 00336 // s/ds. 00337 s0 = ps12 * ps1; 00338 s1 = 3.0f * ps * ps12; 00339 s2 = 3.0f * ps2 * ps1; 00340 s3 = ps2 * ps; 00341 // t/dt. 00342 t0 = -3* pt12; 00343 t1 = 9*pt2 + 3 -12*pt; 00344 t2 =-9*pt2 + 6*pt ; 00345 t3 = 3* pt2; 00346 00347 tgtT.set(0,0,0); 00348 mulAdd(tgtT, Vertices[0] , s0 * t0); 00349 mulAdd(tgtT, Tangents[7] , s1 * t0); 00350 mulAdd(tgtT, Tangents[6] , s2 * t0); 00351 mulAdd(tgtT, Vertices[3] , s3 * t0); 00352 mulAdd(tgtT, Tangents[0] , s0 * t1); 00353 mulAdd(tgtT, Interiors[0], s1 * t1); 00354 mulAdd(tgtT, Interiors[3], s2 * t1); 00355 mulAdd(tgtT, Tangents[5] , s3 * t1); 00356 mulAdd(tgtT, Tangents[1] , s0 * t2); 00357 mulAdd(tgtT, Interiors[1], s1 * t2); 00358 mulAdd(tgtT, Interiors[2], s2 * t2); 00359 mulAdd(tgtT, Tangents[4] , s3 * t2); 00360 mulAdd(tgtT, Vertices[1] , s0 * t3); 00361 mulAdd(tgtT, Tangents[2] , s1 * t3); 00362 mulAdd(tgtT, Tangents[3] , s2 * t3); 00363 mulAdd(tgtT, Vertices[2] , s3 * t3); 00364 00365 // Return the tgt normalized 00366 return tgtT.normed(); 00367 } |
|
complete computation of Vertices, Tangents, and Interiors, provinding the vertices and vertex normals.
Definition at line 36 of file bezier_patch.cpp. References makeInteriors(), NLMISC::CVector::norm(), NLMISC::CVector::normalize(), sint, Tangents, and Vertices.
00037 { 00038 sint i; 00039 static sint starts[8]= {0,1, 1,2, 2,3, 3,0}; 00040 static sint ends[8]= {1,0, 2,1, 3,2, 0,3}; 00041 00042 for(i=0;i<4;i++) 00043 Vertices[i]= vertices[i]; 00044 00045 // For all tangents. 00046 for(i=0;i<8;i++) 00047 { 00048 CVector tgt= Vertices[ends[i]] - Vertices[starts[i]]; 00049 CVector I,J,K; 00050 J= normals[starts[i]]; 00051 I= J^tgt; 00052 K= I^J; 00053 K.normalize(); 00054 // Yes, we store tangents as position, not vectors... 00055 Tangents[i]= Vertices[starts[i]] + K*tgt.norm()/3; 00056 } 00057 00058 makeInteriors(); 00059 } |
|
make default Interiors, according to Vertices and Tangents.
Definition at line 61 of file bezier_patch.cpp. References Interiors, Tangents, and Vertices. Referenced by make().
00062 { 00063 CVector &a = Vertices[0]; 00064 CVector &b = Vertices[1]; 00065 CVector &c = Vertices[2]; 00066 CVector &d = Vertices[3]; 00067 Interiors[0] = Tangents[7] + Tangents[0] - a; 00068 Interiors[1] = Tangents[1] + Tangents[2] - b; 00069 Interiors[2] = Tangents[3] + Tangents[4] - c; 00070 Interiors[3] = Tangents[5] + Tangents[6] - d; 00071 } |
|
Subdivide the bezier patch in 2 bezier patch along s, at s (beetween [0,1]). NB: left goes from 0 to s, right goes from s to 1. Definition at line 391 of file bezier_patch.cpp. References NL3D::CBezierPatch::CBezierCurve::get(), Interiors, s, NL3D::CBezierPatch::CBezierCurve::set(), sint, NL3D::CBezierPatch::CBezierCurve::subdivide(), Tangents, and Vertices. Referenced by NL3D::CPatch::addPatchBlocksInBBoxRecurs(), and NL3D::CPatch::addTrianglesInBBoxRecurs().
00392 { 00393 CBezierCurve curveT[4]; 00394 CBezierCurve curveTLeft[4]; 00395 CBezierCurve curveTRight[4]; 00396 00397 // Setup horizontal curves. 00398 curveT[0].set(Vertices[0], Tangents[7] , Tangents[6] , Vertices[3]); 00399 curveT[1].set(Tangents[0], Interiors[0], Interiors[3], Tangents[5]); 00400 curveT[2].set(Tangents[1], Interiors[1], Interiors[2], Tangents[4]); 00401 curveT[3].set(Vertices[1], Tangents[2] , Tangents[3] , Vertices[2]); 00402 00403 // Subdivide curves. 00404 for(sint i=0;i<4;i++) 00405 curveT[i].subdivide(curveTLeft[i], curveTRight[i], s); 00406 00407 // Setup bezier patchs. 00408 // left. 00409 curveTLeft[0].get(left.Vertices[0], left.Tangents[7] , left.Tangents[6] , left.Vertices[3]); 00410 curveTLeft[1].get(left.Tangents[0], left.Interiors[0], left.Interiors[3], left.Tangents[5]); 00411 curveTLeft[2].get(left.Tangents[1], left.Interiors[1], left.Interiors[2], left.Tangents[4]); 00412 curveTLeft[3].get(left.Vertices[1], left.Tangents[2] , left.Tangents[3] , left.Vertices[2]); 00413 // right. 00414 curveTRight[0].get(right.Vertices[0], right.Tangents[7] , right.Tangents[6] , right.Vertices[3]); 00415 curveTRight[1].get(right.Tangents[0], right.Interiors[0], right.Interiors[3], right.Tangents[5]); 00416 curveTRight[2].get(right.Tangents[1], right.Interiors[1], right.Interiors[2], right.Tangents[4]); 00417 curveTRight[3].get(right.Vertices[1], right.Tangents[2] , right.Tangents[3] , right.Vertices[2]); 00418 } |
|
Subdivide the bezier patch in 2 bezier patch along t, at t (beetween [0,1]). NB: top goes from 0 to t, bottom goes from t to 1. Definition at line 422 of file bezier_patch.cpp. References NL3D::CBezierPatch::CBezierCurve::get(), Interiors, NL3D::CBezierPatch::CBezierCurve::set(), sint, NL3D::CBezierPatch::CBezierCurve::subdivide(), t, Tangents, and Vertices. Referenced by NL3D::CPatch::addPatchBlocksInBBoxRecurs(), and NL3D::CPatch::addTrianglesInBBoxRecurs().
00423 { 00424 CBezierCurve curveS[4]; 00425 CBezierCurve curveSTop[4]; 00426 CBezierCurve curveSBottom[4]; 00427 00428 // Setup vertical curves. 00429 curveS[0].set(Vertices[0], Tangents[0] , Tangents[1] , Vertices[1]); 00430 curveS[1].set(Tangents[7], Interiors[0], Interiors[1], Tangents[2]); 00431 curveS[2].set(Tangents[6], Interiors[3], Interiors[2], Tangents[3]); 00432 curveS[3].set(Vertices[3], Tangents[5] , Tangents[4] , Vertices[2]); 00433 00434 // Subdivide curves. 00435 for(sint i=0;i<4;i++) 00436 curveS[i].subdivide(curveSTop[i], curveSBottom[i], t); 00437 00438 // Setup bezier patchs. 00439 // top. 00440 curveSTop[0].get(top.Vertices[0], top.Tangents[0] , top.Tangents[1] , top.Vertices[1]); 00441 curveSTop[1].get(top.Tangents[7], top.Interiors[0], top.Interiors[1], top.Tangents[2]); 00442 curveSTop[2].get(top.Tangents[6], top.Interiors[3], top.Interiors[2], top.Tangents[3]); 00443 curveSTop[3].get(top.Vertices[3], top.Tangents[5] , top.Tangents[4] , top.Vertices[2]); 00444 // bottom. 00445 curveSBottom[0].get(bottom.Vertices[0], bottom.Tangents[0] , bottom.Tangents[1] , bottom.Vertices[1]); 00446 curveSBottom[1].get(bottom.Tangents[7], bottom.Interiors[0], bottom.Interiors[1], bottom.Tangents[2]); 00447 curveSBottom[2].get(bottom.Tangents[6], bottom.Interiors[3], bottom.Interiors[2], bottom.Tangents[3]); 00448 curveSBottom[3].get(bottom.Vertices[3], bottom.Tangents[5] , bottom.Tangents[4] , bottom.Vertices[2]); 00449 } |
|
The interiors, ia,ib,ic,id. NB: interiors are points, not vectors.
Definition at line 81 of file bezier_patch.h. Referenced by NL3D::CZone::applyHeightField(), applyMatrix(), NL3D::CZone::build(), NL3D::CPatch::buildBBoxFromBezierPatch(), eval(), evalDouble(), evalNormal(), evalTangentS(), evalTangentT(), makeInteriors(), NL3D::CZoneTgtSmoother::makeVerticesCoplanar(), NL3D::CZone::retrieve(), NL3D::CZoneSmoother::smoothTangents(), subdivideS(), subdivideT(), NL3D::CPatchInfo::transform(), and NL3D::CPatch::unpack(). |
|
The tangents ab, ba, bc, cb, cd, dc, da, ad. NB: tangents are points, not vectors.
Definition at line 79 of file bezier_patch.h. Referenced by NL3D::CZone::applyHeightField(), applyMatrix(), NL3D::CZone::build(), NL3D::CPatch::buildBBoxFromBezierPatch(), eval(), evalDouble(), evalNormal(), evalTangentS(), evalTangentT(), make(), makeInteriors(), NL3D::CZoneTgtSmoother::makeVerticesCoplanar(), NL3D::CZone::retrieve(), NL3D::CZoneSmoother::smoothTangents(), subdivideS(), subdivideT(), NL3D::CPatchInfo::transform(), and NL3D::CPatch::unpack(). |
|
The vertices a,b,c,d of the quad patch.
Definition at line 77 of file bezier_patch.h. Referenced by NL3D::CZone::applyHeightField(), applyMatrix(), NL3D::CZone::build(), NL3D::CPatch::buildBBoxFromBezierPatch(), NL3D::CPatch::computeDefaultErrorSize(), eval(), evalDouble(), evalNormal(), evalTangentS(), evalTangentT(), make(), makeInteriors(), NL3D::CZone::retrieve(), NL3D::CZoneSymmetrisation::setOrientedTileState(), NL3D::CZoneSymmetrisation::setTileState(), subdivideS(), subdivideT(), NL3D::CPatchInfo::transform(), and NL3D::CPatch::unpack(). |