dynamic scaling vertexArray with textureWrap (no more stretching)
This commit is contained in:
parent
bdc2144145
commit
e3623072ff
@ -159,12 +159,11 @@ public class Engine {
|
||||
List<String> path2 = new ArrayList<>();
|
||||
path2.add("textures/awesomeface.png");
|
||||
|
||||
ObjectGlTex zangief = new ObjectGlTex(0f,0f,0f,400f,900f, path, Primitive.stdTexWrap);
|
||||
ObjectGlTex zangief = new ObjectGlTex(0f,0f,0f,60f,80f,5f, path, Primitive.stdTexWrap);
|
||||
engine.add_objectGl(zangief);
|
||||
zangief.translate(new Vector3f(-600.0f,-100.0f,10.0f));
|
||||
zangief.setTextureWrap(52,2,70,83);
|
||||
// zangief.translate(new Vector3f(-600.0f,100,10.0f));
|
||||
|
||||
ObjectGlTex smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path2, Primitive.stdTexWrap);
|
||||
ObjectGlTex smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, 1f, path2, Primitive.stdTexWrap);
|
||||
engine.add_objectGl(smiley2);
|
||||
smiley2.translate(new Vector3f(0.0f,0.0f,5.0f));
|
||||
float[] texWrap = Primitive.upperHalfTexWrap;
|
||||
@ -208,16 +207,16 @@ public class Engine {
|
||||
}
|
||||
}
|
||||
|
||||
public static void input(ObjectGl token, int speed) {
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_W))token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_A))token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||
}
|
||||
// public static void input(ObjectGl token, int speed) {
|
||||
// if (Input.isKeyDown(GLFW.GLFW_KEY_W))token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
|
||||
// if (Input.isKeyDown(GLFW.GLFW_KEY_A))token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||
// if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f));
|
||||
// if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||
// }
|
||||
|
||||
public static void input(ObjectGlTex token, int speed) {
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_W)) {
|
||||
token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
|
||||
token.scale(new Vector3f (1.01f, 1.01f, 0.0f));
|
||||
}
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_A)) {
|
||||
token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||
|
@ -16,4 +16,9 @@ public class Vector3f {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public void divXY(float div){
|
||||
this.x /= div;
|
||||
this.y /= div;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user