public void Reset() { Level.Rotation = Vector3.Zero; Translation = Level.GetNode <Spatial>("SpawnPoint").GlobalTransform.origin; ShouldKill = false; velocity = Vector3.Zero; Respawn?.Invoke(); RotationDir = 1; Visible = true; CalibrateCamera?.Invoke(); }
//Stop the calibration thread and clear the data public void ResetCalibrationImmediate() { objPoints.Clear(); CornerPoints.Clear(); corners.Clear(); obj.Clear(); calibrationThread.Abort(); calibrationThread = null; if (CalibrateCamera.OnCalibrationReset != null) { CalibrateCamera.OnCalibrationReset(); } Debug.Log("Reseting...."); }
void CheckForCollisions() { if (GetSlideCount() > 0) { var collision = GetSlideCollision(0); if (collision.Collider is Node node) { var block = node.GetParent <Block>(); if (block.IsPad) { if (lastPad == null) { Level.Rotate(Vector3.Up, Mathf.Deg2Rad(90 * RotationDir)); RotationDir *= -1; var pad = node.GetParent <Block>(); Translation = new Vector3(pad.GlobalTransform.origin.x, Translation.y, pad.GlobalTransform.origin.z); velocity = Vector3.Zero; CalibrateCamera?.Invoke(); lastPad = block; velocity.x = 0; } } else if (block.IsBad) { ShouldKill = true; } else if (block.DisableAfterTouch && IsOnFloor()) { block.MakeItFall(); } if (IsOnFloor() && !block.DisableAfterTouch && !block.IsBad) { LowestPoint = GlobalTransform.origin; CalibrateCameraY?.Invoke(); } if (!block.IsPad) { lastPad = null; } } } }
private void Calibrate() { Debug.Log("Calibrating Async....."); // calibrationMutex.WaitOne(); if (OnCalibrationStarted != null) { CalibrateCamera.OnCalibrationStarted(); } //prepare the data which the calibration process will fill up int maxSize = (int)Mathf.Max(imageWidth, imageHeight); double fx = maxSize; double fy = maxSize; double cx = (double)imageWidth / 2; double cy = (double)imageHeight / 2; double[,] k = new double[3, 3] { { fx, 0d, cx }, { 0d, fy, cy }, { 0d, 0d, 1d } }; double[] d = new double[5]; double projectionError = -1; Vec3d[] rvec = new Vec3d[boardWidth * boardHeight]; Vec3d[] tvec = new Vec3d[boardWidth * boardHeight]; Size boardSize = new Size(boardWidth, boardHeight); try { // calibrate the camera projectionError = Cv2.CalibrateCamera(objPoints, CornerPoints, new Size(imageWidth, imageHeight), k, d, out rvec, out tvec, calibrationFlags, TermCriteria.Both(30, 0.1)); Debug.Log("Error: " + projectionError); } catch (Exception e) { ResetCalibrationImmediate(); Debug.Log("restarting..."); } //register the data and save them calibrationData.RegisterMatrix(k); calibrationData.RegisterDistortionCoefficients(d); calibrationData.projectionError = projectionError; string s = ""; for (int i = 0; i < d.Length; i++) { s += d[i] + " "; } Debug.Log(s); Debug.Log("Finished!!"); if (OnCalibrationFinished != null) { OnCalibrationFinished(calibrationData); } //calibrationMutex.ReleaseMutex(); }