#pragma once #include "base.h" #include "eye.h" class Momentum; class Moon; class Tokenizer; // represents all objects in the simulation class Cosmos { // array of descriptions of moons // config example moon: "p(0.0,0.0,0.0) v(0.0,0.0,0.0) 10.0 ffff00 5.0" // position(x,y,z) velocity(x,y,z) mass, color, size. std::vector _moon; // list of pointers to moons, ordered by least to most mass std::vector _displayMoon; // list of pointers to moons, ordered by z axis (those behind us, then closest to furthest) size_t _firstMass; // first moon with mass int _points; // number of points used by interpolation method double _increment; // virtual time step to take each refresh. _sleep milliseconds between refreshes. double _inc; // _increment / _work int _backgroundColor; // background color for the display int _work; // how many iterations to do per refresh. int _sleep; // number of milliseconds between refreshes bool _trail; // if true, do not erase past positions before drawing new positions bool _energy; // if true, periodically report the total energy of the system // where to view the simulation from. // config example "100.0 0.0 -0.3 0.0 300.0". // Distance from center, left up clockwise rotation (radians), zoom. Eye* _eye; bool _stop; // if true, bring up the simulation with nothing happening bool _autocenter; // if true, autocenter the simulation to have average 0 velocity and 0 position double _length; // amount of virtual time to run the simulation. 0 means forever. double _scaleMass; // amount to scale masses by int _follow; // follow=17 means put the eye on moon #17. -1 means don't follow any moon. Moon* _followMoon; // follow this moon bool _noPerspective; // if true, do not display depth, equivalent to eye at infinite distance bool _ring; // if true, each moon represents a ring around the x==0 z==0 axis void ParseApplet(Tokenizer* t); void Multistep(); // Move everyone one step forward, then measure accelerations and update history void MoonAcceleration(); // Measure accelerations for moons based on current positions void RingAcceleration(); // Set accelerations for rings based on current positions void MeasureAccelerations(); // measure accelerations for either moons or rings void MoveToNewPositions(); // measure accelerations and update history and head void MoveRings(); // ... for rings void MoveMoons(); // ... for moons double _t; // time simulated so far int _counter; // amount of history filled in so far bool _stopped; // whether simulation is currently stopped void (Moon::*_stepFunction)(); // type of step function to use Momentum* _unusedMomentum; // momentum objects currently not being used void RotateRightAndDown(int right, int down); void ShiftRightAndDown(int right, int down); public: Cosmos(); ~Cosmos(); void Clear(); // get rid of all moons void Load(const char* path); // fill cosmos from configuration file Eye* GetEye() { return _eye; } void RightAndDown(int right, int down); bool Stopped() { return _stopped; } void ToggleStopped() { _stopped = !_stopped; } int Sleep() { return _sleep; } void Prepare(); // Prepare to step through simulation. Carefully step a little ways back in time, then AboutFace() to land exactly on the starting time. void Display(HDC& memoryDC); // Paint the current state of the system into memoryDC void ClearDisplay(HDC& memoryDC); // overwrite the display with nothing but background bool Move(); // Move forward by "work" steps, return false if the simulation has finished };