Doc d'ObjectGl dans un Anglais approximatif

This commit is contained in:
Antoine 2021-05-21 21:01:42 +02:00
parent 574e31e02d
commit ee8473e344
3 changed files with 60 additions and 26 deletions

View File

@ -139,7 +139,7 @@ public class Engine {
}
/**
* Est appelé à chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu
* Est appelé àa chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu
* pour quelle corresponde à la taille de la fenêtre
*/
private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback(){

View File

@ -1,14 +1,7 @@
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;
import engine.graphics.*;
import engine.math.*;
/**
*
@ -19,28 +12,29 @@ public class ObjectGl {
protected Shader shader;
protected Matrix4f transform;
/**
* Projection and view matrix are set by the engine do not modify
*/
public static Matrix4f projection;
public static Matrix4f view;
public float zPos;
public float scalingFactor;
private float zPos;
private float width; // To be used in setTextureWrap
private float height;
private float scalingFactor;
private Texture texture;
public ObjectGl(){
}
/**
* Create a rectangle shape, use setTextureWrap to correctly align the texture with the model
* @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 w height of the rectangle
* @param h 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){
public ObjectGl(float z, float w, float h, float size, String tex, Vector3f color){
float[] colorBuffer = null;
// Check des options
if (color != null){
@ -56,10 +50,12 @@ public class ObjectGl {
this.texture = new Texture(tex, 0);
}
this.vertexArray = new VertexArray(Primitive.createRectangle(z, h, w), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
this.vertexArray = new VertexArray(Primitive.createRectangle(z, w, h), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
this.scalingFactor = size;
this.zPos = z;
this.height = h;
this.width = w;
this.scalingFactor = size;
this.transform = Matrix4f.identity();
this.scale(new Vector3f(size, size,1f));
@ -75,10 +71,19 @@ public class ObjectGl {
}
}
/**
* Reset the transform matrix, the model will appear at the 0.0.0 coordinate, his scaleFactor will be set to zero
* Because the model is at position 0 on the z axis he will not show up on screen
*/
public void resetTransform(){
this.transform = Matrix4f.identity();
this.scalingFactor = 1;
}
/**
* Move the object according to vec, direction can change if rotation method have been used
* @param vec Vector3f
*/
public void translate(Vector3f vec){
vec.divXY(this.scalingFactor);
this.transform = this.transform.multiply(Matrix4f.translate(vec));
@ -86,33 +91,55 @@ public class ObjectGl {
}
/**
* 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 le vecteur de transformation
* Scale the model with the vec vector, the x component is used to mitigate size modification in the behavior of other transformation method
* @param vec Vector3f
*/
public void scale(Vector3f vec){
this.scalingFactor *= vec.x;
this.transform = this.transform.multiply(Matrix4f.scale(vec));
}
/**
* rotate the model by angle degree on the local x axis, beware this will change the behavior of the translate method
* @param angle in degree
*/
public void rotateX(float angle){
this.transform = this.transform.multiply(Matrix4f.rotateX(angle));
}
/**
* rotate the model by angle degree on the local y axis, beware this will change the behavior of the translate method
* @param angle in degree
*/
public void rotateY(float angle){
this.transform = this.transform.multiply(Matrix4f.rotateY(angle));
}
/**
* rotate the model by angle degree on the local z axis, beware this will change the behavior of the translate method
* @param angle in degree
*/
public void rotateZ(float angle){
this.transform = this.transform.multiply(Matrix4f.rotateZ(angle));
}
/**
* Set a new texture to be used on the model. You may need to use setTextureWrap tp get the correct wrap
* @param texPath path to the new texture
*/
public void setTexture(String texPath){
this.texture = new Texture(texPath, 0);
}
/**
* Change the wrapping coordinate
* @param x starting wrapping on the horizontal axis
* @param y starting wrapping on the vertical axis
* @param w the length of the wrapping on the horizontal axis
* @param h the length of the wrapping on the vertical axis
*/
public void setTextureWrap(float x, float y, float w, float h){
// TODO set sticky property
// TODO set sticky property + precision issue
this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(this.zPos, w, h));
int texWidth = this.texture.getWidth();
int texHeight = this.texture.getHeight();
@ -133,6 +160,13 @@ public class ObjectGl {
this.vertexArray.swapTextureBufferObject(texture);
}
public float getZPos(){
return zPos;
}
/**
* Do shader binding, texture binding and vertexArray drawing
*/
public void render(){
this.shader.enable();
if (this.texture != null) this.texture.bind();

View File

@ -6,6 +6,6 @@ public class SortZ implements Comparator<ObjectGl>
{
public int compare(ObjectGl a, ObjectGl b)
{
return (int) (a.zPos - b.zPos);
return (int) (a.getZPos() - b.getZPos());
}
}