00001 #include "splat.h"
00002 #include "vuTFunc/simpleFuncs.h"
00003 #include <fstream.h>
00004 #include <math.h>
00005
00006
00007
00008
00009
00010 static float texcoord0[2] = {0.0f, 0.0f};
00011 static float texcoord1[2] = {0.0f, 1.0f};
00012 static float texcoord2[2] = {1.0f, 1.0f};
00013 static float texcoord3[2] = {1.0f, 0.0f};
00014
00015
00016
00017
00018
00019 vu1512111::vu1512111()
00020 {
00021 m_Normals = 0;
00022
00023 m_FPSize = 256;
00024 m_Footprint = 0;
00025 m_GLSplat = 0;
00026
00027 computeSplat();
00028 }
00029
00030
00031
00032
00033
00034 vu1512111::vu1512111(const vu1512111& inst) : vu151211(inst)
00035 {
00036 dword i;
00037
00038 m_NTable = inst.m_NTable;
00039
00040 #if defined(QUANTIZE_NORMALS)
00041 m_Normals = new byte[m_DataSize];
00042 #else
00043 m_Normals = new float[m_DataSize*3];
00044 #endif
00045 for(i=0;i<m_DataSize;++i)
00046 m_Normals[i] = inst.m_Normals[i];
00047
00048 m_FPSize = inst.m_FPSize;
00049 computeSplat();
00050 }
00051
00052
00053
00054
00055
00056 vu1512111::~vu1512111()
00057 {
00058 if (m_Normals)
00059 delete [] m_Normals;
00060 if (m_Footprint)
00061 {
00062 delete [] m_Footprint;
00063 glDeleteTextures(1, &m_GLSplat);
00064 }
00065 }
00066
00067
00068
00069
00070
00071 vu1512111& vu1512111::operator=(const vu1512111& rhs)
00072 {
00073 if (this != &rhs)
00074 {
00075 vu151211::operator=(rhs);
00076
00077 dword i;
00078
00079 m_NTable = rhs.m_NTable;
00080
00081 if (m_Normals)
00082 delete [] m_Normals;
00083
00084 #if defined(QUANTIZE_NORMALS)
00085 m_Normals = new byte[m_DataSize];
00086 #else
00087 m_Normals = new float[m_DataSize*3];
00088 #endif
00089 for(i=0;i<m_DataSize;++i)
00090 m_Normals[i] = rhs.m_Normals[i];
00091
00092 m_FPSize = rhs.m_FPSize;
00093
00094 computeSplat();
00095 }
00096 return *this;
00097 }
00098
00099
00100
00101
00102
00103 void vu1512111::setViewVectors(const vuVector& view,const vuVector& up,const vuVector& right)
00104 {
00105 m_View = view;
00106 m_Shift1 = right*3.2f;
00107 m_Shift2 = up*3.2f;
00108 m_Shift0 = (m_Shift1+m_Shift2)*(-0.5f);
00109 }
00110
00111
00112
00113
00114
00115 void vu1512111::setFootprintSize(dword size)
00116 {
00117 m_FPSize = size;
00118 }
00119
00120
00121
00122
00123
00124 dword vu1512111::getFootprintSize() const
00125 {
00126 return m_FPSize;
00127 }
00128
00129
00130
00131
00132
00133 bool vu1512111::read()
00134 {
00135 bool success = vu151211::read();
00136 if (!success) return false;
00137
00138
00139 if (m_Normals != 0) delete [] m_Normals;
00140 #if defined(QUANTIZE_NORMALS)
00141 m_Normals = new byte[m_DataSize];
00142 #else
00143 m_Normals = new float[m_DataSize*3];
00144 #endif
00145 preprocess();
00146 return true;
00147 }
00148
00149
00150
00151
00152
00153 bool vu1512111::readRaw(void)
00154 {
00155 dword len;
00156 ifstream in;
00157
00158 #ifdef IS_NOCREATE_NEEDED
00159 in.open(m_FileName, ios::in|ios::binary|ios::nocreate);
00160 #else
00161
00162
00163 in.open(m_FileName, ios::in|ios::binary);
00164 #endif
00165
00166 if (!in.is_open()) return false;
00167
00168 in.seekg(0, ios::end);
00169 len = in.tellg();
00170 in.seekg(0, ios::beg);
00171
00172 in >> m_Dim1Size >> m_Dim2Size >> m_Dim3Size;
00173 if (in.fail()) return false;
00174 m_DataSize = m_Dim1Size*m_Dim2Size*m_Dim3Size;
00175
00176 m_Data = new byte[m_DataSize];
00177 in.read((char *) (m_Data), int (m_DataSize));
00178 if (in.fail()) return false;
00179
00180 in.close();
00181
00182
00183 if (m_Normals != 0) delete [] m_Normals;
00184 #if defined(QUANTIZE_NORMALS)
00185 m_Normals = new byte[m_DataSize];
00186 #else
00187 m_Normals = new float[m_DataSize*3];
00188 #endif
00189 preprocess();
00190
00191 return true;
00192 }
00193
00194
00195
00196
00197
00198 void vu1512111::preprocess(void)
00199 {
00200 float norm[3];
00201 float len;
00202 dword w, wh;
00203 dword i, j, k, index;
00204
00205 w = m_Dim1Size;
00206 wh = m_Dim1Size*m_Dim2Size;
00207
00208
00209
00210
00211
00212 index = 0;
00213 #if defined(QUANTIZE_NORMALS)
00214 m_NTable.initCollection(m_DataSize);
00215 #endif
00216 for(k=0;k<m_Dim3Size;++k)
00217 {
00218 for(j=0;j<m_Dim2Size;++j)
00219 {
00220 for(i=0;i<m_Dim1Size;++i)
00221 {
00222 if (i == 0)
00223 norm[0] = m_Data[index+1]-m_Data[index];
00224 else if (i == m_Dim1Size-1)
00225 norm[0] = m_Data[index]-m_Data[index-1];
00226 else
00227 norm[0] = (m_Data[index+1]-m_Data[index-1])*0.5;
00228
00229 if (j == 0)
00230 norm[1] = m_Data[index+w]-m_Data[index];
00231 else if (j == m_Dim2Size-1)
00232 norm[1] = m_Data[index]-m_Data[index-w];
00233 else
00234 norm[1] = (m_Data[index+w]-m_Data[index-w])*0.5;
00235
00236 if ((k == 0) || (k == 1))
00237 norm[2] = m_Data[index+2*wh]-m_Data[index];
00238 else if ((k == m_Dim3Size-1) || (k == m_Dim3Size-2))
00239 norm[2] = m_Data[index]-m_Data[index-2*wh];
00240 else
00241 norm[2] = (m_Data[index+2*wh]-m_Data[index-2*wh])*0.5;
00242
00243 len = (float)sqrt((double)((norm[0]*norm[0])+
00244 (norm[1]*norm[1])+
00245 (norm[2]*norm[2])));
00246 if (len > 0.0f)
00247 {
00248 norm[0] /= len;
00249 norm[1] /= len;
00250 norm[2] /= len;
00251 }
00252 #if defined(QUANTIZE_NORMALS)
00253 m_NTable.addToCollection(norm);
00254 #else
00255 m_Normals[index*3] = norm[0];
00256 m_Normals[index*3+1] = norm[1];
00257 m_Normals[index*3+2] = norm[2];
00258 #endif
00259 ++index;
00260 }
00261 }
00262 }
00263
00264 #if defined(QUANTIZE_NORMALS)
00265 m_NTable.computeTable();
00266
00267
00268
00269
00270
00271 index = 0;
00272 for(k=0;k<m_Dim3Size;++k)
00273 {
00274 for(j=0;j<m_Dim2Size;++j)
00275 {
00276 for(i=0;i<m_Dim1Size;++i)
00277 {
00278 if (i == 0)
00279 norm[0] = m_Data[index+1]-m_Data[index];
00280 else if (i == m_Dim1Size-1)
00281 norm[0] = m_Data[index]-m_Data[index-1];
00282 else
00283 norm[0] = (m_Data[index+1]-m_Data[index-1])*0.5;
00284
00285 if (j == 0)
00286 norm[1] = m_Data[index+w]-m_Data[index];
00287 else if (j == m_Dim2Size-1)
00288 norm[1] = m_Data[index]-m_Data[index-w];
00289 else
00290 norm[1] = (m_Data[index+w]-m_Data[index-w])*0.5;
00291
00292 if ((k == 0) || (k == 1))
00293 norm[2] = m_Data[index+2*wh]-m_Data[index];
00294 else if ((k == m_Dim3Size-1) || (k == m_Dim3Size-2))
00295 norm[2] = m_Data[index]-m_Data[index-2*wh];
00296 else
00297 norm[2] = (m_Data[index+2*wh]-m_Data[index-2*wh])*0.5;
00298
00299 len = (float)sqrt((double)((norm[0]*norm[0])+
00300 (norm[1]*norm[1])+
00301 (norm[2]*norm[2])));
00302 if (len > 0.0f)
00303 {
00304 norm[0] /= len;
00305 norm[1] /= len;
00306 norm[2] /= len;
00307 }
00308 m_Normals[index] = (byte)m_NTable.findNearest(norm);
00309
00310 ++index;
00311 }
00312 }
00313 }
00314 #endif
00315 }
00316
00317
00318
00319
00320
00321 void vu1512111::render(void)
00322 {
00323 int S_index, S_step, S_size;
00324 int M_index, M_step, M_size;
00325 int F_index, F_step, F_size;
00326 float dp[3];
00327 float vals[3];
00328 float *F, *M, *S;
00329 float dF, dM, dS;
00330 float rF, rM;
00331 float *n;
00332 int index;
00333 dword density;
00334
00335 dp[0] = (m_View[0] > 0.0f)?m_View[0]:m_View[0]*-1.0f;
00336 dp[1] = (m_View[1] > 0.0f)?m_View[1]:m_View[1]*-1.0f;
00337 dp[2] = (m_View[2] > 0.0f)?m_View[2]:m_View[2]*-1.0f;
00338
00339
00340
00341
00342
00343 if (dp[0] > dp[1])
00344 {
00345 if (dp[0] > dp[2])
00346 {
00347 if (dp[1] > dp[2])
00348 {
00349
00350 S = &vals[0];
00351 M = &vals[1];
00352 F = &vals[2];
00353
00354 S_size = m_Dim1Size;
00355 if (m_View[0] >= 0.0f){
00356 S_step = 1;
00357 *S = 0.0f;
00358 dS = 1.0f;
00359 index = 0;
00360 }else{
00361 S_step = -1;
00362 *S = (float)m_Dim1Size-1.0f;
00363 dS = -1.0f;
00364 index = m_Dim1Size-1;
00365 }
00366
00367 M_size = m_Dim2Size;
00368 if (m_View[1] >= 0.0f){
00369 M_step = m_Dim1Size;
00370 *M = 0.0f;
00371 dM = 1.0f;
00372 rM = -1.0f * (float)m_Dim2Size;
00373 }else{
00374 M_step = -1*m_Dim1Size;
00375 *M = (float)m_Dim2Size-1.0f;
00376 dM = -1.0f;
00377 rM = (float)m_Dim2Size;
00378 index += (1-m_Dim2Size)*M_step;
00379 }
00380
00381 F_size = m_Dim3Size;
00382 if (m_View[2] >= 0.0f){
00383 F_step = m_Dim1Size*m_Dim2Size;
00384 *F = 0.0f;
00385 dF = 1.0f;
00386 rF = -1.0f * (float)m_Dim3Size;
00387 }else{
00388 F_step = -1*m_Dim1Size*m_Dim2Size;
00389 *F = (float)m_Dim3Size-1.0f;
00390 dF = -1.0f;
00391 rF = (float)m_Dim3Size;
00392 index += (1-m_Dim3Size)*F_step;
00393 }
00394 }
00395 else
00396 {
00397
00398 S = &vals[0];
00399 F = &vals[1];
00400 M = &vals[2];
00401
00402 S_size = m_Dim1Size;
00403 if (m_View[0] >= 0.0f){
00404 S_step = 1;
00405 *S = 0.0f;
00406 dS = 1.0f;
00407 index = 0;
00408 }else{
00409 S_step = -1;
00410 *S = (float)m_Dim1Size-1.0f;
00411 dS = -1.0f;
00412 index = m_Dim1Size-1;
00413 }
00414
00415 F_size = m_Dim2Size;
00416 if (m_View[1] >= 0.0f){
00417 F_step = m_Dim1Size;
00418 *F = 0.0f;
00419 dF = 1.0f;
00420 rF = -1.0f * (float)m_Dim2Size;
00421 }else{
00422 F_step = -1*m_Dim1Size;
00423 *F = (float)m_Dim2Size-1.0f;
00424 dF = -1.0f;
00425 rF = (float)m_Dim2Size;
00426 index += (1-m_Dim2Size)*F_step;
00427 }
00428
00429 M_size = m_Dim3Size;
00430 if (m_View[2] >= 0.0f){
00431 M_step = m_Dim1Size*m_Dim2Size;
00432 *M = 0.0f;
00433 dM = 1.0f;
00434 rM = -1.0f * (float)m_Dim3Size;
00435 }else{
00436 M_step = -1*m_Dim1Size*m_Dim2Size;
00437 *M = (float)m_Dim3Size-1.0f;
00438 dM = -1.0f;
00439 rM = (float)m_Dim3Size;
00440 index += (1-m_Dim3Size)*M_step;
00441 }
00442 }
00443 }
00444 else
00445 {
00446
00447 M = &vals[0];
00448 F = &vals[1];
00449 S = &vals[2];
00450
00451 M_size = m_Dim1Size;
00452 if (m_View[0] >= 0.0f){
00453 M_step = 1;
00454 *M = 0.0f;
00455 dM = 1.0f;
00456 rM = -1.0f* (float)m_Dim1Size;
00457 index = 0;
00458 }else{
00459 M_step = -1;
00460 *M = (float)m_Dim1Size-1.0f;
00461 dM = -1.0f;
00462 rM = (float)m_Dim1Size;
00463 index = m_Dim1Size-1;
00464 }
00465
00466 F_size = m_Dim2Size;
00467 if (m_View[1] >= 0.0f){
00468 F_step = m_Dim1Size;
00469 *F = 0.0f;
00470 dF = 1.0f;
00471 rF = -1.0f * (float)m_Dim2Size;
00472 }else{
00473 F_step = -1*m_Dim1Size;
00474 *F = (float)m_Dim2Size-1.0f;
00475 dF = -1.0f;
00476 rF = (float)m_Dim2Size;
00477 index += (1-m_Dim2Size)*F_step;
00478 }
00479
00480 S_size = m_Dim3Size;
00481 if (m_View[2] >= 0.0f){
00482 S_step = m_Dim1Size*m_Dim2Size;
00483 *S = 0.0f;
00484 dS = 1.0f;
00485 }else{
00486 S_step = -1*m_Dim1Size*m_Dim2Size;
00487 *S = (float)m_Dim3Size-1.0f;
00488 dS = -1.0f;
00489 index += (1-m_Dim3Size)*S_step;
00490 }
00491 }
00492 }
00493 else
00494 {
00495 if (dp[1] > dp[2])
00496 {
00497 if (dp[0] > dp[2])
00498 {
00499
00500 M = &vals[0];
00501 S = &vals[1];
00502 F = &vals[2];
00503
00504 M_size = m_Dim1Size;
00505 if (m_View[0] >= 0.0f){
00506 M_step = 1;
00507 *M = 0.0f;
00508 dM = 1.0f;
00509 rM = -1.0f* (float)m_Dim1Size;
00510 index = 0;
00511 }else{
00512 M_step = -1;
00513 *M = (float)m_Dim1Size-1.0f;
00514 dM = -1.0f;
00515 rM = (float)m_Dim1Size;
00516 index = m_Dim1Size-1;
00517 }
00518
00519 S_size = m_Dim2Size;
00520 if (m_View[1] >= 0.0f){
00521 S_step = m_Dim1Size;
00522 *S = 0.0f;
00523 dS = 1.0f;
00524 }else{
00525 S_step = -1*m_Dim1Size;
00526 *S = (float)m_Dim2Size-1.0f;
00527 dS = -1.0f;
00528 index += (1-m_Dim2Size)*S_step;
00529 }
00530
00531 F_size = m_Dim3Size;
00532 if (m_View[2] >= 0.0f){
00533 F_step = m_Dim1Size*m_Dim2Size;
00534 *F = 0.0f;
00535 dF = 1.0f;
00536 rF = -1.0f * (float)m_Dim3Size;
00537 }else{
00538 F_step = -1*m_Dim1Size*m_Dim2Size;
00539 *F = (float)m_Dim3Size-1.0f;
00540 dF = -1.0f;
00541 rF = (float)m_Dim3Size;
00542 index += (1-m_Dim3Size)*F_step;
00543 }
00544 }
00545 else
00546 {
00547
00548 F = &vals[0];
00549 S = &vals[1];
00550 M = &vals[2];
00551
00552 F_size = m_Dim1Size;
00553 if (m_View[0] >= 0.0f){
00554 F_step = 1;
00555 *F = 0.0f;
00556 dF = 1.0f;
00557 rF = -1.0f* (float)m_Dim1Size;
00558 index = 0;
00559 }else{
00560 F_step = -1;
00561 *F = (float)m_Dim1Size-1.0f;
00562 dF = -1.0f;
00563 rF = (float)m_Dim1Size;
00564 index = m_Dim1Size-1;
00565 }
00566
00567 S_size = m_Dim2Size;
00568 if (m_View[1] >= 0.0f){
00569 S_step = m_Dim1Size;
00570 *S = 0.0f;
00571 dS = 1.0f;
00572 }else{
00573 S_step = -1*m_Dim1Size;
00574 *S = (float)m_Dim2Size-1.0f;
00575 dS = -1.0f;
00576 index += (1-m_Dim2Size)*S_step;
00577 }
00578
00579 M_size = m_Dim3Size;
00580 if (m_View[2] >= 0.0f){
00581 M_step = m_Dim1Size*m_Dim2Size;
00582 *M = 0.0f;
00583 dM = 1.0f;
00584 rM = -1.0f * (float)m_Dim3Size;
00585 }else{
00586 M_step = -1*m_Dim1Size*m_Dim2Size;
00587 *M = (float)m_Dim3Size-1.0f;
00588 dM = -1.0f;
00589 rM = (float)m_Dim3Size;
00590 index += (1-m_Dim3Size)*M_step;
00591 }
00592 }
00593 }
00594 else
00595 {
00596
00597 F = &vals[0];
00598 M = &vals[1];
00599 S = &vals[2];
00600
00601 F_size = m_Dim1Size;
00602 if (m_View[0] >= 0.0f){
00603 F_step = 1;
00604 *F = 0.0f;
00605 dF = 1.0f;
00606 rF = -1.0f* (float)m_Dim1Size;
00607 index = 0;
00608 }else{
00609 F_step = -1;
00610 *F = (float)m_Dim1Size-1.0f;
00611 dF = -1.0f;
00612 rF = (float)m_Dim1Size;
00613 index = m_Dim1Size-1;
00614 }
00615
00616 M_size = m_Dim2Size;
00617 if (m_View[1] >= 0.0f){
00618 M_step = m_Dim1Size;
00619 *M = 0.0f;
00620 dM = 1.0f;
00621 rM = -1.0f * (float)m_Dim2Size;
00622 }else{
00623 M_step = -1*m_Dim1Size;
00624 *M = (float)m_Dim2Size-1.0f;
00625 dM = -1.0f;
00626 rM = (float)m_Dim2Size;
00627 index += (1-m_Dim2Size)*M_step;;
00628 }
00629
00630 S_size = m_Dim3Size;
00631 if (m_View[2] >= 0.0f){
00632 S_step = m_Dim1Size*m_Dim2Size;
00633 *S = 0.0f;
00634 dS = 1.0f;
00635 }else{
00636 S_step = -1*m_Dim1Size*m_Dim2Size;
00637 *S = (float)m_Dim3Size-1.0f;
00638 dS = -1.0f;
00639 index += (1-m_Dim3Size)*S_step;
00640 }
00641 }
00642 }
00643
00644 S_step -= M_step*M_size;
00645 M_step -= F_step*F_size;
00646
00647
00648
00649
00650
00651
00652 float vals2[3];
00653
00654 glBegin(GL_QUADS);
00655 for(S_index=0; S_index<S_size; ++S_index)
00656 {
00657 for(M_index=0; M_index<M_size; ++M_index)
00658 {
00659 for(F_index=0; F_index<F_size; ++F_index)
00660 {
00661 density = m_Data[index];
00662 if (m_TFunc[density][3] > 0.0f)
00663 {
00664 glColor4fv(m_TFunc[density]);
00665 #if defined(QUANTIZE_NORMALS)
00666 n = m_NTable[m_Normals[index]];
00667 #else
00668 n = &m_Normals[index*3];
00669 #endif
00670
00671 #if defined(ONE_SIDED_LIGHTING)
00672 if (n[0]*m_View[0] + n[1]*m_View[1] + n[2]*m_View[2] > 0.0f)
00673 {
00674 n[0] *= -1.0f;
00675 n[1] *= -1.0f;
00676 n[2] *= -1.0f;
00677 }
00678 #endif
00679 glNormal3fv(n);
00680
00681 vals2[0] = T*vals[0];
00682 vals2[1] = T*vals[1];
00683 vals2[2] = 0.5*T*vals[2];
00684
00685 if ((((int)vals[2]) % 2) == 1)
00686 {
00687 vals2[0] += 0.5*T;
00688 vals2[1] += 0.5*T;
00689 }
00690
00691 drawSplatOrtho(vals2);
00692 }
00693
00694 index += F_step;
00695 *F += dF;
00696 }
00697 *F += rF;
00698 *M += dM;
00699 index += M_step;
00700 }
00701 *M += rM;
00702 *S += dS;
00703 index += S_step;
00704 }
00705
00706 glEnd();
00707 }
00708
00709
00710
00711
00712
00713 void vu1512111::computeSplat(void)
00714 {
00715 dword index;
00716 dword i;
00717 dword j;
00718 double x;
00719 double y;
00720 double d;
00721
00722 if (m_Footprint)
00723 {
00724 delete [] m_Footprint;
00725 glDeleteTextures(1, &m_GLSplat);
00726 }
00727 #if defined(COMBINERS)
00728 m_Footprint = new GLubyte[m_FPSize*m_FPSize];
00729 #else
00730 m_Footprint = new GLubyte[m_FPSize*m_FPSize*2];
00731 #endif
00732
00733 index = 0;
00734 for(j=0;j<m_FPSize;++j)
00735 {
00736 for(i=0;i<m_FPSize;++i)
00737 {
00738 x = 0.5 - (double)i/(double)(m_FPSize-1);
00739 y = 0.5 - (double)j/(double)(m_FPSize-1);
00740 d = sqrt(x*x+y*y);
00741 #if !defined(COMBINERS)
00742 m_Footprint[index++] = 255;
00743 #endif
00744 m_Footprint[index++] = (GLubyte)(255.0*gaussSplat(2.0*d));
00745 }
00746 }
00747 }
00748
00749 double vu1512111::gaussSplat(double r)
00750 {
00751 return 0.466*exp(-2*r*r);
00752 }
00753
00754
00755
00756
00757 double vu1512111::nelsonSplat(double r)
00758 {
00759 double s = 0.8893919243498159;
00760 double t = 1.556227804798694;
00761 double a = 0.5575267703530060;
00762 double b = -1.157744128784905;
00763 double c = 0.6710333014812285;
00764 double d = 0.067598983313541278;
00765 double e = 0.2824741750452964;
00766 double f = t*t*(d+e*t);
00767 double g = -t*(2*d+3*e*t);
00768 double h = d+3*e*t;
00769 double v, u, rs, y, z, p, q;
00770
00771 if(r == 0)
00772 {
00773 v = s*((a-f) + s*((-g)/2.0 + s*((b-h)/3.0 + s*(c+e)/4.0)))
00774 + t*(f + t*(g/2.0 + t*(h/3.0 + t*(-e)/4.0)));
00775 }
00776 else if(r < s)
00777 {
00778 rs = r*r;
00779 y = sqrt(s*s-rs);
00780 z = sqrt(t*t-rs);
00781 p = log(y+s);
00782 q = log(z+t);
00783 u = log(r);
00784 v = a*y + b*y*y*y/3.0 + b*y*rs + 0.5*c*rs*(y*s+rs*(p-u))
00785 + c*(y*s*s*s/4.0 - rs*0.125*(y*s+rs*(p-u)))
00786 + f*(z-y) + 0.5*(g-e*rs)*(z*t-y*s+rs*(q-p))
00787 + h*rs*(z-y) + (h/3.0)*(z*z*z-y*y*y)
00788 - e*(0.25*(z*t*t*t-y*s*s*s) - rs*0.125*(z*t-y*s+rs*(q-p)));
00789 }
00790 else if(r < t)
00791 {
00792 rs = r*r;
00793 z = sqrt(t*t-rs);
00794 q = log(z+t);
00795 u = log(r);
00796 v = f*z + 0.5*(g-e*rs)*(z*t+rs*(q-u)) + h*rs*z + (h/3.0)*z*z*z
00797 - e*(0.25*z*t*t*t-rs*0.125*(z*t+rs*(q-u)));
00798 }
00799 else
00800 {
00801 v = 0.0;
00802 }
00803
00804 return 2.0*v;
00805 }
00806
00807
00808
00809
00810
00811 void vu1512111::initOpenGL(void)
00812 {
00813 GLfloat shininess = 50.0f;
00814 GLfloat specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
00815
00816 #if defined(ONE_SIDED_LIGHTING)
00817 glMaterialf(GL_FRONT, GL_SHININESS, shininess);
00818 glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
00819 glEnable(GL_COLOR_MATERIAL);
00820 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
00821
00822 glPolygonMode(GL_FRONT, GL_FILL);
00823 #else
00824 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
00825 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
00826 glEnable(GL_COLOR_MATERIAL);
00827 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
00828
00829 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00830 #endif
00831
00832 glShadeModel(GL_SMOOTH);
00833 glDisable(GL_DEPTH_TEST);
00834 glDisable(GL_ALPHA_TEST);
00835 glDisable(GL_CULL_FACE);
00836
00837 glGenTextures(1, &m_GLSplat);
00838 glBindTexture(GL_TEXTURE_2D, m_GLSplat);
00839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00840 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00842 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
00843 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00844
00845 #if defined(COMBINERS)
00846
00847 gluBuild2DMipmaps(GL_TEXTURE_2D, 1, m_FPSize, m_FPSize,
00848 GL_LUMINANCE, GL_UNSIGNED_BYTE,
00849 (void*)m_Footprint);
00850 glEnable(GL_TEXTURE_2D);
00851
00852 if (!glh_init_extensions("GL_NV_register_combiners "))
00853 cout << "Could not initialize extensions.\n" << flush;
00854
00855 glEnable(GL_REGISTER_COMBINERS_NV);
00856 glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 1);
00857
00858
00859 glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00860 glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
00861 glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00862 glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
00863 glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
00864
00865
00866 glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_PRIMARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
00867 glCombinerInputNV(GL_COMBINER0_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
00868 glCombinerOutputNV(GL_COMBINER0_NV, GL_ALPHA, GL_SPARE0_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
00869
00870
00871 glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00872 glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00873 glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00874 glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00875 glFinalCombinerInputNV(GL_VARIABLE_E_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00876 glFinalCombinerInputNV(GL_VARIABLE_F_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
00877
00878 glEnable(GL_BLEND);
00879 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00880
00881 #else
00882
00883 gluBuild2DMipmaps(GL_TEXTURE_2D, 2, m_FPSize, m_FPSize,
00884 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
00885 (void*)m_Footprint);
00886 glEnable(GL_TEXTURE_2D);
00887
00888 glEnable(GL_BLEND);
00889 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00890 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00891 #endif
00892 }
00893
00894
00895
00896
00897
00898 void vu1512111::drawSplatOrtho(float* v)
00899 {
00900 vuVector pos(v[0], v[1], v[2]);
00901
00902 pos += m_Shift0;
00903 glTexCoord2fv(texcoord0);
00904 glVertex3fv(pos.getData());
00905
00906 pos += m_Shift1;
00907 glTexCoord2fv(texcoord1);
00908 glVertex3fv(pos.getData());
00909
00910 pos += m_Shift2;
00911 glTexCoord2fv(texcoord2);
00912 glVertex3fv(pos.getData());
00913
00914 pos -= m_Shift1;
00915 glTexCoord2fv(texcoord3);
00916 glVertex3fv(pos.getData());
00917 }
00918
00919
00920
00921
00922
00923 void vu1512111::drawSplatPerspective(float* v)
00924 {
00925 }