0

我正在围绕一个球体发射一个射弹。我的代码以逆时针方向移动它就好了。但是,我希望它改为顺时针方向移动。

我猜这是调整我的数学的问题。

// these are my stepping and incrementing variables

int goose1_egg1_step = 1;
int &r_goose1_egg1_step = goose1_egg1_step;
float goose1_egg1_divider = 17500;

// the starting theta/phi values are: 5 and 5

int goose1_egg1_theta=5;
int goose1_egg1_phi=5;

// the ending theta/phi values are: 7 and 1
// there is a difference of 2 between the start and end theta values
// there is a difference of 4 between the start and end phi values

float goose1_egg1_theta_increment = 2/goose1_egg1_divider;
float goose1_egg1_phi_increment = 4/goose1_egg1_divider;

这是我的函数,它用球体显示每帧的更新坐标:

if (goose1_egg1_step < goose1_egg1_divider)
{
    float goose1_egg1_theta_math = (goose1_egg1_theta+(goose1_egg1_theta_increment* r_goose1_egg1_step))/10.0*M_PI;
    float goose1_egg1_phi_math = (goose1_egg1_phi-(goose1_egg1_phi_increment* r_goose1_egg1_step))/10.0*2*M_PI;
    r_goose1_egg1_x = Radius * sin(goose1_egg1_theta_math) * cos(goose1_egg1_phi_math);
    r_goose1_egg1_y = Radius * sin(goose1_egg1_theta_math) * sin(goose1_egg1_phi_math);
    r_goose1_egg1_z = Radius * cos(goose1_egg1_theta_math); 

    glPushMatrix();
    glTranslatef(r_goose1_egg1_x,r_goose1_egg1_y,r_goose1_egg1_z);
    glColor3f (1.0, 0.0, 0.0);
    glutSolidSphere (0.075,5,5);
    glEnd();
    glPopMatrix();
}

这是我增加步长值的方法:

if (r_goose1_egg1_step < goose1_egg1_divider)       
{
    ++(r_goose1_egg1_step);
}    
else
    r_goose1_egg1_step=1;
4

1 回答 1

0

即使您在谈论球体中的“顺时针运动”,当它只在平面上对我有意义时,在我看来,您想要的只是通过更改您创建的两条线中的信号来goose1_egg1_theta_math完成goose1_egg1_phi_math,像这样:

    float goose1_egg1_theta_math = (goose1_egg1_theta-(goose1_egg1_theta_increment* r_goose1_egg1_step))/10.0*M_PI;
    float goose1_egg1_phi_math = (goose1_egg1_phi+(goose1_egg1_phi_increment* r_goose1_egg1_step))/10.0*2*M_PI;

这应该反转您增加球坐标的方式,为您提供您正在寻找的“逆时针”运动。

于 2012-07-09T23:49:23.747 回答