blob: 91e4957bd72225cea4f746056b20d5b6b8dd5ce4 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque,
* Sebastien Gemme - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.topology.impl;
import javax.vecmath.Matrix3d;
import javax.vecmath.Matrix4d;
import javax.vecmath.Vector3d;
import org.eclipse.apogy.common.math.ApogyCommonMathFacade;
import org.eclipse.apogy.common.math.Matrix3x3;
import org.eclipse.apogy.common.math.Tuple3d;
import org.eclipse.apogy.common.topology.INodeVisitor;
import org.eclipse.apogy.common.topology.Node;
public class TransformNodeCustomImpl extends TransformNodeImpl {
protected static final Tuple3d ROTATION_EDEFAULT = null;
protected static final Matrix3d ROTATION_MATRIX_EDEFAULT = null;
public void unsetTransformationMatrix() {
}
public boolean isSetTransformationMatrix() {
return false;
}
@Override
public Matrix3x3 getRotationMatrix() {
Matrix3x3 tmp = super.getRotationMatrix();
if (tmp == null) {
Matrix3d matrix = new Matrix3d();
matrix.setIdentity();
tmp = ApogyCommonMathFacade.INSTANCE.createMatrix3x3(matrix);
setRotationMatrix(tmp);
}
return tmp;
}
@Override
public Matrix4d asMatrix4d() {
Matrix4d result = new Matrix4d();
result.setIdentity();
if (getRotationMatrix() != null) {
result.setRotation(getRotationMatrix().asMatrix3d());
}
if (getPosition() != null) {
result.setTranslation(new Vector3d(getPosition().asTuple3d()));
}
return result;
}
@Override
public void setTransformation(Matrix4d matrix) {
if (matrix == null) {
throw new IllegalArgumentException();
}
Matrix3d rotation = new Matrix3d();
Vector3d translation = new Vector3d();
// FIXME This should work, gave a BadTransformException
matrix.getRotationScale(rotation);
matrix.get(translation);
// matrix.get(rotation, translation);
Matrix3x3 rMat = ApogyCommonMathFacade.INSTANCE.createMatrix3x3(rotation);
Tuple3d trans = ApogyCommonMathFacade.INSTANCE.createTuple3d(translation);
this.setRotationMatrix(rMat);
this.setPosition(trans);
}
@Override
public void accept(INodeVisitor visitor) {
if (visitor.getType().isInstance(this)) {
visitor.visit(this);
}
// We do the same for all the children.
for (Node child : getChildren()) {
child.accept(visitor);
}
}
} // TransformNodeImpl