-
Notifications
You must be signed in to change notification settings - Fork 0
/
swStar.cpp
42 lines (35 loc) · 893 Bytes
/
swStar.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
#include <QGLWidget>
#include "swStar.h"
#include "swSimulator.h"
swStar::swStar() : gravity(0.04) {
type = SW_STAR;
radius = 0.2;
}
swStar::~swStar() {}
void swStar::read(swStream* stream) {
swPhysical::read(stream);
stream->readDouble(gravity);
}
void swStar::write(swStream* stream) {
swPhysical::write(stream);
stream->writeDouble(gravity);
}
void swStar::draw() {
glPushMatrix();
transform();
glPointSize(10);
glBegin(GL_POINTS);
glVertex3f(0, 0, 0);
glEnd();
glPopMatrix();
}
void swStar::tick() {
swPhysical::tick();
foreach(swPhysical* object, parent->objects) {
if(object && object != this) {
swVector diff = pos - object->pos;
double accel = gravity * swSimulator::tickScale / (diff * diff); // G / dist^2
object->vel += diff.normalize() * accel;
}
}
}