Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---Game.java---
- package com.yaakov.mars;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.assets.AssetManager;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.g3d.ModelBatch;
- import com.badlogic.gdx.graphics.g3d.Environment;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.PerspectiveCamera;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.VertexAttributes.Usage;
- import com.badlogic.gdx.graphics.g3d.Material;
- import com.badlogic.gdx.graphics.g3d.Model;
- import com.badlogic.gdx.graphics.g3d.ModelInstance;
- import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
- import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
- import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
- import com.badlogic.gdx.math.Vector3;
- import com.yaakov.mars.Martian;
- import com.yaakov.mars.Render;
- public class Game extends ApplicationAdapter{
- PerspectiveCamera camera;
- AssetManager assetManager;
- Render render;
- ModelBuilder modelBuilder;
- ModelBatch batch;
- Model box;
- ModelInstance boxInstance;
- Environment environment;
- Material material;
- @Override
- public void create(){
- batch = new ModelBatch();
- //assetManager = new AssetManager();
- render = new Render();
- modelBuilder = new ModelBuilder();
- //assetManager.load("badlogic.jpg", Texture.class);
- render.load("badlogic.jpg", Texture.class);
- while(!render.update()){
- float progress = assetManager.getProgress();
- System.out.println(progress);
- }
- //Texture texture = assetManager.get("badlogic.jpg", Texture.class);
- material = new Material(TextureAttribute.createDiffuse(texture));
- box = modelBuilder.createBox(2f, 2f, 2f, material, Usage.Position|Usage.Normal|Usage.TextureCoordinates);
- boxInstance = new ModelInstance(box, 0.f, 0.f, 0.f);
- environment = new Environment();
- environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));
- //environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1.f, -0.8f, -0.2f));
- camera = new PerspectiveCamera(75, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- camera.position.set(0.f, 0.f, 3.f);
- camera.lookAt(0.f, 0.f, 0.f);;
- camera.near = 0.1f;
- camera.far = 300.f;
- }
- @Override
- public void dispose(){
- box.dispose();
- batch.dispose();
- }
- @Override
- public void render() {
- Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- Gdx.gl.glClearColor(1, 1, 1, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT|GL20.GL_DEPTH_BUFFER_BIT);
- camera.rotateAround(Vector3.Zero, new Vector3(0.f, 1.f, 0.f), 1.f);
- camera.update();
- batch.begin(camera);
- batch.render(boxInstance, environment);
- batch.end();
- }
- @Override
- public void resize(int width, int height){
- }
- @Override
- public void pause(){
- }
- @Override
- public void resume(){
- }
- }
- --Render.java--
- package com.yaakov.mars;
- import com.badlogic.gdx.assets.AssetManager;
- public class Render{
- private AssetManager manager;
- public void load(String fileName, Class<Object> type){
- manager.load(fileName, type);
- }
- public void get(String fileName, Class<Object> type){
- manager.get(fileName, type);
- }
- public boolean update(){
- return manager.update();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement