Entire project

This commit is contained in:
Gnarly Narwhal 2019-03-10 22:34:10 -07:00 committed by Gnarwhal
commit ccbbb0a5b0
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
108 changed files with 2908 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package com.gnarly.engine.rects;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import com.gnarly.engine.display.Camera;
import com.gnarly.engine.shaders.Shader;
import com.gnarly.engine.shaders.Shader2c;
public class ColRect extends Rect {
private Shader2c shader;
private float r, g, b, a;
public ColRect(Camera camera, float x, float y, float depth, float width, float height, float r, float g, float b, float a) {
this.camera = camera;
if(vao == null)
initVao();
position = new Vector3f(x, y, depth);
rotation = 0;
sx = width / dims.x;
sy = height / dims.y;
flipX = 1;
flipY = 1;
shader = Shader.SHADER2C;
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public void render() {
shader.enable();
shader.setProjection(camera.getProjection());
shader.setView(camera.getView());
shader.setModel(new Matrix4f().translate(position).translate(dims.mul(0.5f * sx, 0.5f * sy, 1, new Vector3f())).rotateZ(rotation).scale(sx * flipX, sy * flipY, 1).translate(dims.mul(0.5f, new Vector3f()).negate()));
shader.setColor(r, g, b, a);
vao.render();
shader.disable();
}
}

View file

@ -0,0 +1,84 @@
package com.gnarly.engine.rects;
import org.joml.Vector3f;
import com.gnarly.engine.display.Camera;
import com.gnarly.engine.model.Vao;
public abstract class Rect {
protected static final Vector3f dims = new Vector3f(10, 10, 0);
protected static Vao vao = null;
protected Camera camera;
protected Vector3f position;
protected float rotation;
protected float sx, sy;
protected byte flipX, flipY;
protected void initVao() {
float[] vertices = new float[] {
0, 0, 0.0f,
0, dims.y, 0.0f,
dims.x, dims.y, 0.0f,
dims.x, 0, 0.0f
};
int[] indices = new int[] {
0, 1, 3,
3, 1, 2
};
float[] texCoords = new float[] {
0, 0,
0, 1,
1, 1,
1, 0
};
vao = new Vao(vertices, indices);
vao.addAttribute(texCoords, 2);
}
public abstract void render();
public float getX() {
return position.x;
}
public float getY() {
return position.y;
}
public float getWidth() {
return sx * dims.x;
}
public float getHeight() {
return sy * dims.y;
}
public void setRotation(float angle) {
this.rotation = (angle * 3.1415926535f) / 180f;
}
public void setPos(float x, float y) {
this.position.x = x;
this.position.y = y;
}
public void setSize(float width, float height) {
this.sx = width / dims.x;
this.sy = height / dims.y;
}
public void setFlip(int x, int y) {
this.flipX = (byte) x;
this.flipY = (byte) y;
}
public void reset(float x, float y, float width, float height) {
this.position.x = x;
this.position.y = y;
this.sx = width / dims.x;
this.sy = height / dims.y;
}
}

View file

@ -0,0 +1,94 @@
package com.gnarly.engine.rects;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import com.gnarly.engine.display.Camera;
import com.gnarly.engine.shaders.Shader;
import com.gnarly.engine.shaders.Shader2a;
import com.gnarly.engine.texture.Anim;
import com.gnarly.engine.texture.Texture;
public class TexRect extends Rect {
private Camera camera;
private Texture texture;
private Shader shader;
public TexRect(Camera camera, String texPath, float x, float y, float depth, float width, float height) {
this.camera = camera;
if(vao == null)
initVao();
position = new Vector3f(x, y, depth);
rotation = 0;
sx = width / dims.x;
sy = height / dims.y;
flipX = 1;
flipY = 1;
texture = new Texture(texPath);
shader = Shader.SHADER2T;
}
public TexRect(Camera camera, String texPath, int frames, int fps, float x, float y, float depth, float width, float height) {
this.camera = camera;
if(vao == null)
initVao();
position = new Vector3f(x, y, depth);
rotation = 0;
sx = width / dims.x;
sy = height / dims.y;
flipX = 1;
flipY = 1;
texture = new Anim(texPath, frames, fps);
shader = Shader.SHADER2A;
}
public TexRect(Camera camera, Texture texture, float x, float y, float depth, float width, float height) {
this.camera = camera;
if(vao == null)
initVao();
position = new Vector3f(x, y, depth);
rotation = 0;
sx = width / dims.x;
sy = height / dims.y;
flipX = 1;
flipY = 1;
this.texture = texture;
shader = Shader.SHADER2T;
}
public TexRect(Camera camera, Anim anim, float x, float y, float depth, float width, float height) {
this.camera = camera;
if(vao == null)
initVao();
position = new Vector3f(x, y, depth);
rotation = 0;
sx = width / dims.x;
sy = height / dims.y;
flipX = 1;
flipY = 1;
texture = anim;
shader = Shader.SHADER2A;
}
public void render() {
texture.bind();
shader.enable();
shader.setProjection(camera.getProjection());
shader.setView(camera.getView());
shader.setModel(new Matrix4f().translate(position).translate(dims.mul(0.5f * sx, 0.5f * sy, 1, new Vector3f())).rotateZ(rotation).scale(sx * flipX, sy * flipY, 1).translate(dims.mul(0.5f, new Vector3f()).negate()));
if(shader instanceof Shader2a)
((Shader2a) shader).setAnim((Anim) texture);
vao.render();
shader.disable();
texture.unbind();
}
public void pause() {
((Anim) texture).pause();
}
public void setFrame(int frame) {
((Anim) texture).setFrame(frame);
}
}