com.github.fauu.helix.core.Object.java Source code

Java tutorial

Introduction

Here is the source code for com.github.fauu.helix.core.Object.java

Source

/*
 * Copyright (C) 2014 Helix Engine Developers (http://github.com/fauu/HelixEngine)
 *
 * This software is licensed under the GNU General Public License
 * (version 3 or later). See the COPYING file in this distribution.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this software. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Piotr Grabowski <fau999@gmail.com>
 */

package com.github.fauu.helix.core;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class Object {

    private Vector2 position;
    private int elevation;
    private String modelName;
    private ModelInstance modelInstance;
    private Direction facing;
    private boolean visible = true;

    public Object(Vector2 position, String modelName, Model model, int elevation, Direction facing) {
        this.position = position;
        this.elevation = elevation;
        this.modelInstance = new ModelInstance(model);
        this.modelName = modelName;
        this.facing = facing;

        modelInstance.transform.setToTranslation(position.x, elevation, position.y + 1).rotate(new Vector3(0, 1, 0),
                -90);

        final TextureAttribute textureAttribute = (TextureAttribute) modelInstance.materials.first()
                .get(TextureAttribute.Diffuse);
        textureAttribute.textureDescription.magFilter = Texture.TextureFilter.Nearest;
        textureAttribute.textureDescription.minFilter = Texture.TextureFilter.Nearest;
        modelInstance.materials.first().set(textureAttribute);

        modelInstance.materials.first().set(new ColorAttribute(ColorAttribute.createDiffuse(Color.WHITE)));
        modelInstance.materials.first().set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
        //modelInstance.materials.first().set(new FloatAttribute(FloatAttribute.AlphaTest, 0.14f));
    }

    public Vector2 getPosition() {
        return position;
    }

    public int getElevation() {
        return elevation;
    }

    public String getModelName() {
        return modelName;
    }

    public Direction getFacing() {
        return facing;
    }

    public ModelInstance getModelInstance() {
        return modelInstance;
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

}