Skip to content

Commit

Permalink
rotate Y support in director.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashqal committed Jun 17, 2016
1 parent d3c898d commit 076acee
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions vrlib/src/main/java/com/asha/vrlib/MD360Director.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class MD360Director {

private float mEyeZ = 0f;
private float mEyeX = 0f;
private float mAngle = 0f;
private float mAngleX = 0f;
private float mAngleY = 0f;
private float mRatio = 0f;
private float mNearScale = 0f;
private float mLookX = 0f;
Expand All @@ -44,7 +45,8 @@ private MD360Director(Builder builder) {
this.mEyeZ = builder.mEyeZ;
this.mRatio = builder.mRatio;
this.mNearScale = builder.mNearScale;
this.mAngle = builder.mAngle;
this.mAngleX = builder.mAngleX;
this.mAngleY = builder.mAngleY;
this.mEyeX = builder.mEyeX;
this.mLookX = builder.mLookX;
initCamera();
Expand Down Expand Up @@ -92,16 +94,17 @@ private void initModel(){
Matrix.setIdentityM(mAccumulatedRotation, 0);
Matrix.setIdentityM(mSensorMatrix, 0);
// Model Matrix
updateModelRotate(mAngle);
updateModelRotateX(mAngleX);
updateModelRotateY(mAngleY);
}

public void shot(MD360Program program) {

Matrix.setIdentityM(mModelMatrix, 0);

Matrix.setIdentityM(mCurrentRotation, 0);
Matrix.rotateM(mCurrentRotation, 0, -mDeltaY, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, -mDeltaX + mAngle, 0.0f, 1.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, -mDeltaY + mAngleY, 1.0f, 0.0f, 0.0f);
Matrix.rotateM(mCurrentRotation, 0, -mDeltaX + mAngleX, 0.0f, 1.0f, 0.0f);
Matrix.multiplyMM(mCurrentRotation, 0, mSensorMatrix, 0, mCurrentRotation, 0);

// set the accumulated rotation to the result.
Expand Down Expand Up @@ -146,8 +149,12 @@ private void updateViewMatrix() {
Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
}

protected void updateModelRotate(float a) {
mAngle = a;
protected void updateModelRotateX(float a) {
mAngleX = a;
}

protected void updateModelRotateY(float a) {
mAngleY = a;
}

protected void updateProjectionNearScale(float scale){
Expand Down Expand Up @@ -175,11 +182,12 @@ public static Builder builder(){

public static class Builder {
private float mEyeZ = 0f;
private float mAngle = 0;
private float mAngleX = 0;
private float mRatio = 1.5f;
private float mNearScale = 1;
private float mEyeX = 0f;
private float mLookX = 0f;
private float mAngleY = 0;

public Builder setLookX(float mLookX) {
this.mLookX = mLookX;
Expand All @@ -196,8 +204,24 @@ public Builder setEyeZ(float mEyeZ) {
return this;
}

public Builder setAngle(float mAngle) {
this.mAngle = mAngle;

/**
* Deprecated since 1.4.0, please use {@link #setAngleX(float)}
* @param a
* @return
*/
@Deprecated
public Builder setAngle(float a) {
return setAngleX(a);
}

public Builder setAngleX(float mAngle) {
this.mAngleX = mAngle;
return this;
}

public Builder setAngleY(float mAngle) {
this.mAngleY = mAngle;
return this;
}

Expand Down

0 comments on commit 076acee

Please sign in to comment.