KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > PointLight


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image;
19
20 import java.awt.Color JavaDoc;
21
22 /**
23  * A light source which emits a light of constant intensity in all directions.
24  *
25  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
26  * @version $Id: PointLight.java,v 1.5 2005/03/27 08:58:32 cam Exp $
27  */

28 public class PointLight extends AbstractLight {
29     /**
30      * The light position, in user space
31      */

32     private double lightX, lightY, lightZ;
33
34     /**
35      * @return the light's x position
36      */

37     public double getLightX(){
38         return lightX;
39     }
40
41     /**
42      * @return the light's y position
43      */

44     public double getLightY(){
45         return lightY;
46     }
47
48     /**
49      * @return the light's z position
50      */

51     public double getLightZ(){
52         return lightZ;
53     }
54
55     public PointLight(double lightX, double lightY, double lightZ,
56                       Color JavaDoc lightColor){
57         super(lightColor);
58         this.lightX = lightX;
59         this.lightY = lightY;
60         this.lightZ = lightZ;
61     }
62
63     /**
64      * @return true if the light is constant over the whole surface
65      */

66     public boolean isConstant(){
67         return false;
68     }
69
70     /**
71      * Computes the light vector in (x, y, z)
72      *
73      * @param x x-axis coordinate where the light should be computed
74      * @param y y-axis coordinate where the light should be computed
75      * @param z z-axis coordinate where the light should be computed
76      * @param L array of length 3 where the result is stored
77      */

78     public final void getLight(final double x, final double y, final double z,
79                                final double L[]){
80         L[0] = lightX - x;
81         L[1] = lightY - y;
82         L[2] = lightZ - z;
83
84         final double norm = Math.sqrt(L[0]*L[0] +
85                                       L[1]*L[1] +
86                                       L[2]*L[2]);
87
88         if(norm > 0){
89             final double invNorm = 1.0/norm;
90             L[0] *= invNorm;
91             L[1] *= invNorm;
92             L[2] *= invNorm;
93         }
94     }
95 }
96
97
Popular Tags