|
@@ -1,4 +1,5 @@
|
|
|
using System;
|
|
|
+using BBIWARG.Input.InputProviding;
|
|
|
|
|
|
namespace BBIWARG.Utility
|
|
|
{
|
|
@@ -7,30 +8,8 @@ namespace BBIWARG.Utility
|
|
|
|
|
|
public class CoordinateConverter
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private float fieldOfViewHorizontal;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private float fieldOfViewVertical;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private ImageSize imageSize;
|
|
|
+ private IInputProvider inputProvider;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private float relativeRatioHorizontal;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private float relativeRatioVertical;
|
|
|
|
|
|
|
|
|
|
|
@@ -38,14 +17,9 @@ namespace BBIWARG.Utility
|
|
|
|
|
|
|
|
|
|
|
|
- public CoordinateConverter(ImageSize imageSize, float hfov, float vfov)
|
|
|
+ public CoordinateConverter(IInputProvider inputProvider)
|
|
|
{
|
|
|
- this.imageSize = imageSize;
|
|
|
- this.fieldOfViewHorizontal = hfov;
|
|
|
- this.fieldOfViewVertical = vfov;
|
|
|
-
|
|
|
- relativeRatioHorizontal = (float)Math.Tan(hfov / 2);
|
|
|
- relativeRatioVertical = (float)Math.Tan(vfov / 2);
|
|
|
+ this.inputProvider = inputProvider;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -68,11 +42,11 @@ namespace BBIWARG.Utility
|
|
|
|
|
|
public Vector3D convertCoordinate2Dto3D(float x, float y, float depth)
|
|
|
{
|
|
|
- float deltaX = 2 * ((x / imageSize.Width) - 0.5f);
|
|
|
- float deltaY = -2 * ((y / imageSize.Height) - 0.5f);
|
|
|
+ float deltaX = 2 * ((x / inputProvider.ImageWidth) - 0.5f);
|
|
|
+ float deltaY = -2 * ((y / inputProvider.ImageHeight) - 0.5f);
|
|
|
|
|
|
- float tanX = deltaX * relativeRatioHorizontal;
|
|
|
- float tanY = deltaY * relativeRatioVertical;
|
|
|
+ float tanX = deltaX * (float)Math.Tan(inputProvider.FieldOfViewHorizontal / 2);
|
|
|
+ float tanY = deltaY * (float)Math.Tan(inputProvider.FieldOfViewVertical / 2);
|
|
|
|
|
|
float a = depth * depth;
|
|
|
float b = (float)(Math.Pow(tanX, 2) + Math.Pow(tanY, 2));
|
|
@@ -92,12 +66,13 @@ namespace BBIWARG.Utility
|
|
|
|
|
|
public float convertLength3Dto2D(float length, float depth)
|
|
|
{
|
|
|
- float fullLengthX = (float)(2 * Math.Cos(fieldOfViewHorizontal / 2) * depth);
|
|
|
- float fullLengthY = (float)(2 * Math.Cos(fieldOfViewVertical / 2) * depth);
|
|
|
+ float fullLengthX = (float)(2 * Math.Cos(inputProvider.FieldOfViewHorizontal / 2) * depth);
|
|
|
+ float fullLengthY = (float)(2 * Math.Cos(inputProvider.FieldOfViewVertical / 2) * depth);
|
|
|
float fullLengthDiagonal = (float)Math.Sqrt(Math.Pow(fullLengthX, 2) + Math.Pow(fullLengthY, 2));
|
|
|
|
|
|
float ratio = length / fullLengthDiagonal;
|
|
|
- return ratio * imageSize.DiagonalLength;
|
|
|
+ float imageSizeDiagonalLength = (float)Math.Sqrt(inputProvider.ImageWidth*inputProvider.ImageWidth + inputProvider.ImageHeight*inputProvider.ImageHeight);
|
|
|
+ return ratio * imageSizeDiagonalLength;
|
|
|
}
|
|
|
}
|
|
|
}
|