[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[gef3d-commits] r564 - trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d
|
- From: genie@xxxxxxxxxxx
- Date: Tue, 19 Apr 2011 05:46:38 -0400 (EDT)
- Delivered-to: gef3d-commits@eclipse.org
Author: jvonpilgrim
Date: 2011-04-19 05:46:38 -0400 (Tue, 19 Apr 2011)
New Revision: 564
Added:
trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/PositionBasedSurface.java
Modified:
trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/FigureSurface.java
Log:
Refactored FigureSurface: extracted super class PositionBasedSurface.
Modified: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/FigureSurface.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/FigureSurface.java 2011-04-15 17:14:16 UTC (rev 563)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/FigureSurface.java 2011-04-19 09:46:38 UTC (rev 564)
@@ -16,15 +16,7 @@
import org.eclipse.draw2d.FigureListener;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.TreeSearch;
-import org.eclipse.draw3d.geometry.IMatrix4f;
-import org.eclipse.draw3d.geometry.IVector3f;
-import org.eclipse.draw3d.geometry.Math3D;
-import org.eclipse.draw3d.geometry.Math3DCache;
-import org.eclipse.draw3d.geometry.Matrix4f;
import org.eclipse.draw3d.geometry.Position3D;
-import org.eclipse.draw3d.geometry.Vector3f;
-import org.eclipse.draw3d.geometry.Vector3fImpl;
-import org.eclipse.draw3d.util.Draw3DCache;
/**
* A surface that belongs to a 3D figure.
@@ -33,7 +25,7 @@
* @version $Revision$
* @since 10.07.2009
*/
-public class FigureSurface extends AbstractSurface {
+public class FigureSurface extends PositionBasedSurface {
private FigureListener m_figureListener = new FigureListener() {
@@ -44,7 +36,17 @@
private IFigure3D m_host;
+
/**
+ * Returns the position 3D of its host.
+ * @see org.eclipse.draw3d.PositionBasedSurface#getPosition3D()
+ */
+ @Override
+ protected Position3D getPosition3D() {
+ return m_host.getPosition3D();
+ }
+
+ /**
* Creates a new surface for the given figure.
*
* @param i_host the host figure of this surface
@@ -56,22 +58,13 @@
m_host = i_host;
m_host.addFigureListener(m_figureListener);
}
+
+
+
/**
* {@inheritDoc}
*
- * @see org.eclipse.draw3d.AbstractSurface#calculateNormal(org.eclipse.draw3d.geometry.Vector3f)
- */
- @Override
- protected void calculateNormal(Vector3f io_normal) {
- io_normal.set(IVector3f.Z_AXIS_NEG);
- IMatrix4f rotation = m_host.getPosition3D().getAbsoluteRotationMatrix();
- Math3D.transform(io_normal, rotation, io_normal);
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.draw3d.ISurface#findFigureAt(int, int,
* org.eclipse.draw2d.TreeSearch)
*/
@@ -124,120 +117,19 @@
public IFigure3D getHost() {
return m_host;
}
+
/**
* {@inheritDoc}
*
- * @see org.eclipse.draw3d.AbstractSurface#getOrigin(org.eclipse.draw3d.geometry.Vector3f)
- */
- @Override
- protected Vector3f getOrigin(Vector3f io_result) {
- Vector3f result = io_result;
- if (result == null)
- result = new Vector3fImpl();
-
- Position3D position3d = getHost().getPosition3D();
- IMatrix4f matrix = position3d.getRotationLocationMatrix();
-
- result.set(IVector3f.NULLVEC3f);
- result.transform(matrix);
-
- return result;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.ISurface#getSurfaceRotation(org.eclipse.draw3d.geometry.Vector3f)
- */
- public Vector3f getSurfaceRotation(Vector3f o_result) {
- Vector3f result = o_result;
- if (result == null)
- result = new Vector3fImpl();
-
- Position3D absolute = Draw3DCache.getPosition3D();
- try {
- m_host.getPosition3D().getAbsolute(absolute);
- result.set(absolute.getRotation3D());
-
- return result;
- } finally {
- Draw3DCache.returnPosition3D(absolute);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.AbstractSurface#getXAxis(org.eclipse.draw3d.geometry.Vector3f)
- */
- @Override
- protected Vector3f getXAxis(Vector3f io_result) {
- Vector3f result = io_result;
- if (result == null)
- result = new Vector3fImpl();
-
- result.set(IVector3f.X_AXIS);
- rotateVector(result);
-
- return result;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.AbstractSurface#getYAxis(org.eclipse.draw3d.geometry.Vector3f)
- */
- @Override
- protected Vector3f getYAxis(Vector3f io_result) {
- Vector3f result = io_result;
- if (result == null)
- result = new Vector3fImpl();
-
- result.set(IVector3f.Y_AXIS);
- rotateVector(result);
-
- return result;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.draw3d.AbstractSurface#getZAxis(org.eclipse.draw3d.geometry.Vector3f)
- */
- @Override
- protected Vector3f getZAxis(Vector3f io_result) {
- Vector3f result = io_result;
- if (result == null)
- result = new Vector3fImpl();
-
- result.set(IVector3f.Z_AXIS);
- rotateVector(result);
-
- return result;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.draw3d.ISurface#is2DHost()
*/
public boolean is2DHost() {
return true;
}
- private void rotateVector(Vector3f i_vector) {
- Matrix4f rot = Math3DCache.getMatrix4f();
- try {
- IVector3f angles = m_host.getPosition3D().getRotation3D();
- Math3D.rotate(angles, IMatrix4f.IDENTITY, rot);
+
- i_vector.transform(rot);
- } finally {
- Math3DCache.returnMatrix4f(rot);
- }
- }
-
/**
* {@inheritDoc}
*
Added: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/PositionBasedSurface.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/PositionBasedSurface.java (rev 0)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/PositionBasedSurface.java 2011-04-19 09:46:38 UTC (rev 564)
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Jens von Pilgrim and others.
+ * 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:
+ * Jens von Pilgrim - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.draw3d;
+
+import org.eclipse.draw3d.geometry.IMatrix4f;
+import org.eclipse.draw3d.geometry.IVector3f;
+import org.eclipse.draw3d.geometry.Math3D;
+import org.eclipse.draw3d.geometry.Math3DCache;
+import org.eclipse.draw3d.geometry.Matrix4f;
+import org.eclipse.draw3d.geometry.Position3D;
+import org.eclipse.draw3d.geometry.Vector3f;
+import org.eclipse.draw3d.geometry.Vector3fImpl;
+import org.eclipse.draw3d.util.Draw3DCache;
+
+/**
+ * A surface which is defined by a {@link Position3D}.
+ *
+ * @author Jens von Pilgrim (developer@xxxxxxxxx)
+ * @version $Revision$
+ * @since Apr 18, 2011
+ */
+public abstract class PositionBasedSurface extends AbstractSurface {
+
+
+ /**
+ * Returns the position this surface is based on.
+ * @return
+ */
+ protected abstract Position3D getPosition3D();
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.AbstractSurface#calculateNormal(org.eclipse.draw3d.geometry.Vector3f)
+ */
+ @Override
+ protected void calculateNormal(Vector3f io_normal) {
+ io_normal.set(IVector3f.Z_AXIS_NEG);
+ IMatrix4f rotation = getPosition3D().getAbsoluteRotationMatrix();
+ Math3D.transform(io_normal, rotation, io_normal);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.AbstractSurface#getOrigin(org.eclipse.draw3d.geometry.Vector3f)
+ */
+ @Override
+ protected Vector3f getOrigin(Vector3f io_result) {
+ Vector3f result = io_result;
+ if (result == null)
+ result = new Vector3fImpl();
+
+ Position3D position3d = getPosition3D();
+ IMatrix4f matrix = position3d.getRotationLocationMatrix();
+
+ result.set(IVector3f.NULLVEC3f);
+ result.transform(matrix);
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.ISurface#getSurfaceRotation(org.eclipse.draw3d.geometry.Vector3f)
+ */
+ public Vector3f getSurfaceRotation(Vector3f o_result) {
+ Vector3f result = o_result;
+ if (result == null)
+ result = new Vector3fImpl();
+
+ Position3D absolute = Draw3DCache.getPosition3D();
+ try {
+ getPosition3D().getAbsolute(absolute);
+ result.set(absolute.getRotation3D());
+
+ return result;
+ } finally {
+ Draw3DCache.returnPosition3D(absolute);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.AbstractSurface#getXAxis(org.eclipse.draw3d.geometry.Vector3f)
+ */
+ @Override
+ protected Vector3f getXAxis(Vector3f io_result) {
+ Vector3f result = io_result;
+ if (result == null)
+ result = new Vector3fImpl();
+
+ result.set(IVector3f.X_AXIS);
+ rotateVector(result);
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.AbstractSurface#getYAxis(org.eclipse.draw3d.geometry.Vector3f)
+ */
+ @Override
+ protected Vector3f getYAxis(Vector3f io_result) {
+ Vector3f result = io_result;
+ if (result == null)
+ result = new Vector3fImpl();
+
+ result.set(IVector3f.Y_AXIS);
+ rotateVector(result);
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw3d.AbstractSurface#getZAxis(org.eclipse.draw3d.geometry.Vector3f)
+ */
+ @Override
+ protected Vector3f getZAxis(Vector3f io_result) {
+ Vector3f result = io_result;
+ if (result == null)
+ result = new Vector3fImpl();
+
+ result.set(IVector3f.Z_AXIS);
+ rotateVector(result);
+
+ return result;
+ }
+
+ protected void rotateVector(Vector3f i_vector) {
+ Matrix4f rot = Math3DCache.getMatrix4f();
+ try {
+ IVector3f angles = getPosition3D().getRotation3D();
+ Math3D.rotate(angles, IMatrix4f.IDENTITY, rot);
+
+ i_vector.transform(rot);
+ } finally {
+ Math3DCache.returnMatrix4f(rot);
+ }
+ }
+
+}
Property changes on: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/PositionBasedSurface.java
___________________________________________________________________
Added: svn:keywords
+ Date Revision Author HeadURL Id