void CCharShape::CreateMaterial (const char *line) { char matName[32]; TVector3 diff = {0,0,0}; TVector3 spec = {0,0,0}; float exp = 100; string lin = line; SPCharN (lin, "mat", matName); diff = SPVector3N (lin, "diff", MakeVector (0,0,0)); spec = SPVector3N (lin, "spec", MakeVector (0,0,0)); exp = SPFloatN (lin, "exp", 50); /* TCharMaterial *matPtr = (TCharMaterial *) malloc (sizeof (TCharMaterial)); matPtr->diffuse.r = diff.x; matPtr->diffuse.g = diff.y; matPtr->diffuse.b = diff.z; matPtr->diffuse.a = 1.0; matPtr->specular.r = spec.x; matPtr->specular.g = spec.y; matPtr->specular.b = spec.z; matPtr->specular.a = 1.0; matPtr->exp = exp; */ Materials[numMaterials] = (TCharMaterial *) malloc (sizeof (TCharMaterial)); Materials[numMaterials]->diffuse.r = diff.x; Materials[numMaterials]->diffuse.g = diff.y; Materials[numMaterials]->diffuse.b = diff.z; Materials[numMaterials]->diffuse.a = 1.0; Materials[numMaterials]->specular.r = spec.x; Materials[numMaterials]->specular.g = spec.y; Materials[numMaterials]->specular.b = spec.z; Materials[numMaterials]->specular.a = 1.0; Materials[numMaterials]->exp = exp; SPAddIntN (MaterialIndex, matName, numMaterials); // Materials[numMaterials] = matPtr; numMaterials++; }
void CCharShape::CreateMaterial (const string& line) { TVector3 diff = SPVector3N (line, "diff", TVector3 (0,0,0)); TVector3 spec = SPVector3N (line, "spec", TVector3 (0,0,0)); float exp = SPFloatN (line, "exp", 50); std::string mat = SPItemN (line, "mat"); STrimN(mat); Materials.push_back(TCharMaterial()); Materials.back().diffuse.r = diff.x; Materials.back().diffuse.g = diff.y; Materials.back().diffuse.b = diff.z; Materials.back().diffuse.a = 1.0; Materials.back().specular.r = spec.x; Materials.back().specular.g = spec.y; Materials.back().specular.b = spec.z; Materials.back().specular.a = 1.0; Materials.back().exp = exp; if(useActions) Materials.back().matline = line; MaterialIndex[mat] = Materials.size()-1; }
bool CKeyframe::Load (string dir, string filename) { if (loaded && loadedfile == filename) return true; CSPList list (1000); int i; string line; TVector2 pp; numFrames = 0; TVector3 posit; if (list.Load (dir, filename)) { for (i=0; i<list.Count(); i++) { line = list.Line (i); frames[numFrames] = new (TKeyframe2); frames[numFrames]->val[0] = SPFloatN (line, "time", 0); posit = SPVector3N (line, "pos", MakeVector (0, 0, 0)); frames[numFrames]->val[1] = posit.x; frames[numFrames]->val[2] = posit.y; frames[numFrames]->val[3] = posit.z; frames[numFrames]->val[4] = SPFloatN (line, "yaw", 0); frames[numFrames]->val[5] = SPFloatN (line, "pitch", 0); frames[numFrames]->val[6] = SPFloatN (line, "roll", 0); frames[numFrames]->val[7] = SPFloatN (line, "neck", 0); frames[numFrames]->val[8] = SPFloatN (line, "head", 0); pp = SPVector2N (line, "sh", MakeVector2 (0, 0)); frames[numFrames]->val[9] = pp.x; frames[numFrames]->val[10] = pp.y; pp = SPVector2N (line, "arm", MakeVector2 (0, 0)); frames[numFrames]->val[11] = pp.x; frames[numFrames]->val[12] = pp.y; pp = SPVector2N (line, "hip", MakeVector2 (0, 0)); frames[numFrames]->val[13] = pp.x; frames[numFrames]->val[14] = pp.y; pp = SPVector2N (line, "knee", MakeVector2 (0, 0)); frames[numFrames]->val[15] = pp.x; frames[numFrames]->val[16] = pp.y; pp = SPVector2N (line, "ankle", MakeVector2 (0, 0)); frames[numFrames]->val[17] = pp.x; frames[numFrames]->val[18] = pp.y; numFrames++; } loaded = true; loadedfile = filename; return true; } else { MessageN ("keyframe not found:", filename); loaded = false; return false; } }
bool CKeyframe::Load (const string& dir, const string& filename) { if (loaded && loadedfile == filename) return true; CSPList list (1000); if (list.Load (dir, filename)) { frames.resize(list.Count()); for (size_t i=0; i<list.Count(); i++) { const string& line = list.Line(i); frames[i].val[0] = SPFloatN (line, "time", 0); TVector3 posit = SPVector3N (line, "pos", NullVec); frames[i].val[1] = posit.x; frames[i].val[2] = posit.y; frames[i].val[3] = posit.z; frames[i].val[4] = SPFloatN (line, "yaw", 0); frames[i].val[5] = SPFloatN (line, "pitch", 0); frames[i].val[6] = SPFloatN (line, "roll", 0); frames[i].val[7] = SPFloatN (line, "neck", 0); frames[i].val[8] = SPFloatN (line, "head", 0); TVector2 pp = SPVector2N (line, "sh", TVector2(0, 0)); frames[i].val[9] = pp.x; frames[i].val[10] = pp.y; pp = SPVector2N (line, "arm", TVector2(0, 0)); frames[i].val[11] = pp.x; frames[i].val[12] = pp.y; pp = SPVector2N (line, "hip", TVector2(0, 0)); frames[i].val[13] = pp.x; frames[i].val[14] = pp.y; pp = SPVector2N (line, "knee", TVector2(0, 0)); frames[i].val[15] = pp.x; frames[i].val[16] = pp.y; pp = SPVector2N (line, "ankle", TVector2(0, 0)); frames[i].val[17] = pp.x; frames[i].val[18] = pp.y; } loaded = true; loadedfile = filename; return true; } else { Message ("keyframe not found:", filename); loaded = false; return false; } }
bool CCourse::LoadObjectTypes () { CSPList list (MAX_OBJECT_TYPES+10); if (!list.Load (param.obj_dir, "object_types.lst")) { Message ("could not load object types"); return false; } ObjTypes.resize(list.Count()); for (size_t i=0; i<list.Count(); i++) { const string& line = list.Line(i); ObjTypes[i].name = SPStrN (line, "name", ""); ObjTypes[i].textureFile = ObjTypes[i].name; ObjTypes[i].texture = NULL; ObjTypes[i].drawable = SPBoolN (line, "draw", true); if (ObjTypes[i].drawable) { ObjTypes[i].textureFile = SPStrN (line, "texture", ""); } ObjTypes[i].collectable = SPBoolN (line, "snap", -1) != 0; if (ObjTypes[i].collectable == 0) { ObjTypes[i].collectable = -1; } ObjTypes[i].collidable = SPBoolN (line, "coll", false); ObjTypes[i].reset_point = SPBoolN (line, "reset", false); ObjTypes[i].use_normal = SPBoolN (line, "usenorm", false); if (ObjTypes[i].use_normal) { ObjTypes[i].normal = SPVector3N (line, "norm", TVector3(0, 1, 0)); NormVector ((ObjTypes[i].normal)); } ObjTypes[i].poly = 1; } list.MakeIndex (ObjectIndex, "name"); return true; }
bool CEvents::LoadEventList () { CSPList list(256); int i, ii, type; string line, item, race, cup; int num; if (!list.Load (param.common_course_dir, "events.lst")) { Message ("could not load events.lst"); return false; } // pass 1: races for (i=0; i<list.Count(); i++) { line = list.Line (i); type = SPIntN (line, "struct", -1); if (type == 0) { if (numRaces < MAX_RACES2) { RaceList[numRaces].race = SPStrN (line, "race", "error"); item = SPStrN (line, "course", ""); RaceList[numRaces].course = Course.GetCourseIdx (item); item = SPStrN (line, "light", ""); RaceList[numRaces].light = Env.GetLightIdx (item); RaceList[numRaces].snow = SPIntN (line, "snow", 0); RaceList[numRaces].wind = SPIntN (line, "wind", 0); RaceList[numRaces].time = SPVector3N (line, "time", MakeVector (0, 0, 0)); RaceList[numRaces].herrings = SPIndex3N (line, "herring", MakeIndex3 (0, 0, 0)); RaceList[numRaces].music_theme = Music.GetThemeIdx (SPStrN (line, "theme", "normal")); numRaces++; } } } list.MakeIndex (RaceIndex, "race"); // pass 2: cups for (i=0; i<list.Count(); i++) { line = list.Line (i); type = SPIntN (line, "struct", -1); if (type == 1) { if (numCups < MAX_CUPS2) { CupList[numCups].cup = SPStrN (line, "cup", "error"); CupList[numCups].name = SPStrN (line, "name", "unknown"); CupList[numCups].desc = SPStrN (line, "desc", "unknown"); num = SPIntN (line, "num", 0); CupList[numCups].num_races = num; for (ii=0; ii<num; ii++) { race = SPStrN (line, Int_StrN (ii+1), ""); CupList[numCups].races[ii] = GetRaceIdx (race); } numCups++; } } } list.MakeIndex (CupIndex, "cup"); // pass 3: events for (i=0; i<list.Count(); i++) { line = list.Line (i); type = SPIntN (line, "struct", -1); if (type == 2) { if (numEvents < MAX_EVENTS2) { EventList[numEvents].name = SPStrN (line, "name", "unknown"); num = SPIntN (line, "num", 0); EventList[numEvents].num_cups = num; for (ii=0; ii<num; ii++) { cup = SPStrN (line, Int_StrN (ii+1), ""); EventList[numEvents].cups[ii] = GetCupIdx (cup); } numEvents++; } } } list.MakeIndex (EventIndex, "event"); return true; }
bool CCharShape::Load (string dir, string filename, bool with_actions) { CSPList list (500); int i, ii, act; string line, order, name, mat_name, fullname; TVector3 scale, trans, rot; double visible; bool shadow; int node_name, parent_name; useActions = with_actions; CreateRootNode (); newActions = true; file_name = filename; if (!list.Load (dir, filename)) { Message ("could not load character", filename.c_str()); return false; } for (i=0; i<list.Count(); i++) { line = list.Line (i); node_name = SPIntN (line, "node", -1); parent_name = SPIntN (line, "par", -1); mat_name = SPStrN (line, "mat", ""); name = SPStrN (line, "joint", ""); fullname = SPStrN (line, "name", ""); if (SPIntN (line, "material", 0) > 0) { CreateMaterial (line.c_str()); if (useActions) { Matlines[numMatlines] = line; numMatlines++; } } else { visible = SPFloatN (line, "vis", -1.0); shadow = SPBoolN (line, "shad", false); order = SPStrN (line, "order", ""); CreateCharNode (parent_name, node_name, name, fullname, order, shadow); rot = SPVector3N (line, "rot", NullVec); MaterialNode (node_name, mat_name); for (ii=0; ii<(int)order.size(); ii++) { act = order.at(ii)-48; switch (act) { case 0: trans = SPVector3N (line, "trans", MakeVector (0,0,0)); TranslateNode (node_name, trans); break; case 1: RotateNode (node_name, 1, rot.x); break; case 2: RotateNode (node_name, 2, rot.y); break; case 3: RotateNode (node_name, 3, rot.z); break; case 4: scale = SPVector3N (line, "scale", MakeVector (1,1,1)); ScaleNode (node_name, scale); break; case 5: VisibleNode (node_name, visible); break; case 9: RotateNode (node_name, 2, rot.z); break; default: break; } } } } newActions = false; return true; }
bool CCharShape::Load (const string& dir, const string& filename, bool with_actions) { CSPList list (500); useActions = with_actions; CreateRootNode (); newActions = true; if (!list.Load (dir, filename)) { Message ("could not load character", filename); return false; } for (size_t i=0; i<list.Count(); i++) { const string& line = list.Line(i); int node_name = SPIntN (line, "node", -1); int parent_name = SPIntN (line, "par", -1); string mat_name = SPStrN (line, "mat", ""); string name = SPStrN (line, "joint", ""); string fullname = SPStrN (line, "name", ""); if (SPIntN (line, "material", 0) > 0) { CreateMaterial (line); } else { double visible = SPFloatN (line, "vis", -1.0); bool shadow = SPBoolN (line, "shad", false); string order = SPStrN (line, "order", ""); CreateCharNode (parent_name, node_name, name, fullname, order, shadow); TVector3 rot = SPVector3N (line, "rot", NullVec); MaterialNode (node_name, mat_name); for (size_t ii = 0; ii < order.size(); ii++) { int act = order[ii]-48; switch (act) { case 0: { TVector3 trans = SPVector3N (line, "trans", TVector3 (0,0,0)); TranslateNode (node_name, trans); break; } case 1: RotateNode (node_name, 1, rot.x); break; case 2: RotateNode (node_name, 2, rot.y); break; case 3: RotateNode (node_name, 3, rot.z); break; case 4: { TVector3 scale = SPVector3N (line, "scale", TVector3 (1,1,1)); ScaleNode (node_name, scale); break; } case 5: VisibleNode (node_name, visible); break; case 9: RotateNode (node_name, 2, rot.z); break; default: break; } } } } newActions = false; return true; }