]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/scenegraph/G3DparentNode.java
Compiler warning elimination
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scenegraph / G3DparentNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g3d.scenegraph;\r
13 \r
14 import javax.vecmath.Quat4d;\r
15 import javax.vecmath.Vector3d;\r
16 \r
17 import org.simantics.g3d.math.MathTools;\r
18 import org.simantics.g3d.ontology.G3D;\r
19 import org.simantics.g3d.property.annotations.GetPropertyValue;\r
20 import org.simantics.g3d.property.annotations.SetPropertyValue;\r
21 import org.simantics.g3d.scenegraph.base.ParentNode;\r
22 import org.simantics.g3d.tools.NodeTools;\r
23 import org.simantics.objmap.graph.annotations.RelatedGetValue;\r
24 import org.simantics.objmap.graph.annotations.RelatedSetValue;\r
25 \r
26 \r
27 public class G3DparentNode<T extends IG3DNode> extends ParentNode<T> implements IG3DNode{\r
28         private Vector3d position = new Vector3d();\r
29         private Quat4d orientation = MathTools.getIdentityQuat();\r
30         \r
31         \r
32         @Override\r
33         @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")\r
34         public Quat4d getOrientation() {\r
35                 return orientation;\r
36         }\r
37         \r
38         @RelatedGetValue(G3D.URIs.hasOrientation)\r
39         public double[] getOrientationArr() {\r
40                 double arr[] = new double[4];\r
41                 orientation.get(arr);\r
42                 return arr;\r
43                 \r
44         }\r
45         \r
46         @Override\r
47         @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")\r
48         public Vector3d getPosition() {\r
49                 return position;\r
50         }\r
51         \r
52         @RelatedGetValue(G3D.URIs.hasPosition)\r
53         public double[] getPositionArr() {\r
54                 double arr[] = new double[3];\r
55                 position.get(arr);\r
56                 return arr;\r
57         }\r
58         \r
59         @Override\r
60         @SetPropertyValue(G3D.URIs.hasOrientation)\r
61         public void setOrientation(Quat4d orientation) {\r
62                 assert(orientation != null);\r
63                 this.orientation = orientation;\r
64         }\r
65         \r
66         @Override\r
67         @SetPropertyValue(G3D.URIs.hasPosition)\r
68         public void setPosition(Vector3d position) {\r
69                 assert(position != null);\r
70                 this.position = position;\r
71         }\r
72         \r
73         @RelatedSetValue(G3D.URIs.hasOrientation)\r
74         public void setOrientation(double[] arr) {\r
75                 if (arr == null)\r
76                         return;\r
77                 setOrientation(new Quat4d(arr));\r
78         }\r
79         \r
80         @RelatedSetValue(G3D.URIs.hasPosition)\r
81         public void setPosition(double[] arr) {\r
82                 if (arr == null)\r
83                         return;\r
84                 setPosition(new Vector3d(arr));\r
85         }\r
86         \r
87         @Override\r
88         @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")\r
89         public Vector3d getWorldPosition() {\r
90                 IG3DNode parent = (IG3DNode)getParent();\r
91                 if (parent == null)\r
92                         return position;\r
93                 return NodeTools.getWorldPosition(parent, new Vector3d(position));\r
94         }\r
95         \r
96         \r
97         public Vector3d getWorldPosition(Vector3d localPosition) {\r
98                 return NodeTools.getWorldPosition(this,localPosition);\r
99         }\r
100 \r
101         \r
102         @Override\r
103         @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")\r
104         public Quat4d getWorldOrientation() {\r
105                 return getWorldOrientation(new Quat4d(orientation));\r
106         }\r
107         \r
108         public Quat4d getWorldOrientation(Quat4d localOrientation) {\r
109                 IG3DNode parent = (IG3DNode)getParent();\r
110                 if (parent == null)\r
111                         return localOrientation;\r
112                 return NodeTools.getWorldOrientation(parent, localOrientation);\r
113         }\r
114         \r
115         @Override\r
116         public Vector3d getLocalPosition(Vector3d worldPosition) {\r
117                 IG3DNode parent = (IG3DNode)getParent();\r
118                 if (parent == null)\r
119                         return worldPosition;\r
120                 return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));\r
121         }\r
122         \r
123         @Override\r
124         public Quat4d getLocalOrientation(Quat4d worldOrientation) {\r
125                 IG3DNode parent = (IG3DNode)getParent();\r
126                 if (parent == null)\r
127                         return worldOrientation;\r
128                 return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));\r
129         }\r
130         \r
131         @Override\r
132         @SetPropertyValue(G3D.URIs.hasWorldPosition)\r
133         public void setWorldPosition(Vector3d position) {\r
134                 Vector3d localPos = getLocalPosition(position);\r
135                 setPosition(localPos);\r
136         }\r
137         \r
138         @Override\r
139         @SetPropertyValue(G3D.URIs.hasWorldOrientation)\r
140         public void setWorldOrientation(Quat4d orientation) {\r
141                 Quat4d localOr = getLocalOrientation(orientation);\r
142                 setOrientation(localOr);\r
143         }\r
144         \r
145         @Override\r
146         public <C> C getAdapter(Class<C> adapter) {\r
147                 return null;\r
148         }\r
149 }\r