added 2D stuff
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="adopt-openj9-1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="adopt-openj9-1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
@@ -0,0 +1,196 @@
|
|||||||
|
# Blender v3.3.1 OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
o Circle
|
||||||
|
v 0.000000 0.000000 -1.000000
|
||||||
|
v -0.195090 0.000000 -0.980785
|
||||||
|
v -0.382683 0.000000 -0.923880
|
||||||
|
v -0.555570 0.000000 -0.831470
|
||||||
|
v -0.707107 0.000000 -0.707107
|
||||||
|
v -0.831470 0.000000 -0.555570
|
||||||
|
v -0.923880 0.000000 -0.382683
|
||||||
|
v -0.980785 0.000000 -0.195090
|
||||||
|
v -1.000000 0.000000 0.000000
|
||||||
|
v -0.980785 0.000000 0.195090
|
||||||
|
v -0.923880 0.000000 0.382683
|
||||||
|
v -0.831470 0.000000 0.555570
|
||||||
|
v -0.707107 0.000000 0.707107
|
||||||
|
v -0.555570 0.000000 0.831470
|
||||||
|
v -0.382683 0.000000 0.923880
|
||||||
|
v -0.195090 0.000000 0.980785
|
||||||
|
v 0.000000 0.000000 1.000000
|
||||||
|
v 0.195090 0.000000 0.980785
|
||||||
|
v 0.382683 0.000000 0.923880
|
||||||
|
v 0.555570 0.000000 0.831470
|
||||||
|
v 0.707107 0.000000 0.707107
|
||||||
|
v 0.831470 0.000000 0.555570
|
||||||
|
v 0.923880 0.000000 0.382683
|
||||||
|
v 0.980785 0.000000 0.195090
|
||||||
|
v 1.000000 0.000000 0.000000
|
||||||
|
v 0.980785 0.000000 -0.195090
|
||||||
|
v 0.923880 0.000000 -0.382683
|
||||||
|
v 0.831470 0.000000 -0.555570
|
||||||
|
v 0.707107 0.000000 -0.707107
|
||||||
|
v 0.555570 0.000000 -0.831470
|
||||||
|
v 0.382683 0.000000 -0.923880
|
||||||
|
v 0.195090 0.000000 -0.980785
|
||||||
|
v 0.000000 0.000000 -0.941431
|
||||||
|
v -0.183664 0.000000 -0.923341
|
||||||
|
v -0.360270 0.000000 -0.869769
|
||||||
|
v -0.523031 0.000000 -0.782771
|
||||||
|
v -0.665692 0.000000 -0.665692
|
||||||
|
v -0.782771 0.000000 -0.523031
|
||||||
|
v -0.869769 0.000000 -0.360270
|
||||||
|
v -0.923341 0.000000 -0.183664
|
||||||
|
v -0.941431 0.000000 -0.000000
|
||||||
|
v -0.923341 0.000000 0.183664
|
||||||
|
v -0.869769 0.000000 0.360270
|
||||||
|
v -0.782771 0.000000 0.523031
|
||||||
|
v -0.665692 0.000000 0.665692
|
||||||
|
v -0.523031 0.000000 0.782771
|
||||||
|
v -0.360270 0.000000 0.869769
|
||||||
|
v -0.183664 0.000000 0.923341
|
||||||
|
v 0.000000 0.000000 0.941431
|
||||||
|
v 0.183664 0.000000 0.923341
|
||||||
|
v 0.360270 0.000000 0.869769
|
||||||
|
v 0.523031 0.000000 0.782771
|
||||||
|
v 0.665692 0.000000 0.665692
|
||||||
|
v 0.782771 0.000000 0.523031
|
||||||
|
v 0.869769 0.000000 0.360270
|
||||||
|
v 0.923341 0.000000 0.183664
|
||||||
|
v 0.941431 0.000000 -0.000000
|
||||||
|
v 0.923341 0.000000 -0.183664
|
||||||
|
v 0.869769 0.000000 -0.360270
|
||||||
|
v 0.782771 0.000000 -0.523031
|
||||||
|
v 0.665692 0.000000 -0.665692
|
||||||
|
v 0.523031 0.000000 -0.782771
|
||||||
|
v 0.360270 0.000000 -0.869769
|
||||||
|
v 0.183664 0.000000 -0.923341
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
s off
|
||||||
|
f 19/1 50/2 51/3
|
||||||
|
f 5/4 38/5 6/6
|
||||||
|
f 32/7 33/8 1/9
|
||||||
|
f 20/10 51/3 52/11
|
||||||
|
f 6/6 39/12 7/13
|
||||||
|
f 21/14 52/11 53/15
|
||||||
|
f 7/13 40/16 8/17
|
||||||
|
f 21/14 54/18 22/19
|
||||||
|
f 8/17 41/20 9/21
|
||||||
|
f 23/22 54/18 55/23
|
||||||
|
f 10/24 41/20 42/25
|
||||||
|
f 23/22 56/26 24/27
|
||||||
|
f 10/24 43/28 11/29
|
||||||
|
f 24/27 57/30 25/31
|
||||||
|
f 11/29 44/32 12/33
|
||||||
|
f 25/31 58/34 26/35
|
||||||
|
f 12/33 45/36 13/37
|
||||||
|
f 27/38 58/34 59/39
|
||||||
|
f 13/37 46/40 14/41
|
||||||
|
f 28/42 59/39 60/43
|
||||||
|
f 14/41 47/44 15/45
|
||||||
|
f 1/9 34/46 2/47
|
||||||
|
f 28/42 61/48 29/49
|
||||||
|
f 16/50 47/44 48/51
|
||||||
|
f 2/47 35/52 3/53
|
||||||
|
f 29/49 62/54 30/55
|
||||||
|
f 16/50 49/56 17/57
|
||||||
|
f 4/58 35/52 36/59
|
||||||
|
f 30/55 63/60 31/61
|
||||||
|
f 18/62 49/56 50/2
|
||||||
|
f 4/58 37/63 5/4
|
||||||
|
f 31/61 64/64 32/7
|
||||||
|
f 19/1 18/62 50/2
|
||||||
|
f 5/4 37/63 38/5
|
||||||
|
f 32/7 64/64 33/8
|
||||||
|
f 20/10 19/1 51/3
|
||||||
|
f 6/6 38/5 39/12
|
||||||
|
f 21/14 20/10 52/11
|
||||||
|
f 7/13 39/12 40/16
|
||||||
|
f 21/14 53/15 54/18
|
||||||
|
f 8/17 40/16 41/20
|
||||||
|
f 23/22 22/19 54/18
|
||||||
|
f 10/24 9/21 41/20
|
||||||
|
f 23/22 55/23 56/26
|
||||||
|
f 10/24 42/25 43/28
|
||||||
|
f 24/27 56/26 57/30
|
||||||
|
f 11/29 43/28 44/32
|
||||||
|
f 25/31 57/30 58/34
|
||||||
|
f 12/33 44/32 45/36
|
||||||
|
f 27/38 26/35 58/34
|
||||||
|
f 13/37 45/36 46/40
|
||||||
|
f 28/42 27/38 59/39
|
||||||
|
f 14/41 46/40 47/44
|
||||||
|
f 1/9 33/8 34/46
|
||||||
|
f 28/42 60/43 61/48
|
||||||
|
f 16/50 15/45 47/44
|
||||||
|
f 2/47 34/46 35/52
|
||||||
|
f 29/49 61/48 62/54
|
||||||
|
f 16/50 48/51 49/56
|
||||||
|
f 4/58 3/53 35/52
|
||||||
|
f 30/55 62/54 63/60
|
||||||
|
f 18/62 17/57 49/56
|
||||||
|
f 4/58 36/59 37/63
|
||||||
|
f 31/61 63/60 64/64
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
@@ -0,0 +1,18 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
public class Circle extends Shape
|
||||||
|
{
|
||||||
|
public float radius;
|
||||||
|
|
||||||
|
public Circle(float x, float y, float radius, Color color)
|
||||||
|
{
|
||||||
|
super(x, y, color);
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType()
|
||||||
|
{
|
||||||
|
return Type.Circle;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
import RenderEngine.DisplayManager;
|
||||||
|
|
||||||
|
public class Input
|
||||||
|
{
|
||||||
|
public static boolean isKeyPressed(Key key)
|
||||||
|
{
|
||||||
|
switch(key)
|
||||||
|
{
|
||||||
|
case a: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_A);
|
||||||
|
case b: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_B);
|
||||||
|
case c: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_C);
|
||||||
|
case d: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_D);
|
||||||
|
case e: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_E);
|
||||||
|
case f: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_F);
|
||||||
|
case g: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_G);
|
||||||
|
case h: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_H);
|
||||||
|
case i: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_I);
|
||||||
|
case j: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_J);
|
||||||
|
case k: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_K);
|
||||||
|
case l: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_L);
|
||||||
|
case m: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_M);
|
||||||
|
case n: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_N);
|
||||||
|
case o: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_O);
|
||||||
|
case p: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_P);
|
||||||
|
case q: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_Q);
|
||||||
|
case r: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_R);
|
||||||
|
case s: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_S);
|
||||||
|
case t: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_T);
|
||||||
|
case u: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_U);
|
||||||
|
case v: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_V);
|
||||||
|
case w: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_W);
|
||||||
|
case x: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_X);
|
||||||
|
case y: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_Y);
|
||||||
|
case k1: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_1);
|
||||||
|
case k2: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_2);
|
||||||
|
case k3: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_3);
|
||||||
|
case k4: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_4);
|
||||||
|
case k5: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_5);
|
||||||
|
case k6: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_6);
|
||||||
|
case k7: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_7);
|
||||||
|
case k8: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_8);
|
||||||
|
case k9: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_9);
|
||||||
|
case k0: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_0);
|
||||||
|
case kUp: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_UP);
|
||||||
|
case kDown: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_DOWN);
|
||||||
|
case kLeft: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_LEFT);
|
||||||
|
case kRight: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_RIGHT);
|
||||||
|
case kSpace: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_SPACE);
|
||||||
|
case kShift: return org.lwjgl.input.Keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_LSHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float horizontal()
|
||||||
|
{
|
||||||
|
if(isKeyPressed(Key.a) || isKeyPressed(Key.kLeft))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isKeyPressed(Key.d) || isKeyPressed(Key.kRight))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float vertical()
|
||||||
|
{
|
||||||
|
if(isKeyPressed(Key.w) || isKeyPressed(Key.kUp))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isKeyPressed(Key.s) || isKeyPressed(Key.kDown))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMouseDown(Mouse button)
|
||||||
|
{
|
||||||
|
if(button == Mouse.left)
|
||||||
|
{
|
||||||
|
return org.lwjgl.input.Mouse.isButtonDown(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return org.lwjgl.input.Mouse.isButtonDown(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float mouseX()
|
||||||
|
{
|
||||||
|
double res = org.lwjgl.input.Mouse.getX() - DisplayManager.width / 2f;
|
||||||
|
res /= 5.714285714285714;
|
||||||
|
|
||||||
|
return (float)res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float mouseY()
|
||||||
|
{
|
||||||
|
double res = org.lwjgl.input.Mouse.getY() - DisplayManager.height / 2f;
|
||||||
|
res /= 5.714285714285714;
|
||||||
|
|
||||||
|
return (float)res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
public enum Key
|
||||||
|
{
|
||||||
|
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
|
||||||
|
k1, k2, k3, k4, k5, k6, k7, k8, k9, k0, kSpace, kEnter, kUp, kDown, kLeft, kRight, kShift
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
public class Line extends Shape
|
||||||
|
{
|
||||||
|
public float length;
|
||||||
|
|
||||||
|
public float rotation;
|
||||||
|
public float thickness;
|
||||||
|
|
||||||
|
public Line(float x, float y, float length, float rotation, float thickness, Color color)
|
||||||
|
{
|
||||||
|
super(x, y, color);
|
||||||
|
this.length = length;
|
||||||
|
this.rotation = rotation;
|
||||||
|
this.thickness = thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType()
|
||||||
|
{
|
||||||
|
return Type.Line;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
public enum Mouse
|
||||||
|
{
|
||||||
|
left, right
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
public class Rectangle extends Shape
|
||||||
|
{
|
||||||
|
public float width, height;
|
||||||
|
|
||||||
|
public Rectangle(float x, float y, float width, float height, Color color)
|
||||||
|
{
|
||||||
|
super(x, y, color);
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType()
|
||||||
|
{
|
||||||
|
return Type.Rectangle;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
public abstract class Shape
|
||||||
|
{
|
||||||
|
public float x, y;
|
||||||
|
public Color color;
|
||||||
|
public Shape(float x, float y, Color color)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(float x, float y)
|
||||||
|
{
|
||||||
|
this.x += x;
|
||||||
|
this.y += y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(float x, float y)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type
|
||||||
|
{
|
||||||
|
Rectangle, Line, Circle
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Color
|
||||||
|
{
|
||||||
|
red("red"), green("green"), blue("blue"), yellow("yellow"), white("white");
|
||||||
|
|
||||||
|
public String color;
|
||||||
|
|
||||||
|
Color(String color)
|
||||||
|
{
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Type getType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package Engine2D;
|
||||||
|
|
||||||
|
import Entity.Entity;
|
||||||
|
import Models.RawModel;
|
||||||
|
import Models.TexturedModel;
|
||||||
|
import RenderEngine.DisplayManager;
|
||||||
|
import RenderEngine.Loader;
|
||||||
|
import RenderEngine.Renderer;
|
||||||
|
import Shaders.StaticShader;
|
||||||
|
import Textures.ModelTexture;
|
||||||
|
import Tools.OBJLoader;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
import org.lwjgl.util.vector.Vector3f;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import Entity.Camera;
|
||||||
|
|
||||||
|
public abstract class Window2D
|
||||||
|
{
|
||||||
|
private Loader loader;
|
||||||
|
private StaticShader shader;
|
||||||
|
private Renderer renderer;
|
||||||
|
|
||||||
|
public float gameWidth, gameHeight;
|
||||||
|
|
||||||
|
private float rBackground = 0, gBackground = 0, bBackground = 0;
|
||||||
|
|
||||||
|
List<Entity> entities = new ArrayList<>();
|
||||||
|
List<Shape> shapes = new ArrayList<>();
|
||||||
|
|
||||||
|
private Camera cam = new Camera();
|
||||||
|
|
||||||
|
public void createWindow(String title, int width, int height)
|
||||||
|
{
|
||||||
|
DisplayManager.createDisplay(title, true, width, height, false);
|
||||||
|
loader = new Loader();
|
||||||
|
shader = new StaticShader();
|
||||||
|
renderer = new Renderer(shader);
|
||||||
|
|
||||||
|
double res = DisplayManager.width / 2f;
|
||||||
|
res /= 5.714285714285714;
|
||||||
|
res *= 2;
|
||||||
|
gameWidth = (float)res;
|
||||||
|
|
||||||
|
System.out.println("Window game width : " + res);
|
||||||
|
|
||||||
|
res = DisplayManager.height / 2f;
|
||||||
|
res /= 5.714285714285714;
|
||||||
|
res *= 2;
|
||||||
|
gameHeight = (float)res;
|
||||||
|
|
||||||
|
System.out.println("Window game height: " + res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addShape(Shape shape)
|
||||||
|
{
|
||||||
|
switch (shape.getType())
|
||||||
|
{
|
||||||
|
case Rectangle:
|
||||||
|
Rectangle rect = (Rectangle) shape;
|
||||||
|
float[] vertices =
|
||||||
|
{
|
||||||
|
//links unten
|
||||||
|
0 - rect.width / 2, 0 - rect.height / 2, 0,
|
||||||
|
//links oben
|
||||||
|
0 - rect.width / 2, 0 + rect.height / 2, 0,
|
||||||
|
//rechts oben
|
||||||
|
0 + rect.width / 2, 0 + rect.height / 2, 0,
|
||||||
|
//rechts unten
|
||||||
|
0 + rect.width / 2, 0 - rect.height / 2, 0
|
||||||
|
};
|
||||||
|
int[] indices =
|
||||||
|
{
|
||||||
|
3, 0, 1, 1, 3, 2
|
||||||
|
};
|
||||||
|
float[] uvs =
|
||||||
|
{
|
||||||
|
0, 0,
|
||||||
|
0, 0,
|
||||||
|
0, 0,
|
||||||
|
0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
RawModel model = loader.loadToVAO(vertices, indices, uvs);
|
||||||
|
ModelTexture texture = new ModelTexture(loader.loadTexture(shape.color.color));
|
||||||
|
TexturedModel texturedModel = new TexturedModel(model, texture);
|
||||||
|
Entity entity = new Entity(texturedModel, new Vector3f(shape.x, shape.y, -100), 0, 0, 0, 1);
|
||||||
|
entities.add(entity);
|
||||||
|
shapes.add(shape);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Line:
|
||||||
|
Line line = (Line) shape;
|
||||||
|
float[] vertices1 =
|
||||||
|
{
|
||||||
|
//links unten
|
||||||
|
0 - line.length / 2, 0, 0,
|
||||||
|
//links oben
|
||||||
|
0 - line.length / 2, 0 + line.thickness / 2, 0,
|
||||||
|
//rechts oben
|
||||||
|
0 + line.length / 2, 0 + line.thickness / 2, 0,
|
||||||
|
//rechts unten
|
||||||
|
0 + line.length / 2, 0, 0
|
||||||
|
};
|
||||||
|
int[] indices1 =
|
||||||
|
{
|
||||||
|
3, 0, 1, 1, 3, 2
|
||||||
|
};
|
||||||
|
float[] uvs1 =
|
||||||
|
{
|
||||||
|
0, 0,
|
||||||
|
0, 0,
|
||||||
|
0, 0,
|
||||||
|
0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
RawModel model1 = loader.loadToVAO(vertices1, indices1, uvs1);
|
||||||
|
ModelTexture texture1 = new ModelTexture(loader.loadTexture(shape.color.color));
|
||||||
|
TexturedModel texturedModel1 = new TexturedModel(model1, texture1);
|
||||||
|
Entity entity1 = new Entity(texturedModel1, new Vector3f(shape.x, shape.y, -100), 0, 0, line.rotation, 1);
|
||||||
|
entities.add(entity1);
|
||||||
|
shapes.add(shape);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Circle:
|
||||||
|
Circle circle = (Circle) shape;
|
||||||
|
OBJLoader objLoader = new OBJLoader("circle");
|
||||||
|
float[] vertices2 = objLoader.getVertices();
|
||||||
|
int[] indices2 = objLoader.getIndices();
|
||||||
|
float[] uvs2 = objLoader.getUVs();
|
||||||
|
|
||||||
|
|
||||||
|
RawModel model2 = loader.loadToVAO(vertices2, indices2, uvs2);
|
||||||
|
ModelTexture texture2 = new ModelTexture(loader.loadTexture(shape.color.color));
|
||||||
|
TexturedModel texturedModel2 = new TexturedModel(model2, texture2);
|
||||||
|
Entity entity2 = new Entity(texturedModel2, new Vector3f(shape.x, shape.y, -100), -90, 0, 0, circle.radius);
|
||||||
|
entities.add(entity2);
|
||||||
|
shapes.add(shape);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackgroundColor(int r, int g, int b)
|
||||||
|
{
|
||||||
|
rBackground = r;
|
||||||
|
gBackground = g;
|
||||||
|
bBackground = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
renderer.prepare(rBackground, gBackground, bBackground);
|
||||||
|
shader.start();
|
||||||
|
shader.loadViewMatrix(cam);
|
||||||
|
for (int i = 0; i < entities.size(); i++)
|
||||||
|
{
|
||||||
|
Entity e = entities.get(i);
|
||||||
|
Shape s = shapes.get(i);
|
||||||
|
e.setPosition(new Vector3f(s.x, s.y, e.getPosition().z));
|
||||||
|
|
||||||
|
renderer.render(e, shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
shader.stop();
|
||||||
|
DisplayManager.updateDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeWindow()
|
||||||
|
{
|
||||||
|
shader.clear();
|
||||||
|
loader.clear();
|
||||||
|
DisplayManager.closeDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldClose()
|
||||||
|
{
|
||||||
|
return Display.isCloseRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ import org.lwjgl.input.Mouse;
|
|||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
import Textures.ModelTexture;
|
import Textures.ModelTexture;
|
||||||
import org.lwjgl.util.vector.Vector3f;
|
import org.lwjgl.util.vector.Vector3f;
|
||||||
import sun.awt.AWTAccessor;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ public class MainGameLoop
|
|||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
DisplayManager.createDisplay("Rendr", true);
|
DisplayManager.createDisplay("Rendr", true, 800, 600, true);
|
||||||
|
|
||||||
Loader loader = new Loader();
|
Loader loader = new Loader();
|
||||||
StaticShader shader = new StaticShader();
|
StaticShader shader = new StaticShader();
|
||||||
@@ -46,6 +45,7 @@ public class MainGameLoop
|
|||||||
TexturedModel texturedModel = new TexturedModel(model, texture);
|
TexturedModel texturedModel = new TexturedModel(model, texture);
|
||||||
Entity entity = new Entity(texturedModel, new Vector3f(0, 0, -5), 0, 0, 0, 1);
|
Entity entity = new Entity(texturedModel, new Vector3f(0, 0, -5), 0, 0, 0, 1);
|
||||||
|
|
||||||
|
entity.setPosition(new Vector3f(-0.5f, 0, 0));
|
||||||
|
|
||||||
Camera camera = new Camera();
|
Camera camera = new Camera();
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class SwingTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void includeGL(){
|
private void includeGL(){
|
||||||
DisplayManager.createDisplay("Redr", false);
|
DisplayManager.createDisplay("Redr", false, 800, 600, true);
|
||||||
DisplayManager.setDisplayParent(canvas);
|
DisplayManager.setDisplayParent(canvas);
|
||||||
|
|
||||||
Loader loader = new Loader();
|
Loader loader = new Loader();
|
||||||
@@ -78,13 +78,25 @@ public class SwingTest
|
|||||||
|
|
||||||
Camera camera = new Camera();
|
Camera camera = new Camera();
|
||||||
|
|
||||||
|
OBJLoader objLoader = new OBJLoader("Object");
|
||||||
|
float[] vertices = objLoader.getVertices();
|
||||||
|
int[] indices = objLoader.getIndices();
|
||||||
|
float[] uvs = objLoader.getUVs();
|
||||||
|
|
||||||
|
|
||||||
|
RawModel model = loader.loadToVAO(vertices, indices, uvs);
|
||||||
|
ModelTexture texture = new ModelTexture(loader.loadTexture("mossyBricks"));
|
||||||
|
TexturedModel texturedModel = new TexturedModel(model, texture);
|
||||||
|
Entity entity = new Entity(texturedModel, new Vector3f(0, 0, -5), 0, 0, 0, 1);
|
||||||
|
|
||||||
while(!Display.isCloseRequested())
|
while(!Display.isCloseRequested())
|
||||||
{
|
{
|
||||||
renderer.prepare(0.2f, 0.2f, 0.2f);
|
renderer.prepare(0.2f, 0.2f, 0.2f);
|
||||||
shader.start();
|
shader.start();
|
||||||
shader.loadViewMatrix(camera);
|
shader.loadViewMatrix(camera);
|
||||||
// renderer.render(entity, shader);
|
renderer.render(entity, shader);
|
||||||
shader.stop();
|
shader.stop();
|
||||||
|
entity.rotate(0, 1, 0);
|
||||||
DisplayManager.updateDisplay();
|
DisplayManager.updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package EngineTest;
|
||||||
|
|
||||||
|
import Engine2D.*;
|
||||||
|
|
||||||
|
public class Test2D extends Window2D
|
||||||
|
{
|
||||||
|
private static Test2D test;
|
||||||
|
private static Rectangle rect;
|
||||||
|
private static Line line;
|
||||||
|
|
||||||
|
private static Circle circle;
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
test = new Test2D();
|
||||||
|
test.createWindow("Test", 800, 600);
|
||||||
|
|
||||||
|
test.setBackgroundColor(1, 1, 1);
|
||||||
|
|
||||||
|
rect = new Rectangle(0, 0, 10, 10, Shape.Color.green);
|
||||||
|
test.addShape(rect);
|
||||||
|
|
||||||
|
// line = new Line(0, 0, -10, 5, 10, -5, 1, Shape.Color.blue);
|
||||||
|
//test.addShape(line);
|
||||||
|
|
||||||
|
circle = new Circle(0, 0, 10, Shape.Color.blue);
|
||||||
|
test.addShape(circle);
|
||||||
|
|
||||||
|
test.update();
|
||||||
|
|
||||||
|
test.closeWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
while(!test.shouldClose())
|
||||||
|
{
|
||||||
|
super.update();
|
||||||
|
|
||||||
|
if(Input.isMouseDown(Mouse.left))
|
||||||
|
{
|
||||||
|
circle.setPosition(Input.mouseX(), Input.mouseY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,12 +8,14 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class DisplayManager
|
public class DisplayManager
|
||||||
{
|
{
|
||||||
private static final int width = 1280, height = 700;
|
public static int width = 1280, height = 700;
|
||||||
private static final int fps = 60;
|
private static final int fps = 60;
|
||||||
|
|
||||||
//creates a new display with openGL viewport in it
|
//creates a new display with openGL viewport in it
|
||||||
public static void createDisplay(String title, boolean vSync)
|
public static void createDisplay(String title, boolean vSync, int _width, int _height, boolean resizable)
|
||||||
{
|
{
|
||||||
|
width = _width;
|
||||||
|
height = _height;
|
||||||
ContextAttribs attribs = new ContextAttribs(3, 2)
|
ContextAttribs attribs = new ContextAttribs(3, 2)
|
||||||
.withForwardCompatible(true).withProfileCore(true);
|
.withForwardCompatible(true).withProfileCore(true);
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ public class DisplayManager
|
|||||||
Display.create(new PixelFormat(), attribs);
|
Display.create(new PixelFormat(), attribs);
|
||||||
Display.setVSyncEnabled(vSync);
|
Display.setVSyncEnabled(vSync);
|
||||||
Display.setTitle(title);
|
Display.setTitle(title);
|
||||||
Display.setResizable(true);
|
Display.setResizable(resizable);
|
||||||
} catch (LWJGLException e)
|
} catch (LWJGLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package Test2D;
|
||||||
|
|
||||||
|
import Engine2D.*;
|
||||||
|
|
||||||
|
public class TicTacToe extends Window2D
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
new TicTacToe();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[][] grid = new int[3][3];
|
||||||
|
|
||||||
|
private int currentPlayer = 1;
|
||||||
|
|
||||||
|
public TicTacToe()
|
||||||
|
{
|
||||||
|
createWindow("TicTacToe", 800, 800);
|
||||||
|
setBackgroundColor(1, 1, 1);
|
||||||
|
|
||||||
|
addShape(new Line(-25, 0, 120, 90, 1, Shape.Color.blue));
|
||||||
|
addShape(new Line(25, 0, 120, 90, 1, Shape.Color.blue));
|
||||||
|
|
||||||
|
addShape(new Line(0, -25, 120, 0, 1, Shape.Color.blue));
|
||||||
|
addShape(new Line(0, 25, 120, 0, 1, Shape.Color.blue));
|
||||||
|
|
||||||
|
update();
|
||||||
|
closeWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
while(!shouldClose())
|
||||||
|
{
|
||||||
|
super.update();
|
||||||
|
|
||||||
|
if(Input.isMouseDown(Mouse.left))
|
||||||
|
{
|
||||||
|
//get clicked cell
|
||||||
|
int xCell = (int)(Input.mouseX() / 25) + 1;
|
||||||
|
int yCell = (int)(Input.mouseY() / 25) + 1;
|
||||||
|
|
||||||
|
if(xCell <= -1) xCell++;
|
||||||
|
if(xCell > 2) xCell--;
|
||||||
|
|
||||||
|
if(yCell <= -1) yCell++;
|
||||||
|
if(yCell > 2) yCell--;
|
||||||
|
|
||||||
|
if(grid[xCell][yCell] == 0)
|
||||||
|
{
|
||||||
|
if(currentPlayer == 2)
|
||||||
|
{
|
||||||
|
addShape(new Circle((xCell - 1) * 48, (yCell - 1) * 48, 15, Shape.Color.blue));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addShape(new Line((xCell - 1) * 48, (yCell - 1) * 48, 30, 45, 2, Shape.Color.red));
|
||||||
|
addShape(new Line((xCell - 1) * 48, (yCell - 1) * 48, 30, -45, 2, Shape.Color.red));
|
||||||
|
}
|
||||||
|
|
||||||
|
grid[xCell][yCell] = currentPlayer;
|
||||||
|
currentPlayer = currentPlayer == 1 ? 2 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user