Back to project page jmini3d.
The source code is released under:
Copyright 2012 Mobialia http://www.mobialia.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to ...
If you think the Android project jmini3d 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 jmini3d; //from www . j av a 2 s . co m public class Camera { public Vector3 position = new Vector3(); public Vector3 target = new Vector3(); public Vector3 upAxis = new Vector3(); private Vector3 vx = new Vector3(); private Vector3 vy = new Vector3(); private Vector3 vz = new Vector3(); private float fovy = 45; private int width = 0; private int height = 0; private float near = 1; private float far = 1000; public float[] perspectiveMatrix = new float[16]; private float[] modelViewMatrix = new float[16]; private boolean needsMatrixUpdate = true; public Camera() { setTarget(0, 0, 0); setUpAxis(0, 0, 1); } public void setPosition(float x, float y, float z) { if (this.position.x != x || this.position.y != y || this.position.z != z) { position.setAll(x, y, z); needsMatrixUpdate = true; } } public void setTarget(float x, float y, float z) { if (this.target.x != x || this.target.y != y || this.target.z != z) { target.setAll(x, y, z); needsMatrixUpdate = true; } } public void setUpAxis(float x, float y, float z) { if (this.upAxis.x != x || this.upAxis.y != y || this.upAxis.z != z) { upAxis.setAll(x, y, z); needsMatrixUpdate = true; } } public void setFovy(float fovy) { if (this.fovy != fovy) { this.fovy = fovy; needsMatrixUpdate = true; } } public void setNear(float near) { if (this.near != near) { this.near = near; needsMatrixUpdate = true; } } public void setFar(float far) { if (this.far != far) { this.far = far; needsMatrixUpdate = true; } } public void setWidth(int width) { if (this.width != width) { this.width = width; needsMatrixUpdate = true; } } public void setHeight(int height) { if (this.height != height) { this.height = height; needsMatrixUpdate = true; } } public Vector3 getPosition() { return position; } public Vector3 getTarget() { return target; } public Vector3 getUpAxis() { return upAxis; } public float getFovy() { return fovy; } public float getFovx() { return (float) (360 / Utils.PI * Math.atan(Math.tan(fovy * Utils.PI / 360) * width / height)); } public float getNear() { return near; } public float getFar() { return far; } public int getWidth() { return width; } public int getHeight() { return height; } public boolean updateMatrices() { if (needsMatrixUpdate) { MatrixUtils.perspective(perspectiveMatrix, fovy, ((float) width) / height, near, far); MatrixUtils.lookAt(modelViewMatrix, position, target, upAxis, vx, vy, vz); MatrixUtils.multiply(perspectiveMatrix, modelViewMatrix, perspectiveMatrix); needsMatrixUpdate = false; return true; } return false; } }