001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.ext.awt.image;
020:
021: import java.awt.Color;
022:
023: /**
024: * A light source which emits a light of constant intensity in all directions.
025: *
026: * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
027: * @version $Id: PointLight.java 478363 2006-11-22 23:01:13Z dvholten $
028: */
029: public class PointLight extends AbstractLight {
030: /**
031: * The light position, in user space
032: */
033: private double lightX, lightY, lightZ;
034:
035: /**
036: * @return the light's x position
037: */
038: public double getLightX() {
039: return lightX;
040: }
041:
042: /**
043: * @return the light's y position
044: */
045: public double getLightY() {
046: return lightY;
047: }
048:
049: /**
050: * @return the light's z position
051: */
052: public double getLightZ() {
053: return lightZ;
054: }
055:
056: public PointLight(double lightX, double lightY, double lightZ,
057: Color lightColor) {
058: super (lightColor);
059: this .lightX = lightX;
060: this .lightY = lightY;
061: this .lightZ = lightZ;
062: }
063:
064: /**
065: * @return true if the light is constant over the whole surface
066: */
067: public boolean isConstant() {
068: return false;
069: }
070:
071: /**
072: * Computes the light vector in (x, y, z)
073: *
074: * @param x x-axis coordinate where the light should be computed
075: * @param y y-axis coordinate where the light should be computed
076: * @param z z-axis coordinate where the light should be computed
077: * @param L array of length 3 where the result is stored
078: */
079: public final void getLight(final double x, final double y,
080: final double z, final double[] L) {
081:
082: double L0 = lightX - x;
083: double L1 = lightY - y;
084: double L2 = lightZ - z;
085:
086: final double norm = Math.sqrt(L0 * L0 + L1 * L1 + L2 * L2);
087:
088: if (norm > 0) {
089: final double invNorm = 1.0 / norm;
090: L0 *= invNorm;
091: L1 *= invNorm;
092: L2 *= invNorm;
093: }
094:
095: // copy the work-variables into return-array
096: L[0] = L0;
097: L[1] = L1;
098: L[2] = L2;
099: }
100: }
|