Got a working 3rd person camera, and fixed rendering opaque surfaces.
Created entity renderers.
This commit is contained in:
parent
aa18145fca
commit
ba15449dd5
|
|
@ -2,6 +2,8 @@ package shootergame;
|
||||||
|
|
||||||
import mainloop.manager.MainloopManager;
|
import mainloop.manager.MainloopManager;
|
||||||
import shootergame.display.DisplayWindow;
|
import shootergame.display.DisplayWindow;
|
||||||
|
import shootergame.entity.EntityEventHandler;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
import shootergame.mainloop.MainloopEventHandler;
|
||||||
|
|
||||||
|
|
@ -9,6 +11,7 @@ public class Main
|
||||||
{
|
{
|
||||||
public static MainloopManager mainloop;
|
public static MainloopManager mainloop;
|
||||||
public static DisplayWindow window;
|
public static DisplayWindow window;
|
||||||
|
public static Player player = new Player();
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
|
|
@ -20,9 +23,12 @@ public class Main
|
||||||
window = new DisplayWindow("ShooterGame");
|
window = new DisplayWindow("ShooterGame");
|
||||||
window.init();
|
window.init();
|
||||||
|
|
||||||
// Initialize the textures
|
// Initialise the textures
|
||||||
Textures.initTextures(window);
|
Textures.initTextures(window);
|
||||||
|
|
||||||
|
// Initialise the entities
|
||||||
|
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
|
||||||
|
|
||||||
// Start the mainloop
|
// Start the mainloop
|
||||||
mainloop.start();
|
mainloop.start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package shootergame.display;
|
||||||
|
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
|
public class Camera
|
||||||
|
{
|
||||||
|
public Vec3d pos;
|
||||||
|
public Vec2d angle;
|
||||||
|
|
||||||
|
public Camera(Vec3d pos, Vec2d angle, double distance)
|
||||||
|
{
|
||||||
|
Vec3d p = new Vec3d(pos.x, pos.y+5, pos.z);
|
||||||
|
this.angle = new Vec2d(angle.x, -angle.y);
|
||||||
|
this.pos = pos.subtract(MathHelpers.moveTowards3(
|
||||||
|
10, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,12 +2,23 @@ package shootergame.display;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
|
import org.joml.Matrix4f;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
|
import org.lwjgl.system.MemoryStack;
|
||||||
|
|
||||||
|
import mainloop.task.MainloopTask;
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.display.transparent.TransparentObjects;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
|
import shootergame.init.Entities;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.init.Tiles;
|
import shootergame.init.Tiles;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
public class DisplayRender
|
public class DisplayRender
|
||||||
{
|
{
|
||||||
|
|
@ -15,11 +26,18 @@ public class DisplayRender
|
||||||
{
|
{
|
||||||
// Setup GL and clear the colour
|
// Setup GL and clear the colour
|
||||||
GL.createCapabilities();
|
GL.createCapabilities();
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
|
// Push the matrix
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
|
||||||
// Enable some stuff
|
// Enable some stuff
|
||||||
GlHelpers.enableTexture2d();
|
GlHelpers.enableTexture2d();
|
||||||
|
GlHelpers.enableBlend();
|
||||||
|
GlHelpers.enableAlpha();
|
||||||
|
GlHelpers.enableDepthTest();
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Set the colour to white
|
// Set the colour to white
|
||||||
GlHelpers.color4(1, 1, 1, 1);
|
GlHelpers.color4(1, 1, 1, 1);
|
||||||
|
|
@ -27,9 +45,66 @@ public class DisplayRender
|
||||||
// Bind the texmap
|
// Bind the texmap
|
||||||
Textures.texmap.bindTexture();
|
Textures.texmap.bindTexture();
|
||||||
|
|
||||||
Tiles.GRASS.render(new Vec2i(0, 0));
|
GlHelpers.pushMatrix();
|
||||||
|
|
||||||
|
{
|
||||||
|
// Set matrix mode
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
|
TransparentObjects.clear();
|
||||||
|
|
||||||
|
// Set the colour to white
|
||||||
|
GlHelpers.color4(1, 1, 1, 1);
|
||||||
|
|
||||||
|
// Create a matrix
|
||||||
|
Matrix4f m = new Matrix4f();
|
||||||
|
|
||||||
|
// Set the perspective
|
||||||
|
m.setPerspective((float) Math.toRadians(45.0f), ((float)w)/((float)h), 0.01f, 100.0f);
|
||||||
|
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||||
|
glLoadMatrixf(m.get(stack.mallocFloat(16)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the camera angle
|
||||||
|
m.setLookAt(0.0f, 0.0f, 10.0f,
|
||||||
|
0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
Player player = Main.player;
|
||||||
|
Camera camera = new Camera(new Vec3d(player.pos.x, player.pos.y, 0), new Vec2d(player.angle, 45), 0);
|
||||||
|
|
||||||
|
//GlHelpers.translate(0, 0, -5);
|
||||||
|
GlHelpers.rotate(camera.angle.y, 1, 0, 0);
|
||||||
|
GlHelpers.rotate(camera.angle.x, 0, 0, 1);
|
||||||
|
GlHelpers.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z);
|
||||||
|
|
||||||
|
int c = 20;
|
||||||
|
for(int x=-c;x<c;x++) {
|
||||||
|
for(int y=-c;y<c;y++) {
|
||||||
|
Tiles.GRASS.doRender(new Vec2d(x, y), camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c = 4;
|
||||||
|
for(int x=-c;x<c;x++) {
|
||||||
|
for(int y=-c;y<c;y++) {
|
||||||
|
Tiles.TREE.doRender(new Vec2d(x, y), camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Entity e : Entities.entities) {
|
||||||
|
e.doRender(player.pos, camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
TransparentObjects.render(camera);
|
||||||
|
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
// Unbind the texmap
|
// Unbind the texmap
|
||||||
Textures.texmap.unbindTexture();
|
Textures.texmap.unbindTexture();
|
||||||
|
|
||||||
|
// Pop the matrix
|
||||||
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import java.nio.IntBuffer;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import mainloop.task.IMainloopTask;
|
import mainloop.task.IMainloopTask;
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
|
|
@ -15,6 +14,7 @@ import shootergame.input.KeyCharCallback;
|
||||||
import shootergame.input.MouseButtonCallback;
|
import shootergame.input.MouseButtonCallback;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
import shootergame.mainloop.MainloopEventHandler;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.gl.texture.AnimationEventHandler;
|
||||||
|
|
||||||
public class DisplayWindow implements IMainloopTask
|
public class DisplayWindow implements IMainloopTask
|
||||||
{
|
{
|
||||||
|
|
@ -62,17 +62,18 @@ public class DisplayWindow implements IMainloopTask
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the key handlers
|
// Set the key handlers
|
||||||
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
|
||||||
GLFW.glfwSetCursorPosCallback(this.window, new CursorPosCallback());
|
GLFW.glfwSetCursorPosCallback(this.window, new CursorPosCallback());
|
||||||
GLFW.glfwSetCharCallback(this.window, new KeyCharCallback());
|
GLFW.glfwSetCharCallback(this.window, new KeyCharCallback());
|
||||||
GLFW.glfwSetCursorEnterCallback(this.window, new CursorEnterCallback());
|
GLFW.glfwSetCursorEnterCallback(this.window, new CursorEnterCallback());
|
||||||
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
||||||
|
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
||||||
|
|
||||||
// Show the window
|
// Show the window
|
||||||
GLFW.glfwShowWindow(this.window);
|
GLFW.glfwShowWindow(this.window);
|
||||||
|
|
||||||
// Register the display event loop
|
// Register the display event loop
|
||||||
Main.mainloop.register(this);
|
Main.mainloop.register(this);
|
||||||
|
Main.mainloop.register(AnimationEventHandler.ANIMATION_EVENT_HANDLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render()
|
public void render()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package shootergame.display.transparent;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public interface ITransparentObject
|
||||||
|
{
|
||||||
|
public boolean isOpaqueTile();
|
||||||
|
public void render(Vec2d pos, Camera camera);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package shootergame.display.transparent;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
|
class TransparentObject
|
||||||
|
{
|
||||||
|
double distance;
|
||||||
|
ITransparentObject object;
|
||||||
|
Vec2d pos;
|
||||||
|
|
||||||
|
TransparentObject(ITransparentObject object, Camera camera, Vec2d pos) {
|
||||||
|
this.distance = camera.pos.distance(new Vec3d(pos.x, pos.y, 0));
|
||||||
|
this.object = object;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package shootergame.display.transparent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
|
public class TransparentObjects
|
||||||
|
{
|
||||||
|
private static ArrayList<TransparentObject> objects = new ArrayList<TransparentObject>();
|
||||||
|
|
||||||
|
public static void clear() {
|
||||||
|
objects.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(ITransparentObject object, Camera camera, Vec2d pos)
|
||||||
|
{
|
||||||
|
TransparentObject r_to = new TransparentObject(object, camera, pos);
|
||||||
|
ArrayList<TransparentObject> objects_n = new ArrayList<TransparentObject>();
|
||||||
|
boolean added = false;
|
||||||
|
|
||||||
|
// Loop over the transparent object items
|
||||||
|
for(TransparentObject to : objects)
|
||||||
|
{
|
||||||
|
if(r_to.distance > to.distance && !added) {
|
||||||
|
added = true;
|
||||||
|
objects_n.add(r_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
objects_n.add(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!added) {
|
||||||
|
objects_n.add(r_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
objects = objects_n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void render(Camera camera)
|
||||||
|
{
|
||||||
|
// Loop over the objects and render all of them
|
||||||
|
for(TransparentObject to : objects) {
|
||||||
|
to.object.render(to.pos, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.display.transparent.ITransparentObject;
|
||||||
|
import shootergame.display.transparent.TransparentObjects;
|
||||||
|
import shootergame.init.Entities;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class Entity implements ITransparentObject
|
||||||
|
{
|
||||||
|
public Vec2d pos;
|
||||||
|
public double angle;
|
||||||
|
public boolean opaqueTile = true;
|
||||||
|
|
||||||
|
public Entity(Vec2d pos, double angle)
|
||||||
|
{
|
||||||
|
// Add this entity to the list of entities
|
||||||
|
Entities.entities.add(this);
|
||||||
|
|
||||||
|
// Store the specified values
|
||||||
|
this.angle = angle;
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity() {
|
||||||
|
this(new Vec2d(0, 0), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doRender(Vec2d pos, Camera camera)
|
||||||
|
{
|
||||||
|
if(this.opaqueTile) {
|
||||||
|
TransparentObjects.register(this, camera, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
this.render(pos, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOpaqueTile() {
|
||||||
|
return this.opaqueTile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import shootergame.init.Entities;
|
||||||
|
|
||||||
|
public class EntityEventHandler implements IMainloopTask
|
||||||
|
{
|
||||||
|
public static final EntityEventHandler ENTITY_EVENT_HANDLER = new EntityEventHandler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
// Update each entity
|
||||||
|
for(Entity e : Entities.entities) {
|
||||||
|
e.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.gl.VerticalRender;
|
||||||
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class EntityVertical extends Entity
|
||||||
|
{
|
||||||
|
private TextureReference tex;
|
||||||
|
private double h;
|
||||||
|
|
||||||
|
public EntityVertical(TextureReference tex, double height) {
|
||||||
|
this.tex = tex;
|
||||||
|
this.h = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
super.render(pos, camera);
|
||||||
|
VerticalRender.render(pos, camera, tex, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package shootergame.entity.player;
|
||||||
|
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.entity.EntityVertical;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
|
||||||
|
public class Player extends EntityVertical
|
||||||
|
{
|
||||||
|
public Player() {
|
||||||
|
super(Textures.ENTITY_PLAYER, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean MOVE_FORWARD = false;
|
||||||
|
public boolean MOVE_BACKWARD = false;
|
||||||
|
public boolean MOVE_LEFT = false;
|
||||||
|
public boolean MOVE_RIGHT = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
// Call super
|
||||||
|
super.tick();
|
||||||
|
|
||||||
|
// Rotate left
|
||||||
|
if(MOVE_LEFT) {
|
||||||
|
this.angle -= 1;
|
||||||
|
this.angle %= 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotate right
|
||||||
|
if(MOVE_RIGHT) {
|
||||||
|
this.angle += 1;
|
||||||
|
this.angle %= 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move forward
|
||||||
|
if(MOVE_FORWARD) {
|
||||||
|
Vec2d t = MathHelpers.moveTowards2(0.1, Math.toRadians(angle));
|
||||||
|
pos = new Vec2d(t.x+pos.x, t.y+pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move backward
|
||||||
|
if(MOVE_BACKWARD) {
|
||||||
|
Vec2d t = MathHelpers.moveTowards2(-0.1, Math.toRadians(angle));
|
||||||
|
pos = new Vec2d(t.x+pos.x, t.y+pos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package shootergame.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
|
||||||
|
public class Entities
|
||||||
|
{
|
||||||
|
public static final ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ import org.lwjgl.opengl.GL;
|
||||||
import shootergame.display.DisplayWindow;
|
import shootergame.display.DisplayWindow;
|
||||||
import shootergame.util.gl.texture.TextureMap;
|
import shootergame.util.gl.texture.TextureMap;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
import shootergame.util.gl.texture.TextureReferenceAnimation;
|
import shootergame.util.gl.texture.AnimationReference;
|
||||||
|
|
||||||
public class Textures
|
public class Textures
|
||||||
{
|
{
|
||||||
|
|
@ -21,9 +21,41 @@ public class Textures
|
||||||
texmap.init();
|
texmap.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ArrayList<TextureReferenceAnimation> animations = new ArrayList<TextureReferenceAnimation>();
|
public static final ArrayList<AnimationReference> animations = new ArrayList<AnimationReference>();
|
||||||
|
|
||||||
|
public static final TextureMap texmap = new TextureMap(
|
||||||
|
"/home/josua/eclipse-workspace/ShooterGame/src/shootergame/resources/texmap.png");
|
||||||
|
|
||||||
|
public static final TextureReference TILE_GRASS = texmap.getTextureReference(0, 16, 0, 16);
|
||||||
|
public static final TextureReference TILE_SAND = texmap.getTextureReference(16, 32, 0, 16);
|
||||||
|
public static final TextureReference TILE_STONE = texmap.getTextureReference(32, 48, 0, 16);
|
||||||
|
public static final TextureReference TILE_DIRT = texmap.getTextureReference(48, 64, 0, 16);
|
||||||
|
public static final TextureReference TILE_TREE = texmap.getTextureReference(64, 80, 0, 64);
|
||||||
|
|
||||||
|
// Fire
|
||||||
|
public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 16, 16, 32);
|
||||||
|
public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(16, 32, 16, 32);
|
||||||
|
public static final TextureReference TILE_FIRE_2 = texmap.getTextureReference(32, 48, 16, 32);
|
||||||
|
public static final TextureReference TILE_FIRE_3 = texmap.getTextureReference(48, 64, 16, 32);
|
||||||
|
public static final TextureReference TILE_FIRE = new AnimationReference(
|
||||||
|
8, TILE_FIRE_0, TILE_FIRE_1, TILE_FIRE_2, TILE_FIRE_3);
|
||||||
|
|
||||||
|
// Player
|
||||||
|
public static final TextureReference ENTITY_PLAYER_0 = texmap.getTextureReference(0, 16, 32, 48);
|
||||||
|
public static final TextureReference ENTITY_PLAYER_1 = texmap.getTextureReference(16, 32, 32, 48);
|
||||||
|
public static final TextureReference ENTITY_PLAYER_2 = texmap.getTextureReference(32, 48, 32, 48);
|
||||||
|
public static final TextureReference ENTITY_PLAYER_3 = texmap.getTextureReference(48, 64, 32, 48);
|
||||||
|
public static final TextureReference ENTITY_PLAYER = new AnimationReference(
|
||||||
|
10, ENTITY_PLAYER_0, ENTITY_PLAYER_1, ENTITY_PLAYER_2, ENTITY_PLAYER_3);
|
||||||
|
|
||||||
|
// Zombie
|
||||||
|
public static final TextureReference ENTITY_ZOMBIE_0 = texmap.getTextureReference(0, 16, 48, 64);
|
||||||
|
public static final TextureReference ENTITY_ZOMBIE_1 = texmap.getTextureReference(16, 32, 48, 64);
|
||||||
|
public static final TextureReference ENTITY_ZOMBIE_2 = texmap.getTextureReference(32, 48, 48, 64);
|
||||||
|
public static final TextureReference ENTITY_ZOMBIE_3 = texmap.getTextureReference(48, 64, 48, 64);
|
||||||
|
public static final TextureReference ENTITY_ZOMBIE = new AnimationReference(
|
||||||
|
10, ENTITY_ZOMBIE_0, ENTITY_ZOMBIE_1, ENTITY_ZOMBIE_2, ENTITY_ZOMBIE_3);
|
||||||
|
|
||||||
|
|
||||||
public static final TextureMap texmap = new TextureMap("/home/josua/eclipse-workspace/ShooterGame/src/shootergame/resources/texmap.png");
|
|
||||||
|
|
||||||
public static final TextureReference TILE_GRASS = texmap.getTextureReference(0, 0, 16, 16);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
package shootergame.init;
|
package shootergame.init;
|
||||||
|
|
||||||
import shootergame.tiles.Tile;
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.tiles.TileDirt;
|
||||||
|
import shootergame.tiles.TileFire;
|
||||||
import shootergame.tiles.TileGrass;
|
import shootergame.tiles.TileGrass;
|
||||||
|
import shootergame.tiles.TileSand;
|
||||||
|
import shootergame.tiles.TileStone;
|
||||||
|
import shootergame.tiles.TileTree;
|
||||||
|
|
||||||
public class Tiles
|
public class Tiles
|
||||||
{
|
{
|
||||||
public static final Tile GRASS = new TileGrass("grass");
|
public static final Tile GRASS = new TileGrass("grass");
|
||||||
|
public static final Tile FIRE = new TileFire("fire");
|
||||||
|
public static final Tile SAND = new TileSand("sand");
|
||||||
|
public static final Tile STONE = new TileStone("stone");
|
||||||
|
public static final Tile DIRT = new TileDirt("dirt");
|
||||||
|
public static final Tile TREE = new TileTree("tree");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,41 @@
|
||||||
package shootergame.input;
|
package shootergame.input;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
|
||||||
public class KeyCallback implements GLFWKeyCallbackI
|
public class KeyCallback implements GLFWKeyCallbackI
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long arg0, int arg1, int arg2, int arg3, int arg4) {
|
public void invoke(long window, int key, int scancode, int action, int mods)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
|
|
||||||
|
boolean pressed = ! ( action == GLFW_RELEASE );
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_W) {
|
||||||
|
Main.player.MOVE_FORWARD = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_S) {
|
||||||
|
Main.player.MOVE_BACKWARD = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_A) {
|
||||||
|
Main.player.MOVE_LEFT = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_D) {
|
||||||
|
Main.player.MOVE_RIGHT = pressed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 672 B After Width: | Height: | Size: 8.0 KiB |
|
|
@ -1,10 +1,16 @@
|
||||||
package shootergame.tiles;
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.display.transparent.ITransparentObject;
|
||||||
|
import shootergame.display.transparent.TransparentObjects;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
|
||||||
public class Tile
|
public class Tile implements ITransparentObject
|
||||||
{
|
{
|
||||||
private String id;
|
private String id;
|
||||||
|
public boolean opaqueTile = false;
|
||||||
|
|
||||||
public Tile(String id) {
|
public Tile(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
@ -14,6 +20,23 @@ public class Tile
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Vec2i pos) {
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doRender(Vec2d pos, Camera camera)
|
||||||
|
{
|
||||||
|
if(this.opaqueTile) {
|
||||||
|
TransparentObjects.register(this, camera, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
this.render(pos, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOpaqueTile() {
|
||||||
|
return this.opaqueTile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class TileDirt extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileDirt(String id) {
|
||||||
|
super(id, Textures.TILE_DIRT);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class TileFire extends TileVertical
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileFire(String id) {
|
||||||
|
super(id, Textures.TILE_FIRE, 6);
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
this.opaqueTile = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package shootergame.tiles;
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
public class TileFlat extends Tile
|
public class TileFlat extends Tile
|
||||||
{
|
{
|
||||||
|
|
@ -14,17 +18,17 @@ public class TileFlat extends Tile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2i pos)
|
public void render(Vec2d pos, Camera camera)
|
||||||
{
|
{
|
||||||
// Call super
|
// Call super
|
||||||
super.render(pos);
|
super.render(pos, camera);
|
||||||
|
|
||||||
// Render the tile
|
// Render the tile
|
||||||
GlHelpers.begin();
|
GlHelpers.begin();
|
||||||
tex.texCoord(0, 0); GlHelpers.vertex2(pos.x+0, pos.y+0);
|
tex.texCoord(1, 1); GlHelpers.vertex3(pos.x+0, pos.y+0, 0);
|
||||||
tex.texCoord(1, 0); GlHelpers.vertex2(pos.x+1, pos.y+0);
|
tex.texCoord(0, 1); GlHelpers.vertex3(pos.x+1, pos.y+0, 0);
|
||||||
tex.texCoord(1, 1); GlHelpers.vertex2(pos.x+1, pos.y+1);
|
tex.texCoord(0, 0); GlHelpers.vertex3(pos.x+1, pos.y+1, 0);
|
||||||
tex.texCoord(0, 1); GlHelpers.vertex2(pos.x+0, pos.y+1);
|
tex.texCoord(1, 0); GlHelpers.vertex3(pos.x+0, pos.y+1, 0);
|
||||||
GlHelpers.end();
|
GlHelpers.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class TileSand extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileSand(String id) {
|
||||||
|
super(id, Textures.TILE_SAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class TileStone extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileStone(String id) {
|
||||||
|
super(id, Textures.TILE_STONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class TileTree extends TileVertical
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileTree(String id) {
|
||||||
|
super(id, Textures.TILE_TREE, 4);
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
this.opaqueTile = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.gl.VerticalRender;
|
||||||
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
|
||||||
|
public class TileVertical extends Tile
|
||||||
|
{
|
||||||
|
private TextureReference tex;
|
||||||
|
private int h;
|
||||||
|
|
||||||
|
public TileVertical(String id, TextureReference tex, int height) {
|
||||||
|
super(id);
|
||||||
|
|
||||||
|
// Store some variables
|
||||||
|
this.tex = tex;
|
||||||
|
this.h = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
super.render(pos, camera);
|
||||||
|
VerticalRender.render(pos, camera, tex, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -25,11 +25,11 @@ public class GlHelpers
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void vertex3(float x, float y, float z) {
|
public static void vertex3(float x, float y, float z) {
|
||||||
glVertex3f(x, y, z);
|
glVertex3f(x/10, y/10, z/10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void vertex2(float x, float y) {
|
public static void vertex2(float x, float y) {
|
||||||
glVertex2f(x/Main.window.getWidth()*100, y/Main.window.getHeight()*100);
|
glVertex2f(x/10, y/10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void color3(float r, float g, float b) {
|
public static void color3(float r, float g, float b) {
|
||||||
|
|
@ -45,7 +45,7 @@ public class GlHelpers
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void translate(float x, float y, float z) {
|
public static void translate(float x, float y, float z) {
|
||||||
glTranslatef(x, y, z);
|
glTranslatef(x/10, y/10, z/10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disableCullFace() {
|
public static void disableCullFace() {
|
||||||
|
|
@ -105,4 +105,12 @@ public class GlHelpers
|
||||||
public static void rotate(double a, float x, float y, float z) {
|
public static void rotate(double a, float x, float y, float z) {
|
||||||
rotate((float)a, x, y, z);
|
rotate((float)a, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void vertex3(double x, double y, double z) {
|
||||||
|
vertex3((float)x, (float)y, (float)z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void vertex2(double x, double y) {
|
||||||
|
vertex2((float)x, (float)y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package shootergame.util.gl;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.player.Player;
|
||||||
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class VerticalRender
|
||||||
|
{
|
||||||
|
public static void render(Vec2d pos, Camera camera, TextureReference tex, double height)
|
||||||
|
{
|
||||||
|
double h = height;
|
||||||
|
|
||||||
|
// Push the matrix
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
|
||||||
|
// Get the angle between the camera and the tile
|
||||||
|
double angle_r = Math.atan2(pos.y - camera.pos.y, pos.x - camera.pos.x);
|
||||||
|
|
||||||
|
// Make the tile upright
|
||||||
|
GlHelpers.translate(0.5, 0, 0);
|
||||||
|
GlHelpers.translate(pos.x, pos.y, 0);
|
||||||
|
GlHelpers.rotate(Math.toDegrees(angle_r)+90, 0, 0, 1);
|
||||||
|
GlHelpers.translate(-0.5, 0, 0);
|
||||||
|
|
||||||
|
// Render the tile
|
||||||
|
GlHelpers.begin();
|
||||||
|
tex.texCoord(1, 1); GlHelpers.vertex3(0, 0, 0);
|
||||||
|
tex.texCoord(0, 1); GlHelpers.vertex3(1, 0, 0);
|
||||||
|
tex.texCoord(0, 0); GlHelpers.vertex3(1, 0, h);
|
||||||
|
tex.texCoord(1, 0); GlHelpers.vertex3(0, 0, h);
|
||||||
|
GlHelpers.end();
|
||||||
|
|
||||||
|
// Pop the matrix
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package shootergame.util.gl.texture;
|
||||||
|
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import mainloop.task.MainloopTask;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class AnimationEventHandler implements IMainloopTask
|
||||||
|
{
|
||||||
|
public static final AnimationEventHandler ANIMATION_EVENT_HANDLER = new AnimationEventHandler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
// Loop over the animations and update them all
|
||||||
|
for(AnimationReference r : Textures.animations) {
|
||||||
|
r.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package shootergame.util.gl.texture;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class AnimationReference extends TextureReference
|
||||||
|
{
|
||||||
|
private TextureReference[] references;
|
||||||
|
private int upto = 0;
|
||||||
|
private int speed;
|
||||||
|
private TextureReference c;
|
||||||
|
|
||||||
|
public AnimationReference(int speed, TextureReference ... references)
|
||||||
|
{
|
||||||
|
// Store the texture references and the speed
|
||||||
|
this.references = references;
|
||||||
|
this.speed = speed;
|
||||||
|
|
||||||
|
// Register the animation
|
||||||
|
Textures.animations.add(this);
|
||||||
|
c = references[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void texCoord(float x, float y) {
|
||||||
|
c.texCoord(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
// Cycle through all the textures
|
||||||
|
upto += 1;
|
||||||
|
upto %= references.length * speed;
|
||||||
|
c = references[upto / speed];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxX() {
|
||||||
|
return c.getMaxX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxY() {
|
||||||
|
return c.getMaxY();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -37,8 +37,8 @@ public class TextureMap
|
||||||
//texture.free();
|
//texture.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureReference getTextureReference(int start_x, int start_y, int end_x, int end_y) {
|
public TextureReference getTextureReference(int start_x, int end_x, int start_y, int end_y) {
|
||||||
return new TextureReference(start_x, start_y, end_x, end_y)
|
return new TextureReference(start_x, end_x, start_y, end_y)
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package shootergame.util.gl.texture;
|
|
||||||
|
|
||||||
public abstract class TextureReferenceAnimation extends TextureReference
|
|
||||||
{
|
|
||||||
private TextureReference[] references;
|
|
||||||
private int upto = 0;
|
|
||||||
|
|
||||||
public TextureReferenceAnimation(TextureReference[] references)
|
|
||||||
{
|
|
||||||
this.references = references;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void texCoord(float x, float y) {
|
|
||||||
references[upto].texCoord(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick()
|
|
||||||
{
|
|
||||||
// Cycle through all the textures
|
|
||||||
upto += 1;
|
|
||||||
upto %= references.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package shootergame.util.math;
|
package shootergame.util.math;
|
||||||
|
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
public class MathHelpers
|
public class MathHelpers
|
||||||
{
|
{
|
||||||
|
|
@ -32,6 +33,21 @@ public class MathHelpers
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec2d moveTowards2(double amount, double angle) {
|
public static Vec2d moveTowards2(double amount, double angle) {
|
||||||
return new Vec2d(Math.sin(angle), Math.cos(angle));
|
return new Vec2d(Math.sin(angle)*amount, Math.cos(angle)*amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vec3d moveTowards3(double amount, Vec2d angles)
|
||||||
|
{
|
||||||
|
// Create some varibles
|
||||||
|
Vec3d points = new Vec3d(0, 0, 0);
|
||||||
|
double m;
|
||||||
|
|
||||||
|
points.z = Math.sin(angles.y) * amount;
|
||||||
|
m = Math.cos(angles.y);
|
||||||
|
points.x = Math.sin(angles.x) * m * amount;
|
||||||
|
m = Math.cos(angles.x) * m;
|
||||||
|
points.y = m * amount;
|
||||||
|
|
||||||
|
return points;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,20 @@ public class Vec2d
|
||||||
public boolean equal(Vec2d other) {
|
public boolean equal(Vec2d other) {
|
||||||
return x == other.x && y == other.y;
|
return x == other.x && y == other.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec2d add(Vec2d other) {
|
||||||
|
return new Vec2d(this.x + other.x, this.y + other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec2d subtract(Vec2d other) {
|
||||||
|
return new Vec2d(this.x - other.x, this.y - other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec2d multiply(Vec2d other) {
|
||||||
|
return new Vec2d(this.x * other.x, this.y * other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec2d divide(Vec2d other) {
|
||||||
|
return new Vec2d(this.x / other.x, this.y / other.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,4 +47,20 @@ public class Vec2i
|
||||||
public boolean equal(Vec2i other) {
|
public boolean equal(Vec2i other) {
|
||||||
return x == other.x && y == other.y;
|
return x == other.x && y == other.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec2i add(Vec2i other) {
|
||||||
|
return new Vec2i(this.x + other.x, this.y + other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec2i subtract(Vec2i other) {
|
||||||
|
return new Vec2i(this.x - other.x, this.y - other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec2i multiply(Vec2i other) {
|
||||||
|
return new Vec2i(this.x * other.x, this.y * other.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec2i divide(Vec2i other) {
|
||||||
|
return new Vec2i(this.x / other.x, this.y / other.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,20 @@ public class Vec3d
|
||||||
public boolean equal(Vec3d other) {
|
public boolean equal(Vec3d other) {
|
||||||
return x == other.x && y == other.y && z == other.z;
|
return x == other.x && y == other.y && z == other.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec3d add(Vec3d other) {
|
||||||
|
return new Vec3d(this.x + other.x, this.y + other.y, this.z + other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3d subtract(Vec3d other) {
|
||||||
|
return new Vec3d(this.x - other.x, this.y - other.y, this.z - other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3d multiply(Vec3d other) {
|
||||||
|
return new Vec3d(this.x * other.x, this.y * other.y, this.z * other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3d divide(Vec3d other) {
|
||||||
|
return new Vec3d(this.x / other.x, this.y / other.y, this.z / other.z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,4 +54,20 @@ public class Vec3i
|
||||||
public boolean equal(Vec3i other) {
|
public boolean equal(Vec3i other) {
|
||||||
return x == other.x && y == other.y && z == other.z;
|
return x == other.x && y == other.y && z == other.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec3i add(Vec3i other) {
|
||||||
|
return new Vec3i(this.x + other.x, this.y + other.y, this.z + other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3i subtract(Vec3i other) {
|
||||||
|
return new Vec3i(this.x - other.x, this.y - other.y, this.z - other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3i multiply(Vec3i other) {
|
||||||
|
return new Vec3i(this.x * other.x, this.y * other.y, this.z * other.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3i divide(Vec3i other) {
|
||||||
|
return new Vec3i(this.x / other.x, this.y / other.y, this.z / other.z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue