hid player and first person camera

pull/7/head
hYdos 2020-02-26 07:06:05 +10:00
parent 97f7d48b64
commit 183a71fbd8
8 changed files with 36 additions and 34 deletions

View File

@ -3,7 +3,7 @@ package com.github.hydos.ginger;
import com.github.halotroop.litecraft.world.*; import com.github.halotroop.litecraft.world.*;
import com.github.hydos.ginger.engine.api.*; import com.github.hydos.ginger.engine.api.*;
import com.github.hydos.ginger.engine.api.game.*; import com.github.hydos.ginger.engine.api.game.*;
import com.github.hydos.ginger.engine.cameras.Camera; import com.github.hydos.ginger.engine.cameras.*;
import com.github.hydos.ginger.engine.elements.buttons.TextureButton; import com.github.hydos.ginger.engine.elements.buttons.TextureButton;
import com.github.hydos.ginger.engine.elements.objects.*; import com.github.hydos.ginger.engine.elements.objects.*;
import com.github.hydos.ginger.engine.font.*; import com.github.hydos.ginger.engine.font.*;
@ -38,7 +38,10 @@ public class Litecraft extends Game
TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/soil/gravel.png"); TexturedModel dirtModel = ModelLoader.loadGenericCube("block/cubes/soil/gravel.png");
StaticCube.scaleCube(1); StaticCube.scaleCube(1);
Player player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f)); Player player = new Player(dirtModel, new Vector3f(0, 0, -3), 0, 180f, 0, new Vector3f(0.2f, 0.2f, 0.2f));
Camera camera = new Camera(new Vector3f(0, 0.1f, 0), player); Camera camera = new FirstPersonCamera(player);
player.isVisible = false;
ginger3D = new Ginger(); ginger3D = new Ginger();
data = new GameData(player, camera, 30); data = new GameData(player, camera, 30);
data.handleGuis = false; data.handleGuis = false;
@ -55,7 +58,7 @@ public class Litecraft extends Game
FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt"); FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt");
ginger3D.setGlobalFont(font); ginger3D.setGlobalFont(font);
GUIText titleText = ginger3D.registerText("LiteCraft", 3, new Vector2f(0, 0), 1f, true, "PLAYBUTTON"); GUIText titleText = ginger3D.registerText("LiteCraft PRE-ALPHA build 1", 3, new Vector2f(0, 0), 1f, true, "PLAYBUTTON");
titleText.setBorderWidth(0.5f); titleText.setBorderWidth(0.5f);
Light sun = new Light(new Vector3f(100, 105, -100), new Vector3f(1.3f, 1.3f, 1.3f), new Vector3f(0.0001f, 0.0001f, 0.0001f)); Light sun = new Light(new Vector3f(100, 105, -100), new Vector3f(1.3f, 1.3f, 1.3f), new Vector3f(0.0001f, 0.0001f, 0.0001f));

View File

@ -12,6 +12,7 @@ import com.github.hydos.ginger.engine.particle.ParticleMaster;
import com.github.hydos.ginger.engine.postprocessing.*; import com.github.hydos.ginger.engine.postprocessing.*;
import com.github.hydos.ginger.engine.render.MasterRenderer; import com.github.hydos.ginger.engine.render.MasterRenderer;
import com.github.hydos.ginger.engine.render.tools.MousePicker; import com.github.hydos.ginger.engine.render.tools.MousePicker;
import com.github.hydos.ginger.engine.screen.Screen;
import com.github.hydos.ginger.engine.utils.Loader; import com.github.hydos.ginger.engine.utils.Loader;
public class Ginger public class Ginger
@ -38,6 +39,11 @@ public class Ginger
TextMaster.cleanUp(); TextMaster.cleanUp();
Loader.cleanUp(); Loader.cleanUp();
} }
public void openScreen(Screen screen)
{
}
public void postRender() public void postRender()
{ Window.swapBuffers(); } { Window.swapBuffers(); }

View File

@ -13,7 +13,7 @@ public class Camera
private Vector3f position = new Vector3f(0, 0, 0); private Vector3f position = new Vector3f(0, 0, 0);
private float pitch, yaw; private float pitch, yaw;
private float roll; private float roll;
private Player player; public Player player;
public Camera(Player player) public Camera(Player player)
{ this.player = player; } { this.player = player; }

View File

@ -1,21 +1,18 @@
package com.github.hydos.ginger.engine.cameras; package com.github.hydos.ginger.engine.cameras;
import org.lwjgl.glfw.GLFW; import com.github.hydos.ginger.engine.elements.objects.Player;
import com.github.hydos.ginger.engine.io.Window;
import com.github.hydos.ginger.engine.math.vectors.Vector3f; import com.github.hydos.ginger.engine.math.vectors.Vector3f;
public class FirstPersonCamera public class FirstPersonCamera extends Camera
{ {
private Vector3f position = new Vector3f(0, 0, 0); private Vector3f position = new Vector3f(0, 0, 0);
private float pitch, yaw; private float pitch, yaw;
private float roll; private float roll;
public FirstPersonCamera() public FirstPersonCamera(Player player)
{} {
super(player);
public FirstPersonCamera(Vector3f vector3f) }
{ this.position = vector3f; }
public float getPitch() public float getPitch()
{ return pitch; } { return pitch; }
@ -31,21 +28,13 @@ public class FirstPersonCamera
public void move() public void move()
{ {
if (Window.isKeyDown(GLFW.GLFW_KEY_W)) position.x = player.getPosition().x;
{ position.z -= 0.05f; } position.z = player.getPosition().z;
if (Window.isKeyDown(GLFW.GLFW_KEY_A)) position.y = player.getPosition().y;
{ position.x -= 0.05f; }
if (Window.isKeyDown(GLFW.GLFW_KEY_S)) roll = player.getRotX();
{ position.z -= -0.05f; } yaw = -player.getRotY() + 180;
if (Window.isKeyDown(GLFW.GLFW_KEY_D)) pitch = player.getRotZ();
{ position.x += 0.05f; }
if (Window.isKeyDown(GLFW.GLFW_KEY_SPACE))
{ position.y += 0.05f; }
if (Window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT))
{ position.y -= 0.05f; }
if (Window.isKeyDown(GLFW.GLFW_KEY_LEFT))
{ yaw -= 0.5f; }
if (Window.isKeyDown(GLFW.GLFW_KEY_RIGHT))
{ yaw += 0.5f; }
} }
} }

View File

@ -9,6 +9,7 @@ public class RenderObject
private Vector3f position; private Vector3f position;
private float rotX = 0, rotY = 0, rotZ = 0; private float rotX = 0, rotY = 0, rotZ = 0;
private Vector3f scale; private Vector3f scale;
public boolean isVisible = true;
public RenderObject(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale) public RenderObject(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
{ {

View File

@ -82,7 +82,7 @@ public class Window
public static float getFloatTime() public static float getFloatTime()
{ {
float f = (System.nanoTime() / (float) 1000000000); float f = (System.nanoTime() / (long) 1000000000);
return f; return f;
} }
@ -109,7 +109,7 @@ public class Window
public static double getTime() public static double getTime()
{ {
double f = (double) System.nanoTime() / (double) 1000000000; double f = (double) System.nanoTime() / (long) 1000000000;
return f; return f;
} }

View File

@ -66,8 +66,11 @@ public class ObjectRenderer extends Renderer
List<RenderObject> batch = entities.get(model); List<RenderObject> batch = entities.get(model);
for (RenderObject entity : batch) for (RenderObject entity : batch)
{ {
prepareInstance(entity); if(entity.isVisible) {
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0); prepareInstance(entity);
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
}
} }
unbindTexturedModel(); unbindTexturedModel();
} }

View File

@ -4,6 +4,6 @@ public abstract class Screen
{ {
public abstract void render(); public abstract void render();
public abstract void tick();
} }