Commit 13e3e158 authored by Matthias Betz's avatar Matthias Betz
Browse files

Remove abandoned gui.opengl stub before OpenGL view rewrite



OpenGLCamera/UniformLocation were a partial earlier attempt; superseded by
the new gui.gl package per docs/superpowers/plans/2026-06-18-opengl-3d-view.md.

Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent adcc12e8
package de.hft.stuttgart.citydoctor2.gui.opengl;
import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.Matrix4f;
import com.jogamp.opengl.math.Vec2f;
import com.jogamp.opengl.math.Vec3f;
public class OpenGLCamera {
private static final float MIN_DISTANCE = 1f;
private static final float PI = (float) Math.PI;
private static final float SCROLL_PERCENTAGE = 0.1f;
private Matrix4f projMatrix;
private Matrix4f viewMatrix;
private Matrix4f projViewMatrix;
private Matrix4f temp = new Matrix4f();
private UniformLocation projViewModel;
private float rotateAroundZ = 0f;
// rotation temp variables
private Vec3f res = new Vec3f();
private Vec3f rotAxis = new Vec3f();
private Vec3f cross = new Vec3f();
// move temp variables
private Vec2f dir = new Vec2f();
private Vec3f eyePos = new Vec3f();
private Vec3f centerPos = new Vec3f();
private Vec3f up = new Vec3f();
private float distance = 5;
private float[] matrixBuffer = new float[16];
public OpenGLCamera(UniformLocation projViewModel) {
this.projViewModel = projViewModel;
projViewMatrix = new Matrix4f();
viewMatrix = new Matrix4f();
projMatrix = new Matrix4f();
up.setZ(1);
eyePos.setX(distance);
}
public void reshape(int width, int height, float distance) {
// 90 degree fow
float fow = PI / 2f;
float aspectRatio = (float) width / height;
projMatrix.setToPerspective(fow, aspectRatio, MIN_DISTANCE, distance);
updateMatrix();
}
private void updateMatrix() {
viewMatrix.setToLookAt(eyePos, centerPos, up, temp);
projViewMatrix.mul(projMatrix, viewMatrix);
// model matrix is identity
projViewMatrix.get(matrixBuffer);
projViewModel.uploadMat4(matrixBuffer);
}
public void rotate(double dragDiffX, double dragDiffY) {
float rotationX = (float) (-dragDiffX / 500f);
float rotationZ = (float) (-dragDiffY / 500f);
float tempRotationValue = rotateAroundZ + rotationZ;
if (tempRotationValue < -Math.PI / 2 + 0.0001 || tempRotationValue > Math.PI / 2 - 0.0001) {
// to close to 90 degree, stop rotation
rotationZ = 0;
}
rotateAroundZ += rotationZ;
res.minus(eyePos, centerPos);
rotateZ(res, rotationX);
rotAxis.setX(res.x());
rotAxis.setY(res.y());
rotAxis.setZ(res.z() + 5);
cross.cross(rotAxis, res);
cross.normalize();
rotateAroundAxis(res, rotationZ, cross.x(), cross.y(), cross.z());
eyePos.plus(centerPos, res);
updateMatrix();
}
public Vec3f rotateZ(Vec3f vec, float angle) {
float sin = FloatUtil.sin(angle);
float cos = FloatUtil.cos(angle);
float x = vec.x() * cos - vec.y() * sin;
float y = vec.x() * sin + vec.y() * cos;
vec.setX(x);
vec.setY(y);
return vec;
}
private void rotateAroundAxis(Vec3f vector, float angle, float aX, float aY, float aZ) {
float hangle = angle * 0.5f;
float sinAngle = FloatUtil.sin(hangle);
float qx = aX * sinAngle, qy = aY * sinAngle, qz = aZ * sinAngle;
float qw = FloatUtil.cos(hangle);
float w2 = qw * qw, x2 = qx * qx, y2 = qy * qy, z2 = qz * qz, zw = qz * qw;
float xy = qx * qy, xz = qx * qz, yw = qy * qw, yz = qy * qz, xw = qx * qw;
float x = vector.x();
float y = vector.y();
float z = vector.z();
vector.setX((w2 + x2 - z2 - y2) * x + (-zw + xy - zw + xy) * y + (yw + xz + xz + yw) * z);
vector.setY((xy + zw + zw + xy) * x + (y2 - z2 + w2 - x2) * y + (yz + yz - xw - xw) * z);
vector.setZ((xz - yw + xz - yw) * x + (yz + yz + xw + xw) * y + (z2 - y2 - x2 + w2) * z);
}
public void setDistance(float distance) {
this.distance = distance;
res.minus(centerPos, eyePos);
res.normalize();
res.scale(distance);
eyePos.plus(res, centerPos);
updateMatrix();
}
public void scroll(float scroll) {
float addedDistance = distance * scroll * SCROLL_PERCENTAGE;
distance += addedDistance;
setDistance(distance);
}
public void move(float dragDiffX, float dragDiffY) {
res.minus(centerPos, eyePos);
dir.setX(res.x());
dir.setY(res.y());
dir.normalize();
// var yDrag = vec2.create();
// vec2.scale(yDrag, dir, dragDiffY * 0.5);
//
// // handle diffY
// vec3.add(this.centerPos, this.centerPos, vec3.fromValues(yDrag[0], yDrag[1], 0));
// vec3.add(this.eyepos, this.eyepos, vec3.fromValues(yDrag[0], yDrag[1], 0));
// // handle diffX
// var temp = dir[0];
// dir[0] = dir[1];
// dir[1] = -temp;
// vec2.scale(dir, dir, -dragDiffX * 0.5);
//
// vec3.add(this.centerPos, this.centerPos, vec3.fromValues(dir[0], dir[1], 0));
// vec3.add(this.eyepos, this.eyepos, vec3.fromValues(dir[0], dir[1], 0));
this.updateMatrix();
}
}
/*-
* Copyright 2021 Hochschule für Technik Stuttgart
*
* 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 de.hft.stuttgart.citydoctor2.gui.opengl;
import com.jogamp.opengl.GL3;
public class UniformLocation {
private int location;
private GL3 gl;
public UniformLocation(GL3 gl, int location) {
this.location = location;
}
public void uploadMat4(float[] mat) {
gl.glUniformMatrix4fv(location, mat.length, false, mat, 0);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment