From 6e605082c712ae39a492792de1e45d9772eadb08 Mon Sep 17 00:00:00 2001 From: Emanuel Rabina Date: Wed, 7 Feb 2024 22:54:59 +1300 Subject: [PATCH] Manipulate nodes through their transform directly --- .../cli/mediaplayer/ImageScript.groovy | 4 +- .../engine/extensions/JomlExtensions.groovy | 45 ++++++++++---- .../redhorizon/engine/media/Video.groovy | 24 ++++---- .../redhorizon/engine/scenegraph/Node.groovy | 60 ------------------- .../engine/scenegraph/nodes/Sprite.groovy | 2 + 5 files changed, 51 insertions(+), 84 deletions(-) diff --git a/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/mediaplayer/ImageScript.groovy b/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/mediaplayer/ImageScript.groovy index e1f2f0d0..870982be 100644 --- a/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/mediaplayer/ImageScript.groovy +++ b/redhorizon-cli/source/nz/net/ultraq/redhorizon/cli/mediaplayer/ImageScript.groovy @@ -37,7 +37,7 @@ class ImageScript extends Script { var width = imageFile.width var height = imageFile.height - scaleXY(scene.window.renderResolution.calculateScaleToFit(width, height)) - translate(-width / 2, -height / 2) + transform.scaleXY(scene.window.renderResolution.calculateScaleToFit(width, height)) + transform.translate(-width / 2, -height / 2) } } diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/extensions/JomlExtensions.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/extensions/JomlExtensions.groovy index 8c6a246e..38464ce0 100644 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/extensions/JomlExtensions.groovy +++ b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/extensions/JomlExtensions.groovy @@ -1,12 +1,12 @@ -/* +/* * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/) - * + * * 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. @@ -24,7 +24,7 @@ import org.joml.primitives.Rectanglef /** * Extensions to JOMLs objects to work with Red Horizon. - * + * * @author Emanuel Rabina */ class JomlExtensions { @@ -32,7 +32,7 @@ class JomlExtensions { /** * Return an array of points {@code Vector2f}s, each representing a point of * this rectangle. - * + * * @param self * @param clazz * @return An array of 4 vectors, one for each x/y point around the rectangle. @@ -53,7 +53,7 @@ class JomlExtensions { /** * Overload the {@code -} operator to perform vector subtraction. Note that * this creates a new object to store the result and is returned. - * + * * @param self * @param v * @return @@ -66,7 +66,7 @@ class JomlExtensions { /** * Overload the {@code *} operator to perform matrix multiplication. Note * that this creates a new object to store the result and is returned. - * + * * @param self * @param right * @return @@ -79,7 +79,7 @@ class JomlExtensions { /** * Overload the {@code +} operator to perform vector addition. Note that * this creates a new object to store the result and is returned. - * + * * @param self * @param v * @return @@ -89,6 +89,18 @@ class JomlExtensions { return self.add(v, new Vector3f()) } + /** + * Scale just the X and Y components of a matrix by the same value. + * + * @param self + * @param factor + * @return + */ + static Matrix4f scaleXY(Matrix4f self, float factor) { + + return self.scaleXY(factor, factor) + } + /** * Set a rectangle to represent the given values. * @@ -110,7 +122,7 @@ class JomlExtensions { /** * Test whether an XY plane represented by a rectangle is within this frustum. - * + * * @param self * @param plane * @return @@ -119,4 +131,17 @@ class JomlExtensions { return self.testPlaneXY(plane.minX, plane.minY, plane.maxX, plane.maxY) } + + /** + * Translate this matrix by just an X and Y component. + * + * @param self + * @param x + * @param y + * @return + */ + static Matrix4f translate(Matrix4f self, float x, float y) { + + return self.translate(x, y, 0) + } } diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/media/Video.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/media/Video.groovy index e76f8cf2..276b910d 100644 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/media/Video.groovy +++ b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/media/Video.groovy @@ -118,12 +118,12 @@ class Video extends Node