Created a more efficient rotation function

This commit is contained in:
josua 2019-09-27 12:24:49 +10:00
parent 3a25f34520
commit 90c7707e5a
13 changed files with 55 additions and 30 deletions

View File

@ -86,7 +86,7 @@ public class AudioObject
double z = pos.z;
// Calculate the rotation
Vec2d rotated = MathHelpers.rotate2(new Vec2d(x, y), angle_r);
Vec2d rotated = MathHelpers.rotate2(new Vec2d(x, y), -angle_r);
x = rotated.x;
y = rotated.y;

View File

@ -1,15 +1,6 @@
package shootergame.display;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glLoadMatrixf;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glViewport;
import static org.lwjgl.opengl.GL33.*;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL;

View File

@ -61,6 +61,8 @@ public class DisplayWindow implements IMainloopTask
// Set the window hint
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MAJOR, 3);
GLFW.glfwWindowHint(GLFW.GLFW_VERSION_MINOR, 3);
// Create the window
this.window = GLFW.glfwCreateWindow(this.width, this.height, this.name, monitor, 0);

View File

@ -7,7 +7,6 @@ import shootergame.display.bossbar.IBossBar;
import shootergame.init.Items;
import shootergame.init.Textures;
import shootergame.init.Tiles;
import shootergame.tiles.Tile;
import shootergame.time.GameTimer;
import shootergame.util.gl.texture.TextureReference;
import shootergame.util.math.ItemStack;

View File

@ -39,8 +39,6 @@ public class ParticleBlood extends EntityParticle
// Call super
super.tick(chunk, layer);
Main.player.setHealth(100);
// Move in the velocity and remove some of it
pos.x += velocity.x;
pos.y += velocity.y;

View File

@ -10,7 +10,6 @@ import shootergame.entity.EntityHeight;
import shootergame.entity.EntityInventory;
import shootergame.entity.EntityItem;
import shootergame.entity.EntityVertical;
import shootergame.init.Items;
import shootergame.init.Textures;
import shootergame.inventory.Inventory;
import shootergame.util.gl.GlHelpers;

View File

@ -1,12 +1,20 @@
package shootergame.input;
import java.io.IOException;
import static shootergame.input.GameInput.activateItem_last;
import static shootergame.input.GameInput.activateTile_last;
import static shootergame.input.GameInput.dropItem_last;
import static shootergame.input.GameInput.fireGun;
import static shootergame.input.GameInput.hotbar_l;
import static shootergame.input.GameInput.hotbar_r;
import static shootergame.input.GameInput.moveDown;
import static shootergame.input.GameInput.moveUp;
import static shootergame.input.GameInput.move_last;
import static shootergame.input.GameInput.startButton_last;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import static shootergame.input.GameInput.*;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWJoystickCallbackI;

View File

@ -1,7 +1,27 @@
package shootergame.input;
import static org.lwjgl.glfw.GLFW.*;
import static shootergame.input.GameInput.*;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_3;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_4;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_5;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_6;
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_E;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ENTER;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT_SHIFT;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
import static shootergame.input.GameInput.fireGun;
import static shootergame.input.GameInput.moveDown;
import static shootergame.input.GameInput.moveLeft;
import static shootergame.input.GameInput.moveRight;
import static shootergame.input.GameInput.moveUp;
import static shootergame.input.GameInput.move_last;
import org.lwjgl.glfw.GLFWKeyCallbackI;

View File

@ -1,7 +1,6 @@
package shootergame.input.types;
import shootergame.Main;
import shootergame.menu.MenuGame;
import shootergame.menu.MenuGamePause;
import shootergame.util.math.MathHelpers;

View File

@ -1,7 +1,5 @@
package shootergame.input.types;
import shootergame.Main;
public class InputMenu implements Input
{

View File

@ -2,7 +2,6 @@ package shootergame.time;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import mainloop.task.IMainloopTask;

View File

@ -1,6 +1,6 @@
package shootergame.util.gl;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL33.*;
import shootergame.Main;

View File

@ -84,16 +84,28 @@ public class MathHelpers
else return a;
}
/*
def rotate(point, angle):
angle = angle * (math.pi/180)
s = math.sin(angle)
c = math.cos(angle)
x = point[0] * c - point[1] * s
y = point[0] * s + point[1] * c
return [x, y]
*/
public static Vec2d rotate2(Vec2d pos, double angle)
{
// Get the angle and the distance from the centre to the point
double p_angle = Math.atan2(pos.y, pos.x);
double p_distance = Math.sqrt(pos.y*pos.y + pos.x*pos.x);
// Calculate 2 sin and cos values
double s = Math.sin(angle);
double c = Math.cos(angle);
// Return and calculate the new positions
return new Vec2d(
p_distance * Math.sin(angle + p_angle),
p_distance * Math.cos(angle + p_angle));
pos.x * c - pos.y * s,
pos.x * s + pos.y * c);
}
public static double biggest(double a, double b)