Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created July 24, 2017 16:52
Show Gist options
  • Save EgorBo/d6113423f8c38a644fca32832b4b69ea to your computer and use it in GitHub Desktop.
Save EgorBo/d6113423f8c38a644fca32832b4b69ea to your computer and use it in GitHub Desktop.
ARCamera.cs
protected override void OnUpdate(float timeStep)
{
var frame = arSession?.CurrentFrame;
if (frame == null)
return;
var arcamera = frame.Camera;
var transform = arcamera.Transform;
var projection = arcamera.ProjectionMatrix;
float near = projection.M43 / projection.M33;
float far = projection.M43 / (projection.M33 + 1);
//float aspect = projection.M22 / projection.M11;
float aspect = projection.M11 / projection.M22;
float fovH = 360f * (float)Math.Atan(1f / projection.M11) / MathHelper.Pi;
float fovV = 360f * (float)Math.Atan(1f / projection.M22) / MathHelper.Pi;
float projectOffsetX = -projection.M31 / 2f;
float projectOffsetY = -projection.M32 / 2f;
Camera.Skew = projection.M21;
Camera.ProjectionOffset = new Vector2(projectOffsetX, projectOffsetY);
Camera.AspectRatio = aspect;
Camera.Fov = fovV; //TODO: Add FovVertical/FovHorizontal API to urho3d
Camera.NearClip = near;
Camera.FarClip = far;
// Rotation (ARFrame has EulerAngles property)
var ea = arcamera.EulerAngles;
var tod = 180f / MathHelper.Pi;
CameraNode.Rotation = new Quaternion(-ea.X * tod, -ea.Y * tod, ea.Z * tod + 90); //RHD->LHD coordinates
// Position
var row = arcamera.Transform.Row3;
CameraNode.Position = new Vector3(row.X, row.Y, -row.Z);
arSession.CurrentFrame.Dispose();
arcamera.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment