三维场景中斜抛运动顶点的生成
程序员文章站
2022-06-04 10:49:11
...
三维场景中斜抛运动顶点的生成
1 算法思想-斜抛运动
2 代码
void getparabola_vertex_2(glm::vec3 _Point, float _thetaAngle, float _fanAngle)
{
float thetaAngle = radians(_thetaAngle);//斜角
float fanAngle = radians(_fanAngle);//手柄指向和x轴的夹角;
//第一个点
float x;
float y;
float z;
/*x_start = x;
y_start = y;
z_start = z;
startPoint = glm::vec3(x_start, y_start, z_start);*/
float v0 = 8;
float te = 0;
float av = 10;
//计算落地点需要的时间
float parameter_a = -0.5 * av;
float parameter_b = v0 * sin(thetaAngle);
float parameter_c = _Point.y;
float x_solution = getSolution_qe_one_variable(parameter_a, parameter_b, parameter_c);//一次二次方程的解,可以这篇文章的参考文献
te = x_solution;
glm::vec3 pointFall;
float pointfall_y = parameter_c + parameter_b * te + parameter_a * pow(te, 2);
//float xTrajectory = 0;
//float pointfall;
float pointfall_x;
float pointfall_z;
float v1;
float v2;
/*if (_fanAngle!=0)
{*/
v1 = v0 * cos(thetaAngle)*cos(fanAngle);//x轴方向的速度
v2 = v0 * cos(thetaAngle)*sin(fanAngle);//z轴方向的速度
pointfall_x = _Point.x + v1 * te;
pointfall_z = _Point.z + v2 * te;
/*}
else
{
pointfall_x= _Point.x+ v0 * cos(thetaAngle)*te;
pointfall_z = _Point.z;
xTrajectory = _Point.x;
}*/
pointFall = glm::vec3(pointfall_x, pointfall_y, pointfall_z);//落地点的坐标
//t=sqrt(_Point.y)
//计算顶点
float t = 0;
y = parameter_c + parameter_b * t + parameter_a * pow(t, 2);
float step = te / 15;
for (int i = 0; i < 16; i++, t = t + step, y = parameter_c + parameter_b * t + parameter_a * pow(t, 2))
{
//xTrajectory = xTrajectory + v0 * cos(thetaAngle)*t;
x = _Point.x + v1 * t;
z = _Point.z + v2 * t;
/*if (_fanAngle != 0)
{
x = xTrajectory * sin(fanAngle);
z = xTrajectory * cos(fanAngle);
}
else
{
x = _Point.x + v0 * cos(thetaAngle)*t;
z = _Point.z;
xTrajectory = _Point.x;
}*/
if (i == 15)
{
//最后一个坐标放落地点坐标,这个坐标很重要,需要自己
teleportation_2[0 + 6 * 15] = pointFall.x;
teleportation_2[1 + 6 * 15] = 0;
teleportation_2[2 + 6 * 15] = pointFall.z;
teleportation_2[3 + 6 * 15] = 0.5;
teleportation_2[4 + 6 * 15] = 0.0;
teleportation_2[5 + 6 * 15] = 0.5;
}
else
{
teleportation_2[0 + 6 * i] = x;
teleportation_2[1 + 6 * i] = y;
teleportation_2[2 + 6 * i] = z;
teleportation_2[3 + 6 * i] = 0.5;
teleportation_2[4 + 6 * i] = 0.0;
teleportation_2[5 + 6 * i] = 0.5;
}
}
//遍历顶点数组
/*for (int i = 0; i < num_vertex * 6; i++)
{
cout << teleportation[i] << " ";
if ((i + 1) % 6 == 0)
{
cout << endl;
}
}*/
}
3 参考文献
[1].求解一元二次方程的根c++
上一篇: 解决Spring Security OAuth在访问/oauth/token时候报Bad client credentials/401 authentication is required
下一篇: 算法学习之贪婪技术(贪心算法)
推荐阅读