python基础3d动画_python - 3D动画中每个球体的随机方向 - SO中文参考 - www.soinside.com...

我正在尝试创建3D动画,每个球体都沿随机方向(向上,向下,向左,向右,向后或向前)移动。它们都在3D世界中移动(每个球体都有随机的X,Y和Z值),并且投影在2D屏幕上。我期望每个球体在随机方向上独立于其他球体而运动,但这些球体似乎完全在一个方向上运动,如下所示。

鉴于我的代码,我不明白为什么它会这样工作:# random X, Y, Z: fill X, Y and Z coordinates with uniform random values that serve as coordinates

for sphere in spheres:

sphere.position.xy = np.random.uniform(-20, 20, size=2)

sphere.position.z = np.random.uniform(z_near, z_far)

# Create two angles for each sphere, theta and phi, to compute the change of direction.

sphere.theta_deg = np.random.rand(1) * 360; # Angle thera controls the horizontal orientation of the gaze.

sphere.phi_deg = np.random.rand(1) * 360; # Angle Phi controls the vertical orientation of the gaze.

# Different directions

speed = 3; #degrees/seconds

theta_rad = sphere.theta_deg * np.pi /180; #direction converted to radians

phi_rad = sphere.phi_deg* np.pi /180; #direction converted to radians

dx = speed*np.sin(-phi_rad-theta_rad)/frameRate;

dy = -speed*np.cos(phi_rad + theta_rad)/frameRate;

dz = -speed*np.cos(theta_rad)/frameRate;

while 1:

# Modulate the angular directions

dx = speed*np.sin(-phi_rad-theta_rad)/frameRate;

dy = -speed*np.cos(phi_rad + theta_rad)/frameRate;

dz = -speed*np.cos(theta_rad)/frameRate;

for sphere in spheres:

# Update Spheres Positions

sphere.position.x += dx

sphere.position.y += dy

sphere.position.z += dz

球体位置应该在每帧更新,并且应该是随机的。

非常感谢您的帮助!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值