Skip to content

Commit

Permalink
Fix jittery repositioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jun 9, 2024
1 parent 6e08586 commit f8e6a2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import org.joml.FrustumIntersection
import org.joml.Matrix4f
import org.joml.Vector3f
import org.joml.primitives.Rectanglef
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.util.concurrent.CopyOnWriteArrayList

Expand All @@ -32,14 +34,15 @@ import java.util.concurrent.CopyOnWriteArrayList
*/
class Node<T extends Node> implements SceneEvents, Scriptable<T>, Visitable {

private static final Logger logger = LoggerFactory.getLogger(Node)

final Matrix4f transform = new Matrix4f()
final Rectanglef bounds = new Rectanglef()

String name
Node parent
CopyOnWriteArrayList<Node> children = new CopyOnWriteArrayList<>()

private final Vector3f position = new Vector3f()
private final Vector3f scale = new Vector3f(1, 1, 1)
private final Matrix4f globalTransform = new Matrix4f()
private final Vector3f globalPosition = new Vector3f()
Expand Down Expand Up @@ -168,12 +171,12 @@ class Node<T extends Node> implements SceneEvents, Scriptable<T>, Visitable {
*/
void position(Vector3f newPosition) {

var currentPosition = getPosition(position)
var currentScale = getScale(scale)
transform.translate(
(currentPosition.x - newPosition.x) * currentScale.x as float,
(currentPosition.y - newPosition.y) * currentScale.y as float,
(currentPosition.z - newPosition.z) * currentScale.z as float)
transform.setTranslation(
-newPosition.x * currentScale.x as float,
-newPosition.y * currentScale.y as float,
-newPosition.z * currentScale.z as float
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Camera extends Node<Camera> {
*/
Matrix4f getViewProjection(Matrix4f dest) {

return projection.mulOrthoAffine(transform, dest)
return projection.mulOrthoAffine(getView(), dest)
}

@Override
Expand Down

0 comments on commit f8e6a2d

Please sign in to comment.