1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.scenegraph;
\r
14 import javax.vecmath.Quat4d;
\r
15 import javax.vecmath.Vector3d;
\r
17 import org.simantics.g3d.ontology.G3D;
\r
18 import org.simantics.g3d.property.annotations.GetPropertyValue;
\r
19 import org.simantics.g3d.property.annotations.PropertyContributor;
\r
20 import org.simantics.g3d.property.annotations.SetPropertyValue;
\r
21 import org.simantics.g3d.scenegraph.base.INode;
\r
22 import org.simantics.g3d.scenegraph.base.Node;
\r
23 import org.simantics.g3d.tools.NodeTools;
\r
24 import org.simantics.objmap.graph.annotations.RelatedGetValue;
\r
25 import org.simantics.objmap.graph.annotations.RelatedSetValue;
\r
28 @PropertyContributor
\r
29 public class G3DNode extends Node implements IG3DNode {
\r
31 private Vector3d position = new Vector3d();
\r
32 private Quat4d orientation = new Quat4d(0,0,0,1);
\r
35 @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")
\r
36 public Quat4d getOrientation() {
\r
40 @RelatedGetValue(G3D.URIs.hasOrientation)
\r
41 public double[] getOrientationArr() {
\r
42 double arr[] = new double[4];
\r
43 orientation.get(arr);
\r
49 @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")
\r
50 public Vector3d getPosition() {
\r
54 @RelatedGetValue(G3D.URIs.hasPosition)
\r
55 public double[] getPositionArr() {
\r
56 double arr[] = new double[3];
\r
62 @SetPropertyValue(G3D.URIs.hasOrientation)
\r
63 public void setOrientation(Quat4d orientation) {
\r
64 assert(orientation != null);
\r
65 this.orientation = orientation;
\r
67 firePropertyChanged(G3D.URIs.hasOrientation);
\r
70 @RelatedSetValue(G3D.URIs.hasOrientation)
\r
71 public void setOrientation(double[] arr) {
\r
74 setOrientation(new Quat4d(arr));
\r
78 @SetPropertyValue(G3D.URIs.hasPosition)
\r
79 public void setPosition(Vector3d position) {
\r
80 assert(position != null);
\r
81 this.position = position;
\r
83 firePropertyChanged(G3D.URIs.hasPosition);
\r
86 @RelatedSetValue(G3D.URIs.hasPosition)
\r
87 public void setPosition(double[] arr) {
\r
90 setPosition(new Vector3d(arr));
\r
94 @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")
\r
95 public Vector3d getWorldPosition() {
\r
96 IG3DNode parent = (IG3DNode)getParent();
\r
99 return NodeTools.getWorldPosition(parent, new Vector3d(position));
\r
103 public Vector3d getWorldPosition(Vector3d localPosition) {
\r
104 return NodeTools.getWorldPosition(this,localPosition);
\r
109 @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")
\r
110 public Quat4d getWorldOrientation() {
\r
111 return getWorldOrientation(new Quat4d(orientation));
\r
114 public Quat4d getWorldOrientation(Quat4d localOrientation) {
\r
115 IG3DNode parent = (IG3DNode)getParent();
\r
116 if (parent == null)
\r
117 return localOrientation;
\r
118 return NodeTools.getWorldOrientation(parent, localOrientation);
\r
122 public Vector3d getLocalPosition(Vector3d worldPosition) {
\r
123 IG3DNode parent = (IG3DNode)getParent();
\r
124 if (parent == null)
\r
125 return worldPosition;
\r
126 return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));
\r
130 public Quat4d getLocalOrientation(Quat4d worldOrientation) {
\r
131 IG3DNode parent = (IG3DNode)getParent();
\r
132 if (parent == null)
\r
133 return worldOrientation;
\r
134 return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));
\r
138 @SetPropertyValue(G3D.URIs.hasWorldPosition)
\r
139 public void setWorldPosition(Vector3d position) {
\r
140 Vector3d localPos = getLocalPosition(position);
\r
141 setPosition(localPos);
\r
145 @SetPropertyValue(G3D.URIs.hasWorldOrientation)
\r
146 public void setWorldOrientation(Quat4d orientation) {
\r
147 Quat4d localOr = getLocalOrientation(orientation);
\r
148 setOrientation(localOr);
\r
152 public Object getAdapter(Class adapter) {
\r
153 if (INode.class == adapter)
\r
155 if (IG3DNode.class == adapter)
\r