Skip to content

Commit 2d3c543

Browse files
committed
add refence position to textureRenderer
1 parent bc55ac3 commit 2d3c543

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/MightyLibrary/mightylib/graphics/shape/Renderer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,14 @@ public Shape getShape(){
157157
return shape;
158158
}
159159

160-
161160
public void setShape(Shape shape){
162161
this.shape = shape;
163162
}
164163

164+
public Vector3f position(){
165+
return position;
166+
}
167+
165168
public void unload(){
166169
shape.unload();
167170
modelBuffer.clear();

src/MightyLibrary/mightylib/graphics/shape/_2D/TextureRenderer.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import MightyLibrary.mightylib.graphics.shape.Shape;
55
import MightyLibrary.mightylib.main.WindowInfo;
66
import MightyLibrary.mightylib.resources.Resources;
7+
import MightyLibrary.mightylib.util.math.EDirection;
78
import MightyLibrary.mightylib.util.math.MightyMath;
89
import org.joml.Matrix4f;
910
import org.joml.Vector2f;
1011
import org.joml.Vector3f;
1112
import org.joml.Vector4f;
1213

1314
public class TextureRenderer extends Renderer {
15+
protected EDirection reference;
1416
protected final WindowInfo windowInfo;
1517
protected final int positionIndex, textureIndex;
1618
protected Vector4f texturePosition;
@@ -19,6 +21,7 @@ public TextureRenderer(WindowInfo info, String shaderName) {
1921
super(shaderName, true, true);
2022

2123
windowInfo = info;
24+
reference = EDirection.LeftUp;
2225

2326
texturePosition = new Vector4f(0f, 1f, 0f,1f);
2427

@@ -31,12 +34,48 @@ public TextureRenderer(WindowInfo info, String shaderName) {
3134

3235

3336
private float[] calculatePosition(){
34-
return new float[]{
37+
float [] temp = new float[]{
3538
0, 1,
3639
0, 0,
3740
1, 0,
3841
1, 1
3942
};
43+
44+
switch(this.reference){
45+
case None:
46+
case Up:
47+
case Down:
48+
temp[0] = -0.5f; temp[2] = -0.5f; temp[4] = 0.5f; temp[6] = 0.5f;
49+
break;
50+
case RightDown:
51+
case Right:
52+
case RightUp:
53+
temp[0] = -1; temp[2] = -1; temp[4] = 0f; temp[6] = 0f;
54+
break;
55+
}
56+
57+
switch(this.reference){
58+
case None:
59+
case Left:
60+
case Right:
61+
temp[1] = 0.5f; temp[3] = -0.5f; temp[5] = -0.5f; temp[7] = 0.5f;
62+
break;
63+
case LeftDown:
64+
case Down:
65+
case RightDown:
66+
temp[1] = -1; temp[3] = 0; temp[5] = 0f; temp[7] = -1f;
67+
break;
68+
}
69+
70+
return temp;
71+
}
72+
73+
public TextureRenderer setReference(EDirection reference){
74+
this.reference = reference;
75+
76+
shape.updateVbo(calculatePosition(), positionIndex);
77+
78+
return this;
4079
}
4180

4281

@@ -55,13 +94,17 @@ private float[] texturePos(){
5594
}
5695

5796
// Set size with size of pixel
58-
public void setSizePix(float width, float height){
97+
public TextureRenderer setSizePix(float width, float height){
5998
setScale(new Vector3f(width, height, 1.0f));
99+
100+
return this;
60101
}
61102

62103

63-
public void setPosition(Vector2f position){
104+
public TextureRenderer setPosition(Vector2f position){
64105
super.setPosition(new Vector3f(position.x, position.y, 0.0f));
106+
107+
return this;
65108
}
66109

67110
public void updateShape(){

src/MightyLibrary/project/scenes/MenuScene.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
import MightyLibrary.mightylib.scene.Scene;
77
import MightyLibrary.mightylib.util.math.Color4f;
88
import MightyLibrary.mightylib.util.math.EDirection;
9+
import MightyLibrary.mightylib.util.math.MightyMath;
10+
import MightyLibrary.mightylib.util.tweenings.ETweeningBehaviour;
11+
import MightyLibrary.mightylib.util.tweenings.ETweeningOption;
12+
import MightyLibrary.mightylib.util.tweenings.ETweeningType;
13+
import MightyLibrary.mightylib.util.tweenings.type.FloatTweening;
914
import MightyLibrary.project.lib.ActionId;
1015
import org.joml.Vector2f;
1116
import org.joml.Vector2i;
1217
import org.joml.Vector3f;
1318

1419
public class MenuScene extends Scene {
1520
private GUIList guiList;
21+
BackgroundlessButton buttonQuit;
22+
23+
FloatTweening rotation;
1624

1725
public void init(String[] args) {
1826
super.init(args);
@@ -54,7 +62,7 @@ public void init(String[] args) {
5462
buttonCollisionTest.OverlapsText.setColor(new Color4f(0.3f))
5563
.setText("->TestCollisionScene<-");
5664

57-
BackgroundlessButton buttonQuit = button2DScene.copy();
65+
buttonQuit = button2DScene.copy();
5866
buttonQuit.Text.setPosition(new Vector2f(windowSize.x * 0.5f, windowSize.y * 0.9f))
5967
.setText("Quit");
6068

@@ -69,6 +77,11 @@ public void init(String[] args) {
6977
guiList.GUIs.put(2, buttonCollisionTest);
7078
guiList.GUIs.put(3, buttonQuit);
7179
guiList.ShouldLoop = false;
80+
81+
rotation = new FloatTweening();
82+
rotation.setTweeningOption(ETweeningOption.LoopReversed)
83+
.setTweeningValues(ETweeningType.Sinusoidal, ETweeningBehaviour.InOut)
84+
.initTwoValue(2, 0f, MightyMath.PI_FLOAT * 2f);
7285
}
7386

7487

@@ -96,6 +109,9 @@ public void update() {
96109
}
97110
}
98111
}
112+
113+
rotation.update();
114+
buttonQuit.Text.setRotation(rotation.value(), new Vector3f(0, 0, 1));
99115
}
100116

101117

0 commit comments

Comments
 (0)