Skip to content
Snippets Groups Projects
Commit 386f3521 authored by Johannes Eder's avatar Johannes Eder
Browse files

more camera movements

parent 16105e98
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,11 @@ public class MovingCameraWithPitchAndYaw extends Camera {
/** Alter the yaw angle. */
public void yaw(float amount) {
yawAngle += amount;
if(yawAngle >= 360.f) {
yawAngle = yawAngle - 360.f;
} else if(yawAngle <= -360) {
yawAngle = yawAngle + 360.f;
}
}
/** Move forward for the given distance. */
......@@ -102,6 +107,7 @@ public class MovingCameraWithPitchAndYaw extends Camera {
rotate(pitchAngle, X_UNIT_VECTOR);
rotate(yawAngle, Z_UNIT_VECTOR);
translate(-pos.x, -pos.y, -pos.z);
}
/** {@inheritDoc} */
......
......@@ -23,6 +23,7 @@ import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.drawLine;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.drawMaterialGroups;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.flushName;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.moveTo;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.normalize;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.prepareName;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.restoreMatrix;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.rotate;
......@@ -52,6 +53,7 @@ import org.fortiss.tooling.graphicsGL.model.scene.Object3D;
import org.fortiss.tooling.graphicsGL.ui.camera.Camera;
import org.fortiss.tooling.graphicsGL.ui.picker.ModelObjectPicker;
import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives;
import org.fortiss.tooling.graphicsGL.util.Graph3DModelElementFactory;
import org.lwjgl.util.glu.Sphere;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;
......@@ -97,7 +99,6 @@ public class Graph3DViewObject extends ViewObjectBase {
/** {@inheritDoc} */
@Override
public void renderObject(Camera c) {
renderCoordSys(graph.getCoordinateSystem());
setColor(WHITE);
for(GraphPoint3D p : graph.getPointsList()) {
......@@ -125,7 +126,47 @@ public class Graph3DViewObject extends ViewObjectBase {
for(GraphText3D t : graph.getTextsList()) {
renderText(c, t.getText(), convert(t.getPosition()));
}
debug(c);
setColor(WHITE);
}
private void debug(Camera c) {
// for debugging
// GLPrimitives.saveMatrix();
// GLPrimitives.scale(0.5f, 0.5f, 0.5f);
// setColor(Graphics3DModelElementFactory.RED);
//
// Vector3f up = ((MovingCameraWithPitchAndYaw)c).getCameraUp();
// // up.x *= 4;
// // up.y *= 4;
// // up.z *= 4;
//
// drawLine(new Vector3f(0, 0, 0), up);
// renderPoint(up);
// renderText(c, "up", up);
//
// Vector3f right = ((MovingCameraWithPitchAndYaw)c).getCameraLookAt();
// // right.x *= 4;
// // right.y *= 4;
// // right.z *= 4;
//
// setColor(Graphics3DModelElementFactory.GREEN);
// drawLine(new Vector3f(0, 0, 0), right);
// renderPoint(right);
//
// renderText(c, "lookAt", right);
//
// // Vector3f look = ((MovingCameraWithPitchAndYaw)c).getLookAt();
// //
// // setColor(Graphics3DModelElementFactory.BLUE);
// // drawLine(new Vector3f(0, 0, 0), look);
// // renderPoint(look);
// GLPrimitives.scale(1.f, 1.f, 1.f);
// GLPrimitives.restoreMatrix();
}
/** Renders objects as billboards at the given position */
......@@ -195,16 +236,6 @@ public class Graph3DViewObject extends ViewObjectBase {
}
/** returns the normalized vector */
private Vector3f normalize(Vector3f v) {
float length = (float)Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
v.x /= length;
v.y /= length;
v.z /= length;
return v;
}
/** {@inheritDoc} */
@Override
public void renderObjectForPicking(ModelObjectPicker picker, Camera c) {
......@@ -231,6 +262,11 @@ public class Graph3DViewObject extends ViewObjectBase {
restoreMatrix();
}
/** Renders the given point. */
private void renderPoint(Vector3f p) {
renderPoint(Graph3DModelElementFactory.graphPoint(p.x, p.y, p.z));
}
/** Renders the coordinate system if present. */
private void renderCoordSys(CoordinateSystem3D coordinateSystem) {
if(coordinateSystem != null) {
......
......@@ -450,6 +450,30 @@ public class GLPrimitives {
}
/** Creates a transformation matrix for billboards. Result is stored in bbmat */
public static void createBillboardMatrix2(float[] bbmat, Vector3f right, Vector3f up,
Vector3f look, Vector3f pos) {
bbmat[0] = right.x;
bbmat[1] = right.y;
bbmat[2] = right.z;
bbmat[3] = 0;
bbmat[4] = up.x;
bbmat[5] = up.y;
bbmat[6] = up.z;
bbmat[7] = 0;
bbmat[8] = look.x;
bbmat[9] = look.y;
bbmat[10] = look.z;
bbmat[11] = 0;
// Add the translation in as well.
bbmat[12] = pos.x;
bbmat[13] = pos.y;
bbmat[14] = pos.z;
bbmat[15] = 0;
}
/** Prepare a name for the given object and picker. */
public static void prepareName(Object obj, ModelObjectPicker picker) {
int name = picker.registerPickableObject(obj);
......@@ -509,4 +533,20 @@ public class GLPrimitives {
gluLookAt(posX, posY, posZ, targetX, targetY, targetZ, 0.0f, 0.0f, 1.0f);
}
/** Sets the camera position, lookAt, and normal(pointing upwards) vector. */
public static void cameraVectors(float posX, float posY, float posZ, float targetX,
float targetY, float targetZ, float upX, float upY, float upZ) {
gluLookAt(posX, posY, posZ, targetX, targetY, targetZ, upX, upY, upZ);
}
/** returns the normalized vector */
public static Vector3f normalize(Vector3f v) {
float length = (float)Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
v.x /= length;
v.y /= length;
v.z /= length;
return v;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment