All pastes #214091 Raw Edit

Anonymous

public text v1 · immutable
#214091 ·published 2006-10-21 20:51 UTC
rendered paste body
#include "solarsys.h"
#include "appTest.h"

#define SOL_DATA_DIR "data/"

// --------------------------------------------------------------------------------//
//  Galaxy member functions 	-----------------------------------------------------//
// --------------------------------------------------------------------------------//
Galaxy::Galaxy(AppTest* app) {
	Galaxy::app = app;
	galaxy_name ="";
}

void Galaxy::Set_Name(const std::string& new_name) {
	galaxy_name = new_name;
}

std::string Galaxy::Get_Name() {
	return ( galaxy_name );
}

System* Galaxy::Get_Current_Sys () {
	return ( current_sys );
}

bool Galaxy::Load_Systems (const std::string& file_name ) {
	
	std::ifstream inFile;	
	std::string data;
	System* system; 

	// Temp var for System data
	int id;
	std::string name;
	long ra; 
	long dec;
	long distance; 

	// Temp var for Star data
	std::string SpectralType; 
	long AbsMag;  
	

	inFile.open(  (SOL_DATA_DIR + file_name).c_str() );
	if (!inFile) {
		printf ( "Galaxy::Load_Systems -> Unable to open %s\n" ,  file_name.c_str() );
		return (false);
	}
	inFile >> data;  // Skip first entry, Total # stars
	while ( inFile >> data) {
	// Data Format
	// ID RA         DEC       Distance  AbsMag  Star_Type/s
	// 1  0.00091185 1.0890133 921.37572 9.09766 F5
		// Get data 
		id = std::atoi(data.c_str()); 

		inFile >> data; // RA
		ra  = std::atol (data.c_str() );
		inFile >> data; // DEC
		dec = std::atol (data.c_str() );
		inFile >> data; // Distance
		distance = std::atol (data.c_str() );
		inFile >> data; // AbsMag // Think it's actual the apparent mag from rading cel docs
		AbsMag = std::atol (data.c_str());
		inFile >> data; // StarType
		SpectralType = data;
		// No System name yet, will do later 
		name = "Unnamed";


		system = new System;
		system->Init ( id , name , ra , dec , distance );
		if (id==0) {	current_sys = system; } // Keep a pointer to the start system
		// Loop through the systems Stars and create the star's
		// Note, only adding one star per system to start
		system->Add_Star ( "Default Star" , SpectralType ,AbsMag );
		systems.push_back(system); 
		printf ("Loading System ID:%i\n" , id );
	}
    inFile.close();
     return 0;
}

// Just print the galaxy name on screen
void Galaxy::Show_Info() {

	int x = 10; 
	int y = 10;
	csRef<iFont> font;

	csRef<iGraphics3D> g3d = app->GetEngine();

	csRef<iGraphics2D> g2d = g3d.GetDriver2D ();
	font = g2d->GetFontServer()->LoadFont(CSFONT_LARGE);
	int glyphWidth, glyphHeight;
	font->GetMaxSize (glyphWidth, glyphHeight);
	int white = g2d ->FindRGB (255,0,0);
	g2d ->Write (font, x ,g2d->GetHeight () - 
				(glyphHeight == -1? 20 : (glyphHeight+1)) - y,white, 0, galaxy_name.c_str());


}


// --------------------------------------------------------------------------------//
// System member functions --------------------------------------------------------//
// --------------------------------------------------------------------------------//
System::System() {
	id = 0;
}

void System::Init ( int Id, std::string Name , long Ra, long Dec, long Distance ) {

	id = Id;
	ra = Ra;
	dec = Dec;
	distance = Distance;

	// Calculate a coordinate position for this system
	
	
}

bool System::Add_Star ( std::string name, std::string classification,
							 long luminosity ) {

	Star* star;

	star = new Star;
	star->Init ( name, classification, luminosity , this );
	stars.push_back(star);
	return true;
}	

// iterate through all the systems stars and tell them to create mesh objects
bool System::Create_Bodys(){
	std::vector<Star> itr;

	
		for (std::vector<Star*>::iterator itr = stars.begin();
     			itr != stars.end();
     			++itr) {
				(*itr)->Create_Bodys();
				//Star * mystar = *itr;
  				//mystar->Create_Bodys();
				printf("Star\n");
		} // end for iterate stars
	
	
	return true ;
}

// --------------------------------------------------------------------------------//
// Star member functions ----------------------------------------------------------//
// --------------------------------------------------------------------------------//

Star::Star() {
		system = NULL;
		name = "";
		classification = "";
		luminosity = 0;

		mass = 0;
		center.x = 0;
		center.y = 0;
		center.z = 0;
}

void Star::Init( std::string new_name, std::string classification,
							 long new_luminosity, System* parent_system ) {


		system = parent_system;
		name = "Default";
		classification = classification;
		luminosity = new_luminosity;

		mass = 0;
		center.x = 0;
		center.y = 0;
		center.z = 0;

}

std::string Star::Get_Name () { 
	return ( name );
}

bool Star::Create_Mesh () {
	
	//csRef<iGraphics3D> g3d = app->Get_g3d ();
	return true;
}

bool Star::Create_Bodys() {
	printf ("Star:%s\n", name.c_str());
	return true;
}



// --------------------------------------------------------------------------------//
//  Body member functions 	-----------------------------------------------------//
// --------------------------------------------------------------------------------//

Body::Body() {
	
}

Body::Body(std::string name_in, double mass_in) {
	name = name_in;
	mass = mass_in;
}
/*
bool Body::CreateSphere(std::string name,
								csVector3 radius,
								csVector3 center,
								std::string matname,
								csVector3 pos ) {

  // Create iEngine referance 
	csRef<iEngine> engine = app->GetEngine ();

	if (!engine) return ReportError("Failed to locate 3D engine!");

	// Create the ball mesh factory.
	csRef<iMeshFactoryWrapper> ballFact = engine->CreateMeshFactory(
	"crystalspace.mesh.object.genmesh", "ballFact");

	if (ballFact == 0) {
		csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
		"SolApp",
		"Error creating mesh object factory!");
	}

	csRef<iGeneralFactoryState> gmstate = scfQueryInterface<iGeneralFactoryState> (
	ballFact->GetMeshObjectFactory ());

	csEllipsoid ellips (center, radius);
	gmstate->GenerateSphere (ellips, 64);
	// Create the mesh.
	room = engine->FindSector("Scene" , 0 );
	csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (ballFact, name , room));
	movable = mesh->GetMovable();
	movable->SetPosition ( pos );
	iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName (matname);
	mesh->GetMeshObject ()->SetMaterialWrapper (mat);

	// Create a body and attach the mesh.
	csRef<iRigidBody> rb = dynSys->CreateBody ();
	rb->SetProperties (radius.Norm()/2, csVector3 (0), csMatrix3 ());
	rb->SetPosition ( center );
	rb->AttachMesh (mesh);

	// Create and attach a sphere collider.
	rb->AttachColliderSphere (radius.Norm()/2, csVector3 (0), 10, 1, 0.8f);
	return true;
}*/