-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProceduralSystem.cpp
69 lines (56 loc) · 1.53 KB
/
ProceduralSystem.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "ProceduralSystem.h"
#include "ObjectManager.h"
#include "Planet.h"
#include "StarInterface.h"
#include "RandomGenerator.hpp"
#include "Display.h"
// DEBUG
#include <stdlib.h>
#include <iostream>
ProceduralSystem::ProceduralSystem(b2World * world)
: world_(world)
{
}
ProceduralSystem::ProceduralSystem()
: ProceduralSystem(0) {}
ProceduralSystem::~ProceduralSystem() {}
void ProceduralSystem::SetStar(StarInterface * star) {
star_ = star;
planets_.clear();
Init();
}
b2Vec2 ProceduralSystem::GetGravityAcceleration(b2Vec2 pos) {
b2Vec2 g(0.0, 0.0);
g += planets_[0]->GetGravityAcceleration(pos);
return g;
}
void ProceduralSystem::Init() {
std::shared_ptr<Planet> p = std::make_shared<Planet>();
RandomGenerator RG;
RG.SetRange(0.0, 2.0 * 3.141592653);
double alpha = RG.GetValue();
// double alpha = drand48() * 2.0 * 3.14159;
p->SetPosition(5000.0 * cos(alpha), 5000.0 * sin(alpha));
p->SetAngle(0.0);
double radius = star_->GetRadius();
p->SetRadius(radius);
p->SetCoreRadius(100.0);
p->SetAngularVelocity(1.0);
float * pColor = star_->GetColor();
p->SetColor(pColor[0], pColor[1], pColor[2]);
p->SetSeed(-1);
planets_.push_back(p);
p->Init(world_);
}
void ProceduralSystem::Update(double delta_time) {
(void)delta_time;
planets_[0]->Update();
}
void ProceduralSystem::Render() {
glPushMatrix();
planets_[0]->Render();
glPopMatrix();
}
std::vector<std::shared_ptr<Planet>> ProceduralSystem::GetPlanets() {
return planets_;
}