421 |
{ |
{ |
422 |
"Type" : "2", |
"Type" : "2", |
423 |
"Name": "FisheyePaperQuad", |
"Name": "FisheyePaperQuad", |
424 |
"Data": "Pt corners[4]; Paper::Paper* paper; ", |
"Data": "Paper::Paper* paper; float x0, y0, x1, y1;", |
425 |
"Params" : """ |
"Params" : """ |
426 |
Paper paper, float x0, float y0, float x1, float y1 |
Paper paper, float x0, float y0, float x1, float y1 |
427 |
""", |
""", |
428 |
"ParamCode" : """ |
"ParamCode" : """ |
429 |
this->paper = paper; |
this->paper = paper; |
430 |
corners[0].x = corners[1].x = x0; |
this->x0 = x0; |
431 |
corners[0].y = corners[3].y = y0; |
this->y0 = y0; |
432 |
corners[2].x = corners[3].x = x1; |
this->x1 = x1; |
433 |
corners[1].y = corners[2].y = y1; |
this->y1 = y1; |
434 |
""", |
""", |
435 |
"RenderCode" : """ |
"RenderCode" : """ |
436 |
DBG(dbg) << "Paper\\n"; |
DBG(dbg) << "Paper\\n"; |
440 |
ZVec paperx = coords1.transform(Pt(1, 0)) - paperorigin; |
ZVec paperx = coords1.transform(Pt(1, 0)) - paperorigin; |
441 |
ZVec papery = coords1.transform(Pt(0, 1)) - paperorigin; |
ZVec papery = coords1.transform(Pt(0, 1)) - paperorigin; |
442 |
|
|
443 |
|
ZPt borig = coords2.transform(Pt(0, 0)); |
444 |
|
ZVec b0 = coords2.transform(Pt(1, 0)) - borig; |
445 |
|
ZVec b1 = coords2.transform(Pt(0, 1)) - borig; |
446 |
|
|
447 |
|
b0 = 1.0 / (b0.x * b0.x + b0.y * b0.y) * b0; |
448 |
|
b1 = 1.0 / (b1.x * b1.x + b1.y * b1.y) * b1; |
449 |
|
|
450 |
Paper::LightParam lightParam; |
Paper::LightParam lightParam; |
451 |
lightParam.orig = paperorigin-ZPt(0,0,0); |
lightParam.orig = paperorigin-ZPt(0,0,0); |
452 |
lightParam.e0 = paperx; |
lightParam.e0 = paperx; |
462 |
lightParam.e0 << " " << |
lightParam.e0 << " " << |
463 |
lightParam.e1 << " " << |
lightParam.e1 << " " << |
464 |
lightParam.e2 << " " << |
lightParam.e2 << " " << |
465 |
"\\nCorners" << |
"\\nx0,x1,y0,y1: " << |
466 |
corners[0] << |
x0 << " " << x1 << " " << |
467 |
corners[1] << |
y0 << " " << y1 << "\\n" |
|
corners[2] << |
|
|
corners[3] << |
|
|
"\\nCorners trans:" << |
|
|
coords1.transform(corners[0]) << |
|
|
coords1.transform(corners[1]) << |
|
|
coords1.transform(corners[2]) << |
|
|
coords1.transform(corners[3]) << |
|
|
"\\n" |
|
468 |
; |
; |
469 |
} |
} |
470 |
GLERR |
GLERR |
473 |
if (dbg) cout << "Pass\\n"; |
if (dbg) cout << "Pass\\n"; |
474 |
(*it).setUpVP(&lightParam); |
(*it).setUpVP(&lightParam); |
475 |
|
|
476 |
GLERR |
float xstep = (x1 - x0) / 16; |
477 |
glBegin(GL_QUADS); |
float ystep = (y1 - y0) / 16; |
|
|
|
|
glTexCoord2f(corners[0].x,corners[0].y); |
|
|
coords1.vertex(corners[0]); |
|
|
|
|
|
glTexCoord2f(corners[1].x,corners[1].y); |
|
|
coords1.vertex(corners[1]); |
|
|
|
|
|
glTexCoord2f(corners[2].x,corners[2].y); |
|
|
coords1.vertex(corners[2]); |
|
478 |
|
|
479 |
glTexCoord2f(corners[3].x,corners[3].y); |
for (float y_ = y0; y_ + ystep <= y1; y_ += ystep) { |
480 |
coords1.vertex(corners[3]); |
glBegin(GL_QUAD_STRIP); |
481 |
glEnd(); |
for (float x = x0; x <= x1; x += xstep) { |
482 |
|
int i = 0; |
483 |
|
for (float y = y_; i < 2; i++, y += ystep) { |
484 |
|
glTexCoord2f(x, y); |
485 |
|
|
486 |
|
// Map (x,y) into coords2 as (a,b) |
487 |
|
|
488 |
|
ZPt pos = coords1.transform(Pt(x,y)); |
489 |
|
float a = b0.dot(pos - borig); |
490 |
|
float b = b1.dot(pos - borig); |
491 |
|
|
492 |
|
// Modulate distance from coords2 origin |
493 |
|
float m = 1 + 2.0 / (1 + a * a + b * b); |
494 |
|
|
495 |
|
coords2.vertex(Pt(m*a, m*b)); |
496 |
|
} |
497 |
|
} |
498 |
|
glEnd(); |
499 |
|
} |
500 |
|
|
501 |
GLERR |
GLERR |
502 |
(*it).tearDownVP(); |
(*it).tearDownVP(); |