gpt4 book ai didi

algorithm - 生成漂亮的星空图案

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:20:15 24 4
gpt4 key购买 nike

我正在尝试使用 C++ 和 SDL 为游戏生成滚动星空。我使用的是一种简单、幼稚的算法,它只会在黑色背景上创建大量白色像素。然而,这个“星空”看起来太不自然了——可能是因为随机数生成器的质量很差(我使用了 rand() 函数)。

是否有任何特殊算法可以生成看起来或多或少逼真的星空?

谢谢。

最佳答案

总是有 this经典的。亮点:

[...] imagine the stars to be points in 3D space, all of them moving towards the viewer, along the Z-axis. At each time step, the 3D coordinates of the stars will be projected onto the screen, and displayed.

For a smoother effect, we can make the stars black when they first appear (so you don't notice them) then get brighter as they get closer.

There are two ways the sense of vastness can be modeled. The first is simply to model a huge area of space, which is impractical to say the least. The second is to make the stars move with a range of velocities.

关于algorithm - 生成漂亮的星空图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5021608/

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