SortZ est maintenant VRAIMENT compatibles avec les flottants ajout d'ombre sous les sprites

This commit is contained in:
Antoine
2021-06-16 17:29:40 +02:00
parent 6dbfaa6e14
commit 846716db11
5 changed files with 65 additions and 18 deletions

View File

@ -40,7 +40,7 @@ public class UIElementText extends UIDummy{
public void setBackground(Vector3f color){
this.colorBg = color;
this.background = new ObjectGl(this.zPos, objs.size() * 10f, 10f, this.scalingFactor, null, this.colorBg );
this.background = new ObjectGl(this.zPos, objs.size() * 10f, 10f, this.scalingFactor - 0.1f, null, this.colorBg );
engine.add_objectGl(this.background);
}

View File

@ -30,15 +30,15 @@ public class ObjectGl {
/**
* xPos and yPos will stop to be relevant if you use rotate function
*/
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;
protected float xPos;
protected float yPos;
protected float zPos;
protected float xAngle;
protected float yAngle;
protected float zAngle;
protected float width; // To be used in setTextureWrap
protected float height;
protected float scalingFactor;
public boolean useTime;

View File

@ -6,6 +6,9 @@ public class SortZ implements Comparator<ObjectGl>
{
public int compare(ObjectGl a, ObjectGl b)
{
return (int) (a.getZPos() - b.getZPos());
float diff = a.getZPos() - b.getZPos();
if (diff < 0) return -1;
else if (diff > 0) return 1;
else return 0;
}
}

View File

@ -1,11 +1,42 @@
package engine.object;
import engine.math.Matrix4f;
import engine.math.Vector3f;
public class Sprite extends ObjectGl {
private ObjectGl shadow;
public Sprite(float z, float size, String tex, Vector3f color) {
super(z, 1f, 1f, size, tex, color);
this.shadow = null;
}
/**
* Move the object according to vec, direction can change if rotation method have been used
* @param vec Vector3f
*/
public void translate(Vector3f vec){
this.xPos += vec.x;
this.yPos += vec.y;
this.zPos += vec.z;
Vector3f vecTemp = vec.divXYZ(this.scalingFactor);
this.transform = this.transform.multiply(Matrix4f.translate(vecTemp));
if (this.shadow != null){
this.shadow.translate(new Vector3f(vec.x, 0f, 0f));
}
}
/**
* Ajoute une ombre sous le personnage
*/
public void setShadow(){
this.shadow = new ObjectGl(this.zPos, this.width, this.height * 0.3f, this.scalingFactor, "textures/shadow.png", null);
this.shadow.translate(new Vector3f(this.xPos, this.yPos - this.height * 4.3f, -8f)); // 8 ça fait bcp mais y du z-fighting sinon jsp pk
}
public ObjectGl getShadow(){
return this.shadow;
}
}