mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-22 04:12:07 +01:00
Something is broken, but we are not sure and too dizzy to find out :(
This commit is contained in:
parent
42c11c185d
commit
cdda1317a6
2 changed files with 52 additions and 19 deletions
|
@ -57,6 +57,7 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
|
||||||
|
|
||||||
// Store a photoSphereGeometry geometry as framework for the photo texture.
|
// Store a photoSphereGeometry geometry as framework for the photo texture.
|
||||||
private PhotoSphereGeometry photoSphereGeometry = null;
|
private PhotoSphereGeometry photoSphereGeometry = null;
|
||||||
|
public float [] points = new float[4];
|
||||||
|
|
||||||
// Store projection matrix.
|
// Store projection matrix.
|
||||||
private float projectionMatrix[] = new float [16];
|
private float projectionMatrix[] = new float [16];
|
||||||
|
@ -65,7 +66,9 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
|
||||||
private float modelMatrix[] = new float [16];
|
private float modelMatrix[] = new float [16];
|
||||||
|
|
||||||
// Store view matrix.
|
// 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.
|
// Store the model view projection matrix.
|
||||||
private float mvpMatrix [] = new float [32];
|
private float mvpMatrix [] = new float [32];
|
||||||
|
@ -114,8 +117,15 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
|
||||||
if(requestedBitmap != null)
|
if(requestedBitmap != null)
|
||||||
uploadImage();
|
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.
|
// 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, viewMatrix, 0, mvpMatrix, 0);
|
||||||
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, mvpMatrix, 16);
|
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());
|
glDrawElements(GL_TRIANGLES, photoSphereGeometry.getIndexBuffer().capacity(), GL_UNSIGNED_SHORT, photoSphereGeometry.getIndexBuffer());
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
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(textureCoordinatesLocation);
|
||||||
glDisableVertexAttribArray(positionLocation);
|
glDisableVertexAttribArray(positionLocation);
|
||||||
|
|
||||||
|
@ -169,8 +189,8 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
|
||||||
// Set OpenGL state.
|
// Set OpenGL state.
|
||||||
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
//glEnable(GL_CULL_FACE);
|
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
//glEnable(GL_CULL_FACE);
|
||||||
//glFrontFace(GL_CW);
|
//glFrontFace(GL_CW);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
|
@ -181,6 +201,7 @@ public class PhotoSphereRenderer implements GLSurfaceView.Renderer {
|
||||||
glGenTextures(1, textureID, 0);
|
glGenTextures(1, textureID, 0);
|
||||||
|
|
||||||
// Initialize matrices.
|
// Initialize matrices.
|
||||||
|
Matrix.setIdentityM(modelViewMatrix, 0);
|
||||||
Matrix.setRotateM(modelMatrix, 0, 90, 1.0f, 0.0f, 0.0f);
|
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);
|
//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
|
* @param outRayDirection will be filled by the direction of the ray
|
||||||
*/
|
*/
|
||||||
public void getRay(float x, float y, float [] outRayStart, float [] outRayDirection) {
|
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);
|
Matrix.setIdentityM(modelMatrix, 0); // HACK
|
||||||
GLU.gluUnProject(x, y, 1.0f, modelMatrix, 0, projectionMatrix, 0, view, 0, outRayDirection, 0);
|
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 vertexSource The vertex shader source
|
||||||
* @param fragmentSource The fragment shader source
|
* @param fragmentSource The fragment shader source
|
||||||
* @return shader program
|
* @return shader program
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.hardware.SensorManager;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +65,7 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
|
||||||
|
|
||||||
if(!useTouchInput)
|
if(!useTouchInput)
|
||||||
return true;
|
return true;
|
||||||
/*
|
|
||||||
// Retrieve ray in world space.
|
// Retrieve ray in world space.
|
||||||
renderer.getRay(event.getX(), event.getY(), rayStart, rayDirection);
|
renderer.getRay(event.getX(), event.getY(), rayStart, rayDirection);
|
||||||
|
|
||||||
|
@ -80,7 +81,8 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
|
||||||
|
|
||||||
// Since the conditions are
|
// Since the conditions are
|
||||||
if(D < 0) {
|
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);
|
D = (float) Math.sqrt(D);
|
||||||
|
@ -90,12 +92,11 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
|
||||||
float px = rayStart[0] + t*rayDirection[0];
|
float px = rayStart[0] + t*rayDirection[0];
|
||||||
float py = rayStart[1] + t*rayDirection[1];
|
float py = rayStart[1] + t*rayDirection[1];
|
||||||
float pz = rayStart[2] + t*rayDirection[2];
|
float pz = rayStart[2] + t*rayDirection[2];
|
||||||
|
/*
|
||||||
synchronized (rotationMatrix) {
|
renderer.points[0] = px;
|
||||||
Matrix.translateM(rotationMatrix, 0, px, py, pz);
|
renderer.points[1] = py;
|
||||||
}
|
renderer.points[2] = pz;
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
// Calculate angles.
|
// Calculate angles.
|
||||||
float angleY = (float) Math.toDegrees(Math.atan2(pz, px));
|
float angleY = (float) Math.toDegrees(Math.atan2(pz, px));
|
||||||
float angleXZ = (float) Math.toDegrees(Math.acos(py));
|
float angleXZ = (float) Math.toDegrees(Math.acos(py));
|
||||||
|
@ -106,17 +107,22 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
|
||||||
oldAngleXZ = angleXZ;
|
oldAngleXZ = angleXZ;
|
||||||
System.arraycopy(getRotationMatrix(), 0, tempMatrix, 0, 16);
|
System.arraycopy(getRotationMatrix(), 0, tempMatrix, 0, 16);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
synchronized (rotationMatrix) {
|
synchronized (rotationMatrix) {
|
||||||
System.arraycopy(tempMatrix, 0, rotationMatrix, 0, 16);
|
System.arraycopy(tempMatrix, 0, rotationMatrix, 0, 16);
|
||||||
//Matrix.rotateM(rotationMatrix, 0, oldAngleY-angleY, 0.0f, 1.0f, 0.0f);
|
float[] s = new float[16];
|
||||||
Matrix.rotateM(rotationMatrix, 0, oldAngleXZ-angleXZ, 1.0f, 0.0f, 0.0f);
|
Matrix.setIdentityM(s, 0);
|
||||||
//Matrix.setLookAtM(rotationMatrix, 0, 0.0f, 0.0f, 0.0f, px, py, pz, 1.0f, 0.0f, 0.0f);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +167,11 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
|
||||||
*/
|
*/
|
||||||
public void setUseTouchInput(boolean useTouchInput) {
|
public void setUseTouchInput(boolean useTouchInput) {
|
||||||
this.useTouchInput = useTouchInput;
|
this.useTouchInput = useTouchInput;
|
||||||
|
if(useTouchInput) {
|
||||||
|
synchronized (rotationMatrix) {
|
||||||
|
Matrix.setIdentityM(rotationMatrix, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue