]> gerrit.simantics Code Review - simantics/3d.git/blob - dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/animation/ChanneledColorInterpolator.java
Release
[simantics/3d.git] / dev / org.simantics.proconf.g3d / src / org / simantics / proconf / g3d / animation / ChanneledColorInterpolator.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.animation;\r
12 \r
13 import com.jme.renderer.ColorRGBA;\r
14 import com.jme.scene.state.MaterialState;\r
15 \r
16 public class ChanneledColorInterpolator implements Interpolator {\r
17     private ScalarInterpolator rInterpolator;\r
18     private ScalarInterpolator gInterpolator;\r
19     private ScalarInterpolator bInterpolator;\r
20     \r
21     //Material m = null;\r
22     MaterialState m = null;\r
23     int type = 1;\r
24     \r
25     public static final int AMBIENT = 0;\r
26     public static final int DIFFUSE = 1;\r
27     public static final int SPECULAR = 2;\r
28     public static final int EMISSIVE = 3;\r
29     \r
30     \r
31     public ChanneledColorInterpolator(ScalarInterpolator rInterpolator, ScalarInterpolator gInterpolator, ScalarInterpolator bInterpolator) {\r
32         this.rInterpolator = rInterpolator;\r
33         this.gInterpolator = gInterpolator;\r
34         this.bInterpolator = bInterpolator;\r
35     }\r
36     \r
37     public void interpolate(double delta) {\r
38         double r = rInterpolator.evaluate(delta);\r
39         double g = gInterpolator.evaluate(delta);\r
40         double b = bInterpolator.evaluate(delta);\r
41 \r
42         ColorRGBA c = new ColorRGBA((float)r, (float)g, (float)b,0.f);\r
43         switch (type) {\r
44         case AMBIENT : \r
45             m.setAmbient(c);\r
46             break;\r
47         case DIFFUSE:\r
48             m.setDiffuse(c);\r
49             break;\r
50         case SPECULAR:\r
51             m.setSpecular(c);\r
52             break;\r
53         case EMISSIVE:\r
54             m.setEmissive(c);\r
55             break;\r
56         }\r
57     }\r
58     \r
59     public void setTarget(Object target) {\r
60        // m = (Material)target;\r
61          m = (MaterialState)target;\r
62     }\r
63     \r
64     public void setType(int type) {\r
65         this.type = type;\r
66     }\r
67 \r
68 }\r