level.h

00001 
00002 
00003 
00004 #define LEVEL_DIMENSION_X                       50.0f
00005 #define LEVEL_DIMENSION_Y                       50.0f
00006 #define LEVEL_DIMENSION_Z                       50.0f
00007 #define LEVEL_DIMENSION_OFFSET          -128.0f
00008 #define LEVEL_SCALE_X                           0.5f
00009 #define LEVEL_SCALE_Y                           0.5f
00010 #define LEVEL_SCALE_Z                           0.5f
00011 #define LEVEL_ROTATION_OFFSET           -10.0f
00012 #define LEVEL_ROTATION_TRIM                     0.1f
00013 
00014 
00015 
00016 void parseXML(IXMLReader* xml)
00017 {
00018         stringc nodeName = "";
00019         int objectCount = 0;
00020 
00021         while(xml && xml->read())
00022         {
00023                 switch(xml->getNodeType())
00024                 {
00025                         case EXN_ELEMENT:
00026                         {
00027                                 nodeName = xml->getNodeName();
00028 
00029                                 if ( nodeName.equals_ignore_case(stringc("level")) )
00030                                 {
00031                                         //levelName = xml->getAttributeValue(L"name");
00032                                         levelTime = xml->getAttributeValueAsInt(L"time");
00033                                         //levelPoints = xml->getAttributeValueAsInt(L"points");
00034                                 }
00035                                 else if ( nodeName.equals_ignore_case(stringc("player")) )
00036                                 {
00037                                         // Setup global cal3D Model
00038                                         stringc mesh = "";
00039                                         float x, y, z;
00040                                         float rx, ry, rz;
00041                                         float sx, sy, sz;
00042                                         mesh = xml->getAttributeValue(L"mesh");
00043                                         x = (xml->getAttributeValueAsFloat(L"pos_x") + LEVEL_DIMENSION_OFFSET) * LEVEL_DIMENSION_X;
00044                                         y = (xml->getAttributeValueAsFloat(L"pos_y") + LEVEL_DIMENSION_OFFSET) * LEVEL_DIMENSION_Y;
00045                                         z = (xml->getAttributeValueAsFloat(L"pos_z") + LEVEL_DIMENSION_OFFSET) * LEVEL_DIMENSION_Z;
00046                                         rx = xml->getAttributeValueAsFloat(L"rot_x") - LEVEL_ROTATION_OFFSET;
00047                                         ry = xml->getAttributeValueAsFloat(L"rot_y") - LEVEL_ROTATION_OFFSET;
00048                                         rz = xml->getAttributeValueAsFloat(L"rot_z") - LEVEL_ROTATION_OFFSET;
00049                                         sx = xml->getAttributeValueAsFloat(L"scale_x") * LEVEL_SCALE_X;
00050                                         sy = xml->getAttributeValueAsFloat(L"scale_y") * LEVEL_SCALE_X;
00051                                         sz = xml->getAttributeValueAsFloat(L"scale_z") * LEVEL_SCALE_X;
00052 
00053                                         ISceneNode* parent = smgr->getRootSceneNode();
00054                                         player.node = new CCal3DSceneNode(makeMediaString(mesh).c_str(), parent, smgr, -1);
00055                                         if (! player.node->init())
00056                                         {
00057                                                 stringw text("cannot load: ");
00058                                                 text.append(makeMediaString(mesh).c_str());
00059                                                 text.append(stringw(" !!! wrong path ???"));
00060                                                 device->setWindowCaption(text.c_str());
00061                                                 return;
00062                                         }
00063                                         player.node->setPosition(v3(x,y,z));
00064                                         player.node->setRotation(v3(rx,ry,rz));
00065                                         player.node->setScale(v3(sx,sy,sz));
00066 
00067                                         // collision
00068                                         //player.node->setDebugDataVisible(true);
00069                                 }
00070                                 else if ( nodeName.equals_ignore_case(stringc("object")) )
00071                                 {
00072                                         int objID = -1;
00073                                         stringc objType = "";
00074                                         stringc objMesh = "";
00075                                         float x, y, z;
00076                                         float rx, ry, rz;
00077                                         float sx, sy, sz;
00078 
00079                                         if (12 != xml->getAttributeCount())
00080                                         {
00081                                                 std::cout << "parseXML() inconsistent object attributes: atrCnt=" << xml->getAttributeCount() << " (should be 12)" << endl;
00082                                         }
00083 
00084                                         objID = xml->getAttributeValueAsInt(L"id");
00085                     objectCount++;
00086                                         
00087                                         if (objectCount != objID)
00088                                         {
00089                                                 cout << "parseXML() inconsistent object count: objCnt=" << objectCount << " objID=" << objID << endl;
00090                                         }
00091 
00092                                         objType = xml->getAttributeValue(L"type");
00093                                         objMesh = xml->getAttributeValue(L"mesh");
00094                                         x = (xml->getAttributeValueAsFloat(L"pos_x") + LEVEL_DIMENSION_OFFSET) * LEVEL_DIMENSION_X;
00095                                         y = (xml->getAttributeValueAsFloat(L"pos_y") + LEVEL_DIMENSION_OFFSET) * LEVEL_DIMENSION_Y;
00096                                         z = (xml->getAttributeValueAsFloat(L"pos_z") + LEVEL_DIMENSION_OFFSET) * LEVEL_DIMENSION_Z;
00097                                         rx = (xml->getAttributeValueAsFloat(L"rot_x") + LEVEL_ROTATION_OFFSET) * LEVEL_ROTATION_TRIM;
00098                                         ry = (xml->getAttributeValueAsFloat(L"rot_y") + LEVEL_ROTATION_OFFSET) * LEVEL_ROTATION_TRIM;
00099                                         rz = (xml->getAttributeValueAsFloat(L"rot_z") + LEVEL_ROTATION_OFFSET) * LEVEL_ROTATION_TRIM;
00100                                         sx = xml->getAttributeValueAsFloat(L"scale_x") * LEVEL_SCALE_X;
00101                                         sy = xml->getAttributeValueAsFloat(L"scale_y") * LEVEL_SCALE_Y;
00102                                         sz = xml->getAttributeValueAsFloat(L"scale_z") * LEVEL_SCALE_Z;
00103 
00104                                         IAnimatedMesh* mesh = smgr->getMesh(makeMediaString(objMesh).c_str());
00105                                         if (mesh)
00106                                         {
00107                                                 // finaly, create an object
00108                                                 //ISceneNode* newNode = smgr->addMeshSceneNode(mesh->getMesh(0));
00109                                                 ISceneNode* newNode = smgr->addTestSceneNode(100.0f);   //dbg
00110                                                 newNode->setMaterialTexture(0, driver->getTexture("media/wall.bmp"));   // dbg
00111                                                 
00112                                                 //dbg:
00113                                                 //newNode->setDebugDataVisible(true);
00114                                                 //newNode->setMaterialFlag(EMF_LIGHTING, false);
00115                                                 //newNode->setMaterialFlag(EMF_BILINEAR_FILTER, true);
00116                                                 //newNode->setMaterialFlag(EMF_TRILINEAR_FILTER, true);
00117                                                 //newNode->setMaterialFlag(EMF_GOURAUD_SHADING, false);
00118                                                 //newNode->setMaterialFlag(EMF_WIREFRAME, true);
00119 
00120                                                 // set properties of object
00121                                                 newNode->setID(objID);
00122                                                 newNode->setPosition(v3(x, y, z));
00123                                                 newNode->setRotation(v3(rx, ry, rz));
00124                                                 newNode->setScale(v3(sx, sy, sz));
00125 
00126                                                 // copy into our own structure
00127                                                 Obj* newO = new Obj();
00128                                                 newO->mesh = mesh->getMesh(0);
00129                                                 newO->node = newNode;
00130                                                 
00131                                                 if (objType.equals_ignore_case(stringc("ring").c_str()))
00132                                                 {
00133                                                         // remove initial rotation on rings
00134                                                         newO->rot = v3(0,0,0);
00135                                                         // change ring-color
00136                                                         newO->node->getMaterial(0).EmissiveColor.set(0,155,0,0); // bright red
00137                                                 }
00138                                                 else
00139                                                 {
00140                                                         newO->rot = newNode->getRotation();
00141                                                 }
00142                                                 newO->name = objType;
00143 
00144                                                 // insert into list
00145                                                 objects.push_back(newO);
00146                                         }
00147                                 }
00148                                 else
00149                                 {
00150                                         cout << "parseXML() unknown node-name:" << nodeName.c_str() << endl;
00151                                 }
00152                         }
00153                 }
00154         }
00155 }
00156 
00157 
00158 void loadNextLevel()
00159 {
00160         // todo: iterate through all levels in folder LEVELPATH
00161         IXMLReader* xml = device->getFileSystem()->createXMLReader(LEVELPATH);
00162         if (!xml)
00163         {
00164                 cout << "loadNextLevel() cannot open file '" << LEVELPATH << "'" << endl;
00165         }
00166         else
00167         {
00168                 cout << "loadNextLevel() parsing xml-file: " << LEVELPATH << endl;
00169                 parseXML(xml);
00170         }
00171 
00172         if (xml)
00173         {
00174                 xml->drop(); // don't forget to delete the xml reader 
00175         }
00176 }

Generated on Sun Dec 2 18:30:26 2007 for DrgonWings by  doxygen 1.5.4