Première implémentation du tracking d'un personnage

This commit is contained in:
Antoine 2021-06-02 22:12:57 +02:00
parent 48c0a66f11
commit 9a93fafd0d
3 changed files with 35 additions and 25 deletions

View File

@ -26,7 +26,8 @@ public class Engine {
private final int width;
private final int height;
private float aspectRatio;
private float viewXPos;
/**
* Create the engine and initial attributes use .init() to start the engine
@ -36,9 +37,9 @@ public class Engine {
this.objectsGl = new ArrayList<>();
this.width = width;
this.height = height;
this.aspectRatio = aspectRatio;
ObjectGl.projection = Matrix4f.orthographic(-1000, 1000, -1000 * aspectRatio, 1000 * aspectRatio, 0.1f, 100.0f);
ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f, 0.0f, 1.0f));
this.viewXPos = 0.0f;
}
/**
@ -121,7 +122,6 @@ public class Engine {
/**
* Add obj to the render queue
*
* @param obj ObjectGl to render
*/
public void add_objectGl(ObjectGl obj) {
@ -132,6 +132,11 @@ public class Engine {
objectsGl.remove(obj);
}
public void translateView(Vector3f vec){
ObjectGl.view = ObjectGl.view.multiply(Matrix4f.translate(vec));
viewXPos += vec.x;
}
public static void correctViewport(int width, int height){
int heightViewport, widthViewport, x, y;
if (width >= height * 4.0f/3.0f){
@ -207,20 +212,23 @@ public class Engine {
// Add objects to render
String path = "textures/zangief_sprite.png";
String path2 = "textures/awesomeface.png";
String pathToBG = "textures/background_beach.png";
ObjectGl zangief = new ObjectGl(0f, 60f, 80f, 10f, path, null);
zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.STICK_TOP);
ObjectGl zangief = new ObjectGl(10.0f, 1f, 1f, 10f, path, null);
zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT);
engine.add_objectGl(zangief);
zangief.translate(new Vector3f(-5000.0f, 500.0f, 10.0f));
zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f));
zangief.useTime = true;
zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/FlashFrag.glsl");
zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f));
ObjectGl smiley2 = new ObjectGl(0.0f, 500.0f, 500.0f, 1f, path2, null);
engine.add_objectGl(smiley2);
smiley2.translate(new Vector3f(0.0f, 0.0f, 5.0f));
smiley2.translate(new Vector3f(0.0f, 0.0f, 15.0f));
//Create background
ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null);
background.setTextureWrap(0,0,621, 224, ObjectGl.DEFAULT);
background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f));
engine.add_objectGl(background);
long timer = System.currentTimeMillis();
long lastFrame;
@ -241,9 +249,6 @@ public class Engine {
List<Integer> listJump = new ArrayList<>();
listJump.add(InputConst.buttonA);
jump = new Button("jump", listJump, gamepad1);
}
@ -254,9 +259,6 @@ public class Engine {
if (Joystick1Present) {
gamepad1.inputRefresh();
// System.out.println(gamepad1.getAxisDiscreet(GLFW_GAMEPAD_AXIS_LEFT_X));
// Check si le personnage a sauté
if (jump.isButtonPressed()){
// Le personnage saute
@ -264,8 +266,12 @@ public class Engine {
}
}
KeyboardInput.keyboardInput(zangief, speed);
// input(smiley2, speed); //Code pas à jour
KeyboardInput.keyboardInput(zangief, speed);
Vector3f vecTransView = new Vector3f((-zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f);
engine.translateView(vecTransView);
System.out.println(zangief.getXPos());
System.out.println(engine.viewXPos);
/*
********************

View File

@ -94,14 +94,15 @@ public class KeyboardInput extends GLFWKeyCallback {
keyPressed = true;
} else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) {
keyPressed = true;
token.scale(new Vector3f(1.001f,1.001f,1.0f));
}
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) {
token.translate(new Vector3f (speed * -5.0f, 0.0f, 0.0f));
token.translate(new Vector3f (speed * -1.0f, 0.0f, 0.0f));
token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP);
keyPressed = true;
}
else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_D)) {
token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
token.translate(new Vector3f (speed * 1.0f, 0.0f, 0.0f));
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
keyPressed = true;
}

View File

@ -34,6 +34,9 @@ public class ObjectGl {
private float xPos;
private float yPos;
private float zPos;
private float xAngle;
private float yAngle;
private float zAngle;
private float width; // To be used in setTextureWrap
private float height;
private float scalingFactor;
@ -75,9 +78,9 @@ public class ObjectGl {
this.vertexArray = new VertexArray(Primitive.createRectangle(this.zPos, this.width, this.height), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
this.scalingFactor = size;
this.scalingFactor = 1;
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1f));
this.scale(new Vector3f(size, size,1.0f));
this.stick_state = DEFAULT;
this.useTime = false;
@ -110,11 +113,11 @@ public class ObjectGl {
* @param vec Vector3f
*/
public void translate(Vector3f vec){
vec.divXY(this.scalingFactor);
this.transform = this.transform.multiply(Matrix4f.translate(vec));
this.xPos += vec.x;
this.yPos += vec.y;
this.zPos += vec.z;
vec.divXY(this.scalingFactor);
this.transform = this.transform.multiply(Matrix4f.translate(vec));
}
/**