Commit e8901f0a authored by Florian Hölzl's avatar Florian Hölzl

No commit message

No commit message
parent d0553679
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test-src"/>
<classpathentry exported="true" kind="lib" path="lib/slick-util.jar"/>
<classpathentry kind="output" path="build"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.fortiss.tooling.graphics3D.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Fortiss Tooling Graphics 3D UI
Bundle-SymbolicName: org.fortiss.tooling.graphics3D.ui;singleton:=true
Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.fortiss.tooling.graphics3D.ui.ToolingGraphics3DUIActivator
Require-Bundle: org.fortiss.tooling.graphics3D;bundle-version="2.1.0";visibility:=reexport,
org.fortiss.tooling.base.ui;bundle-version="2.1.0";visibility:=reexport,
org.lwjgl;bundle-version="2.8.4";visibility:=reexport,
org.fortiss.af3.expression.ui;bundle-version="2.1.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: fortiss GmbH
Export-Package: org.fortiss.tooling.graphics3D.ui,
org.fortiss.tooling.graphics3D.ui.camera,
org.fortiss.tooling.graphics3D.ui.draw,
org.fortiss.tooling.graphics3D.ui.editor,
org.fortiss.tooling.graphics3D.ui.light,
org.fortiss.tooling.graphics3D.ui.objects,
org.fortiss.tooling.graphics3D.ui.picker,
org.fortiss.tooling.graphics3D.ui.util,
org.newdawn.slick,
org.newdawn.slick.loading,
org.newdawn.slick.openal,
org.newdawn.slick.opengl,
org.newdawn.slick.opengl.renderer,
org.newdawn.slick.tests,
org.newdawn.slick.util
Bundle-ClassPath: lib/slick-util.jar,
.
# <copyright>
# </copyright>
#
# $Id$
bin.includes = .,\
META-INF/,\
plugin.xml,\
lib/slick-util.jar
source.. = src/,\
test-src/
output.. = build/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
<copyright>
</copyright>
$Id$
-->
<plugin>
<extension
point="org.fortiss.tooling.kernel.ui.modelEditorBinding">
<modelEditorBinding
binding="test.org.fortiss.tooling.graphics3D.ui.Test3DEditorBinding">
<modelElementClass
modelElementClass="org.fortiss.af3.expression.model.DataDictionary">
</modelElementClass>
</modelEditorBinding>
</extension>
</plugin>
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphics3D.ui;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: E9B79759E2C0C013BE2B19DE87749838
*/
public class ToolingGraphics3DUIActivator extends AbstractUIPlugin {
/** The plug-in ID. */
public static final String PLUGIN_ID = ToolingGraphics3DUIActivator.class.getPackage()
.getName(); //$NON-NLS-1$
/** The shared instance. */
private static ToolingGraphics3DUIActivator plugin;
/** {@inheritDoc} */
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/** {@inheritDoc} */
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/** Returns the shared instance. */
public static ToolingGraphics3DUIActivator getDefault() {
return plugin;
}
/** Returns the image descriptor for the given icon file. */
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphics3D.ui.camera;
import static org.lwjgl.util.glu.GLU.gluLookAt;
import org.lwjgl.util.vector.Vector3f;
/**
* Class representing the camera with the Z axis as up vector.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 6DFDC1792DF675AF5ED360810E3635D7
*/
public class Camera {
/** The camera position. */
protected Vector3f pos = new Vector3f(10.0f, 10.0f, 10.0f);
/** The camera target. */
private Vector3f target = new Vector3f();
/** Constructor. */
public Camera() {
}
/** Sets the camera position. */
public void setPosition(float cx, float cy, float cz) {
pos = new Vector3f(cx, cy, cz);
}
/** Alters the camera position with the given deltas. */
public void alterPosition(float dx, float dy, float dz) {
setPosition(pos.x + dx, pos.y + dy, pos.z + dz);
}
/** Sets the camera target. */
public void setTarget(float tx, float ty, float tz) {
target = new Vector3f(tx, ty, tz);
}
/** Alters the camera target with the given deltas. */
public void alterTarget(float dx, float dy, float dz) {
target.x = target.x + dx;
target.y = target.y + dy;
target.z = target.z + dz;
}
/** Applies the camera position and view target to GL before rendering starts. */
public void applyForRendering() {
gluLookAt(pos.x, pos.y, pos.z, target.x, target.y, target.z, 0, 0, 1.0f);
}
/** Applies the camera position and view target to GL before picking starts. */
public void applyForPicking() {
gluLookAt(pos.x, pos.y, pos.z, target.x, target.y, target.z, 0, 0, 1.0f);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphics3D.ui.camera;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.toRadians;
import static org.fortiss.tooling.graphics3D.ui.util.GLPrimitives.X_UNIT_VECTOR;
import static org.fortiss.tooling.graphics3D.ui.util.GLPrimitives.Z_UNIT_VECTOR;
import static org.fortiss.tooling.graphics3D.ui.util.GLPrimitives.rotate;
import static org.fortiss.tooling.graphics3D.ui.util.GLPrimitives.translate;
import static org.lwjgl.util.glu.GLU.gluLookAt;
/**
* A {@link Camera} which can be configured with pitch and yaw angle.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 8D71137B475BD3A8ECD299C288D95E15
*/
public class MovingCameraWithPitchAndYaw extends Camera {
/** The yaw angle. */
private float yawAngle = 0.0f;
/** The pitch angle. */
private float pitchAngle = 0.0f;
/** Alter the pitch angle. */
public void pitch(float amount) {
pitchAngle += amount;
if(pitchAngle >= 85.0f) {
pitchAngle = 85.0f;
} else if(pitchAngle <= -85.0) {
pitchAngle = -85.0f;
}
}
/** Alter the yaw angle. */
public void yaw(float amount) {
yawAngle += amount;
}
/** Move forward for the given distance. */
public void forward(float distance) {
float dx = distance * (float)sin(toRadians(yawAngle));
float dy = distance * (float)cos(toRadians(yawAngle));
super.alterPosition(dx, dy, 0);
}
/** Move backward for the given distance. */
public void backward(float distance) {
forward(-distance);
}
/** Move left for the given distance. */
public void left(float distance) {
float dx = distance * (float)sin(toRadians(yawAngle - 90));
float dy = distance * (float)cos(toRadians(yawAngle - 90));
super.alterPosition(dx, dy, 0);
}
/** Move right for the given distance. */
public void right(float distance) {
left(-distance);
}
/** Move up for the given distance. */
public void up(float distance) {
super.alterPosition(0, 0, distance);
}
/** Move down for the given distance. */
public void down(float distance) {
up(-distance);
}
/** {@inheritDoc} */
@Override
public void applyForRendering() {
// from origin look at Y axis
gluLookAt(0, 0, 0, 0, 1.0f, 0, 0, 0, 1.0f);
rotate(pitchAngle, X_UNIT_VECTOR);
rotate(yawAngle, Z_UNIT_VECTOR);
translate(-pos.x, -pos.y, -pos.z);
}
/** {@inheritDoc} */
@Override
public void applyForPicking() {
applyForRendering();
}
/** {@inheritDoc} */
@Override
public void setTarget(float tx, float ty, float tz) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
@Override
public void alterTarget(float dx, float dy, float dz) {
throw new UnsupportedOperationException();
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphics3D.ui.draw;
import static org.fortiss.tooling.graphics3D.ui.ToolingGraphics3DUIActivator.getDefault;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glViewport;
import static org.lwjgl.opengl.GLContext.useContext;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import org.eclipse.swt.SWT;
import org.eclipse.swt.opengl.GLCanvas;
import org.eclipse.swt.opengl.GLData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Listener;
import org.lwjgl.LWJGLException;
/**
* Canvas for drawing LWJGL content onto a SWT widget. It uses double buffer, dpeth buffer and four
* sample buffers.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 83ECFD2B231D8EC0A50D3D363571A870
*/
public class Lwjgl3DCanvas extends GLCanvas {
/** Constructor. */
public Lwjgl3DCanvas(Composite parent, GLData data) {
super(parent, SWT.NONE, data);
}
/** Constructor. */
public Lwjgl3DCanvas(Composite parent) {
this(parent, createDefaultGLData());
}
/** Creates the default {@link GLData}. */
private static GLData createDefaultGLData() {
GLData data = new GLData();
// use double buffering
data.doubleBuffer = true;
// allow depth buffering
data.depthSize = 1;
// enable four sample buffers for anti-aliasing
data.sampleBuffers = 1;
data.samples = 4;
return data;
}
/** Adds the given listener to handle the canvas resize events. */
public void addResizeHandler(Listener handler) {
addListener(SWT.Resize, handler);
}
/** Sets this canvas as the current canvas and tells OGL to use it. */
public void setCurrentAndUseContext() {
try {
setCurrent();
useContext(this);
} catch(LWJGLException ex) {
error(getDefault(), ex.getMessage(), ex);
}
}
/** Sets the view port and perspective projection matrix. */
public void setViewportAndPerspective(int width, int height, float fieldOfViewAngle,
float nearDistance, float farDistance) {
if(nearDistance <= 0 || farDistance <= 0) {
throw new IllegalArgumentException("Z distances of perspective must be greater 0.");
}
float aspect = (float)width / (float)height;
setCurrentAndUseContext();
// set viewport and alter set projection matrix
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfViewAngle, aspect, nearDistance, farDistance);
// return GL state to model matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphics3D.ui.draw;
import static org.eclipse.ui.PlatformUI.getWorkbench;
/**
* Thread class for the render thread with a default sleep period of 40ms (i.e. about 25fps).
* The thread executes a refresh of the canvas using a Display async execution and dies as soon as
* the canvas is disposed. Note that the refresh is only performed if the canvas is not disposed and
* is visible.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 6CD38411345BE68238AF29F9A98D9CC5
*/
public class Lwjgl3DRenderThread extends Thread {
/** The GLCanvas to be rendered by this thread. */
private final Lwjgl3DCanvas canvas;
/** The render thread sleep period. */
private int sleepPeriod = 40;
/** The content renderer runnable. */
private final Runnable contentRenderer;
/** Constructor. */
public Lwjgl3DRenderThread(Lwjgl3DCanvas canvas, Runnable contentRenderer) {
if(canvas == null) {
throw new IllegalArgumentException("Canvas may not be null.");
}
if(contentRenderer == null) {
throw new IllegalArgumentException("Content render may not be null.");
}
this.canvas = canvas;
this.contentRenderer = contentRenderer;
}
/** Sets the sleep period of the render thread in milliseconds. */
public void setSleepPeriod(int sleepPeriod) {
this.sleepPeriod = sleepPeriod;
}
/** {@inheritDoc} */
@Override
public void run() {
try {
sleep(sleepPeriod);
while(!canvas.isDisposed()) {
getWorkbench().getDisplay().asyncExec(refresher);
sleep(sleepPeriod);
}
} catch(InterruptedException e) {
e.printStackTrace();
}
}
/** The refresher display runner. */
private Runnable refresher = new Runnable() {
@Override
public void run() {
if(!canvas.isDisposed() && canvas.isVisible()) {
canvas.setCurrentAndUseContext();
contentRenderer.run();
canvas.swapBuffers();
}
}
};
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphics3D.ui.editor;