-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswStarfield.cpp
46 lines (37 loc) · 1.14 KB
/
swStarfield.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cmath>
#include <QFile>
#include <QGLWidget>
#include "swStarfield.h"
swStarfield::swStarfield() : swDrawable(0, 0, 0, 2, 2) {
type = SW_STARFIELD;
}
swStarfield::swStarfield(QString file) : swDrawable(0, 0, 0, 2, 2) {
swObject::read(file);
}
swStarfield::swStarfield(swStream* stream) : swDrawable(0, 0, 0, 2, 2) {
type = SW_STARFIELD;
read(stream);
}
swStarfield::~swStarfield() {}
void swStarfield::read(swStream *stream) {
stream->readInt(pointCount);
points = new double[pointCount * 3];
stream->read((char*)points, pointCount * sizeof(double) * 3);
}
void swStarfield::write(swStream *stream) {
stream->writeInt(pointCount);
stream->write((char*)points, pointCount * sizeof(double) * 3);
}
void swStarfield::draw() {
glPushMatrix();
transform();
glPointSize(2);
glColor3f(1, 1, 1);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_DOUBLE, 0, points);
glDrawArrays(GL_POINTS, 0, pointCount);
glDisableClientState(GL_VERTEX_ARRAY);
// step the rotation forward
rot += 0.01 * M_PI / 180;
glPopMatrix();
}