Skip to content

Commit

Permalink
Merge pull request #172 from ashqal/dev-m250
Browse files Browse the repository at this point in the history
Dev m250
  • Loading branch information
ashqal authored Jul 2, 2017
2 parents cc6de95 + cce76cc commit 204d10d
Show file tree
Hide file tree
Showing 23 changed files with 361 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onHotspotHit(IMDHotspot hitHotspot, MDRay ray) {
})
.pinchEnabled(true)
.projectionFactory(new CustomProjectionFactory())
.build(R.id.gl_view);
.build(findViewById(R.id.gl_view));
}

private Uri getDrawableUri(@DrawableRes int resId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public abstract class MD360PlayerActivity extends Activity {
private static final SparseArray<String> sProjectionMode = new SparseArray<>();
private static final SparseArray<String> sAntiDistortion = new SparseArray<>();
private static final SparseArray<String> sPitchFilter = new SparseArray<>();
private static final SparseArray<String> sFlingEnabled = new SparseArray<>();

static {
sDisplayMode.put(MDVRLibrary.DISPLAY_MODE_NORMAL,"NORMAL");
Expand Down Expand Up @@ -91,6 +92,9 @@ public abstract class MD360PlayerActivity extends Activity {

sPitchFilter.put(1,"FILTER PITCH");
sPitchFilter.put(0,"FILTER NOP");

sFlingEnabled.put(1, "FLING ENABLED");
sFlingEnabled.put(0, "FLING DISABLED");
}

public static void startVideo(Context context, Uri uri){
Expand Down Expand Up @@ -425,6 +429,17 @@ public float onFilterPitch(float input) {
}
})
.init(R.id.spinner_pitch_filter);

SpinnerHelper.with(this)
.setData(sFlingEnabled)
.setDefault(getVRLibrary().isFlingEnabled() ? 1 : 0)
.setClickHandler(new SpinnerHelper.ClickHandler() {
@Override
public void onSpinnerClicked(int index, int key, String value) {
getVRLibrary().setFlingEnabled(key == 1);
}
})
.init(R.id.spinner_fling_enable);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public MD360Director createDirector(int index) {
})
.projectionFactory(new CustomProjectionFactory())
.barrelDistortionConfig(new BarrelDistortionConfig().setDefaultEnabled(false).setScale(0.95f))
.build(R.id.gl_view);
.build(findViewById(R.id.gl_view));
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_md_using_surface_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@
android:layout_width="100dp"
android:minWidth="100dp"
android:layout_height="wrap_content"/>

<android.support.v7.widget.AppCompatSpinner
android:layout_marginLeft="8dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:id="@+id/spinner_fling_enable"
android:layout_width="100dp"
android:minWidth="100dp"
android:layout_height="wrap_content"/>
</LinearLayout>


Expand Down
34 changes: 21 additions & 13 deletions vrlib/src/main/java/com/asha/vrlib/MD360Director.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,27 @@ private void updateViewMatrixIfNeed(){

if (camera || world){
Matrix.multiplyMM(mViewMatrix, 0, mCameraMatrix, 0, mWorldRotationMatrix, 0);
mViewQuaternion.fromMatrix(mViewMatrix);
float pitch = mViewQuaternion.getPitch();
float yaw = mViewQuaternion.getYaw();
float roll = mViewQuaternion.getRoll();

float filterPitch = mDirectorFilter.onFilterPitch(pitch);
float filterYaw = mDirectorFilter.onFilterYaw(yaw);
float filterRoll = mDirectorFilter.onFilterRoll(roll);

if (pitch != filterPitch || yaw != filterYaw || roll != filterRoll){
mViewQuaternion.setEulerAngles(filterPitch, filterYaw, filterRoll);
mViewQuaternion.toMatrix(mViewMatrix);
}
filterViewMatrix();
}
}

private void filterViewMatrix() {
if (mDirectorFilter == null) {
return;
}

mViewQuaternion.fromMatrix(mViewMatrix);
float pitch = mViewQuaternion.getPitch();
float yaw = mViewQuaternion.getYaw();
float roll = mViewQuaternion.getRoll();

float filterPitch = mDirectorFilter.onFilterPitch(pitch);
float filterYaw = mDirectorFilter.onFilterYaw(yaw);
float filterRoll = mDirectorFilter.onFilterRoll(roll);

if (pitch != filterPitch || yaw != filterYaw || roll != filterRoll){
mViewQuaternion.setEulerAngles(filterPitch, filterYaw, filterRoll);
mViewQuaternion.toMatrix(mViewMatrix);
}
}

Expand Down
69 changes: 68 additions & 1 deletion vrlib/src/main/java/com/asha/vrlib/MDTouchHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.asha.vrlib;

import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;

import com.asha.vrlib.model.MDFlingConfig;
import com.asha.vrlib.model.MDPinchConfig;

import java.util.LinkedList;
Expand All @@ -29,6 +32,10 @@ public class MDTouchHelper {
private float mSensitivity;
private float defaultScale;
private float mGlobalScale;
private ValueAnimator valueAnimator;

private boolean mFlingEnabled;
private MDFlingConfig mFlingConfig;

private static final int MODE_INIT = 0;
private static final int MODE_PINCH = 1;
Expand All @@ -49,13 +56,55 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (mCurrentMode == MODE_PINCH) return false;

if (mAdvanceGestureListener != null)
if (mAdvanceGestureListener != null){
mAdvanceGestureListener.onDrag(distanceX / mGlobalScale, distanceY / mGlobalScale);
}
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (mCurrentMode == MODE_PINCH) return false;
if (!mFlingEnabled) return false;

animStart(velocityX, velocityY);
return true;
}
});
}

private void animCancel(){
if (valueAnimator != null){
valueAnimator.cancel();
}
}

private void animStart(float velocityX, float velocityY) {
animCancel();

PropertyValuesHolder hvx = PropertyValuesHolder.ofFloat("vx", velocityX, 0);
PropertyValuesHolder hvy = PropertyValuesHolder.ofFloat("vy", velocityY, 0);
valueAnimator = ValueAnimator.ofPropertyValuesHolder(hvx, hvy).setDuration(mFlingConfig.getDuring());
valueAnimator.setInterpolator(mFlingConfig.getInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
private long lastTime = 0;

@Override
public void onAnimationUpdate(ValueAnimator animation) {
long now = animation.getCurrentPlayTime();
long dur = (now - lastTime);
float sx = (float) animation.getAnimatedValue("vx") * dur / -1000 * mFlingConfig.getSensitivity();
float sy = (float) animation.getAnimatedValue("vy") * dur / -1000 * mFlingConfig.getSensitivity();
lastTime = now;

if (mAdvanceGestureListener != null){
mAdvanceGestureListener.onDrag(sx / mGlobalScale, sy / mGlobalScale);
}
}
});
valueAnimator.start();
}

public boolean handleTouchEvent(MotionEvent event) {
int action = event.getAction() & MotionEvent.ACTION_MASK;
if(action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
Expand Down Expand Up @@ -89,6 +138,8 @@ public boolean handleTouchEvent(MotionEvent event) {
// mLastMovePoint.set(lineCenter[0], lineCenter[1]);
handlePinch(distance);
}
} else if (action == MotionEvent.ACTION_DOWN){
animCancel();
}

mGestureDetector.onTouchEvent(event);
Expand Down Expand Up @@ -132,6 +183,10 @@ public void setAdvanceGestureListener(MDVRLibrary.IAdvanceGestureListener listen
this.mAdvanceGestureListener = listener;
}

public boolean isPinchEnabled() {
return mPinchEnabled;
}

public void setPinchEnabled(boolean mPinchEnabled) {
this.mPinchEnabled = mPinchEnabled;
}
Expand All @@ -146,6 +201,18 @@ public void setPinchConfig(MDPinchConfig pinchConfig) {
setScaleInner(this.defaultScale);
}

public boolean isFlingEnabled() {
return mFlingEnabled;
}

public void setFlingEnabled(boolean flingEnabled) {
this.mFlingEnabled = flingEnabled;
}

public void setFlingConfig(MDFlingConfig flingConfig) {
this.mFlingConfig = flingConfig;
}

private class PinchInfo{
private float x1;
private float y1;
Expand Down
Loading

0 comments on commit 204d10d

Please sign in to comment.