gpt4 book ai didi

c++ - OpenGl 每 N 秒生成一个对象 "jump"

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:58 24 4
gpt4 key购买 nike

<分区>

我试图让我正在绘制的立方体看起来每隔几秒就“跳跃”一次。这是我的代码:

            for (int i=0; i<25; i++)
{
if(j<rows)
{

//Timer used in vibration calculation when drawing cubes
float time = (std::clock() - timer);
//Calculate the amount of simulated vibration based on amount of distortion (intensity)
float offset = sin(1.0f * 3.14159265359f * time) * shake;

//Draw cubes right and left of centre point
drawCube((x+xShift), y, (-300 +depth), 1.0f, cubeColour, offset);
drawCube((x-xShift), y, (-300 +depth), 1.0f, cubeColour, offset);
xShift -= gap;
}
}

drawCube代码是:

void drawCube(float x, float y, float z, float opacity, float col[], float offset)
{
//Draw cube taking into account any offset caused by simulated vibration
glTranslatef((-x+offset), (-y+offset), -z);
glColor4f(col[0], col[1], col[2], opacity);
glutWireCube(20);
glTranslatef((x-offset), (y-offset), z);

}

我假设我需要使用一个计时器,它每 N 秒增加一次 y 值,这样立方体看起来会跳跃,但我不确定该怎么做?

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