1 18 package org.apache.batik.ext.awt.image; 19 20 import java.awt.Color ; 21 22 28 public class SpotLight extends AbstractLight { 29 32 private double lightX, lightY, lightZ; 33 34 37 private double pointAtX, pointAtY, pointAtZ; 38 39 42 private double specularExponent; 43 44 47 private double limitingConeAngle, limitingCos; 48 49 52 private final double[] S = new double[3]; 53 54 57 public double getLightX(){ 58 return lightX; 59 } 60 61 64 public double getLightY(){ 65 return lightY; 66 } 67 68 71 public double getLightZ(){ 72 return lightZ; 73 } 74 75 78 public double getPointAtX(){ 79 return pointAtX; 80 } 81 82 85 public double getPointAtY(){ 86 return pointAtY; 87 } 88 89 92 public double getPointAtZ(){ 93 return pointAtZ; 94 } 95 96 99 public double getSpecularExponent(){ 100 return specularExponent; 101 } 102 103 106 public double getLimitingConeAngle(){ 107 return limitingConeAngle; 108 } 109 110 public SpotLight(final double lightX, final double lightY, final double lightZ, 111 final double pointAtX, final double pointAtY, final double pointAtZ, 112 final double specularExponent, final double limitingConeAngle, 113 final Color lightColor){ 114 super(lightColor); 115 116 this.lightX = lightX; 117 this.lightY = lightY; 118 this.lightZ = lightZ; 119 this.pointAtX = pointAtX; 120 this.pointAtY = pointAtY; 121 this.pointAtZ = pointAtZ; 122 this.specularExponent = specularExponent; 123 this.limitingConeAngle = limitingConeAngle; 124 this.limitingCos = Math.cos(limitingConeAngle*Math.PI/180.); 125 126 S[0] = pointAtX - lightX; 127 S[1] = pointAtY - lightY; 128 S[2] = pointAtZ - lightZ; 129 130 double norm = Math.sqrt(S[0]*S[0] 131 + S[1]*S[1] 132 + S[2]*S[2]); 133 134 S[0] /= norm; 135 S[1] /= norm; 136 S[2] /= norm; 137 } 138 139 142 public boolean isConstant(){ 143 return false; 144 } 145 146 154 public final void getLight(final double x, final double y, final double z, 155 final double L[]){ 156 L[0] = lightX - x; 158 L[1] = lightY - y; 159 L[2] = lightZ - z; 160 161 final double norm = Math.sqrt(L[0]*L[0] + 162 L[1]*L[1] + 163 L[2]*L[2]); 164 165 L[0] /= norm; 166 L[1] /= norm; 167 L[2] /= norm; 168 169 double LS = -(L[0]*S[0] + L[1]*S[1] + L[2]*S[2]); 170 171 if(LS > limitingCos){ 172 double Iatt = limitingCos/LS; 173 Iatt *= Iatt; 174 Iatt *= Iatt; 175 Iatt *= Iatt; 176 Iatt *= Iatt; 177 Iatt *= Iatt; 178 Iatt *= Iatt; 180 Iatt = 1 - Iatt; 181 LS = Iatt*Math.pow(LS, specularExponent); 182 183 L[0] *= LS; 184 L[1] *= LS; 185 L[2] *= LS; 186 } 187 else{ 188 L[0] = 0; 189 L[1] = 0; 190 L[2] = 0; 191 } 192 } 193 } 194 195 | Popular Tags |