Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / views / Renderer.java
NoranekoFelician on 12 Nov 2 KB Portをクリックし、判別します
package gameEngine.views;

import org.joml.Vector3f;

import static org.lwjgl.opengl.GL11.*;

public abstract class Renderer {
    public Vector3f position = new Vector3f(0, 0, 0);
    public Vector3f rotation = new Vector3f(0, 0, 0);
    public Vector3f scale = new Vector3f(1, 1, 1);
    public Color color = new Color(1f, 1f, 1f, 1f);

    public void setPosition(float x, float y){
        this.position.x = x;
        this.position.y = y;
    }

    public void setPosition(float x, float y, float z){
        this.position = new Vector3f(x,y,z);
    }

    public void setPosition(Vector3f pos){
        this.position = pos;
    }

    public void setRotation(float x, float y, float z){
        this.rotation = new Vector3f(x,y,z);
    }

    public void setRotation(Vector3f rot){
        this.rotation = rot;
    }

    public void setScale(float x, float y){
        this.scale.x = x;
        this.scale.y = y;
    }

    public void setScale(float x, float y, float z){
        this.scale = new Vector3f(x,y,z);
    }

    public void setScale(Vector3f scale){
        this.scale = scale;
    }

    protected void prepareRendering() {
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glOrtho(0, Window.get().width, Window.get().height, 0, -1000, 1000);

        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();

        float zScale = (position.z >= 0) ? 1.0f + (position.z * 0.1f) : 1.0f / (1.0f + Math.abs(position.z) * 0.1f);
        glTranslatef(position.x, position.y, position.z);
        glRotatef(rotation.x, 1, 0, 0);
        glRotatef(rotation.y, 0, 1, 0);
        glRotatef(rotation.z, 0, 0, 1);
        glScalef(scale.x * zScale, scale.y * zScale, scale.z);

        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glColor4f(color.r, color.g, color.b, color.a);
    }

    protected void endRendering() {
        glDisable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 0);

        glPopMatrix();
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
    }

    public abstract void render();
}