-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanet.h
45 lines (39 loc) · 815 Bytes
/
Planet.h
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
#pragma once
#include <math.h>
#include "Vec3.h"
struct Planet
{
Vec3 planetCoordinate, planetVelocity;
float planetMess, planetRadius;
Planet() {
this->planetMess = 0.0f;
this->planetRadius = 0.0f;
}
float getKineticEnergy()
{
float velocitySquare = this->planetVelocity.MagnitudeSquared();
return 0.5f*this->planetMess*velocitySquare;
}
void setVelocity(float energy)
{
float v = sqrt(2 * energy / this->planetMess);
float w = this->planetVelocity.Magnitude();
if (w < 0.00001f)
{
this->planetVelocity.x = v;
}
else
{
this->planetVelocity *= v / w;
}
}
void setVelocity(Vec3 c)
{
this->planetVelocity = c;
}
void setMess(float mess)
{
this->planetMess = mess;
this->planetRadius = powf(mess, 1.0f / 3.0f);
}
};