-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCelestialBody.cpp
More file actions
27 lines (23 loc) · 887 Bytes
/
CelestialBody.cpp
File metadata and controls
27 lines (23 loc) · 887 Bytes
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
//
// Created by barth on 10/10/2022.
//
#include "CelestialBody.h"
CelestialBody::CelestialBody(const char *name, float radius, float rotationPeriod, float orbitPeriod, float orbitRadius,
std::shared_ptr<BlinnPhongMaterial> material, Scene &scene) :
_mesh(MeshBuilder::makeUvSphere(name, scene, 32)) {
_mesh->transform()->setScale(radius);
_mesh->setMaterial(material);
_rotationPeriod = rotationPeriod;
_orbitPeriod = orbitPeriod;
_orbitRadius = orbitRadius;
}
void CelestialBody::update(float time) {
if (_orbitPeriod != 0) {
_mesh->transform()->setPosition(
_orbitRadius * std::cos(time / _orbitPeriod),
0.0f,
_orbitRadius * std::sin(time / _orbitPeriod)
);
}
if (_rotationPeriod != 0) _mesh->transform()->setRotationY(-time / _rotationPeriod);
}