mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-24 13:22:08 +01:00
Fix rotation and other minor problems
This commit is contained in:
parent
e222a1812b
commit
395c82f341
2 changed files with 15 additions and 31 deletions
|
@ -103,6 +103,7 @@ public class Renderer implements GLSurfaceView.Renderer {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
|
GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
// Release bitmap for garbage collection.
|
// Release bitmap for garbage collection.
|
||||||
bitmap = null;
|
bitmap = null;
|
||||||
|
@ -124,16 +125,14 @@ public class Renderer implements GLSurfaceView.Renderer {
|
||||||
|
|
||||||
glUniformMatrix4fv(mvpLocation, 1, false, mvpMatrix, 0);
|
glUniformMatrix4fv(mvpLocation, 1, false, mvpMatrix, 0);
|
||||||
glUniform1i(texLocation, 0);
|
glUniform1i(texLocation, 0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, textureID[0]);
|
||||||
glDrawElements(GL_TRIANGLES, sphere.getIndexBuffer().capacity(), GL_UNSIGNED_SHORT, sphere.getIndexBuffer());
|
glDrawElements(GL_TRIANGLES, sphere.getIndexBuffer().capacity(), GL_UNSIGNED_SHORT, sphere.getIndexBuffer());
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
glDisableVertexAttribArray(textureCoordinatesLocation);
|
glDisableVertexAttribArray(textureCoordinatesLocation);
|
||||||
glDisableVertexAttribArray(positionLocation);
|
glDisableVertexAttribArray(positionLocation);
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
|
|
||||||
int error = glGetError();
|
|
||||||
if(error != GL_NO_ERROR)
|
|
||||||
Log.e("Renderer", "Error: " + getEGLErrorString(error));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,28 +155,15 @@ public class Renderer implements GLSurfaceView.Renderer {
|
||||||
* @param config surface configuration
|
* @param config surface configuration
|
||||||
*/
|
*/
|
||||||
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
|
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
|
||||||
initialize();
|
|
||||||
|
|
||||||
//TODO: (re)move tmp code
|
|
||||||
Matrix.setIdentityM(modlMatrix, 0);
|
|
||||||
//Matrix.translateM(modlMatrix, 0, 0, 0, 4.0f);
|
|
||||||
Matrix.setLookAtM(viewMatrix, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize OpenGL state and data.
|
|
||||||
*/
|
|
||||||
public void initialize() {
|
|
||||||
|
|
||||||
// Initialize sphere.
|
// Initialize sphere.
|
||||||
sphere = new Sphere(10.0f, 32, 32); // TODO: choose useful parameters.
|
sphere = new Sphere(10.0f, 32, 32); // TODO: choose useful parameters.
|
||||||
|
|
||||||
// Set OpenGL state.
|
// Set OpenGL state.
|
||||||
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_FRONT);
|
glFrontFace(GL_CW);
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
// Build shader program.
|
// Build shader program.
|
||||||
|
@ -185,15 +171,10 @@ public class Renderer implements GLSurfaceView.Renderer {
|
||||||
|
|
||||||
// Generate texture.
|
// Generate texture.
|
||||||
glGenTextures(1, textureID, 0);
|
glGenTextures(1, textureID, 0);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Initialize matrices.
|
||||||
* Reset OpenGL state and delete data.
|
Matrix.setIdentityM(modlMatrix, 0);
|
||||||
*/
|
Matrix.setLookAtM(viewMatrix, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
|
||||||
public void deinitialize() {
|
|
||||||
sphere = null;
|
|
||||||
glDeleteTextures(1, textureID, 0);
|
|
||||||
glDeleteProgram(programID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,14 +23,14 @@ public class SphereSurfaceView extends GLSurfaceView implements SensorEventListe
|
||||||
// The actual rotation matrix determined by user input.
|
// The actual rotation matrix determined by user input.
|
||||||
private final float rotationMatrix [] = new float[16];
|
private final float rotationMatrix [] = new float[16];
|
||||||
|
|
||||||
// The following fields are used as cache.
|
// This matrix is used to compensate sensor coordinate system rotation.
|
||||||
private final float tmpMatrix[] = new float[9];
|
private final float offsetMatrix [] = new float[16];
|
||||||
private final float tmpVector[] = new float[3];
|
|
||||||
|
|
||||||
public SphereSurfaceView(Context context) {
|
public SphereSurfaceView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
Matrix.setIdentityM(rotationMatrix, 0);
|
Matrix.setIdentityM(rotationMatrix, 0);
|
||||||
|
Matrix.setRotateM(offsetMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ROTATION_VECTOR).get(0);
|
Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ROTATION_VECTOR).get(0);
|
||||||
|
@ -81,7 +81,10 @@ public class SphereSurfaceView extends GLSurfaceView implements SensorEventListe
|
||||||
if(USE_TOUCH)
|
if(USE_TOUCH)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
|
synchronized (rotationMatrix) {
|
||||||
|
SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
|
||||||
|
Matrix.multiplyMM(rotationMatrix, 0, rotationMatrix, 0, offsetMatrix, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue