Something is broken, but we are not sure and too dizzy to find out :(

bugfix
Paul Schaub 5 years ago
parent 42c11c185d
commit cdda1317a6
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
  1. 34
      app/src/main/java/de/trac/spherical/rendering/PhotoSphereRenderer.java
  2. 37
      app/src/main/java/de/trac/spherical/rendering/PhotoSphereSurfaceView.java

@ -57,6 +57,7 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
// Store a photoSphereGeometry geometry as framework for the photo texture.
private PhotoSphereGeometry photoSphereGeometry = null;
public float [] points = new float[4];
// Store projection matrix.
private float projectionMatrix[] = new float [16];
@ -65,7 +66,9 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
private float modelMatrix[] = new float [16];
// Store view matrix.
// private float viewMatrix [] = new float [16];
private float viewMatrix [] = new float [16];
private float modelViewMatrix [] = new float[16];
// Store the model view projection matrix.
private float mvpMatrix [] = new float [32];
@ -114,8 +117,15 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
if(requestedBitmap != null)
uploadImage();
// DEBUG - BEGIN
Matrix.setRotateM(modelMatrix, 0, 90, 1.0f, 0.0f, 0.0f);
System.arraycopy(surfaceView.getRotationMatrix(), 0, viewMatrix, 0, 16);
Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0);
Matrix.scaleM(modelViewMatrix, 0, -1, -1, -1);
// DEBUG - END
// Update transformation matrix.
Matrix.multiplyMM(mvpMatrix, 16, surfaceView.getRotationMatrix(), 0, modelMatrix, 0);
Matrix.multiplyMM(mvpMatrix, 16, viewMatrix, 0, modelMatrix, 0);
//Matrix.multiplyMM(mvpMatrix, 0, viewMatrix, 0, mvpMatrix, 0);
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, mvpMatrix, 16);
@ -135,6 +145,16 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
glDrawElements(GL_TRIANGLES, photoSphereGeometry.getIndexBuffer().capacity(), GL_UNSIGNED_SHORT, photoSphereGeometry.getIndexBuffer());
glBindTexture(GL_TEXTURE_2D, 0);
// DEBUG - BEGIN
//Matrix.multiplyMV(res, 0, viewMatrix, 0, points, 0);
Matrix.translateM(modelMatrix, 0, points[0], points[1], points[2]);
Matrix.scaleM(modelMatrix, 0, 0.1f, 0.1f, 0.1f);
Matrix.multiplyMM(mvpMatrix, 16, viewMatrix, 0, modelMatrix, 0);
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, mvpMatrix, 16);
glUniformMatrix4fv(mvpLocation, 1, false, mvpMatrix, 0);
glDrawElements(GL_TRIANGLES, photoSphereGeometry.getIndexBuffer().capacity(), GL_UNSIGNED_SHORT, photoSphereGeometry.getIndexBuffer());
// DEBUG - END
glDisableVertexAttribArray(textureCoordinatesLocation);
glDisableVertexAttribArray(positionLocation);
@ -169,8 +189,8 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
// Set OpenGL state.
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
glDisable(GL_CULL_FACE);
//glEnable(GL_CULL_FACE);
//glFrontFace(GL_CW);
glActiveTexture(GL_TEXTURE0);
@ -181,6 +201,7 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
glGenTextures(1, textureID, 0);
// Initialize matrices.
Matrix.setIdentityM(modelViewMatrix, 0);
Matrix.setRotateM(modelMatrix, 0, 90, 1.0f, 0.0f, 0.0f);
//Matrix.setLookAtM(viewMatrix, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
}
@ -236,12 +257,13 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
* @param outRayDirection will be filled by the direction of the ray
*/
public void getRay(float x, float y, float [] outRayStart, float [] outRayDirection) {
GLU.gluUnProject(x, y, 0.0f, modelMatrix, 0, projectionMatrix, 0, view, 0, outRayStart, 0);
GLU.gluUnProject(x, y, 1.0f, modelMatrix, 0, projectionMatrix, 0, view, 0, outRayDirection, 0);
Matrix.setIdentityM(modelMatrix, 0); // HACK
GLU.gluUnProject(x, view[3] - y - 1, 0.0f, modelMatrix, 0, projectionMatrix, 0, view, 0, outRayStart, 0);
GLU.gluUnProject(x, view[3] - y - 1, 1.0f, modelMatrix, 0, projectionMatrix, 0, view, 0, outRayDirection, 0);
}
/**
* Builds a shader program given vertex and fragment shader soruce.
* Builds a shader program given vertex and fragment shader source.
* @param vertexSource The vertex shader source
* @param fragmentSource The fragment shader source
* @return shader program

@ -9,6 +9,7 @@ import android.hardware.SensorManager;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Build;
import android.util.Log;
import android.view.MotionEvent;
/**
@ -64,7 +65,7 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
if(!useTouchInput)
return true;
/*
// Retrieve ray in world space.
renderer.getRay(event.getX(), event.getY(), rayStart, rayDirection);
@ -80,7 +81,8 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
// Since the conditions are
if(D < 0) {
throw new RuntimeException("Ray must intersect with sphere, check camera position");
D = -D;
//throw new RuntimeException("Ray must intersect with sphere, check camera position");
}
D = (float) Math.sqrt(D);
@ -90,12 +92,11 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
float px = rayStart[0] + t*rayDirection[0];
float py = rayStart[1] + t*rayDirection[1];
float pz = rayStart[2] + t*rayDirection[2];
synchronized (rotationMatrix) {
Matrix.translateM(rotationMatrix, 0, px, py, pz);
}
*/
/*
/*
renderer.points[0] = px;
renderer.points[1] = py;
renderer.points[2] = pz;
*/
// Calculate angles.
float angleY = (float) Math.toDegrees(Math.atan2(pz, px));
float angleXZ = (float) Math.toDegrees(Math.acos(py));
@ -106,17 +107,22 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
oldAngleXZ = angleXZ;
System.arraycopy(getRotationMatrix(), 0, tempMatrix, 0, 16);
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_MOVE:
synchronized (rotationMatrix) {
System.arraycopy(tempMatrix, 0, rotationMatrix, 0, 16);
//Matrix.rotateM(rotationMatrix, 0, oldAngleY-angleY, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(rotationMatrix, 0, oldAngleXZ-angleXZ, 1.0f, 0.0f, 0.0f);
//Matrix.setLookAtM(rotationMatrix, 0, 0.0f, 0.0f, 0.0f, px, py, pz, 1.0f, 0.0f, 0.0f);
float[] s = new float[16];
Matrix.setIdentityM(s, 0);
Matrix.rotateM(s, 0, oldAngleY + angleY, 0, 1 ,0);
Matrix.rotateM(s, 0, oldAngleXZ + angleXZ, 1, 0, 1);
System.arraycopy(s, 0, rotationMatrix, 0, 16);
//Matrix.rotateM(rotationMatrix, 0, (oldAngleY-angleY), px, 0.0f, pz);
//Matrix.rotateM(rotationMatrix, 0, oldAngleXZ-angleXZ, 0.0f, 1.0f, 0.0f);
//Matrix.setLookAtM(rotationMatrix, 0, 0.0f, 0.0f, 0.0f, , py, 0, 1.0f, 0.0f, 0.0f);
}
break;
}
*/
return true;
}
@ -161,6 +167,11 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
*/
public void setUseTouchInput(boolean useTouchInput) {
this.useTouchInput = useTouchInput;
if(useTouchInput) {
synchronized (rotationMatrix) {
Matrix.setIdentityM(rotationMatrix, 0);
}
}
}
/**

Loading…
Cancel
Save