OSDN Git Service

ran gdx-tools HeaderFixer tool
[mikumikustudio/libgdx-mikumikustudio.git] / gdx / src / com / badlogic / gdx / graphics / g3d / environment / SphericalHarmonics.java
1 /*******************************************************************************\r
2  * Copyright 2011 See AUTHORS file.\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  * \r
8  *   http://www.apache.org/licenses/LICENSE-2.0\r
9  * \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  ******************************************************************************/
16
17 package com.badlogic.gdx.graphics.g3d.environment;
18
19 import com.badlogic.gdx.graphics.Color;
20 import com.badlogic.gdx.utils.GdxRuntimeException;
21
22 public class SphericalHarmonics {
23         // <kalle_h> last term is no x*x * y*y but x*x - y*y
24         private final static float coeff[] = {0.282095f, 0.488603f, 0.488603f, 0.488603f, 1.092548f, 1.092548f, 1.092548f, 0.315392f, 0.546274f};
25         private final static float clamp(final float v) {
26                 return v < 0f ? 0f : (v > 1f ? 1f : v);
27         }
28         
29         public final float data[];
30         
31         public SphericalHarmonics() {
32                 data = new float[9*3];
33         }
34         
35         public SphericalHarmonics(final float copyFrom[]) {
36                 if (copyFrom.length != (9*3))
37                         throw new GdxRuntimeException("Incorrect array size");
38                 data = copyFrom.clone();
39         }
40         
41         public SphericalHarmonics set(final float values[]) {
42                 for (int i = 0; i < data.length; i++)
43                         data[i] = values[i];
44                 return this;
45         }
46         
47         public SphericalHarmonics set(final AmbientCubemap other) {
48                 return set(other.data);
49         }
50         
51         public SphericalHarmonics set(final Color color) {
52                 return set(color.r, color.g, color.b);
53         }
54         
55         public SphericalHarmonics set(float r, float g, float b) {
56                 for (int idx = 0; idx < data.length;) {
57                         data[idx++] = r;
58                         data[idx++] = g;
59                         data[idx++] = b;
60                 }
61                 return this;
62         }
63 }