Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
63b7b8f7
Commit
63b7b8f7
authored
Feb 27, 2025
by
Matthias Betz
Browse files
progress for opengl
parent
7a5a9132
Changes
5
Show whitespace changes
Inline
Side-by-side
CityDoctorParent/Extensions/CityDoctorGUI/pom.xml
View file @
63b7b8f7
...
@@ -59,6 +59,13 @@
...
@@ -59,6 +59,13 @@
<groupId>
org.openjfx
</groupId>
<groupId>
org.openjfx
</groupId>
<artifactId>
javafx-swing
</artifactId>
<artifactId>
javafx-swing
</artifactId>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.huskerdev/openglfx-jogl -->
<dependency>
<groupId>
com.huskerdev
</groupId>
<artifactId>
openglfx-jogl
</artifactId>
<version>
4.1.19
</version>
</dependency>
</dependencies>
</dependencies>
<profiles>
<profiles>
<profile>
<profile>
...
...
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/MainWindow.java
View file @
63b7b8f7
package
de.hft.stuttgart.citydoctor2.gui
;
package
de.hft.stuttgart.citydoctor2.gui
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Optional
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
javax.imageio.ImageIO
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
com.huskerdev.openglfx.GLExecutor
;
import
com.huskerdev.openglfx.canvas.GLCanvas
;
import
com.huskerdev.openglfx.jogl.JOGLExecutor
;
import
com.huskerdev.openglfx.jogl.events.JOGLEvent
;
import
com.huskerdev.openglfx.jogl.events.JOGLReshapeEvent
;
import
com.jogamp.opengl.GL2
;
import
com.jogamp.opengl.GL3
;
import
de.hft.stuttgart.citydoctor2.CityDoctorValidation
;
import
de.hft.stuttgart.citydoctor2.CityDoctorValidation
;
import
de.hft.stuttgart.citydoctor2.check.ValidationConfiguration
;
import
de.hft.stuttgart.citydoctor2.check.ValidationConfiguration
;
import
de.hft.stuttgart.citydoctor2.datastructure.BoundingBox
;
import
de.hft.stuttgart.citydoctor2.datastructure.BoundingBox
;
...
@@ -19,9 +42,35 @@ import javafx.beans.value.ChangeListener;
...
@@ -19,9 +42,35 @@ import javafx.beans.value.ChangeListener;
import
javafx.embed.swing.SwingFXUtils
;
import
javafx.embed.swing.SwingFXUtils
;
import
javafx.fxml.FXML
;
import
javafx.fxml.FXML
;
import
javafx.fxml.FXMLLoader
;
import
javafx.fxml.FXMLLoader
;
import
javafx.scene.*
;
import
javafx.scene.AmbientLight
;
import
javafx.scene.control.*
;
import
javafx.scene.Group
;
import
javafx.scene.Node
;
import
javafx.scene.PerspectiveCamera
;
import
javafx.scene.Scene
;
import
javafx.scene.SceneAntialiasing
;
import
javafx.scene.SubScene
;
import
javafx.scene.control.Alert
;
import
javafx.scene.control.Alert.AlertType
;
import
javafx.scene.control.Alert.AlertType
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.ButtonType
;
import
javafx.scene.control.ComboBox
;
import
javafx.scene.control.ContextMenu
;
import
javafx.scene.control.Label
;
import
javafx.scene.control.ListCell
;
import
javafx.scene.control.ListView
;
import
javafx.scene.control.MenuItem
;
import
javafx.scene.control.ProgressBar
;
import
javafx.scene.control.RadioButton
;
import
javafx.scene.control.SplitPane
;
import
javafx.scene.control.Tab
;
import
javafx.scene.control.TabPane
;
import
javafx.scene.control.TextArea
;
import
javafx.scene.control.TextField
;
import
javafx.scene.control.ToggleButton
;
import
javafx.scene.control.ToggleGroup
;
import
javafx.scene.control.ToolBar
;
import
javafx.scene.control.TreeItem
;
import
javafx.scene.control.TreeView
;
import
javafx.scene.image.Image
;
import
javafx.scene.image.Image
;
import
javafx.scene.image.ImageView
;
import
javafx.scene.image.ImageView
;
import
javafx.scene.image.WritableImage
;
import
javafx.scene.image.WritableImage
;
...
@@ -29,6 +78,8 @@ import javafx.scene.input.Dragboard;
...
@@ -29,6 +78,8 @@ import javafx.scene.input.Dragboard;
import
javafx.scene.input.MouseButton
;
import
javafx.scene.input.MouseButton
;
import
javafx.scene.input.MouseEvent
;
import
javafx.scene.input.MouseEvent
;
import
javafx.scene.input.TransferMode
;
import
javafx.scene.input.TransferMode
;
import
javafx.scene.layout.Background
;
import
javafx.scene.layout.BackgroundFill
;
import
javafx.scene.layout.BorderPane
;
import
javafx.scene.layout.BorderPane
;
import
javafx.scene.layout.HBox
;
import
javafx.scene.layout.HBox
;
import
javafx.scene.layout.Pane
;
import
javafx.scene.layout.Pane
;
...
@@ -36,15 +87,6 @@ import javafx.scene.layout.Priority;
...
@@ -36,15 +87,6 @@ import javafx.scene.layout.Priority;
import
javafx.scene.paint.Color
;
import
javafx.scene.paint.Color
;
import
javafx.scene.transform.Rotate
;
import
javafx.scene.transform.Rotate
;
import
javafx.stage.Stage
;
import
javafx.stage.Stage
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.*
;
public
class
MainWindow
extends
Application
{
public
class
MainWindow
extends
Application
{
...
@@ -82,7 +124,7 @@ public class MainWindow extends Application {
...
@@ -82,7 +124,7 @@ public class MainWindow extends Application {
private
TreeView
<
Renderable
>
attributeView
;
private
TreeView
<
Renderable
>
attributeView
;
@FXML
@FXML
TreeView
<
Renderable
>
otherObjectsView
;
private
TreeView
<
Renderable
>
otherObjectsView
;
@FXML
@FXML
private
TreeView
<
Renderable
>
polygonView
;
private
TreeView
<
Renderable
>
polygonView
;
...
@@ -809,12 +851,47 @@ public class MainWindow extends Application {
...
@@ -809,12 +851,47 @@ public class MainWindow extends Application {
}
}
private
void
setup3dView
()
{
private
void
setup3dView
()
{
JOGLExecutor
exec
=
new
JOGLExecutor
();
GLCanvas
canvas
=
new
GLCanvas
(
exec
);
canvas
.
setMinHeight
(
300
);
canvas
.
setMaxHeight
(
300
);
canvas
.
setMinWidth
(
500
);
canvas
.
setBackground
(
new
Background
(
new
BackgroundFill
(
Color
.
BLACK
,
null
,
null
)));
canvas
.
setOnMouseClicked
(
me
->
{
System
.
out
.
println
(
"Height: "
+
canvas
.
getHeight
());
});
// HBox box = new HBox();
// box.getChildren().add(canvas);
canvas
.
addOnInitEvent
(
event
->
{
GL3
gl
=
((
JOGLEvent
)
event
).
getGl
();
});
canvas
.
addOnReshapeEvent
(
event
->
{
GL3
gl
=
((
JOGLReshapeEvent
)
event
).
getGl
();
});
canvas
.
addOnRenderEvent
(
event
->
{
GL3
gl
=
((
JOGLEvent
)
event
).
getGl
();
});
canvas
.
addOnDisposeEvent
(
event
->
{
GL3
gl
=
((
JOGLEvent
)
event
).
getGl
();
});
Group
root
=
new
Group
();
Group
root
=
new
Group
();
geomScene
=
new
SubScene
(
root
,
500
,
300
,
true
,
SceneAntialiasing
.
BALANCED
);
geomScene
=
new
SubScene
(
root
,
500
,
300
,
true
,
SceneAntialiasing
.
BALANCED
);
geomScene
.
heightProperty
().
bind
(
meshView
.
heightProperty
());
geomScene
.
heightProperty
().
bind
(
meshView
.
heightProperty
());
geomScene
.
widthProperty
().
bind
(
meshView
.
widthProperty
());
geomScene
.
widthProperty
().
bind
(
meshView
.
widthProperty
());
geomScene
.
setFill
(
Color
.
AZURE
);
geomScene
.
setFill
(
Color
.
AZURE
);
meshView
.
getChildren
().
add
(
geomScene
);
meshView
.
getChildren
().
add
(
geomScene
);
// meshView.getChildren().add(canvas);
// to avoid strange behaviour of the GUI resizeing itself
meshView
.
setBackground
(
new
Background
(
new
BackgroundFill
(
null
,
null
,
null
)));
geomScene
.
addEventFilter
(
MouseEvent
.
MOUSE_PRESSED
,
me
->
{
geomScene
.
addEventFilter
(
MouseEvent
.
MOUSE_PRESSED
,
me
->
{
clickStart
[
0
]
=
me
.
getScreenX
();
clickStart
[
0
]
=
me
.
getScreenX
();
...
...
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/opengl/OpenGLCamera.java
0 → 100644
View file @
63b7b8f7
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
=
1
f
;
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
=
0
f
;
// 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
/
2
f
;
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
/
500
f
);
float
rotationZ
=
(
float
)
(-
dragDiffY
/
500
f
);
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
();
}
}
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/opengl/UniformLocation.java
0 → 100644
View file @
63b7b8f7
/*-
* 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
);
}
}
CityDoctorParent/pom.xml
View file @
63b7b8f7
...
@@ -20,6 +20,10 @@
...
@@ -20,6 +20,10 @@
<jfx-version>
17.0.12
</jfx-version>
<jfx-version>
17.0.12
</jfx-version>
</properties>
</properties>
<repositories>
<repositories>
<repository>
<id>
jogl
</id>
<url>
https://jogamp.org/deployment/maven/
</url>
</repository>
<repository>
<repository>
<id>
non-maven-libs
</id>
<id>
non-maven-libs
</id>
<url>
${nonMavenLibsPath}
</url>
<url>
${nonMavenLibsPath}
</url>
...
@@ -173,7 +177,7 @@
...
@@ -173,7 +177,7 @@
<dependency>
<dependency>
<groupId>
org.jogamp.gluegen
</groupId>
<groupId>
org.jogamp.gluegen
</groupId>
<artifactId>
gluegen-rt-main
</artifactId>
<artifactId>
gluegen-rt-main
</artifactId>
<version>
2.
3.2
</version>
<version>
2.
5.0
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
gov.nist.math
</groupId>
<groupId>
gov.nist.math
</groupId>
...
@@ -183,7 +187,7 @@
...
@@ -183,7 +187,7 @@
<dependency>
<dependency>
<groupId>
org.jogamp.jogl
</groupId>
<groupId>
org.jogamp.jogl
</groupId>
<artifactId>
jogl-all-main
</artifactId>
<artifactId>
jogl-all-main
</artifactId>
<version>
2.
3.2
</version>
<version>
2.
5.0
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<groupId>
org.apache.logging.log4j
</groupId>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment