]> gerrit.simantics Code Review - simantics/3d.git/blob - dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/animation/ResourceAnimationController.java
latest release (0.41)
[simantics/3d.git] / dev / org.simantics.proconf.g3d / src / org / simantics / proconf / g3d / animation / ResourceAnimationController.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 java.util.ArrayList;\r
14 import java.util.List;\r
15 \r
16 import org.simantics.db.Graph;\r
17 import org.simantics.db.Resource;\r
18 \r
19 public class ResourceAnimationController implements AnimationController {\r
20         List<Animatable> animatables = new ArrayList<Animatable>();\r
21     \r
22         Resource source;\r
23         \r
24     public ResourceAnimationController(Resource source) {\r
25         this.source = source;\r
26     }\r
27     \r
28         public void addAnimatable(Animatable animatable) {\r
29                 animatables.add(animatable);\r
30                 \r
31         }\r
32         \r
33         public void setAnimatable(Animatable animatable) {\r
34                 animatables.clear();\r
35                 animatables.add(animatable);\r
36                 \r
37         }\r
38         \r
39         protected double getValue(Graph graph) {\r
40                 //return PropertyUtils.getScalarDoubleValue(source);\r
41                 return graph.getScalarDouble(source);\r
42                 //source.getDoubleValue();\r
43         }\r
44         \r
45         public void updateAnimation(Graph graph, double frameTime) {\r
46                 double d = getValue(graph);\r
47                 d = d - Math.floor(d);\r
48         if (d > 1.0) {\r
49             d = 1.0;\r
50         } else if (d < 0.0) {\r
51             d = 0.0;\r
52         }\r
53         for (Animatable a : animatables)\r
54             a.animate(d,frameTime);\r
55         }\r
56         \r
57         public void dispose() {\r
58                 \r
59         }\r
60         \r
61         \r
62         \r
63 \r
64 }\r