-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObjectSpawner.cpp
59 lines (48 loc) · 2.78 KB
/
ObjectSpawner.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
#include <utility>
#include <utility>
#include "BaseObjects/KinematicObject.h"
#include "ObjectSpawner.h"
#include "Util/RandomRange.h"
#include "BaseObjects/CollidableObject.h"
const float OBJECT_RANGE = 150.0f;
KinematicObject *ObjectSpawner::createSphere(std::string name, GLuint texId,
GLfloat r, GLfloat g, GLfloat b,
GLdouble radius_min, GLdouble radius_max,
float rotspeed, float rot_x, float rot_y, float rot_z) {
auto sphere = new KinematicObject(std::move(name),
Eigen::Vector3d{
// random position within world space
(Random::ZeroToOne() - 0.5f) * OBJECT_RANGE,
(Random::ZeroToOne() - 0.5f) * OBJECT_RANGE,
(Random::ZeroToOne() - 0.5f) * OBJECT_RANGE},
Eigen::Vector3d::Zero(),
Eigen::Vector3d::Zero());
sphere->angularThrust = Eigen::Vector3d{rot_x, rot_y, rot_z};
sphere->angularVelocity = Eigen::Vector3d{rotspeed, rotspeed, rotspeed};
sphere->linearVelocity = Eigen::Vector3d::Zero();
GLfloat r_col_r = r / 255.0f;
GLfloat r_col_g = g / 255.0f;
GLfloat r_col_b = b / 255.0f;
float val = Random::RangeF(radius_min, radius_max);
GLdouble r_radius = val;
sphere->addChild(std::make_shared<SphereRenderObject>(sphere->getName() + "Renderer",
texId,
r_col_r, r_col_g, r_col_b,
r_radius));
sphere->addChild(std::make_shared<CollidableObject>(sphere->getName() + "Collider", r_radius));
return sphere;
}
KinematicObject *ObjectSpawner::createCube(std::string name, GLuint texId,
GLfloat r, GLfloat g, GLfloat b) {
auto cube = new KinematicObject(std::move(name),
Eigen::Vector3d{
(Random::ZeroToOne() - 0.5f) * OBJECT_RANGE,
(Random::ZeroToOne() - 0.5f) * OBJECT_RANGE,
(Random::ZeroToOne() - 0.5f) * OBJECT_RANGE},
Eigen::Vector3d::Zero(),
Eigen::Vector3d::Zero());
// TODO: implement
/*cube->addChild(std::make_shared<RenderObject>(cube->getName() + "Renderer",
texId, Random::Range(218, 255), Random::Range(244, 255), Random::Range(0, 100)));*/
return cube;
}