gpt4 book ai didi

c++ - 我的弹射器游戏产生的距离不正确

转载 作者:行者123 更新时间:2023-11-30 02:35:20 25 4
gpt4 key购买 nike

我的弹射器游戏中似乎有一个涉及距离方程的严重问题。该方程旨在计算弹射器以给定速度和发射角度发射的射弹的距离。通常距离总是高得离谱。

速度是根据特定的用户输入密度计算的,因此也可能存在问题。我禁用了角度有效性检查并将触发角度设置为 90(这不会给我 0 距离)并且我得到了相当高的数字。

我无法验证导致程序出现问题的原因,因为我不学习物理,而且我知道方程式中的任何错误(我们的老师向我们提供了公式)。我想知道是否有任何精通物理的程序员可以帮助我修复这个游戏?

附言我认为问题可能是由我的弧度转换引起的。这是我的代码片段:

          cout << "Choose a material to launch:" << endl
<< "1) BIRCH WOOD (670 kg/m^3)\n2) ICE (917 kg/m^3)\n3) FLAMING COAL (1500 kg/m^3)\n4) ASBESTOS (2450 kg/m^3)" << endl;
cin >> materialChoice;
materialChoice = int(materialChoice);
while (materialChoice < 1 || materialChoice > 4)
{
cout << "Please choose a valid material type:" << endl
<< "1) BIRCH WOOD (670 kg/m^3)\n2) ICE (917 kg/m^3) 3) FLAMING COAL (1500 kg/m^3)\n4) ASBESTOS (2450 kg/m^3)" << endl;
cin >> materialChoice;
materialChoice = int(materialChoice);
}

switch (materialChoice)
{
case 1:
density = 670;
break;
case 2:
density = 917;
break;
case 3:
density = 1500;
break;
default:
density = 2450;
}

cout << "Now select a launch angle between 20 and 70 degrees:" << endl;
cin >> angleChoice;

while (angleChoice < 20 || angleChoice > 70)
{
cout << "Please select a valid launch angle between 20 and 70 degrees:" << endl;
cin >> angleChoice;
}

cout << "Now select the radius of the projectile between 6 cm and 10 cm:" << endl;
cin >> radius;
while (radius < 6 || radius > 10)
{
cout << "Please select a valid radius for the projectile between 6 cm and 10 cm:" << endl;
cin >> radius;
}
velocity = 360000.0/(density * radius);
distance = 2 * sin(RADIAN * (angleChoice)) * velocity * cos(RADIAN * (angleChoice)) * velocity/9.8;

cout << "The projectile goes flying! Press any number to check where it landed" << endl;
cin >> null;
shortDiff = (abs(distance - 24));

最佳答案

RADIAN 的值应该是PI/180
(PI 弧度)/(180 度)*(以度为单位的角度) 将为您提供以弧度为单位的结果。
进行更改,然后根据需要进行调试。

关于c++ - 我的弹射器游戏产生的距离不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33752042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com