From 7439137e4d43e1dc9d8fd974ce1a22155d62804c Mon Sep 17 00:00:00 2001 From: Antoine Date: Wed, 9 Jun 2021 14:34:32 +0200 Subject: [PATCH] Hitbox added --- shaders/StylishShaders/HitboxFrag.glsl | 13 ++++++++++++ src/engine/TestEngine.java | 4 ++++ src/engine/camera/TrackingDummy.java | 2 +- src/engine/camera/TrackingSF3ThirdStrick.java | 3 --- src/engine/object/Hitbox.java | 21 +++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 shaders/StylishShaders/HitboxFrag.glsl create mode 100644 src/engine/object/Hitbox.java diff --git a/shaders/StylishShaders/HitboxFrag.glsl b/shaders/StylishShaders/HitboxFrag.glsl new file mode 100644 index 0000000..6d36147 --- /dev/null +++ b/shaders/StylishShaders/HitboxFrag.glsl @@ -0,0 +1,13 @@ +#version 410 + +in vec3 color; +in vec3 fragCoord; + +out vec4 FragColor; + +uniform float time; + +void main() +{ + FragColor = vec4(color, 0.4f); +} \ No newline at end of file diff --git a/src/engine/TestEngine.java b/src/engine/TestEngine.java index edfc1c8..4a6502f 100644 --- a/src/engine/TestEngine.java +++ b/src/engine/TestEngine.java @@ -3,6 +3,7 @@ package engine; import engine.gui.UIElementText; import engine.input.*; import engine.math.Vector3f; +import engine.object.Hitbox; import engine.object.ObjectGl; import engine.object.Sprite; import engine.sound.*; @@ -59,6 +60,9 @@ public class TestEngine { zangief2.translate(new Vector3f(1000.0f, 200.0f, 0.0f)); zangief2.flipTextureWrapH(); + Hitbox hitboxTest = new Hitbox(35.0f, 100.0f, 50.0f, 10.0f, new Vector3f(1.0f, 0.0f, 0.0f)); + engine.add_objectGl(hitboxTest); + engine.setCameraTrackingSF3ThirdStrike(zangief, zangief2); //Create background diff --git a/src/engine/camera/TrackingDummy.java b/src/engine/camera/TrackingDummy.java index cddfd2f..4fe7190 100644 --- a/src/engine/camera/TrackingDummy.java +++ b/src/engine/camera/TrackingDummy.java @@ -4,6 +4,6 @@ import engine.math.Vector3f; public interface TrackingDummy { - public Vector3f getViewVector(); + Vector3f getViewVector(); } diff --git a/src/engine/camera/TrackingSF3ThirdStrick.java b/src/engine/camera/TrackingSF3ThirdStrick.java index f2f6df6..8073f97 100644 --- a/src/engine/camera/TrackingSF3ThirdStrick.java +++ b/src/engine/camera/TrackingSF3ThirdStrick.java @@ -29,8 +29,6 @@ public class TrackingSF3ThirdStrick implements TrackingDummy { ObjectGl left = obj1.getXPos() >= obj2.getXPos() ? obj2 : obj1; ObjectGl right = obj1.getXPos() < obj2.getXPos() ? obj2 : obj1; - System.out.println(viewXPos); - if ((right.getXPos() + right.getWidth() * right.getScalingFactor()) > viewXPos + dimension){ vec.x = - Math.abs((right.getXPos() + right.getWidth() * right.getScalingFactor()) - (viewXPos + dimension)); } else if (left.getXPos() < viewXPos - dimension){ @@ -38,6 +36,5 @@ public class TrackingSF3ThirdStrick implements TrackingDummy { } return vec; - } } diff --git a/src/engine/object/Hitbox.java b/src/engine/object/Hitbox.java new file mode 100644 index 0000000..d1aa2bd --- /dev/null +++ b/src/engine/object/Hitbox.java @@ -0,0 +1,21 @@ +package engine.object; + +import engine.math.Vector3f; + +public class Hitbox extends ObjectGl{ + + + /** + * Create a rectangle shape, use setTextureWrap to correctly align the texture with the model + * + * @param z depth of your model the larger it is the more it will be "close" to the camera + * @param w height of the rectangle + * @param h width of the rectangle + * @param size scaling factor of the rectangle, the model could not show up because this value is too small or too large, a good compromise is between 2 and 15 + * @param color set to null if you don't want a Color on your model + */ + public Hitbox(float z, float w, float h, float size, Vector3f color) { + super(z, w, h, size, null, color); + this.setShader("shaders/ObjectGlColor/vert.glsl", "shaders/StylishShaders/HitboxFrag.glsl"); + } +}