| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
#include <cstdio> |
| 38 |
#include "softsurfacemaps.h" |
| 39 |
|
| 40 |
_SoNurbsVertex3SurfaceMap::~_SoNurbsVertex3SurfaceMap(){} |
| 41 |
void _SoNurbsVertex3SurfaceMap::domain( float * ) { } |
| 42 |
void _SoNurbsVertex3SurfaceMap::uuderiv( float * ) { } |
| 43 |
void _SoNurbsVertex3SurfaceMap::uvderiv( float * ) { } |
| 44 |
void _SoNurbsVertex3SurfaceMap::vvderiv( float * ) { } |
| 45 |
|
| 46 |
static int numVerts = 0; |
| 47 |
static float texCachePt[2][2] = {{0.0, 0.0},{0.0, 0.0}}; |
| 48 |
static float curTexPt[2] = {0.0, 0.0}; |
| 49 |
static int validTexCoords = 0; |
| 50 |
|
| 51 |
void |
| 52 |
_SoNurbsVertex3SurfaceMap::point( float *v ) |
| 53 |
{ |
| 54 |
computeNormal(); |
| 55 |
|
| 56 |
// Render the vertices as independent triangles. |
| 57 |
// If less than three vertices have been sent, |
| 58 |
// just put them in the cache. Otherwise, send |
| 59 |
// the cache vertices and the current vertex to |
| 60 |
// the GL. |
| 61 |
if (numVerts > 1) { |
| 62 |
|
| 63 |
// Send down first cache vertex |
| 64 |
::glNormal3fv( cachePt[0].norm ); |
| 65 |
if (validTexCoords) |
| 66 |
::glTexCoord2fv( texCachePt[0] ); |
| 67 |
::glVertex3fv( cachePt[0].p ); |
| 68 |
|
| 69 |
// Send down second cache vertex |
| 70 |
::glNormal3fv( cachePt[1].norm ); |
| 71 |
if (validTexCoords) |
| 72 |
::glTexCoord2fv( texCachePt[1] ); |
| 73 |
::glVertex3fv( cachePt[1].p ); |
| 74 |
|
| 75 |
// Send down current vertex |
| 76 |
::glNormal3fv( P.norm ); |
| 77 |
if (validTexCoords) |
| 78 |
::glTexCoord2fv( curTexPt ); |
| 79 |
::glVertex3fv( v ); |
| 80 |
isUsed = 1; |
| 81 |
} |
| 82 |
|
| 83 |
// Save the point away in the correct cache location. |
| 84 |
cachePt[ptIndex].p[0] = v[0]; |
| 85 |
cachePt[ptIndex].p[1] = v[1]; |
| 86 |
cachePt[ptIndex].p[2] = v[2]; |
| 87 |
cachePt[ptIndex].p[3] = 1.0; |
| 88 |
cachePt[ptIndex].norm[0] = P.norm[0]; |
| 89 |
cachePt[ptIndex].norm[1] = P.norm[1]; |
| 90 |
cachePt[ptIndex].norm[2] = P.norm[2]; |
| 91 |
texCachePt[ptIndex][0] = curTexPt[0]; |
| 92 |
texCachePt[ptIndex][1] = curTexPt[1]; |
| 93 |
ptIndex = 1 - ptIndex; |
| 94 |
numVerts++; |
| 95 |
} |
| 96 |
|
| 97 |
void |
| 98 |
_SoNurbsVertex3SurfaceMap::startNewTriStrip() |
| 99 |
{ |
| 100 |
// A new tri strip has begun from scratch. |
| 101 |
// Just reset the ptIndex to start saving points. |
| 102 |
ptIndex = 0; |
| 103 |
numVerts = 0; |
| 104 |
validTexCoords = 0; |
| 105 |
} |
| 106 |
|
| 107 |
void |
| 108 |
_SoNurbsVertex3SurfaceMap::swapTriStripVertices() |
| 109 |
{ |
| 110 |
if (!isUsed) |
| 111 |
return; |
| 112 |
|
| 113 |
swapCalled = 1; |
| 114 |
ptIndex = 1 - ptIndex; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
void |
| 119 |
_SoNurbsVertex3SurfaceMap::uderiv( float *v ) |
| 120 |
{ |
| 121 |
P.du[0] = v[0]; |
| 122 |
P.du[1] = v[1]; |
| 123 |
P.du[2] = v[2]; |
| 124 |
} |
| 125 |
|
| 126 |
void |
| 127 |
_SoNurbsVertex3SurfaceMap::vderiv( float *v ) |
| 128 |
{ |
| 129 |
P.dv[0] = v[0]; |
| 130 |
P.dv[1] = v[1]; |
| 131 |
P.dv[2] = v[2]; |
| 132 |
} |
| 133 |
|
| 134 |
void |
| 135 |
_SoNurbsVertex3SurfaceMap::computeNormal( void ) |
| 136 |
{ |
| 137 |
/* compute normal, modulo factor of 1/P.p[3]^4 */ |
| 138 |
P.norm[0] = P.du[1]*P.dv[2] - P.du[2]*P.dv[1]; |
| 139 |
P.norm[1] = P.du[2]*P.dv[0] - P.du[0]*P.dv[2]; |
| 140 |
P.norm[2] = P.du[0]*P.dv[1] - P.du[1]*P.dv[0]; |
| 141 |
|
| 142 |
// |
| 143 |
// The normals must be normalized because on PIs, the nmode() |
| 144 |
// gl call doesn't work. |
| 145 |
// |
| 146 |
float *p = P.norm; |
| 147 |
float len = sqrtf(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]); |
| 148 |
if( len == 0.0 ) return; |
| 149 |
len = 1.0/len; |
| 150 |
p[0] *= len; |
| 151 |
p[1] *= len; |
| 152 |
p[2] *= len; |
| 153 |
} |
| 154 |
|
| 155 |
_SoNurbsVertex4SurfaceMap::~_SoNurbsVertex4SurfaceMap(){} |
| 156 |
void _SoNurbsVertex4SurfaceMap::domain( float * ) { } |
| 157 |
void _SoNurbsVertex4SurfaceMap::uuderiv( float * ) { } |
| 158 |
void _SoNurbsVertex4SurfaceMap::uvderiv( float * ) { } |
| 159 |
void _SoNurbsVertex4SurfaceMap::vvderiv( float * ) { } |
| 160 |
|
| 161 |
void |
| 162 |
_SoNurbsVertex4SurfaceMap::point( float *v ) |
| 163 |
{ |
| 164 |
P.p[0] = v[0]; |
| 165 |
P.p[1] = v[1]; |
| 166 |
P.p[2] = v[2]; |
| 167 |
P.p[3] = v[3]; |
| 168 |
|
| 169 |
computeFirstPartials( ); |
| 170 |
computeNormal( ); |
| 171 |
|
| 172 |
// Render the vertices as independent triangles. |
| 173 |
// If less than three vertices have been sent, |
| 174 |
// just put them in the cache. Otherwise, send |
| 175 |
// the cache vertices and the current vertex to |
| 176 |
// the GL. |
| 177 |
if (numVerts > 1) { |
| 178 |
|
| 179 |
// Send down first cache vertex |
| 180 |
::glNormal3fv( cachePt[0].norm ); |
| 181 |
if (validTexCoords) |
| 182 |
::glTexCoord2fv( texCachePt[0] ); |
| 183 |
::glVertex4fv( cachePt[0].p ); |
| 184 |
|
| 185 |
// Send down second cache vertex |
| 186 |
::glNormal3fv( cachePt[1].norm ); |
| 187 |
if (validTexCoords) |
| 188 |
::glTexCoord2fv( texCachePt[1] ); |
| 189 |
::glVertex4fv( cachePt[1].p ); |
| 190 |
|
| 191 |
// Send down current vertex |
| 192 |
::glNormal3fv( P.norm ); |
| 193 |
if (validTexCoords) |
| 194 |
::glTexCoord2fv( curTexPt ); |
| 195 |
::glVertex4fv( v ); |
| 196 |
isUsed = 1; |
| 197 |
} |
| 198 |
|
| 199 |
// Save the point away in the correct cache location. |
| 200 |
cachePt[ptIndex].p[0] = v[0]; |
| 201 |
cachePt[ptIndex].p[1] = v[1]; |
| 202 |
cachePt[ptIndex].p[2] = v[2]; |
| 203 |
cachePt[ptIndex].p[3] = v[3]; |
| 204 |
cachePt[ptIndex].norm[0] = P.norm[0]; |
| 205 |
cachePt[ptIndex].norm[1] = P.norm[1]; |
| 206 |
cachePt[ptIndex].norm[2] = P.norm[2]; |
| 207 |
texCachePt[ptIndex][0] = curTexPt[0]; |
| 208 |
texCachePt[ptIndex][1] = curTexPt[1]; |
| 209 |
ptIndex = 1 - ptIndex; |
| 210 |
numVerts++; |
| 211 |
} |
| 212 |
|
| 213 |
void |
| 214 |
_SoNurbsVertex4SurfaceMap::startNewTriStrip() |
| 215 |
{ |
| 216 |
// A new tri strip has begun from scratch. |
| 217 |
// Just reset the ptIndex to start saving points. |
| 218 |
ptIndex = 0; |
| 219 |
numVerts = 0; |
| 220 |
validTexCoords = 0; |
| 221 |
} |
| 222 |
|
| 223 |
void |
| 224 |
_SoNurbsVertex4SurfaceMap::swapTriStripVertices() |
| 225 |
{ |
| 226 |
if (!isUsed) |
| 227 |
return; |
| 228 |
|
| 229 |
swapCalled = 1; |
| 230 |
ptIndex = 1 - ptIndex; |
| 231 |
} |
| 232 |
|
| 233 |
void |
| 234 |
_SoNurbsVertex4SurfaceMap::uderiv( float *v ) |
| 235 |
{ |
| 236 |
P.du[0] = v[0]; |
| 237 |
P.du[1] = v[1]; |
| 238 |
P.du[2] = v[2]; |
| 239 |
P.du[3] = v[3]; |
| 240 |
} |
| 241 |
|
| 242 |
void |
| 243 |
_SoNurbsVertex4SurfaceMap::vderiv( float *v ) |
| 244 |
{ |
| 245 |
P.dv[0] = v[0]; |
| 246 |
P.dv[1] = v[1]; |
| 247 |
P.dv[2] = v[2]; |
| 248 |
P.dv[3] = v[3]; |
| 249 |
} |
| 250 |
|
| 251 |
void |
| 252 |
_SoNurbsVertex4SurfaceMap::computeFirstPartials( void ) |
| 253 |
{ |
| 254 |
|
| 255 |
/* compute u partial, modulo factor of 1/P.p[3]^2 */ |
| 256 |
P.du[0] = P.du[0]*P.p[3] - P.du[3]*P.p[0]; |
| 257 |
P.du[1] = P.du[1]*P.p[3] - P.du[3]*P.p[1]; |
| 258 |
P.du[2] = P.du[2]*P.p[3] - P.du[3]*P.p[2]; |
| 259 |
|
| 260 |
/* compute v partial, modulo factor of 1/P.p[3]^2 */ |
| 261 |
P.dv[0] = P.dv[0]*P.p[3] - P.dv[3]*P.p[0]; |
| 262 |
P.dv[1] = P.dv[1]*P.p[3] - P.dv[3]*P.p[1]; |
| 263 |
P.dv[2] = P.dv[2]*P.p[3] - P.dv[3]*P.p[2]; |
| 264 |
} |
| 265 |
|
| 266 |
void |
| 267 |
_SoNurbsVertex4SurfaceMap::computeNormal( void ) |
| 268 |
{ |
| 269 |
/* compute normal, modulo factor of 1/P.p[3]^4 */ |
| 270 |
P.norm[0] = P.du[1]*P.dv[2] - P.du[2]*P.dv[1]; |
| 271 |
P.norm[1] = P.du[2]*P.dv[0] - P.du[0]*P.dv[2]; |
| 272 |
P.norm[2] = P.du[0]*P.dv[1] - P.du[1]*P.dv[0]; |
| 273 |
|
| 274 |
// |
| 275 |
// The normals must be normalized because on PIs, the nmode() |
| 276 |
// gl call doesn't work. |
| 277 |
// |
| 278 |
float *p = P.norm; |
| 279 |
float len = sqrtf(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]); |
| 280 |
if (len <=0.0) return; |
| 281 |
len = 1.0/len; |
| 282 |
p[0] *= len; |
| 283 |
p[1] *= len; |
| 284 |
p[2] *= len; |
| 285 |
} |
| 286 |
|
| 287 |
void _SoNurbsColor4SurfaceMap::domain( float * ) { } |
| 288 |
void _SoNurbsColor4SurfaceMap::point( float *p ) |
| 289 |
{ |
| 290 |
::glColor4fv( p ); |
| 291 |
|
| 292 |
// Save the color away in case a swaptmesh comes |
| 293 |
// along in which case the point would be reused |
| 294 |
// at the start of the new tmesh. |
| 295 |
cachePt[ptIndex][0] = p[0]; |
| 296 |
cachePt[ptIndex][1] = p[1]; |
| 297 |
cachePt[ptIndex][2] = p[2]; |
| 298 |
cachePt[ptIndex][3] = p[3]; |
| 299 |
ptIndex = 1 - ptIndex; |
| 300 |
} |
| 301 |
|
| 302 |
void |
| 303 |
_SoNurbsColor4SurfaceMap::startNewTriStrip() |
| 304 |
{ |
| 305 |
// A new tri strip has begun from scratch. |
| 306 |
// Just reset the ptIndex to start saving points. |
| 307 |
ptIndex = 0; |
| 308 |
} |
| 309 |
|
| 310 |
void |
| 311 |
_SoNurbsColor4SurfaceMap::swapTriStripVertices() |
| 312 |
{ |
| 313 |
ptIndex = 1 - ptIndex; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
_SoNurbsColor4SurfaceMap::~_SoNurbsColor4SurfaceMap(){} |
| 318 |
void _SoNurbsColor4SurfaceMap::uderiv( float * ) { } |
| 319 |
void _SoNurbsColor4SurfaceMap::vderiv( float * ) { } |
| 320 |
void _SoNurbsColor4SurfaceMap::uuderiv( float * ) { } |
| 321 |
void _SoNurbsColor4SurfaceMap::uvderiv( float * ) { } |
| 322 |
void _SoNurbsColor4SurfaceMap::vvderiv( float * ) { } |
| 323 |
|
| 324 |
void _SoNurbsTexture2SurfaceMap::domain( float * ) { } |
| 325 |
void _SoNurbsTexture2SurfaceMap::point( float *p ) |
| 326 |
{ |
| 327 |
// Save the point as it will be used when a vertex comes along. |
| 328 |
curTexPt[0] = p[0]; |
| 329 |
curTexPt[1] = p[1]; |
| 330 |
validTexCoords = 1; |
| 331 |
} |
| 332 |
|
| 333 |
_SoNurbsTexture2SurfaceMap::~_SoNurbsTexture2SurfaceMap() { } |
| 334 |
void _SoNurbsTexture2SurfaceMap::uderiv( float * ) { } |
| 335 |
void _SoNurbsTexture2SurfaceMap::vderiv( float * ) { } |
| 336 |
void _SoNurbsTexture2SurfaceMap::uuderiv( float * ) { } |
| 337 |
void _SoNurbsTexture2SurfaceMap::uvderiv( float * ) { } |
| 338 |
void _SoNurbsTexture2SurfaceMap::vvderiv( float * ) { } |