Back to project page Gallery97.
The source code is released under:
GNU General Public License
If you think the Android project Gallery97 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package pl.kacprzak.klub97; /*from w w w . ja v a2 s.c o m*/ import android.util.Log; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.PerspectiveCamera; import com.badlogic.gdx.graphics.g3d.Environment; import com.badlogic.gdx.graphics.g3d.ModelBatch; import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight; import com.badlogic.gdx.graphics.g3d.environment.PointLight; import com.badlogic.gdx.math.Matrix4; public class MieszkanieScreen extends AbstractScreen { public ModelBatch modelBatch; public Environment environment; public PerspectiveCamera cam; static final float ALPHA = 0.2f; Matrix4 rotationMatrix; float[] init = {-6, 19, -3.5f}; float[] s = {0,0}; public MieszkanieScreen(MieszkanieStart game) { super(game); Log.e("my log", "Mieszkanie screen created."); rotationMatrix = new Matrix4(); modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); environment.add(new PointLight().set(0.8f, 0.8f, 0.8f, 0f, 0f, 0f, 1f)); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0.0f, 0.0f, 0.0f); cam.near = 0.1f; cam.far = 300f; cam.update(); } @Override public void dispose() { game.model.dispose(); modelBatch.dispose(); game.manager.dispose(); } @Override public void hide() { } @Override public void pause() { } @Override public void render(float deltaR) { Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); // Matrix4 matrix = new Matrix4(); // Gdx.input.getRotationMatrix(rotationMatrix.val); // Gdx.input.getRotationMatrix(matrix.val); // for(int i = 0; i<rotationMatrix.val.length; i++){ // rotationMatrix.val[i] = lowPass(matrix.val[i], rotationMatrix.val[i]); // } // s = InputListener.s; for(int j=0; j<InputListener.rotMatrix.length; j++){ rotationMatrix.val[j] = InputListener.rotMatrix[j]; } if(game.instance != null){ modelBatch.begin(cam); if(collision(init[0]+s[0]+InputListener.ds[0]*deltaR,init[1]+s[1]+InputListener.ds[1]*deltaR)){ s[0] = s[0]; s[1] = s[1]; //Log.e("col", "col true "+(init[0]+s[0])+" "+(init[1]+s[1])); }else{ s[0] += InputListener.ds[0]*deltaR; s[1] += InputListener.ds[1]*deltaR; //Log.v("col", "col false "+(init[0]+s[0]+InputListener.ds[0]*deltaR)+" "+(init[1]+s[1]+InputListener.ds[1]*deltaR)); } //rotationMatrix.translate(s[0],s[1],s[2]); rotationMatrix.translate(init[0]+s[0],init[1]+s[1],init[2]); game.instance.transform = rotationMatrix; modelBatch.render(game.instance, environment); modelBatch.end(); } } private boolean collision(float x, float y) { if(x > -1 || x < -15 || y < 1 || y > 22) return true; if(y < 2.5f && (x < -11 && x > -12)) return true; if((x < -7 && x > -11) && (y > 2.5 && y < 4)) return true; if((y > 4 && y < 5) && (x < -1 && x > -5)) return true; if((x < -10) && (y < 6)) return true; if((x < -6 && x > -5)) return true; return false; } protected float lowPass( float newInput, float oldIntput ) { if (oldIntput == 0) return newInput; return oldIntput + ALPHA * (newInput - oldIntput); } @Override public void resize(int arg0, int arg1) { } @Override public void resume() { } @Override public void show() { } }