Update references based on merge

This commit is contained in:
Simon Leistikow 2017-12-19 16:28:43 +01:00
parent 055a39cd50
commit fab5bffb7e
4 changed files with 84 additions and 38 deletions

View File

@ -85,7 +85,7 @@ public class MainActivity extends AppCompatActivity {
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
PhotoSphereSurfaceView.USE_TOUCH = !PhotoSphereSurfaceView.USE_TOUCH; sphereFragment.toggleUseTouchInput();
displayUI(false); displayUI(false);
} }
}); });

View File

@ -75,4 +75,8 @@ public class SphereFragment extends ImageFragment implements View.OnTouchListene
} }
surfaceView.setBitmap(bitmap); surfaceView.setBitmap(bitmap);
} }
public void toggleUseTouchInput() {
surfaceView.setUseTouchInput(!surfaceView.getUseTouchInput());
}
} }

View File

@ -94,6 +94,11 @@ public class PhotoSphereParser {
throwIfUnexpectedEOF(i, r.length); throwIfUnexpectedEOF(i, r.length);
int exifLen = integer(r); int exifLen = integer(r);
//Check for broken or unavailable header
if (exifLen <= 1) {
return null;
}
//Skip EXIF header //Skip EXIF header
r = new byte[exifLen - 2]; r = new byte[exifLen - 2];
i = inputStream.read(r); i = inputStream.read(r);

View File

@ -16,15 +16,22 @@ import android.view.MotionEvent;
*/ */
public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEventListener { public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEventListener {
public static boolean USE_TOUCH = false; // TODO: determine dynamically // Decision variable for either using touch or device rotation input.
private boolean useTouchInput = false;
// 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 temporary rotation delta matrix.
private final float tempMatrix [] = new float[16];
// These vectors Are used for ray determination. // These vectors Are used for ray determination.
private final float rayStart [] = new float[4]; private final float rayStart [] = new float[4];
private final float rayDirection [] = new float[4]; private final float rayDirection [] = new float[4];
//
float oldAngleXZ, oldAngleY;
// The renderer used by this view. // The renderer used by this view.
private PhotoSphereRenderer renderer; private PhotoSphereRenderer renderer;
@ -55,12 +62,9 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
if(!USE_TOUCH) if(!useTouchInput)
return true; return true;
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
// 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);
@ -87,15 +91,32 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
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) {
Matrix.translateM(rotationMatrix, 0, px, py, pz);
}
/*
// Calculate angles. // Calculate angles.
//float angleX = (float) Math.toDegrees(Math.atan2(py, px)); float angleY = (float) Math.toDegrees(Math.atan2(pz, px));
//float angleY = (float) Math.toDegrees(Math.acos(pz/Matrix.length(px, py, pz))); float angleXZ = (float) Math.toDegrees(Math.acos(py));
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
oldAngleY = angleY;
oldAngleXZ = angleXZ;
System.arraycopy(getRotationMatrix(), 0, tempMatrix, 0, 16);
break;
case MotionEvent.ACTION_MOVE:
synchronized (rotationMatrix) { synchronized (rotationMatrix) {
Matrix.setLookAtM(rotationMatrix, 0, 0.0f, 0.0f, 0.0f, px, py, pz, 1.0f, 0.0f, 0.0f); 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);
} }
break;
} }
*/
return true; return true;
} }
@ -107,7 +128,7 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
@Override @Override
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
if(USE_TOUCH) if(useTouchInput)
return; return;
synchronized (rotationMatrix) { synchronized (rotationMatrix) {
@ -133,4 +154,20 @@ public class PhotoSphereSurfaceView extends GLSurfaceView implements SensorEvent
public void setBitmap(Bitmap bitmap) { public void setBitmap(Bitmap bitmap) {
renderer.requestBitmapUpload(bitmap); renderer.requestBitmapUpload(bitmap);
} }
/**
* Sets input to be used for transformation calculation.
* @param useTouchInput true, if touch input should be used
*/
public void setUseTouchInput(boolean useTouchInput) {
this.useTouchInput = useTouchInput;
}
/**
* Returns if touch input is used for transformation calculations.
* @return true, if touch input is used, false
*/
public boolean getUseTouchInput() {
return useTouchInput;
}
} }