1 /*******************************************************************************
\r
2 * Copyright 2011 See AUTHORS file.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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 ******************************************************************************/
17 package com.badlogic.gdx.graphics.g3d.environment;
19 import com.badlogic.gdx.graphics.Color;
20 import com.badlogic.gdx.utils.GdxRuntimeException;
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);
29 public final float data[];
31 public SphericalHarmonics() {
32 data = new float[9*3];
35 public SphericalHarmonics(final float copyFrom[]) {
36 if (copyFrom.length != (9*3))
37 throw new GdxRuntimeException("Incorrect array size");
38 data = copyFrom.clone();
41 public SphericalHarmonics set(final float values[]) {
42 for (int i = 0; i < data.length; i++)
47 public SphericalHarmonics set(final AmbientCubemap other) {
48 return set(other.data);
51 public SphericalHarmonics set(final Color color) {
52 return set(color.r, color.g, color.b);
55 public SphericalHarmonics set(float r, float g, float b) {
56 for (int idx = 0; idx < data.length;) {