OpenGL-在随机方向上移动的对象
OpenGL - Objects moving in random direction
我正在使用OpenGL和C制作一个2D视频游戏,但我遇到了一些麻烦。我试图让一定数量的物体,比如说100,以随机的速度和方向漫游,但它不起作用,我相信有更好的方法可以做到这一点,但我想不通。
到目前为止,这是我的课,我想被画100次:
#include "stdafx.h"
#include <math.h>
#ifndef _THING_H
#define _THING_H
class thingClase {
public:
float ypos, xpos, zpos;
float count;
thingClase() {
xpos = rand()%80;
ypos = rand()%80;
zpos = 1;
count = 1;
}
};
thingClase thing[100];
int thingNum = 0;
int thingTotal = 100;
int width = 1;
bool alive;
#endif /* _THING_H */
我的主要功能包括:
void drawThing() {
for (thingNum = 0; thingNum < thingTotal; thingNum++) {
glPushMatrix();
glTranslated(thing[thingNum].xpos, thing[thingNum].ypos, thing[thingNum].zpos);
glPopMatrix();
}
}
所以,我看到你正在设置一个转换来绘制一些东西:
void drawThing() {
// EDIT:
//
// Set the matrix mode!
glMatrixMode(GL_MODELVIEW);
for (thingNum = 0; thingNum < thingTotal; thingNum++) {
// Yes, good, matrix is saved!
glPushMatrix();
// Yes, translate to the thing's position
glTranslated(thing[thingNum].xpos, thing[thingNum].ypos, thing[thingNum].zpos);
// Draw the thing here!
//
// You know, like call a display list or something.
// Restore the matrix, also good!
glPopMatrix();
}
}
你需要有一幅画。因此,如果您使用的是旧的、更易于使用的OpenGL,请制作一个显示列表或使用glBegin
和glEnd
。
然后,在您感到舒适之后,制作并使用VBO和着色器,就像我们今天OpenGL的方式一样。
相关文章:
- 当 std::move 与 C 样式数组或不移动对象时会发生什么
- 如果这不是类的"复制构造函数",是否可以移动对象?
- 我可以从向量的开头移动对象吗?为什么不呢
- 为什么可以使用已删除的移动构造函数和赋值运算符移动对象?
- 使用参数将仅可移动对象捕获到 lambda
- 初始化不可移动对象数组:为什么这样的代码无法在 GCC 上编译?
- c++ 从成员函数创建新线程并移动对象和整个对象
- 返回unique_ptr或只是移动对象
- 将 OpenGL 实例化图形与移动对象一起使用
- 如何在给定两个点的线上移动对象?
- 使用文件描述符移动对象
- 为什么移动对象不会使其为空?
- 被引用的移动对象
- Maya c++ API,移动对象?
- 为什么传递std ::移动(对象)和此对象的成员函数会导致sigsegv
- 命令模式:如何进行连续操作?(例如,移动对象)
- 返回具有显式构造函数的不可复制的不可移动对象
- 如何在 C++ 中的特定边界内移动对象
- 在阵列中向上移动对象
- DirectX 11 基于旋转移动对象