|
|
@@ -118,38 +118,56 @@ public class UserSettings {
|
|
|
PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
|
|
|
}
|
|
|
}
|
|
|
+/*
|
|
|
+描述1
|
|
|
+已知:
|
|
|
+ 屏幕宽高比例w:h=16:9,屏幕尺寸s=60.11英寸,屏幕距离d=2.50米,实际指向右边树的角度为e=5.56°。
|
|
|
+可知:
|
|
|
+ 屏幕尺寸s1 = (s * 0.0254)米
|
|
|
+ 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2
|
|
|
+结果:
|
|
|
+ 向量(玩家->右边树)在屏幕上投影的长度比例q = tan(e) * d / unit
|
|
|
+*/
|
|
|
+
|
|
|
+/*
|
|
|
+描述2(适配各种尺寸的屏幕)
|
|
|
+已知:
|
|
|
+ 屏幕宽高比例w:h=16:9,屏幕尺寸s=(任意)英寸,屏幕距离d=(任意)米,游戏指向右边树的角度为r=27.30°。
|
|
|
+ 借用描述1的结果q
|
|
|
+可知:
|
|
|
+ 屏幕尺寸s1 = (s * 0.0254)米
|
|
|
+ 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2
|
|
|
+ 实际指向右边树的角度为e = atan(q * unit / d)
|
|
|
+结果:
|
|
|
+ 游戏转动角度:实际转动角度 = r / e
|
|
|
+*/
|
|
|
public class BowRotateConvert {
|
|
|
public float screenSize = 60; //屏幕尺寸(英寸)
|
|
|
public float screenDistance = 2.5f; //玩家距离屏幕多远(米)
|
|
|
|
|
|
// 游戏旋转角度 : 实际旋转角度
|
|
|
public float GetRate() {
|
|
|
- float rateMeterInch = 0.0254f; //比率(米:英寸)
|
|
|
- float weightScreenWidth = 16; //屏幕宽比值
|
|
|
- float weightScreenHeight = 9; //屏幕高比值
|
|
|
- //单位屏幕比值对应大小
|
|
|
- float unitWeightSize = rateMeterInch * screenSize
|
|
|
- / (Mathf.Pow(weightScreenWidth, 2) + Mathf.Pow(weightScreenHeight, 2));
|
|
|
- float screenWidth = weightScreenWidth * unitWeightSize;
|
|
|
- float screenCenterToTreeSize = GetTreeWeight() * unitWeightSize;
|
|
|
- return GetTreeAngleInRadian() / Mathf.Atan(screenCenterToTreeSize / screenDistance);
|
|
|
- }
|
|
|
-
|
|
|
- private float GetTreeWeight() {
|
|
|
- float screenSize = 60.11f; //屏幕尺寸(英寸)
|
|
|
- float screenDistance = 2.5f; //玩家距离屏幕多远(米)
|
|
|
- float rateMeterInch = 0.0254f; //比率(米:英寸)
|
|
|
- float weightScreenWidth = 16; //屏幕宽比值
|
|
|
- float weightScreenHeight = 9; //屏幕高比值
|
|
|
- //单位屏幕比值对应大小
|
|
|
- float unitWeightSize = rateMeterInch * screenSize
|
|
|
- / (Mathf.Pow(weightScreenWidth, 2) + Mathf.Pow(weightScreenHeight, 2));
|
|
|
- float q1 = (float) Math.Tan(5.56 / 180 * Math.PI) * screenDistance; //实际玩家到左树的横向距离
|
|
|
- float w1 = q1 / unitWeightSize; //实际玩家到左树的横向距离比重
|
|
|
- return w1;
|
|
|
+ double w = 16;
|
|
|
+ double h = 9;
|
|
|
+ double s = Convert.ToDouble(screenSize);
|
|
|
+ double d = Convert.ToDouble(screenDistance);
|
|
|
+ double r = 27.3 / 180 * Math.PI;
|
|
|
+ double q = get_q();
|
|
|
+ double s1 = s * 0.0254;
|
|
|
+ double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
|
|
|
+ double e = Math.Atan(q * unit / d);
|
|
|
+ return (float) (r / e);
|
|
|
}
|
|
|
|
|
|
- private float GetTreeAngleInRadian() {
|
|
|
- return (float) (27.3 / 180 * Math.PI);
|
|
|
+ private double get_q() {
|
|
|
+ double w = 16;
|
|
|
+ double h = 9;
|
|
|
+ double s = 60.11;
|
|
|
+ double d = 2.5;
|
|
|
+ double e = 5.56 / 180 * Math.PI;
|
|
|
+ double s1 = s * 0.0254;
|
|
|
+ double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
|
|
|
+ double q = Math.Tan(e) * d / unit;
|
|
|
+ return q;
|
|
|
}
|
|
|
}
|