2012-07-09 64 views
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; 
+1

如果您认为这是一个调整数学的问题,那么您应该先尝试一下。 – anthropomorphic 2012-07-10 00:04:27

+0

+1(抵消)不明白downvote。看起来对我来说是一个完全合法的问题。反对的观点值得欢迎。 – 2012-07-10 13:51:06

回答

0

即使你是在一个球体中谈论“顺时针运动”,当它在飞机上对我来说只是有意义的时候,在我看来,只要改变两条线上的信号就可以完成你想要做的事情,这两条线你创建了goose1_egg1_theta_mathgoose1_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; 

这应该扭转你增加你球面坐标的方式,给你你要寻找的“逆时针”的议案。

+0

非常感谢您的回复。我的3D数学不是很热(显然),你的建议做到了。在此期间,我一直在乘以-1等所有其他罪/ cos - 在黑暗中拍摄......所以我很感激它。我原来的帖子遗漏了我的一些文字,所以我虚心地感谢你。 – kropcke 2012-07-10 06:52:30

+0

@kropcke我很高兴我能帮上忙。 :) 如果这是你正在寻找的东西,你应该将它标记为答案,这样其他人就会知道这不再是一个悬而未决的问题。 – MeloMCR 2012-07-10 11:16:00

+0

再次感谢MeloMCR。刚刚标记了一下。我希望在未来帮助回答其他人的问题。 – kropcke 2012-07-10 18:27:45