Merge branch 'liteCraft' into Vulkan
commit
2c97efa6e7
11
.classpath
11
.classpath
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
<classpathentry kind="src" path="src/main/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -16,18 +16,11 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
<classpathentry kind="src" path="src/main/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -21,7 +21,8 @@ import com.github.hydos.ginger.engine.opengl.api.*;
|
||||||
import com.github.hydos.ginger.engine.opengl.postprocessing.PostProcessing;
|
import com.github.hydos.ginger.engine.opengl.postprocessing.PostProcessing;
|
||||||
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
||||||
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
import com.github.hydos.ginger.engine.opengl.render.models.GLTexturedModel;
|
||||||
import com.github.hydos.ginger.engine.opengl.utils.GLLoader;
|
import com.github.hydos.ginger.engine.opengl.utils.*;
|
||||||
|
|
||||||
import tk.valoeghese.gateways.client.io.*;
|
import tk.valoeghese.gateways.client.io.*;
|
||||||
|
|
||||||
public class Litecraft extends Game
|
public class Litecraft extends Game
|
||||||
|
@ -36,15 +37,19 @@ public class Litecraft extends Game
|
||||||
public Vector4i dbgStats = new Vector4i();
|
public Vector4i dbgStats = new Vector4i();
|
||||||
private long frameTimer;
|
private long frameTimer;
|
||||||
|
|
||||||
public Litecraft()
|
public Litecraft(int windowWidth, int windowHeight, float frameLimit)
|
||||||
{
|
{
|
||||||
Litecraft.INSTANCE = this;
|
Litecraft.INSTANCE = this;
|
||||||
// set constants
|
// set constants
|
||||||
this.setupConstants();
|
this.setupConstants();
|
||||||
this.setupGinger(1280, 720, 60);
|
this.setupGinger(windowWidth, windowHeight, frameLimit);
|
||||||
Blocks.init(); // make sure blocks are initialised
|
// make sure blocks are initialised ??? (Currently does nothing)
|
||||||
|
Blocks.init();
|
||||||
this.frameTimer = System.currentTimeMillis();
|
this.frameTimer = System.currentTimeMillis();
|
||||||
setupKeybinds(); // setup keybinds
|
// setup keybinds
|
||||||
|
setupKeybinds();
|
||||||
|
// Open the title screen if nothing is already open.
|
||||||
|
if (GingerRegister.getInstance().currentScreen == null && world == null) ((GingerGL)engine).openScreen(new TitleScreen());
|
||||||
// start the game loop
|
// start the game loop
|
||||||
this.engine.startGameLoop();
|
this.engine.startGameLoop();
|
||||||
}
|
}
|
||||||
|
@ -78,9 +83,9 @@ public class Litecraft extends Game
|
||||||
// Render shadows
|
// Render shadows
|
||||||
GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
|
GingerRegister.getInstance().masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
|
||||||
// If there's a world, render it!
|
// If there's a world, render it!
|
||||||
if (this.world != null) renderWorld(this);
|
if (this.world != null) renderWorld();
|
||||||
// Render any overlays (GUIs, HUDs)
|
// Render any overlays (GUIs, HUDs)
|
||||||
this.engine.renderOverlays(this);
|
this.engine.renderOverlays();
|
||||||
// Put what's stored in the inactive framebuffer on the screen
|
// Put what's stored in the inactive framebuffer on the screen
|
||||||
Window.swapBuffers();
|
Window.swapBuffers();
|
||||||
}
|
}
|
||||||
|
@ -95,15 +100,17 @@ public class Litecraft extends Game
|
||||||
this.frameTimer += 1000;
|
this.frameTimer += 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderWorld(Game game)
|
public void renderWorld()
|
||||||
{
|
{
|
||||||
GameData data = game.data;
|
GameData data = GingerRegister.getInstance().game.data;
|
||||||
GingerUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer);
|
if (Window.renderAPI == RenderAPI.OpenGL)
|
||||||
|
{
|
||||||
|
GLUtils.preRenderScene(((GingerGL)engine).getRegistry().masterRenderer);
|
||||||
((GingerGL)engine).contrastFbo.bindFBO();
|
((GingerGL)engine).contrastFbo.bindFBO();
|
||||||
((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane);
|
((GingerGL)engine).getRegistry().masterRenderer.renderScene(data.entities, data.normalMapEntities, data.lights, data.camera, data.clippingPlane);
|
||||||
((GingerGL)engine).contrastFbo.unbindFBO();
|
((GingerGL)engine).contrastFbo.unbindFBO();
|
||||||
PostProcessing.doPostProcessing(((GingerGL)engine).contrastFbo.colorTexture);
|
PostProcessing.doPostProcessing(((GingerGL)engine).contrastFbo.colorTexture);
|
||||||
if (data.handleGuis) ((GingerGL)engine).renderOverlays(game);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update()
|
public void update()
|
||||||
|
@ -129,7 +136,7 @@ public class Litecraft extends Game
|
||||||
KeyCallbackHandler.trackWindow(Window.getWindow());
|
KeyCallbackHandler.trackWindow(Window.getWindow());
|
||||||
MouseCallbackHandler.trackWindow(Window.getWindow());
|
MouseCallbackHandler.trackWindow(Window.getWindow());
|
||||||
// set up ginger utilities
|
// set up ginger utilities
|
||||||
GingerUtils.init();
|
GLUtils.init();
|
||||||
|
|
||||||
switch (Window.renderAPI)
|
switch (Window.renderAPI)
|
||||||
{
|
{
|
||||||
|
@ -181,14 +188,11 @@ public class Litecraft extends Game
|
||||||
public void tick()
|
public void tick()
|
||||||
{
|
{
|
||||||
tps += 1;
|
tps += 1;
|
||||||
// Open the title screen if it's not already open.
|
|
||||||
if (GingerRegister.getInstance().currentScreen == null && world == null) ((GingerGL)engine).openScreen(new TitleScreen());
|
|
||||||
|
|
||||||
if (this.player instanceof PlayerEntity && camera != null)
|
if (this.player instanceof PlayerEntity && camera != null)
|
||||||
{
|
{
|
||||||
Input.invokeAllListeners();
|
Input.invokeAllListeners();
|
||||||
((PlayerEntity) this.player).updateMovement();
|
((PlayerEntity) this.player).updateMovement();
|
||||||
data.camera.updateMovement();
|
camera.updateMovement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class StarterGL
|
||||||
System.out.println("GLFW version: " + GLFW.glfwGetVersionString());
|
System.out.println("GLFW version: " + GLFW.glfwGetVersionString());
|
||||||
System.out.println("LWJGL version: " + Version.getVersion());
|
System.out.println("LWJGL version: " + Version.getVersion());
|
||||||
// Put SoundSystem version here
|
// Put SoundSystem version here
|
||||||
new Litecraft();
|
// TODO: Put a commandline reader here to check for desired width, height, and frame limit!
|
||||||
|
new Litecraft(1280, 720, 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,14 +178,11 @@ public class World implements BlockAccess, WorldGenConstants
|
||||||
public void render(BlockRenderer blockRenderer)
|
public void render(BlockRenderer blockRenderer)
|
||||||
{
|
{
|
||||||
blockRenderer.prepareModel(this.dummy.getModel());
|
blockRenderer.prepareModel(this.dummy.getModel());
|
||||||
try
|
this.chunks.forEach((pos, c) ->
|
||||||
{
|
{
|
||||||
this.chunks.forEach((pos, c) -> c.render(blockRenderer));
|
if (c != null && c.isFullyGenerated())
|
||||||
}
|
c.render(blockRenderer);
|
||||||
catch (NullPointerException e)
|
});
|
||||||
{
|
|
||||||
System.out.println("Null chunk - we should look into fixing this");
|
|
||||||
}
|
|
||||||
blockRenderer.unbindModel();
|
blockRenderer.unbindModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.info.RenderAPI;
|
import com.github.hydos.ginger.engine.common.info.RenderAPI;
|
||||||
import com.github.hydos.ginger.engine.common.io.Window;
|
import com.github.hydos.ginger.engine.common.io.Window;
|
||||||
import com.github.hydos.ginger.engine.vulkan.api.GingerVK;
|
import com.github.hydos.ginger.engine.vulkan.api.*;
|
||||||
|
|
||||||
/** @author hydos06
|
/** @author hydos06
|
||||||
* the non ARR vulkan test example */
|
* the non ARR vulkan test example */
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package com.github.hydos.ginger.engine.common.api;
|
package com.github.hydos.ginger.engine.common.api;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.api.game.Game;
|
|
||||||
import com.github.hydos.ginger.engine.common.io.Window;
|
import com.github.hydos.ginger.engine.common.io.Window;
|
||||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||||
import com.github.hydos.ginger.engine.common.util.Timer;
|
import com.github.hydos.ginger.engine.common.util.Timer;
|
||||||
import com.github.hydos.ginger.engine.common.util.Timer.TickListener;
|
import com.github.hydos.ginger.engine.common.util.Timer.TickListener;
|
||||||
import com.github.hydos.ginger.engine.opengl.api.GingerUtils;
|
import com.github.hydos.ginger.engine.opengl.utils.GLUtils;
|
||||||
|
|
||||||
public abstract class GingerEngine
|
public abstract class GingerEngine
|
||||||
{
|
{
|
||||||
|
@ -42,7 +41,7 @@ public abstract class GingerEngine
|
||||||
// Things that should be run as often as possible, without limits
|
// Things that should be run as often as possible, without limits
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
GingerUtils.update();
|
GLUtils.update();
|
||||||
Window.update();
|
Window.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,5 +49,5 @@ public abstract class GingerEngine
|
||||||
|
|
||||||
public abstract void openScreen(Screen screen);
|
public abstract void openScreen(Screen screen);
|
||||||
|
|
||||||
public abstract void renderOverlays(Game game);
|
public abstract void renderOverlays();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.github.hydos.ginger.engine.common.api.game.Game;
|
||||||
import com.github.hydos.ginger.engine.common.elements.buttons.TextureButton;
|
import com.github.hydos.ginger.engine.common.elements.buttons.TextureButton;
|
||||||
import com.github.hydos.ginger.engine.common.font.GUIText;
|
import com.github.hydos.ginger.engine.common.font.GUIText;
|
||||||
import com.github.hydos.ginger.engine.common.screen.Screen;
|
import com.github.hydos.ginger.engine.common.screen.Screen;
|
||||||
import com.github.hydos.ginger.engine.opengl.postprocessing.Fbo;
|
import com.github.hydos.ginger.engine.opengl.postprocessing.FrameBufferObject;
|
||||||
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
||||||
|
|
||||||
/** Used if a game wants to access engine variables safely */
|
/** Used if a game wants to access engine variables safely */
|
||||||
|
@ -20,7 +20,7 @@ public class GingerRegister
|
||||||
|
|
||||||
public List<GUIText> texts;
|
public List<GUIText> texts;
|
||||||
public List<TextureButton> guiButtons;
|
public List<TextureButton> guiButtons;
|
||||||
public List<Fbo> fbos;
|
public List<FrameBufferObject> frameBufferObjects;
|
||||||
public Game game;
|
public Game game;
|
||||||
public Screen currentScreen;
|
public Screen currentScreen;
|
||||||
public boolean wireframe = false;
|
public boolean wireframe = false;
|
||||||
|
|
|
@ -1,93 +1,21 @@
|
||||||
package com.github.hydos.ginger.engine.common.cameras;
|
package com.github.hydos.ginger.engine.common.cameras;
|
||||||
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.lwjgl.glfw.*;
|
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||||
import com.github.hydos.ginger.engine.common.io.Window;
|
|
||||||
|
|
||||||
public class Camera
|
public abstract class Camera
|
||||||
{
|
{
|
||||||
private float distanceFromPlayer = 5;
|
|
||||||
private float angleAroundPlayer = 0;
|
|
||||||
private Vector3f position = new Vector3f(0, 0, 0);
|
|
||||||
private float pitch, yaw;
|
|
||||||
private float roll;
|
|
||||||
public RenderObject player;
|
public RenderObject player;
|
||||||
|
private float pitch, yaw, roll;
|
||||||
public Camera(RenderObject playerEntity)
|
private Vector3f position = new Vector3f(0, 0, 0);
|
||||||
{ this.player = playerEntity; }
|
|
||||||
|
|
||||||
public Camera(Vector3f vector3f, RenderObject player)
|
|
||||||
{
|
|
||||||
this.position = vector3f;
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateAngleAroundPlayer()
|
|
||||||
{
|
|
||||||
if (Window.isMouseDown(1))
|
|
||||||
{
|
|
||||||
float angleChange = (float) (Window.dx * 0.3f);
|
|
||||||
angleAroundPlayer -= angleChange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateCameraPosition(float horizDistance, float verticDistance)
|
|
||||||
{
|
|
||||||
float theta = player.getRotY() + angleAroundPlayer;
|
|
||||||
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
|
|
||||||
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
|
|
||||||
position.x = player.getPosition().x - offsetX;
|
|
||||||
position.z = player.getPosition().z - offsetZ;
|
|
||||||
position.y = player.getPosition().y + verticDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float calculateHorizontalDistance()
|
|
||||||
{
|
|
||||||
float hD = (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch)));
|
|
||||||
if (hD < 0)
|
|
||||||
hD = 0;
|
|
||||||
return hD;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculatePitch()
|
|
||||||
{
|
|
||||||
if (Window.isMouseDown(1))
|
|
||||||
{
|
|
||||||
float pitchChange = (float) (Window.dy * 0.2f);
|
|
||||||
pitch += pitchChange;
|
|
||||||
if (pitch < 0)
|
|
||||||
{
|
|
||||||
pitch = 0;
|
|
||||||
}
|
|
||||||
else if (pitch > 90)
|
|
||||||
{ pitch = 90; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private float calculateVerticalDistance()
|
|
||||||
{ return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch + 4))); }
|
|
||||||
|
|
||||||
private void calculateZoom()
|
|
||||||
{
|
|
||||||
GLFW.glfwSetScrollCallback(Window.getWindow(), new GLFWScrollCallback()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void invoke(long win, double dx, double dy)
|
|
||||||
{
|
|
||||||
float zoomLevel = (float) dy * 0.1f;
|
|
||||||
distanceFromPlayer -= zoomLevel;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPitch()
|
|
||||||
{ return pitch; }
|
|
||||||
|
|
||||||
public Vector3f getPosition()
|
public Vector3f getPosition()
|
||||||
{ return position; }
|
{ return position; }
|
||||||
|
|
||||||
|
public float getPitch()
|
||||||
|
{ return pitch; }
|
||||||
|
|
||||||
public float getRoll()
|
public float getRoll()
|
||||||
{ return roll; }
|
{ return roll; }
|
||||||
|
|
||||||
|
@ -97,17 +25,6 @@ public class Camera
|
||||||
public void invertPitch()
|
public void invertPitch()
|
||||||
{ this.pitch = -pitch; }
|
{ this.pitch = -pitch; }
|
||||||
|
|
||||||
public void updateMovement()
|
|
||||||
{
|
|
||||||
calculateZoom();
|
|
||||||
calculatePitch();
|
|
||||||
calculateAngleAroundPlayer();
|
|
||||||
float horizontalDistance = calculateHorizontalDistance();
|
|
||||||
float verticalDistance = calculateVerticalDistance();
|
|
||||||
calculateCameraPosition(horizontalDistance, verticalDistance);
|
|
||||||
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPitch(float pitch)
|
public void setPitch(float pitch)
|
||||||
{ this.pitch = pitch; }
|
{ this.pitch = pitch; }
|
||||||
|
|
||||||
|
@ -116,4 +33,6 @@ public class Camera
|
||||||
|
|
||||||
public void setRoll(float roll)
|
public void setRoll(float roll)
|
||||||
{ this.roll = roll; }
|
{ this.roll = roll; }
|
||||||
|
|
||||||
|
public abstract void updateMovement();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,27 +13,22 @@ public class FirstPersonCamera extends Camera
|
||||||
|
|
||||||
public FirstPersonCamera(RenderObject playerEntity)
|
public FirstPersonCamera(RenderObject playerEntity)
|
||||||
{
|
{
|
||||||
super(playerEntity);
|
this.player = playerEntity;
|
||||||
playerEntity.setVisible(false);
|
playerEntity.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getPitch()
|
public float getPitch()
|
||||||
{ return pitch; }
|
{ return pitch; }
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector3f getPosition()
|
public Vector3f getPosition()
|
||||||
{ return position; }
|
{ return position; }
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getRoll()
|
public float getRoll()
|
||||||
{ return roll; }
|
{ return roll; }
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getYaw()
|
public float getYaw()
|
||||||
{ return yaw; }
|
{ return yaw; }
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateMovement()
|
public void updateMovement()
|
||||||
{
|
{
|
||||||
position.x = player.getPosition().x;
|
position.x = player.getPosition().x;
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.github.hydos.ginger.engine.common.cameras;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.*;
|
||||||
|
|
||||||
|
import com.github.hydos.ginger.engine.common.elements.objects.RenderObject;
|
||||||
|
import com.github.hydos.ginger.engine.common.io.Window;
|
||||||
|
|
||||||
|
public class ThirdPersonCamera extends Camera
|
||||||
|
{
|
||||||
|
public ThirdPersonCamera(RenderObject playerEntity)
|
||||||
|
{
|
||||||
|
this.player = playerEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float distanceFromPlayer = 5;
|
||||||
|
private float angleAroundPlayer = 0;
|
||||||
|
private void calculatePitch()
|
||||||
|
{
|
||||||
|
if (Window.isMouseDown(1))
|
||||||
|
{
|
||||||
|
float pitchChange = (float) (Window.dy * 0.2f);
|
||||||
|
setPitch(getPitch() + pitchChange);
|
||||||
|
if (getPitch() < 0)
|
||||||
|
{
|
||||||
|
setPitch(0);
|
||||||
|
}
|
||||||
|
else if (getPitch() > 90)
|
||||||
|
{ setPitch(90); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMovement()
|
||||||
|
{
|
||||||
|
calculateZoom();
|
||||||
|
calculatePitch();
|
||||||
|
calculateAngleAroundPlayer();
|
||||||
|
float horizontalDistance = calculateHorizontalDistance();
|
||||||
|
float verticalDistance = calculateVerticalDistance();
|
||||||
|
calculateCameraPosition(horizontalDistance, verticalDistance);
|
||||||
|
this.setYaw(180 - (player.getRotY() + angleAroundPlayer));
|
||||||
|
}
|
||||||
|
|
||||||
|
private float calculateHorizontalDistance()
|
||||||
|
{
|
||||||
|
float hD = (float) (distanceFromPlayer * Math.cos(Math.toRadians(getPitch())));
|
||||||
|
if (hD < 0)
|
||||||
|
hD = 0;
|
||||||
|
return hD;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float calculateVerticalDistance()
|
||||||
|
{ return (float) (distanceFromPlayer * Math.sin(Math.toRadians(getPitch() + 4))); }
|
||||||
|
|
||||||
|
private void calculateZoom()
|
||||||
|
{
|
||||||
|
GLFW.glfwSetScrollCallback(Window.getWindow(), new GLFWScrollCallback()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void invoke(long win, double dx, double dy)
|
||||||
|
{
|
||||||
|
float zoomLevel = (float) dy * 0.1f;
|
||||||
|
distanceFromPlayer -= zoomLevel;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateAngleAroundPlayer()
|
||||||
|
{
|
||||||
|
if (Window.isMouseDown(1))
|
||||||
|
{
|
||||||
|
float angleChange = (float) (Window.dx * 0.3f);
|
||||||
|
angleAroundPlayer -= angleChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateCameraPosition(float horizDistance, float verticDistance)
|
||||||
|
{
|
||||||
|
float theta = player.getRotY() + angleAroundPlayer;
|
||||||
|
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
|
||||||
|
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
|
||||||
|
getPosition().x = player.getPosition().x - offsetX;
|
||||||
|
getPosition().z = player.getPosition().z - offsetZ;
|
||||||
|
getPosition().y = player.getPosition().y + verticDistance;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package com.github.hydos.ginger.engine.common.fbo;
|
package com.github.hydos.ginger.engine.common.fbo;
|
||||||
|
|
||||||
public abstract class FboCallbackHandler
|
public abstract class FBOCallbackHandler
|
||||||
{
|
{
|
||||||
public void cleanUp()
|
public void cleanUp()
|
||||||
{}
|
{}
|
|
@ -48,7 +48,7 @@ public class Window
|
||||||
static double newY = 0;
|
static double newY = 0;
|
||||||
public static GLCapabilities glContext;
|
public static GLCapabilities glContext;
|
||||||
public static int actualWidth, actualHeight;
|
public static int actualWidth, actualHeight;
|
||||||
//temp stuff to test out fbo fixes
|
// FIXME: temp stuff to test out FBO fixes
|
||||||
private static int oldWindowWidth = Window.getWidth();
|
private static int oldWindowWidth = Window.getWidth();
|
||||||
private static int oldWindowHeight = Window.getHeight();
|
private static int oldWindowHeight = Window.getHeight();
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,7 @@ public class StaticCube
|
||||||
|
|
||||||
public static Mesh getCube()
|
public static Mesh getCube()
|
||||||
{
|
{
|
||||||
if (mesh == null)
|
if (mesh == null) mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length);
|
||||||
{ mesh = new Mesh(vertices, textureCoords, new float[vertices.length], indices, vertices.length); }
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class GingerGL extends GingerEngine
|
||||||
{
|
{
|
||||||
public MousePicker picker;
|
public MousePicker picker;
|
||||||
public FontType globalFont;
|
public FontType globalFont;
|
||||||
public Fbo contrastFbo;
|
public FrameBufferObject contrastFbo;
|
||||||
|
|
||||||
public void cleanup()
|
public void cleanup()
|
||||||
{
|
{
|
||||||
|
@ -60,9 +60,9 @@ public class GingerGL extends GingerEngine
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderOverlays(Game game)
|
public void renderOverlays()
|
||||||
{
|
{
|
||||||
getRegistry().masterRenderer.renderGuis(game.data.guis);
|
getRegistry().masterRenderer.renderGuis(getRegistry().game.data.guis);
|
||||||
if (getRegistry().currentScreen != null) getRegistry().masterRenderer.renderGuis(getRegistry().currentScreen.elements);
|
if (getRegistry().currentScreen != null) getRegistry().masterRenderer.renderGuis(getRegistry().currentScreen.elements);
|
||||||
TextMaster.render();
|
TextMaster.render();
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class GingerGL extends GingerEngine
|
||||||
getRegistry().registerGame(game);
|
getRegistry().registerGame(game);
|
||||||
timer = new Timer(game.data.tickSpeed);
|
timer = new Timer(game.data.tickSpeed);
|
||||||
timer.addTickListener(gameTickListener);
|
timer.addTickListener(gameTickListener);
|
||||||
contrastFbo = new Fbo(new ContrastChanger());
|
contrastFbo = new FrameBufferObject(new ContrastChanger());
|
||||||
getRegistry().masterRenderer = masterRenderer;
|
getRegistry().masterRenderer = masterRenderer;
|
||||||
picker = new MousePicker(game.data.camera, masterRenderer.getProjectionMatrix());
|
picker = new MousePicker(game.data.camera, masterRenderer.getProjectionMatrix());
|
||||||
PostProcessing.init();
|
PostProcessing.init();
|
||||||
|
|
|
@ -2,9 +2,9 @@ package com.github.hydos.ginger.engine.opengl.postprocessing;
|
||||||
|
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.fbo.FboCallbackHandler;
|
import com.github.hydos.ginger.engine.common.fbo.FBOCallbackHandler;
|
||||||
|
|
||||||
public class ContrastChanger extends FboCallbackHandler
|
public class ContrastChanger extends FBOCallbackHandler
|
||||||
{
|
{
|
||||||
private ImageRenderer renderer;
|
private ImageRenderer renderer;
|
||||||
private ContrastShader shader;
|
private ContrastShader shader;
|
||||||
|
|
|
@ -8,10 +8,10 @@ import java.nio.ByteBuffer;
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
import org.lwjgl.system.Callback;
|
import org.lwjgl.system.Callback;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.fbo.FboCallbackHandler;
|
import com.github.hydos.ginger.engine.common.fbo.FBOCallbackHandler;
|
||||||
import com.github.hydos.ginger.engine.common.io.Window;
|
import com.github.hydos.ginger.engine.common.io.Window;
|
||||||
|
|
||||||
public class Fbo
|
public class FrameBufferObject
|
||||||
{
|
{
|
||||||
long window;
|
long window;
|
||||||
int width = 1024;
|
int width = 1024;
|
||||||
|
@ -20,7 +20,7 @@ public class Fbo
|
||||||
boolean destroyed;
|
boolean destroyed;
|
||||||
Object lock = new Object();
|
Object lock = new Object();
|
||||||
/* cool ginger feature which handles fbos once they need to be rendered */
|
/* cool ginger feature which handles fbos once they need to be rendered */
|
||||||
public FboCallbackHandler handler;
|
public FBOCallbackHandler handler;
|
||||||
/* Multisampled FBO objects */
|
/* Multisampled FBO objects */
|
||||||
public int multisampledColorRenderBuffer;
|
public int multisampledColorRenderBuffer;
|
||||||
int multisampledDepthRenderBuffer;
|
int multisampledDepthRenderBuffer;
|
||||||
|
@ -34,7 +34,7 @@ public class Fbo
|
||||||
GLFWFramebufferSizeCallback fbCallback;
|
GLFWFramebufferSizeCallback fbCallback;
|
||||||
Callback debugProc;
|
Callback debugProc;
|
||||||
|
|
||||||
public Fbo(FboCallbackHandler handler)
|
public FrameBufferObject(FBOCallbackHandler handler)
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.window = Window.getWindow();
|
this.window = Window.getWindow();
|
|
@ -4,27 +4,27 @@ import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
public class ImageRenderer
|
public class ImageRenderer
|
||||||
{
|
{
|
||||||
private Fbo fbo;
|
private FrameBufferObject frameBufferObject;
|
||||||
|
|
||||||
protected ImageRenderer()
|
protected ImageRenderer()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
protected ImageRenderer(int width, int height)
|
protected ImageRenderer(int width, int height)
|
||||||
{ this.fbo = new Fbo(new ContrastChanger()); }
|
{ this.frameBufferObject = new FrameBufferObject(new ContrastChanger()); }
|
||||||
|
|
||||||
protected void cleanUp()
|
protected void cleanUp()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
protected int getOutputTexture()
|
protected int getOutputTexture()
|
||||||
{ return fbo.colorTexture; }
|
{ return frameBufferObject.colorTexture; }
|
||||||
|
|
||||||
protected void renderQuad()
|
protected void renderQuad()
|
||||||
{
|
{
|
||||||
if (fbo != null)
|
if (frameBufferObject != null)
|
||||||
{ fbo.bindFBO(); }
|
{ frameBufferObject.bindFBO(); }
|
||||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||||
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
|
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
|
||||||
if (fbo != null)
|
if (frameBufferObject != null)
|
||||||
{ fbo.unbindFBO(); }
|
{ frameBufferObject.unbindFBO(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.github.hydos.ginger.engine.opengl.api;
|
package com.github.hydos.ginger.engine.opengl.utils;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.font.TextMaster;
|
import com.github.hydos.ginger.engine.common.font.TextMaster;
|
||||||
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
|
import com.github.hydos.ginger.engine.common.obj.ModelLoader;
|
||||||
|
@ -7,7 +7,7 @@ import com.github.hydos.ginger.engine.opengl.render.MasterRenderer;
|
||||||
import com.github.hydos.ginger.engine.opengl.render.models.*;
|
import com.github.hydos.ginger.engine.opengl.render.models.*;
|
||||||
import com.github.hydos.ginger.engine.opengl.render.texture.ModelTexture;
|
import com.github.hydos.ginger.engine.opengl.render.texture.ModelTexture;
|
||||||
|
|
||||||
public class GingerUtils
|
public class GLUtils
|
||||||
{
|
{
|
||||||
public static GLTexturedModel createTexturedModel(String texturePath, String modelPath)
|
public static GLTexturedModel createTexturedModel(String texturePath, String modelPath)
|
||||||
{
|
{
|
|
@ -1,18 +1,17 @@
|
||||||
package com.github.hydos.ginger.engine.vulkan.api;
|
package com.github.hydos.ginger.engine.vulkan.api;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.vulkan.io.VkWindow;
|
|
||||||
|
import com.github.hydos.ginger.engine.vulkan.io.VKWindow;
|
||||||
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
|
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
|
||||||
|
|
||||||
public class GingerVK
|
public class GingerVK
|
||||||
{
|
{
|
||||||
|
public void start(String gameName)
|
||||||
public void start(String gameName) {
|
{
|
||||||
System.out.println("Game " + gameName + " successfuly started in Vulkan mode.");
|
System.out.println("Game " + gameName + " successfuly started in Vulkan mode.");
|
||||||
VKUtils.createInstance();
|
VKUtils.createInstance();
|
||||||
VkWindow.createSurface();
|
VKWindow.createSurface();
|
||||||
VKUtils.createPhysicalDevice();
|
VKUtils.createPhysicalDevice();
|
||||||
VKUtils.createLogicalDevice();
|
VKUtils.createLogicalDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,13 @@ import org.lwjgl.vulkan.VK12;
|
||||||
|
|
||||||
import com.github.hydos.ginger.engine.common.io.Window;
|
import com.github.hydos.ginger.engine.common.io.Window;
|
||||||
import com.github.hydos.ginger.engine.vulkan.VKConstants;
|
import com.github.hydos.ginger.engine.vulkan.VKConstants;
|
||||||
import com.github.hydos.ginger.engine.vulkan.utils.VKUtils;
|
import com.github.hydos.ginger.engine.vulkan.utils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used for window related vulkan only things
|
* used for window related vulkan only things
|
||||||
* @author hydos
|
* @author hydos
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class VkWindow
|
public class VKWindow
|
||||||
{
|
{
|
||||||
public static void createSurface()
|
public static void createSurface()
|
||||||
{
|
{
|
Loading…
Reference in New Issue