]> gerrit.simantics Code Review - simantics/3d.git/blob - dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/animation/ScaledResourceAnimationController.java
Release
[simantics/3d.git] / dev / org.simantics.proconf.g3d / src / org / simantics / proconf / g3d / animation / ScaledResourceAnimationController.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 org.simantics.db.Graph;\r
14 import org.simantics.db.Resource;\r
15 \r
16 public class ScaledResourceAnimationController extends ResourceAnimationController {\r
17         double min;\r
18         double max;\r
19         double irange;\r
20         \r
21         public ScaledResourceAnimationController(Resource source, double min, double max) {\r
22                 super(source);\r
23                 this.max = max;\r
24                 this.min = min;\r
25                 this.irange = 1.0/(max - min);\r
26         }\r
27 \r
28         \r
29         @Override\r
30         public void updateAnimation(Graph graph, double frameTime) {\r
31                 double d = (getValue(graph) - min) * irange;\r
32         if (d > 1.0) {\r
33             d = 1.0;\r
34         } else if (d < 0.0) {\r
35             d = 0.0;\r
36         }\r
37         for (Animatable a : animatables)\r
38             a.animate(d,frameTime);\r
39         }\r
40 }\r