00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023 #include "lightningmaker.h"
00024 #include "triplex.h"
00025 #include "imagecalculator.h"
00026
00030 lightningMaker::lightningMaker(QVector<QVector<int> >& distanceMap, QVector<QVector<triplex> >& normalMap, QRectF& window, QSize resolution, QImage* destination, triplex camera, triplex light):distanceMap(distanceMap), window(window), destination(destination), camera(camera), light(light), normalMap(normalMap), resolution(resolution){
00031 stepx = window.width() / resolution.width();
00032 stepy = window.height() / resolution.height();
00033 stepz = stepx;
00034 }
00035
00041 void lightningMaker::run(){
00042 for (int i=0; i<distanceMap.count(); i++){
00043 for (int j=0; j<distanceMap[i].count(); j++){
00044 triplex N = normalMap[i][j];
00045
00046 triplex point(window.left() + i*stepx, window.top() + j*stepy, window.left() + distanceMap[i][j]*stepz);
00047
00048 triplex L = (point - camera).normalize();
00049
00050 triplex R = N * 2 * (N.scalar(L)) - L;
00051
00052 triplex V = (point - camera).normalize();
00053 float resultante = abs(V.scalar(R));
00054 destination->setPixel(i,j, ImageCalculator:: intToRGBA(1000 * resultante * resultante));
00055 }
00056 }
00057 }