[Add] Planets rotate. Woo.

This commit is contained in:
Rtch90 2018-01-13 18:05:28 +00:00
parent 6ff77553f6
commit 0732584c0d
7 changed files with 62 additions and 27 deletions

View File

@ -9,67 +9,67 @@ const CustomSBody sol_system[] = {
{
"Mercury", StarSystem::TYPE_PLANET_SMALL,
0, fixed(38, 100), fixed(55, 1000), 340,
fixed(387,1000), fixed(205,1000), DEG2RAD(7.0)
fixed(387,1000), fixed(205,1000), DEG2RAD(7.0), fixed(59, 1)
},
{
"Venus", StarSystem::TYPE_PLANET_CO2_THICK_ATMOS,
0, fixed(95,100), fixed(815,1000), 735,
fixed(723,1000), fixed(7,1000), DEG2RAD(3.39)
fixed(723,1000), fixed(7,1000), DEG2RAD(3.39), fixed(243, 1)
},
{
"Earth", StarSystem::TYPE_PLANET_INDIGENOUS_LIFE,
0, fixed(1,1), fixed(1,1), 288,
fixed(1,1), fixed(167,10000),
fixed(1,1), fixed(167,10000), 0, fixed(1,1)
},
{
"Moon", StarSystem::TYPE_PLANET_DWARF,
3, fixed(273,1000), fixed(12,1000), 220,
fixed(257,100000), fixed(549,10000), DEG2RAD(5.145)
fixed(257,100000), fixed(549,10000), DEG2RAD(5.145), fixed(273, 10)
},
{
"Mars", StarSystem::TYPE_PLANET_SMALL,
0, fixed(533,1000), fixed(107,1000), 227,
fixed(152,100), fixed(933,10000), DEG2RAD(1.85)
fixed(152,100), fixed(933,10000), DEG2RAD(1.85), fixed(1027, 1000)
},
{
"Jupiter", StarSystem::TYPE_PLANET_LARGE_GAS_GIANT,
0, fixed(11,1), fixed(3178,10), 165,
fixed(5204,1000), fixed(488,10000), DEG2RAD(1.305)
fixed(5204,1000), fixed(488,10000), DEG2RAD(1.305), fixed(4, 10)
},
{
"Saturn", StarSystem::TYPE_PLANET_MEDIUM_GAS_GIANT,
0, fixed(9,1), fixed(95152,100), 134,
fixed(9582,1000), fixed(557,10000), DEG2RAD(2.485)
fixed(9582,1000), fixed(557,10000), DEG2RAD(2.485), fixed(4, 10)
},
{
"Uranus", StarSystem::TYPE_PLANET_SMALL_GAS_GIANT,
0, fixed(4,1), fixed(145,10), 76,
fixed(19229,1000), fixed(444,10000), DEG2RAD(0.772)
fixed(19229,1000), fixed(444,10000), DEG2RAD(0.772), fixed(7, 10)
},
{
"Neptune", StarSystem::TYPE_PLANET_SMALL_GAS_GIANT,
0, fixed(38,10), fixed(17147,100), 72,
fixed(30104,1000), fixed(112, 10000), DEG2RAD(1.768)
fixed(30104,1000), fixed(112, 10000), DEG2RAD(1.768), fixed(75, 100)
},
/* Moons of jupiter. */
{
"Io", StarSystem::TYPE_PLANET_HIGHLY_VOLCANIC,
6, fixed(286,1000), fixed(15,1000), 130,
fixed(282,100000), fixed(41,10000), DEG2RAD(2.21)
fixed(282,100000), fixed(41,10000), DEG2RAD(2.21), fixed(177, 10)
},
{
"Europa", StarSystem::TYPE_PLANET_WATER,
6, fixed(245,1000), fixed(8,1000), 102,
fixed(441,100000), fixed(9,1000), 0.0
fixed(441,100000), fixed(9,1000), 0.0, fixed(355, 10)
},
{ 0 }
};

View File

@ -12,6 +12,7 @@ struct CustomSBody {
fixed semiMajorAxis; /* In AUs. */
fixed eccentricity;
float inclination; /* Radians. */
fixed rotationPeriod; /* In days. */
};
struct CustomSystem {

View File

@ -44,7 +44,6 @@ void DynamicBody::SetMassDistributionFromCollMesh(const CollMesh* m) {
max.z = MAX(m->pVertex[i+2], max.z);
}
float size = ((max.x-min.x) + (max.y-min.y) + (max.z-min.z)) / 6.0f;
printf("size %f\n", size);
dMassSetSphere(&m_mass, 1, size);
/* Boxes go mental after a while due to inertia tensor being fishy. */
//dMassSetBox(&m_mass, 1, max.x-min.x, max.y-min.y, max.z-min.z);

View File

@ -202,8 +202,8 @@ void L3D::MainLoop(void) {
StarSystem s(0, 0, 0);
HyperspaceTo(&s);
const float zpos = EARTH_RADIUS * 1;
Frame* pframe = *(Space::rootFrame->m_children.begin());
const float zpos = EARTH_RADIUS * 3;
Frame* pframe = *(++(++(Space::rootFrame->m_children.begin())));
Frame* stationFrame = new Frame(pframe, "Station frame..");
stationFrame->SetRadius(5000);
@ -244,7 +244,7 @@ void L3D::MainLoop(void) {
infoView = new InfoView();
SetView(world_view);
//player->SetDockedWith(station);
player->SetDockedWith(station);
Uint32 last_stats = SDL_GetTicks();
int frame_stat = 0;

View File

@ -57,6 +57,43 @@ void Space::MoveOrbitingObjectFrames(Frame* f) {
}
}
static Frame* MakeFrameFor(StarSystem::SBody* sbody, Body* b, Frame* f) {
Frame* orbFrame, *rotFrame;
if(!sbody->parent) {
b->SetFrame(f);
return f;
}
switch(sbody->GetSuperType()) {
/*
* For planets we want a non-rotating frame for a few radii
* and a rotating frame in the same position but with maybe 1.1*radius,
* which actually contains the object.
*/
case StarSystem::SUPERTYPE_GAS_GIANT:
case StarSystem::SUPERTYPE_ROCKY_PLANET:
orbFrame = new Frame(f, sbody->name.c_str());
orbFrame->sBody = sbody;
orbFrame->SetRadius(10*sbody->GetRadius());
assert(sbody->GetRotationPeriod() != 0);
rotFrame = new Frame(orbFrame, sbody->name.c_str());
rotFrame->SetRadius(1.1*sbody->GetRadius());
rotFrame->SetAngVelocity(vector3d(0,2*M_PI/sbody->GetRotationPeriod(), 0));
b->SetFrame(rotFrame);
return orbFrame;
/* Stars want a single small non-rotating frame. */
case StarSystem::SUPERTYPE_STAR:
default:
orbFrame = new Frame(f, sbody->name.c_str());
orbFrame->sBody = sbody;
orbFrame->SetRadius(1.2*sbody->GetRadius());
b->SetFrame(orbFrame);
return orbFrame;
}
}
void Space::GenBody(StarSystem::SBody* sbody, Frame* f) {
Body* b;
@ -71,19 +108,8 @@ void Space::GenBody(StarSystem::SBody* sbody, Frame* f) {
}
b->SetLabel(sbody->name.c_str());
Frame* myframe;
if(sbody->parent) {
myframe = new Frame(f, sbody->name.c_str());
myframe->SetRadius(10*sbody->GetRadius());
myframe->sBody = sbody;
b->SetFrame(myframe);
} else {
b->SetFrame(f);
myframe = f;
}
f = myframe;
b->SetPosition(vector3d(0, 0, 0));
f = MakeFrameFor(sbody, b, f);
AddBody(b);

View File

@ -331,6 +331,7 @@ void StarSystem::CustomGetChildOf(SBody* parent, const CustomSBody* customDef, c
child->mass = c->mass;
child->averageTemp = c->averageTemp;
child->name = c->name;
child->rotationPeriod = c->rotationPeriod;
child->orbit.eccentricity = c->eccentricity.ToDouble();
child->orbit.semiMajorAxis = c->semiMajorAxis.ToDouble() * AU;
@ -486,6 +487,7 @@ StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
planet->parent = primary;
//planet->radius = EARTH_RADIUS*bodyTypeInfo[type].radius;
planet->mass = mass;
planet->rotationPeriod = fixed(rand.Int32(1,200), 24);
fixed ecc = rand.NFixed(3);
fixed semiMajorAxis = fixed(i+1, 10); /* In AUs. */
@ -623,6 +625,8 @@ void StarSystem::SBody::PickPlanetType(SBody* star, const fixed distToPrimary, M
moon->tmp = 0;
moon->parent = this;
//moon->radius = EARTH_RADIUS*bodyTypeInfo[type].radius;
moon->rotationPeriod = fixed(rand.Int32(1,200), 24);
moon->mass = mass;
fixed ecc = rand.NFixed(3);
fixed semiMajorAxis = fixed(i+2, 2000);

View File

@ -100,6 +100,10 @@ public:
else
return mass.ToDouble() * EARTH_MASS;
}
/* Returned in seconds. */
double GetRotationPeriod(void) const {
return rotationPeriod.ToDouble()*60*60*24;
}
int tmp;
Orbit orbit;
@ -108,6 +112,7 @@ public:
fixed radius;
fixed mass; /* Earth masses if planet, solar masses if star. */
fixed radMin, radMax; /* In AU's. */
fixed rotationPeriod; /* In days. */
int averageTemp;
BodySuperType supertype;