| 1 |
//#include <SDL/SDL.h> |
| 2 |
|
| 3 |
typedef unsigned char Byte; |
| 4 |
typedef unsigned int uint; |
| 5 |
|
| 6 |
#include <GL/glew.h> |
| 7 |
#include "CgUtil.h" |
| 8 |
|
| 9 |
//#include <GL/gl.h> |
| 10 |
#include <math.h> |
| 11 |
//#include <GL/glu.h> |
| 12 |
|
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include <vcg/space/point3.h> |
| 16 |
#include <vcg/space/color4.h> |
| 17 |
|
| 18 |
|
| 19 |
using namespace vcg; |
| 20 |
using namespace std; |
| 21 |
|
| 22 |
#include "CubeMapSamp.h" |
| 23 |
#include "OctaMapSamp.h" |
| 24 |
|
| 25 |
#include "Mol.h" |
| 26 |
#include "HardSettings.h" |
| 27 |
#include "MyCanvas.h" |
| 28 |
#include "ShadowMap.h" |
| 29 |
|
| 30 |
bool use_accurate_halo=true; |
| 31 |
|
| 32 |
|
| 33 |
bool validView(Point3f p){ |
| 34 |
if (!hardSettings.doubleSM) return true; |
| 35 |
if (p[0]>0) return true; |
| 36 |
if (p[0]<0) return false; |
| 37 |
|
| 38 |
if (p[1]<0) return true; |
| 39 |
if (p[1]>0) return false; |
| 40 |
|
| 41 |
if (p[2]<0) return true; |
| 42 |
return false; |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
extern int CSIZE; // size for alo patch |
| 47 |
extern int BSIZE; // size for bonds patches |
| 48 |
|
| 49 |
//extern uint shadowFrame, shadowTexture, offsetFrame, haloFrame, haloTexture, finalFrame; |
| 50 |
//uint finalFrame=0; // frame dove metto l'immagine finale! 0 se lo schermo. |
| 51 |
|
| 52 |
CgUtil shadowSettings; |
| 53 |
CgUtil shadowSettingsAcc; |
| 54 |
|
| 55 |
// functions defined later. |
| 56 |
static void setMatrices(vcg::Point3f L, int screensize, int screensizeHard, bool sx); |
| 57 |
static void restoreMatrices(); |
| 58 |
|
| 59 |
static GLint lastviewport[4]; |
| 60 |
|
| 61 |
|
| 62 |
float matSM[4][4]; // matrix used during shadowmmap drawing |
| 63 |
float matFinal[4][4];// matrix for FP computation = matSM x (MV)^(-1) |
| 64 |
float HSratio; // ratio betweenhard and soft shadowbuffer |
| 65 |
|
| 66 |
extern Mol mol; |
| 67 |
extern int winx,winy; |
| 68 |
|
| 69 |
// FOR HALOS |
| 70 |
void prepareDepthTextureForCurrentViewpoint(){ |
| 71 |
|
| 72 |
// Draw depth texture from current viewpoint |
| 73 |
|
| 74 |
haloCanvas.SetSameRes( mainCanvas ); |
| 75 |
haloCanvas.SetAsOutput(); |
| 76 |
|
| 77 |
if (use_accurate_halo) |
| 78 |
shadowSettingsAcc.BindShaders(); |
| 79 |
else |
| 80 |
shadowSettings.BindShaders(); |
| 81 |
|
| 82 |
|
| 83 |
glClear( GL_DEPTH_BUFFER_BIT ) ; |
| 84 |
|
| 85 |
mol.Draw(); |
| 86 |
|
| 87 |
mainCanvas.SetAsOutput(); |
| 88 |
|
| 89 |
glActiveTextureARB(GL_TEXTURE1_ARB); |
| 90 |
haloCanvas.SetAsTexture(); |
| 91 |
glEnable(GL_TEXTURE_2D); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
Point3f lastL(0,0,0); // last used light |
| 96 |
|
| 97 |
void ShadowMap::Update(){ |
| 98 |
lastL.Zero(); |
| 99 |
} |
| 100 |
|
| 101 |
void ShadowMap::computeAsTexture(vcg::Point3f L, bool makeboth, MyCanvas &canvas){ |
| 102 |
|
| 103 |
if (lastL!=L) { |
| 104 |
|
| 105 |
canvas.SetAsOutput(); |
| 106 |
|
| 107 |
|
| 108 |
setMatrices(L, canvas.GetSoftRes(),canvas.GetHardRes(), true); |
| 109 |
glClearDepth(1); |
| 110 |
glClear( GL_DEPTH_BUFFER_BIT ); |
| 111 |
glDisable(GL_SCISSOR_TEST); |
| 112 |
glDepthFunc(GL_LESS); |
| 113 |
|
| 114 |
m.DrawShadowmap(false); |
| 115 |
restoreMatrices(); |
| 116 |
|
| 117 |
|
| 118 |
if (hardSettings.doubleSM && makeboth) { |
| 119 |
setMatrices(L, canvas.GetSoftRes(), canvas.GetHardRes(), false); |
| 120 |
glClearDepth(-10000); |
| 121 |
glClear( GL_DEPTH_BUFFER_BIT); |
| 122 |
glDepthFunc(GL_GREATER); |
| 123 |
|
| 124 |
glDisable(GL_SCISSOR_TEST); |
| 125 |
|
| 126 |
m.DrawShadowmap(false); |
| 127 |
|
| 128 |
restoreMatrices(); |
| 129 |
} |
| 130 |
|
| 131 |
glClearDepth(1); |
| 132 |
glDepthFunc(GL_LESS); |
| 133 |
|
| 134 |
mainCanvas.SetAsOutput(); |
| 135 |
|
| 136 |
lastL=L; |
| 137 |
} |
| 138 |
|
| 139 |
glActiveTextureARB(GL_TEXTURE1_ARB); |
| 140 |
|
| 141 |
canvas.SetAsTexture(); |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
extern ShadowMap shadowmap; |
| 147 |
float extractCurrentScaleFactor(float x[4][4]); |
| 148 |
float extractCurrentScaleFactor(); |
| 149 |
//float shadowScaleFactor=1; |
| 150 |
|
| 151 |
|
| 152 |
void ShadowMap::FeedParameters(){ |
| 153 |
for (int i=0; i<3; i++) { |
| 154 |
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, i+3, |
| 155 |
matFinal[0][i],matFinal[1][i],matFinal[2][i],matFinal[3][i] |
| 156 |
); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
extern CgUtil cgSettings; |
| 161 |
|
| 162 |
/*void DrawTmp(){ |
| 163 |
|
| 164 |
cgSettings.BindShaders(); |
| 165 |
|
| 166 |
glEnable(GL_TEXTURE_2D); |
| 167 |
//glBindTexture(GL_TEXTURE_2D, molTexture); |
| 168 |
|
| 169 |
glActiveTextureARB(GL_TEXTURE1_ARB); |
| 170 |
glBindTexture(GL_TEXTURE_2D, shadowTexture); |
| 171 |
|
| 172 |
shadowmap.m.Draw(); |
| 173 |
// shadowmap.m.DrawShadowmap(false); |
| 174 |
|
| 175 |
|
| 176 |
glDisable(GL_VERTEX_PROGRAM_ARB); |
| 177 |
glDisable(GL_FRAGMENT_PROGRAM_ARB); |
| 178 |
glDisable(GL_BLEND); |
| 179 |
|
| 180 |
|
| 181 |
glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); |
| 182 |
glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); |
| 183 |
glBindTexture(GL_TEXTURE_2D, shadowTexture);*/ |
| 184 |
// glBindTexture(GL_TEXTURE_2D, shadowTexture); |
| 185 |
|
| 186 |
/* glBegin(GL_QUADS); |
| 187 |
glColor3f(0,0,1); |
| 188 |
float h=-0.25, k=-0.25; |
| 189 |
glTexCoord2f(0,0); glVertex3d( k, h,0.1); |
| 190 |
glTexCoord2f(1,0); glVertex3d( k,+1,0.1); |
| 191 |
glTexCoord2f(1,1); glVertex3d(+1,+1,0.1); |
| 192 |
glTexCoord2f(0,1); glVertex3d(+1, h,0.1); |
| 193 |
glEnd(); |
| 194 |
|
| 195 |
glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); |
| 196 |
glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); |
| 197 |
|
| 198 |
glBegin(GL_QUADS); |
| 199 |
glColor3f(1,1,1); |
| 200 |
glTexCoord2f(0,0); glVertex3d(k-0.75,h-0.75,0); |
| 201 |
glTexCoord2f(1,0); glVertex3d(k-0.75,0.25,0); |
| 202 |
glTexCoord2f(1,1); glVertex3d(0.25,0.25,0); |
| 203 |
glTexCoord2f(0,1); glVertex3d(0.25,h-0.75,0); |
| 204 |
glEnd(); |
| 205 |
*/ |
| 206 |
/*glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); |
| 207 |
glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); */ |
| 208 |
/*}*/ |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
bool ShadowMap::init(){ |
| 213 |
shadowSettings.SetForShadowMap(false); |
| 214 |
shadowSettingsAcc.SetForShadowMap(true); |
| 215 |
|
| 216 |
mainCanvas.RedirectToVideo(); |
| 217 |
mainCanvas.SetVideoSize(winx); |
| 218 |
|
| 219 |
|
| 220 |
// test shadow and shadowAO canvases |
| 221 |
shadowmapCanvas.SetRes(hardSettings.SHADOWMAP_SIZE); |
| 222 |
shadowmapCanvas.ratio2x1=(hardSettings.doubleSM==1); |
| 223 |
if (!shadowmapCanvas.Test() ) return false; |
| 224 |
|
| 225 |
shadowAOCanvas.SetRes(hardSettings.AOSM_SIZE); |
| 226 |
shadowAOCanvas.ratio2x1=(hardSettings.doubleSM==1); |
| 227 |
//shadowAOCanvas.ratio2x1=(hardSettings.doubleSM==1); |
| 228 |
if (!shadowAOCanvas.Test() ) return false; |
| 229 |
|
| 230 |
mainCanvas.SetAsOutput(); |
| 231 |
return true; |
| 232 |
} |
| 233 |
|
| 234 |
bool ShadowMap::initHalo(){ |
| 235 |
|
| 236 |
// test halo canvases |
| 237 |
haloCanvas.SetSameRes(mainCanvas); |
| 238 |
if (!haloCanvas.Test() ) return false; |
| 239 |
|
| 240 |
|
| 241 |
mainCanvas.SetAsOutput(); |
| 242 |
return true; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
bool AOgpu2::init(){ |
| 247 |
if (!moltextureCanvas.Test()) return false; |
| 248 |
mainCanvas.SetAsOutput(); |
| 249 |
} |
| 250 |
|
| 251 |
float myrand(); |
| 252 |
|
| 253 |
static CgUtil aogpu_settings; |
| 254 |
static CgUtil aogpustick_settings; |
| 255 |
|
| 256 |
void AOgpu2::Reset(Mol &m){ |
| 257 |
moltextureCanvas.SetAsOutput(); |
| 258 |
|
| 259 |
glClearColor(0,0,0,1); |
| 260 |
glClear( GL_COLOR_BUFFER_BIT); |
| 261 |
} |
| 262 |
|
| 263 |
void AOgpu2::Bind(){ |
| 264 |
moltextureCanvas.SetAsOutput(); |
| 265 |
} |
| 266 |
|
| 267 |
AOgpu2::AOgpu2( Point3f dir, Mol &m, int ndir){ |
| 268 |
|
| 269 |
shadowmap.computeAsTexture(dir, true, shadowAOCanvas ); |
| 270 |
glFinish(); |
| 271 |
|
| 272 |
moltextureCanvas.SetAsOutput(); |
| 273 |
|
| 274 |
glDisable(GL_VERTEX_PROGRAM_ARB); |
| 275 |
glEnable(GL_FRAGMENT_PROGRAM_ARB); |
| 276 |
|
| 277 |
|
| 278 |
aogpu_settings.BindDrawAOShader(); |
| 279 |
for (int i=0; i<3; i++) { |
| 280 |
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, i, |
| 281 |
matSM[0][i],matSM[1][i],matSM[2][i],matSM[3][i] |
| 282 |
); |
| 283 |
//printf("Sending %d (%f %f %f %f)\n", i, mat[0][i],mat[1][i],mat[2][i],mat[3][i]); |
| 284 |
} |
| 285 |
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 3, dir[0],dir[1],dir[2], 4.0/ndir ); |
| 286 |
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 4, |
| 287 |
0,stick_radius,0,0 |
| 288 |
); |
| 289 |
|
| 290 |
m.DrawOnTexture(); |
| 291 |
|
| 292 |
glDisable(GL_BLEND); |
| 293 |
|
| 294 |
glEnable(GL_VERTEX_PROGRAM_ARB); |
| 295 |
|
| 296 |
}; |
| 297 |
|
| 298 |
void AOgpu2::UnBind(){ |
| 299 |
mainCanvas.SetAsOutput(); |
| 300 |
}; |
| 301 |
|
| 302 |
float myrand(){ |
| 303 |
static int k=0; |
| 304 |
k+=1231543214; |
| 305 |
return ((k%12421)/12421.0); |
| 306 |
} |
| 307 |
|
| 308 |
void Bond::DrawOnTexture(){ |
| 309 |
//glColor3f(myrand(),myrand(),myrand()); |
| 310 |
float h=0.0; |
| 311 |
|
| 312 |
float Xm=(-1.0)-1.0/BSIZE; |
| 313 |
float Xp=+1.0+1.0/BSIZE; |
| 314 |
float Ym=Xm, |
| 315 |
Yp=+1.0+1.0/CSIZE/1.0; |
| 316 |
Point3f tmp=startp^dir; |
| 317 |
startp.Normalize(); |
| 318 |
tmp.Normalize(); |
| 319 |
glMultiTexCoord3fARB(GL_TEXTURE2_ARB, startp[0],startp[1],startp[2]); |
| 320 |
glMultiTexCoord3fARB(GL_TEXTURE3_ARB, tmp[0],tmp[1],tmp[2] ); |
| 321 |
|
| 322 |
glMultiTexCoord3fARB(GL_TEXTURE1_ARB, b[0],b[1],b[2] ); |
| 323 |
glTexCoord2f(Xm,Yp); glVertex2f(-h+tx, -h+ty+CSIZE); |
| 324 |
glTexCoord2f(Xm,Ym); glVertex2f(-h+tx, -h+ty); |
| 325 |
glMultiTexCoord3fARB(GL_TEXTURE1_ARB, a[0],a[1],a[2] ); |
| 326 |
glTexCoord2f(Xp,Ym); glVertex2f(-h+tx+BSIZE,-h+ty); |
| 327 |
glTexCoord2f(Xp,Yp); glVertex2f(-h+tx+BSIZE,-h+ty+CSIZE); |
| 328 |
} |
| 329 |
|
| 330 |
void QAtom::DrawOnTexture(){ |
| 331 |
glColor3f(myrand(),myrand(),myrand()); |
| 332 |
float h=0.0; |
| 333 |
|
| 334 |
float Xm=(-1.0)-1.0/CSIZE/1.0; |
| 335 |
float Xp=+1.0+1.0/CSIZE/1.0; |
| 336 |
float Ym=Xm, Yp=Xp; |
| 337 |
glMultiTexCoord4fARB(GL_TEXTURE1_ARB, px,py,pz,r ); |
| 338 |
glTexCoord2f(Xm,Ym); glVertex2f(-h+tx, -h+ty); |
| 339 |
glTexCoord2f(Xp,Ym); glVertex2f(-h+tx+CSIZE,-h+ty); |
| 340 |
glTexCoord2f(Xp,Yp); glVertex2f(-h+tx+CSIZE,-h+ty+CSIZE); |
| 341 |
glTexCoord2f(Xm,Yp); glVertex2f(-h+tx, -h+ty+CSIZE); |
| 342 |
} |
| 343 |
|
| 344 |
void Mol::DrawOnTexture(){ |
| 345 |
|
| 346 |
|
| 347 |
glEnable(GL_BLEND); |
| 348 |
glBlendFunc(GL_ONE, GL_ONE ); |
| 349 |
|
| 350 |
glMatrixMode(GL_PROJECTION); |
| 351 |
glPushMatrix(); |
| 352 |
glLoadIdentity(); |
| 353 |
glOrtho(0,moltextureCanvas.GetSoftRes(),0,moltextureCanvas.GetSoftRes(), 0,1); |
| 354 |
|
| 355 |
|
| 356 |
glMatrixMode(GL_MODELVIEW); |
| 357 |
glPushMatrix(); |
| 358 |
glLoadIdentity(); |
| 359 |
|
| 360 |
|
| 361 |
glGetIntegerv(GL_VIEWPORT, lastviewport); |
| 362 |
glViewport(0,0,moltextureCanvas.GetSoftRes(),moltextureCanvas.GetSoftRes()); |
| 363 |
|
| 364 |
glActiveTextureARB(GL_TEXTURE1_ARB); |
| 365 |
glDisable(GL_TEXTURE_2D); |
| 366 |
glActiveTextureARB(GL_TEXTURE0_ARB); |
| 367 |
glDisable(GL_TEXTURE_2D); |
| 368 |
|
| 369 |
glBegin(GL_QUADS); |
| 370 |
for (int i=0; i < (int)atom.size(); i++) |
| 371 |
atom[i].DrawOnTexture(); |
| 372 |
glEnd(); |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
if (sticks) { |
| 379 |
aogpustick_settings.BindDrawAOShaderSticks(); |
| 380 |
//glDisable(GL_BLEND); |
| 381 |
//glDisable(GL_FRAGMENT_PROGRAM_ARB); |
| 382 |
glBegin(GL_QUADS); |
| 383 |
for (int i=0; i < (int)bond.size(); i++) bond[i].DrawOnTexture(); |
| 384 |
glEnd(); |
| 385 |
//glEnable(GL_FRAGMENT_PROGRAM_ARB); |
| 386 |
} |
| 387 |
glMatrixMode(GL_PROJECTION); |
| 388 |
glPopMatrix(); |
| 389 |
glMatrixMode(GL_MODELVIEW); |
| 390 |
glPopMatrix(); |
| 391 |
glViewport(lastviewport[0],lastviewport[1],lastviewport[2],lastviewport[3]); |
| 392 |
}; |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
static void restoreMatrices(){ |
| 401 |
glMatrixMode(GL_PROJECTION); |
| 402 |
glPopMatrix(); |
| 403 |
glMatrixMode(GL_MODELVIEW); |
| 404 |
glPopMatrix(); |
| 405 |
glViewport(lastviewport[0],lastviewport[1],lastviewport[2],lastviewport[3]); |
| 406 |
} |
| 407 |
|
| 408 |
static void setMatrices(vcg::Point3f L, int screensize, int screensizeHard, bool sx){ |
| 409 |
// orthonormal basis |
| 410 |
L.Normalize(); |
| 411 |
Point3f ax,ay,az=L; |
| 412 |
ax=az^Point3f(1,0,0); |
| 413 |
if (ax.SquaredNorm()<0.1) ax=az^Point3f(0,1,0); |
| 414 |
ax=ax.Normalize(); |
| 415 |
ay=(az^ax).Normalize(); |
| 416 |
|
| 417 |
glMatrixMode(GL_PROJECTION); |
| 418 |
glPushMatrix(); |
| 419 |
glLoadIdentity(); |
| 420 |
/* if (!sx) { |
| 421 |
glScalef(1,1,-1); |
| 422 |
}*/ |
| 423 |
|
| 424 |
|
| 425 |
GLfloat nearPlane = 1.0; |
| 426 |
GLfloat farPlane = 201; |
| 427 |
glOrtho(-1,+1,-1,+1, nearPlane, farPlane); |
| 428 |
|
| 429 |
glMatrixMode(GL_MODELVIEW); |
| 430 |
|
| 431 |
// PREPARE MATRIX for shadow test... |
| 432 |
|
| 433 |
glPushMatrix(); |
| 434 |
glLoadIdentity(); |
| 435 |
glOrtho(-1,+1,-1,+1, nearPlane, farPlane); |
| 436 |
|
| 437 |
gluLookAt(0,0,-4, 0,0,0, 0,1,0); |
| 438 |
gluLookAt( az[0],az[1],az[2], 0,0,0, ay[0], ay[1], ay[2] ); |
| 439 |
|
| 440 |
float r=shadowmap.m.r; |
| 441 |
float px=shadowmap.m.px; |
| 442 |
float py=shadowmap.m.py; |
| 443 |
float pz=shadowmap.m.pz; |
| 444 |
glScalef(1/r,1/r,1/r); |
| 445 |
glTranslatef(-px,-py,-pz); |
| 446 |
|
| 447 |
glGetFloatv(GL_MODELVIEW_MATRIX, &(matSM[0][0])); |
| 448 |
|
| 449 |
// ...done! |
| 450 |
|
| 451 |
glLoadIdentity(); |
| 452 |
gluLookAt(0,0,-4, 0,0,0, 0,1,0); |
| 453 |
gluLookAt( az[0],az[1],az[2], 0,0,0, ay[0], ay[1], ay[2] ); |
| 454 |
|
| 455 |
//shadowScaleFactor=extractCurrentScaleFactor()/r; |
| 456 |
|
| 457 |
glGetIntegerv(GL_VIEWPORT, lastviewport); |
| 458 |
|
| 459 |
if (sx) { |
| 460 |
glViewport(0,0,screensize,screensize); |
| 461 |
glEnable(GL_SCISSOR_TEST); |
| 462 |
glScissor(0,0,screensize,screensize); |
| 463 |
} |
| 464 |
else { |
| 465 |
glViewport(screensize,0,screensize,screensize); |
| 466 |
glEnable(GL_SCISSOR_TEST); |
| 467 |
glScissor(screensize,0,screensize,screensize); |
| 468 |
} |
| 469 |
|
| 470 |
HSratio = float(screensize) / float(screensizeHard) ; |
| 471 |
//for (int i=0; i<4; i++) |
| 472 |
//for (int j=0; j<2; j++) matSM[i][j] /=ratio; |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
// quick and dirty |
| 478 |
#include <vcg/math/matrix44.h> |
| 479 |
void ShadowMap::GetCurrentPVMatrix(){ |
| 480 |
|
| 481 |
float matP[16]; |
| 482 |
float matMV[16]; |
| 483 |
|
| 484 |
glGetFloatv(GL_PROJECTION_MATRIX, matP); |
| 485 |
glGetFloatv(GL_MODELVIEW_MATRIX, matMV); |
| 486 |
|
| 487 |
Matrix44f A(matSM[0]); |
| 488 |
Matrix44f B(matMV); |
| 489 |
Matrix44f C(matP); |
| 490 |
|
| 491 |
A=vcg::Transpose( A ); |
| 492 |
B=vcg::Transpose( B ); |
| 493 |
C=vcg::Transpose( C ); |
| 494 |
|
| 495 |
Matrix44f P = C*B; |
| 496 |
P=vcg::Invert( P ); |
| 497 |
Matrix44f res = A*P; |
| 498 |
|
| 499 |
Matrix44f mul; |
| 500 |
Matrix44f add; |
| 501 |
|
| 502 |
GLint vp[4]; |
| 503 |
glGetIntegerv(GL_VIEWPORT, vp); |
| 504 |
|
| 505 |
mul.SetScale(Point3f(2.0f/vp[2], 2.0f/vp[3], 2)); |
| 506 |
add.SetTranslate(Point3f(-1,-1,-1)); |
| 507 |
|
| 508 |
//Matrix44f mulHS; |
| 509 |
//mulHS.SetScale(Point3f(HSratio,HSratio,1) ); |
| 510 |
|
| 511 |
res=res*add*mul; |
| 512 |
|
| 513 |
for (int i=0; i<4; i++) |
| 514 |
for (int j=0; j<4; j++) |
| 515 |
matFinal[i][j]=res[j][i]; |
| 516 |
} |
| 517 |
/* |
| 518 |
void ShadowMap::GetCurrentPVMatrix(){ |
| 519 |
|
| 520 |
computeAxBm1xCm1( &(res[0][0]) , &(A[0][0]) , &(B[0][0]) , &(C[0][0])); |
| 521 |
}*/ |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
void test(){ |
| 526 |
|
| 527 |
return; |
| 528 |
float nf[2]; |
| 529 |
glGetFloatv(GL_DEPTH_RANGE, nf); |
| 530 |
FILE *f=fopen("test.txt","w"); |
| 531 |
fprintf(f,"near=%f,far=%f\n\n",nf[0],nf[1]); |
| 532 |
fclose(f); |
| 533 |
|
| 534 |
float mat[16]; |
| 535 |
float matP[16]; |
| 536 |
|
| 537 |
glGetFloatv(GL_MODELVIEW_MATRIX, mat); |
| 538 |
glGetFloatv(GL_PROJECTION_MATRIX, matP); |
| 539 |
|
| 540 |
|
| 541 |
Matrix44f A(mat); |
| 542 |
A=vcg::Transpose( A ); |
| 543 |
|
| 544 |
Matrix44f B(matP); |
| 545 |
B=vcg::Transpose( B ); |
| 546 |
|
| 547 |
A = B*A; |
| 548 |
|
| 549 |
for (int i=0; i<4; i++) |
| 550 |
for (int j=0; j<4; j++) |
| 551 |
mat[i*4+j]=A[j][i]; |
| 552 |
|
| 553 |
glMatrixMode(GL_PROJECTION); |
| 554 |
glLoadIdentity( ); |
| 555 |
|
| 556 |
glMatrixMode(GL_MODELVIEW); |
| 557 |
glLoadMatrixf( mat ); |
| 558 |
|
| 559 |
|
| 560 |
} |