public static Vector3D <double> ConvertCoordinateLeftHand(PolarPoint p) { Vector3D <double> v = new Vector3D <double>(); v.Y = p.Length * Math.Sin(p.Elevation); double cos = p.Length * Math.Cos(p.Elevation); v.X = Math.Sin(p.Azimuth) * cos; v.Z = Math.Cos(p.Azimuth) * cos; return(v); }
private bool MoveHowitzer(GameStatus gameStatus) { bool mouseInScreen = 0 <= Mouse.X && Mouse.X < GameSettings.WindowWidth && 0 <= Mouse.Y && Mouse.Y < GameSettings.WindowHeight; if (mouseInScreen && Mouse.Left) { int depthAtMouse = GetDepthAt(Mouse.X, Mouse.Y); int mouseXCenter = Mouse.X - GameSettings.WindowWidth / 2; int mouseYCenter = GameSettings.WindowHeight / 2 - Mouse.Y; PolarPoint pp = GetPolarPointAt(mouseXCenter, mouseYCenter, depthAtMouse); double diffBulletAzimuth = pp.Azimuth - (bulletTarget != null ? bulletTarget.Azimuth : 0); bulletTarget = pp; double v0 = bulletSpeed; double g = 9.8; double[] angles = Util.CalcFiringAngle(bulletTarget.Length / 1000.0, bulletTarget.Elevation, v0, g); this.firingAngle = angles[directShot ? 0 : 1]; double srv1Deg = firingAngle * 180 / Math.PI; double srv2Deg = pp.Azimuth * 180 / Math.PI; int tmp = (int)Math.Round(1500 + srv1Deg * 7); SerialPort.Write(string.Format("srv1:{0}\n", tmp)); // 1500 usec中心 Console.WriteLine(string.Format("{0}, {1}", srv1Deg, tmp)); SerialPort.Write(string.Format("srv2:{0}\n", (int)Math.Round(1500 + srv2Deg * 10))); // 1500 usec中心 // http://homepage3.nifty.com/rio_i/lab/avr/09pwm.html waitUntil = gameStatus.CurrentTimeInMillis + (int)(7000 * Math.Abs(diffBulletAzimuth) / Math.PI) + 1000; DX.PlaySoundMem(turretMoveSound, DX.DX_PLAYTYPE_BACK); //waitUntil = gameStatus.CurrentTimeInMillis; return(true); } return(false); }
private bool MoveHowitzer(GameStatus gameStatus) { bool mouseInScreen = 0 <= Mouse.X && Mouse.X < GameSettings.WindowWidth && 0 <= Mouse.Y && Mouse.Y < GameSettings.WindowHeight; if (mouseInScreen && Mouse.Left) { int depthAtMouse = GetDepthAt(Mouse.X, Mouse.Y); int mouseXCenter = Mouse.X - GameSettings.WindowWidth / 2; int mouseYCenter = GameSettings.WindowHeight / 2 - Mouse.Y; PolarPoint pp = GetPolarPointAt(mouseXCenter, mouseYCenter, depthAtMouse); double diffBulletAzimuth = pp.Azimuth - (bulletTarget != null ? bulletTarget.Azimuth : 0); bulletTarget = pp; double v0 = bulletSpeed; double g = 9.8; double[] angles = Util.CalcFiringAngle(bulletTarget.Length / 1000.0, bulletTarget.Elevation, v0, g); this.firingAngle = angles[directShot ? 0 : 1]; double srv1Deg = firingAngle * 180 / Math.PI; double srv2Deg = pp.Azimuth * 180 / Math.PI; int tmp = (int)Math.Round(1500 + srv1Deg * 7); SerialPort.Write(string.Format("srv1:{0}\n", tmp)); // 1500 usec中心 Console.WriteLine(string.Format("{0}, {1}", srv1Deg, tmp)); SerialPort.Write(string.Format("srv2:{0}\n", (int)Math.Round(1500 + srv2Deg * 10))); // 1500 usec中心 // http://homepage3.nifty.com/rio_i/lab/avr/09pwm.html waitUntil = gameStatus.CurrentTimeInMillis + (int)(7000 * Math.Abs(diffBulletAzimuth) / Math.PI) + 1000; DX.PlaySoundMem(turretMoveSound, DX.DX_PLAYTYPE_BACK); //waitUntil = gameStatus.CurrentTimeInMillis; return true; } return false; }