Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slerped head tracking for RajawaliVRRenderer.java to remove sensor jitter. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions RajawaliVR/src/rajawali/vr/RajawaliVRRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ public class RajawaliVRRenderer extends RajawaliSideBySideRenderer {
protected HeadTransform mHeadTransform;
protected float[] mHeadViewMatrix;
protected Matrix4 mHeadViewMatrix4;
private Quaternion mCameraOrientation;
protected Quaternion cam1, cam2;

public RajawaliVRRenderer(Context context) {
super(context);
mHeadTransform = new HeadTransform();
mHeadViewMatrix = new float[16];
mHeadViewMatrix4 = new Matrix4();
mCameraOrientation = new Quaternion();
cam1 = new Quaternion();
cam2 = new Quaternion();
}

@Override
Expand All @@ -38,11 +39,13 @@ public void onRender(double deltaTime) {
mHeadTracker.getLastHeadView(mHeadViewMatrix, 0);
mHeadViewMatrix4.setAll(mHeadViewMatrix);

mCameraOrientation.fromMatrix(mHeadViewMatrix4);
mCameraOrientation.x *= -1;
mCameraOrientation.y *= -1;
mCameraOrientation.z *= -1;
setCameraOrientation(mCameraOrientation);
cam1.fromMatrix(mHeadViewMatrix4);
cam1.x *= -1;
cam1.y *= -1;
cam1.z *= -1;

cam2.slerp(cam1, .3);
setCameraOrientation(cam2);
super.onRender(deltaTime);
}
}