dynamic scaling vertexArray with textureWrap (no more stretching)

This commit is contained in:
Antoine
2021-05-20 23:28:45 +02:00
parent bdc2144145
commit e3623072ff
6 changed files with 39 additions and 16 deletions

View File

@ -21,14 +21,17 @@ public class ObjectGl {
public float zPos;
public float width;
public float height;
public float scalingFactor;
public ObjectGl(){
}
public ObjectGl(float x, float y, float z, float h, float w){
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);
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1f));
this.scalingFactor = size;
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
this.zPos = z;
this.width = w;
@ -40,11 +43,18 @@ public class ObjectGl {
}
public void translate(Vector3f vec){
vec.divXY(this.scalingFactor);
this.transform = this.transform.multiply(Matrix4f.translate(vec));
this.zPos += vec.z;
}
/**
* Comme on foncitonne avec des sprite 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
*/
public void scale(Vector3f vec){
this.scalingFactor *= vec.x;
this.transform = this.transform.multiply(Matrix4f.scale(vec));
}

View File

@ -4,12 +4,15 @@ 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[] color) {
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;
this.width = w;

View File

@ -3,6 +3,7 @@ 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;
@ -15,10 +16,12 @@ public class ObjectGlTex extends ObjectGl{
}
public ObjectGlTex(float x, float y, float z, float h, float w, List<String> texPath, float[] texCoord) {
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.width = w;
@ -36,6 +39,7 @@ public class ObjectGlTex extends ObjectGl{
}
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;
@ -48,7 +52,6 @@ public class ObjectGlTex extends ObjectGl{
x + w , y + h ,
x , y + h ,
};
// TODO scaling object
this.setTextureWrap(result);
}

View File

@ -4,15 +4,18 @@ 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, List<String> texPath, float[] texCoord, float[] color) {
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.width = w;