private static WritableRaster shadow ( int i , int j , WritableRaster tmpWR , WritableRaster demWR , double res , double [ ] normalSunVector , double [ ] inverseSunVector ) { int n = 0 ; double zcompare = - Double . MAX_VALUE ; double dx = ( inverseSunVector [ 0 ] * n ) ; double dy = ( inverseSunVector [ 1 ] * n ) ; int nCols = tmpWR . getWidth ( ) ; int nRows = tmpWR . getHeight ( ) ; int idx = ( int ) Math . round ( i + dx ) ; int jdy = ( int ) Math . round ( j + dy ) ; double vectorToOrigin [ ] = new double [ 3 ] ; while ( idx >= 0 && idx <= nCols - 1 && jdy >= 0 && jdy <= nRows - 1 ) { vectorToOrigin [ 0 ] = dx * res ; vectorToOrigin [ 1 ] = dy * res ; int tmpY = ( int ) ( j + dy ) ; if ( tmpY < 0 ) { tmpY = 0 ; } else if ( tmpY > nRows ) { tmpY = nRows - 1 ; } int tmpX = ( int ) ( i + dx ) ; if ( tmpX < 0 ) { tmpX = 0 ; } else if ( tmpY > nCols ) { tmpX = nCols - 1 ; } vectorToOrigin [ 2 ] = demWR . getSampleDouble ( idx , jdy , 0 ) ; // vectorToOrigin[2] = (pitRandomIter.getSampleDouble(idx, jdy, 0) + // pitRandomIter // .getSampleDouble(tmpX, tmpY, 0)) / 2; double zprojection = scalarProduct ( vectorToOrigin , normalSunVector ) ; if ( ( zprojection < zcompare ) ) { tmpWR . setSample ( idx , jdy , 0 , 0 ) ; } else { zcompare = zprojection ; } n = n + 1 ; dy = ( inverseSunVector [ 1 ] * n ) ; dx = ( inverseSunVector [ 0 ] * n ) ; idx = ( int ) Math . round ( i + dx ) ; jdy = ( int ) Math . round ( j + dy ) ; } return tmpWR ; }
Evaluate the shadow map .