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

Add method to set near and far clip. #86

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions Assets/Cardboard/Scripts/CardboardLensDistortion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static class CardboardLensDistortion

private static CardboardMesh leftEyeMesh;
private static CardboardMesh rightEyeMesh;
private static float eyeNearClip = 0.1f;
private static float eyeFarClip = 1000f;

private static float[] projectionMatrixLeft;
private static float[] projectionMatrixRight;
Expand Down Expand Up @@ -87,7 +89,8 @@ private static CardboardUv CardboardLensDistortion_undistortedUvForDistortedUv(
private static void CardboardLensDistortion_getProjectionMatrix(IntPtr lens_Distortion, CardboardEye eye,
float z_near, float z_far, float[] projection_matrix)
{
CardboardUtility.Matrix4x4ToArray(Matrix4x4.Perspective(70, 0.8f, 0.5f, 1000)).CopyTo(projection_matrix, 0);
CardboardUtility.Matrix4x4ToArray(
Matrix4x4.Perspective(70, 0.8f, z_near, z_far)).CopyTo(projection_matrix, 0);
}

private static void CardboardLensDistortion_getEyeFromHeadMatrix(IntPtr lens_Distortion, CardboardEye eye,
Expand Down Expand Up @@ -133,15 +136,21 @@ public static (CardboardMesh, CardboardMesh) GetEyeMeshes()
return (leftEyeMesh, rightEyeMesh);
}

public static void SetCamClip(float newNear, float newFar)
{
eyeNearClip = newNear;
eyeFarClip = newFar;
}

public static void RefreshProjectionMatrix()
{
projectionMatrixLeft = new float[16];
eyeFromHeadMatrixLeft = new float[16];
projectionMatrixRight = new float[16];
eyeFromHeadMatrixRight = new float[16];
CardboardLensDistortion_getProjectionMatrix(_lensDistortion, CardboardEye.kLeft, 0.1f, 100f,
CardboardLensDistortion_getProjectionMatrix(_lensDistortion, CardboardEye.kLeft, eyeNearClip, eyeFarClip,
projectionMatrixLeft);
CardboardLensDistortion_getProjectionMatrix(_lensDistortion, CardboardEye.kRight, 0.1f, 100f,
CardboardLensDistortion_getProjectionMatrix(_lensDistortion, CardboardEye.kRight, eyeNearClip, eyeFarClip,
projectionMatrixRight);

CardboardLensDistortion_getEyeFromHeadMatrix(_lensDistortion, CardboardEye.kLeft, eyeFromHeadMatrixLeft);
Expand Down
7 changes: 7 additions & 0 deletions Assets/Cardboard/Scripts/CardboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public static void SetCardboardProfile(string url)
CardboardQrCode.SetCardboardProfile(url);
}

public static void SetCameraNearFarClip(float newNearClip, float newFarClip)
{
CardboardLensDistortion.SetCamClip(newNearClip, newFarClip);
if (initiated)
RefreshParameters();
}

//This method will set cardbaord profile ONLY when cardboard qr has not yet been scanned by camera.
//This behaviour is the same as the legacy cardboard gvr_set_default_viewer_profile
public static void SetCardboardInitialProfile(string url)
Expand Down
Loading