/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Aug 21, 2005 */ package ml.backend.sg; import ml.math.AxisAlignedBoundingBox; import ml.math.Matrix3; import ml.math.Matrix4; import ml.math.Quaternion; import ml.math.Vector3D; abstract public class TransformableNode extends Node { /** * translate the node contents * @param distance the distance and direction in which to translate */ public void translate(Vector3D distance) { Matrix4 matrix=new Matrix4(); matrix.clear(); for(int i=0;i<4;i++) { matrix.X[i][i]=1; } matrix.X[0][3]=distance.X1; matrix.X[1][3]=distance.X2; matrix.X[2][3]=distance.X3; applyMatrix(matrix); } /** * rotate the node contents * @param axis the axis around which to rotate * @param angle the angle by which to rotate */ public void rotate(Vector3D axis, double angle) { Quaternion rotation=new Quaternion(); Matrix3 result; rotation.fromAxisAngle(axis,angle); result=rotation.toRotationMatrix3(); applyMatrix(result); } /** * rotate the node contents * @param quat the quaternion of the rotation */ public void rotate(Quaternion quat) { Matrix3 result; result=quat.toRotationMatrix3(); applyMatrix(result); } /** * scale the node contents * @param pivot the pivot point, that is, the point that won't be moved by the operation * @param amount the amount by which to scale along each axis */ public void scale(Vector3D pivot, Vector3D amount) { Matrix4 matrix=new Matrix4(); // recenter pivot on origin translate(pivot.multiply(-1)); // build scale matrix matrix.clear(); matrix.X[0][0]=amount.X1; matrix.X[0][0]=amount.X2; matrix.X[0][0]=amount.X3; matrix.X[3][3]=1.0; // apply scale matrix applyMatrix(matrix); // undo translation on pivot translate(pivot); } /** * apply a 3x3 transformation matrix to this scene graph node * * @param matrix the matrix to be applied */ public abstract void applyMatrix(Matrix3 matrix); /** * apply a 4x4 transformation matrix to this scene graph node * * @param matrix the matrix to be applied */ public abstract void applyMatrix(Matrix4 matrix); /** * Generate a minimal axis-aligned bounding box around this this scene graph node. * * @return a minimal axis-aligned bounding box */ public abstract AxisAlignedBoundingBox getBoundingBox(); /** * Query for intersection of a ray with this scene graph node * * @param ray The ray to be checked for intersection * @return the coordinates of the intersection point or null, if none exists */ public abstract Vector3D getIntersectionPoint(ml.math.Ray ray); }