J'ai viré les classes useless

This commit is contained in:
Antoine
2021-05-21 19:15:48 +02:00
parent ecbe08fdc3
commit 770d134722
6 changed files with 90 additions and 148 deletions

View File

@ -1,11 +1,15 @@
package engine.object;
import engine.graphics.Texture;
import engine.math.Primitive;
import engine.graphics.VertexArray;
import engine.graphics.Shader;
import engine.math.Matrix4f;
import engine.math.Vector3f;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@ -21,20 +25,54 @@ public class ObjectGl {
public float zPos;
public float scalingFactor;
private Texture texture;
public ObjectGl(){
}
public ObjectGl(float x, float y, float z, float h, float w, float size){
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, null);
/**
* Create a rectangle shape
* @param z depth of your model the larger it is the more it will be "close" to the camera
* @param h height of the rectangle
* @param w width of the rectangle
* @param size scaling factor of the rectangle, the model could not show up because this value is too small or too large, a good compromise is between 2 and 15
* @param tex set to null if you don't want a tex on your model
* @param color set to null if you don't want a Color on your model
*/
public ObjectGl(float z, float h, float w, float size, String tex, Vector3f color){
float[] colorBuffer = null;
// Check des options
if (color != null){
colorBuffer = new float[] {
color.x, color.y, color.z,
color.x, color.y, color.z,
color.x, color.y, color.z,
color.x, color.y, color.z
};
}
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1f));
if (tex != null){
this.texture = new Texture(tex, 0);
}
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
this.vertexArray = new VertexArray(Primitive.createRectangle(z, h, w), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
this.scalingFactor = size;
this.zPos = z;
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1f));
// use different shader for each set of option
if (tex == null && color == null){
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
} else if (tex == null){
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl"); // TODO
} else if (color == null){
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
} else {
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl"); // TODO
}
}
public void resetTransform(){
@ -48,9 +86,9 @@ public class ObjectGl {
}
/**
* Comme on foncitonne avec des sprite on part du principe que x et y sont scale de manière uniforme
* Comme on fonctionne avec des sprites on part du principe que x et y sont scale de manière uniforme
* ou tout du moins que this.scalingFactor corresponds au scaling de x
* @param vec
* @param vec le vecteur de transformation
*/
public void scale(Vector3f vec){
this.scalingFactor *= vec.x;
@ -69,14 +107,42 @@ public class ObjectGl {
this.transform = this.transform.multiply(Matrix4f.rotateZ(angle));
}
public void setTexture(String texPath){
this.texture = new Texture(texPath, 0);
}
public void setTextureWrap(float x, float y, float w, float h){
this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(this.zPos, w, h));
int texWidth = this.texture.getWidth();
int texHeight = this.texture.getHeight();
x /= texWidth;
w /= texWidth;
y /= texHeight;
h /= texHeight;
float[] result = {
x , y ,
x + w , y ,
x + w , y + h ,
x , y + h ,
};
this.setTextureWrap(result);
}
public void setTextureWrap(float[] texture){
this.vertexArray.swapTextureBufferObject(texture);
}
public void render(){
this.shader.enable();
if (this.texture != null) this.texture.bind();
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);
this.shader.setUniformMat4f("transform", this.transform);
this.vertexArray.render();
if (this.texture != null) this.texture.unbind();
this.shader.disable();
}

View File

@ -1,19 +0,0 @@
package engine.object;
import engine.math.Primitive;
import engine.graphics.Shader;
import engine.graphics.VertexArray;
import engine.math.Matrix4f;
import engine.math.Vector3f;
public class ObjectGlColor extends ObjectGl{
public ObjectGlColor(float x, float y, float z, float h, float w, float size, float[] color) {
super();
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, null);
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1));
this.scalingFactor = size;
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
this.zPos = z;
}
}

View File

@ -1,81 +0,0 @@
package engine.object;
import engine.math.Primitive;
import engine.graphics.*;
import engine.math.Matrix4f;
import engine.math.Vector3f;
import java.util.ArrayList;
import java.util.List;
public class ObjectGlTex extends ObjectGl{
protected List<Texture> textures;
public ObjectGlTex(){
}
public ObjectGlTex(float x, float y, float z, float h, float w, float size, List<String> texPath, float[] texCoord) {
super();
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, texCoord);
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1));
this.scalingFactor = size;
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
this.zPos = z;
this.setTexture(texPath);
}
public void setTexture(List<String> texPath){
this.textures = new ArrayList<>();
int count = 0;
for (String path : texPath){
textures.add(new Texture(path, count));
count++;
}
}
public void setTextureWrap(float x, float y, float w, float h){
this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(0.0f,0.0f,this.zPos,w,h));
int texWidth = this.textures.get(0).getWidth();
int texHeight = this.textures.get(0).getHeight();
x /= texWidth;
w /= texWidth;
y /= texHeight;
h /= texHeight;
float[] result = {
x , y ,
x + w , y ,
x + w , y + h ,
x , y + h ,
};
this.setTextureWrap(result);
}
public void setTextureWrap(float[] texture){
this.vertexArray.swapTextureBufferObject(texture);
}
@Override
public void render() {
this.shader.enable();
this.shader.setUniformMat4f("projection", projection);
this.shader.setUniformMat4f("view", view);
this.shader.setUniformMat4f("transform", this.transform);
for (Texture t : textures){
t.bind();
}
this.vertexArray.render();
for (Texture t : textures){
t.unbind();
}
this.shader.disable();
}
}

View File

@ -1,23 +0,0 @@
package engine.object;
import engine.graphics.Shader;
import engine.graphics.VertexArray;
import engine.math.Primitive;
import engine.math.Matrix4f;
import engine.math.Vector3f;
import java.util.List;
public class ObjectGlTexColor extends ObjectGlTex{
public ObjectGlTexColor(float x, float y, float z, float h, float w, float size, List<String> texPath, float[] texCoord, float[] color) {
super();
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, texCoord);
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1));
this.scalingFactor = size;
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
this.zPos = z;
this.setTexture(texPath);
}
}