int InitGL() // All Setup For OpenGL goes here { glShadeModel(GL_SMOOTH); // Enables Smooth Shading glClearColor(0.0, 0.0, 0.0, 1.0); glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculation glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Uses default lighting parameters glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glEnable(GL_NORMALIZE); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); glEnable(GL_LIGHT1); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); // and now some init I need to do for other stuff ilInit(); /* Initialization of DevIL */ // mouse stuff pointer = toGLTexture("./dati/models/textures/mirino.png"); lastx = middleX; lasty = middleY; relativeX = 0.0; relativeY = 0.0; glutWarpPointer(middleX, middleY); // put the cursor in the middle of the screen //for the menu InitMenu(); // for the text t3dInit(); // for the skybox initSkybox(); // for the blend initAssets(); // for the sounds if (!sound_hit.loadFromFile("./dati/audio/hit.wav")) return -1; if (!sound_miss.loadFromFile("./dati/audio/miss.wav")) return -1; if (!sound_youreempty.loadFromFile("./dati/audio/youreempty.wav")) return -1; if (!sound_ohno.loadFromFile("./dati/audio/ohno.wav")) return -1; music.setLoop(true); if (!music.openFromFile("./dati/audio/Rango_Theme.ogg")) return -1; music.play(); return TRUE; // Initialization Went OK }
Game::Game() { _window = new sf::RenderWindow(sf::VideoMode(displayconsts::DISPLAY_WIDTH,displayconsts::DISPLAY_HEIGHT), "Pixel Garden"); initAssets(); this->_mouse = new zf::Mouse(); this->_keyInput = new InputControl(); _pgsSequence = std::vector<int>(58); for(int i = 0 ; i < _pgsSequence.size() ; i++) { _pgsSequence[i] = i; } random_shuffle(_pgsSequence.begin(),_pgsSequence.end()); _pgsColor = std::vector<TextureRegion*>(0); for(int i = 0 ; i < _pgsSequence.size() ; i++) { _pgsColor.push_back(0); } for(int i = 0 ; i < _pgsSequence.size() ; i++) { int r = i % 7 ; switch(r) { case 0: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.red; break; case 1: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.blue; break; case 2: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.green; break; case 3: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.orange; break; case 4: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.purple; break; case 5: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.yellow; break; case 6: _pgsColor[_pgsSequence[i]]=&_assets.pixel.pgs.cyan; break; default : // just in case ? _pgsColor[i]=&_assets.pixel.pgs.gray; } } }
void TestGame2::init() { initAssets(); initScene(); initLua(); }
void ofApp::setup() { ofBackground(20); ofSetFrameRate(30); initAssets(); ChladniDB::setup(); midiIn.ignoreTypes(false, false, false); midiIn.addListener(this); midiIn.setVerbose(true); // midiIn.listPorts(); midiIn.openPort("virtualMIDI Bus 1"); // by name // panel.setup(); // panel.add(button.setup("something")); // button.setup("something"); // ofSoundStreamListDevices(); // button.draw(); PianoKeys::Key::baseOnCol = ofColor(255, 100, 100); // ofSetEscapeQuitsApp(false); int pianoHeight = 50; pianoKeys = PianoKeys(0, 7, 0, 0, ofGetWidth(), pianoHeight); channels = Channels(5, 0, pianoHeight); plateManager = new PlateManager(); // plateManager->setup(5, 5); plateManager->setup(5, 1); pm = plateManager; cam.setTranslationKey('t'); cam.setFarClip(20000); resetView(); PlateManager::drawSpecial = false; panel.setup(""); midiNotesGroup.setup("MIDI notes"); patternFreqsGroup.setup("Pattern Frequencies"); // panel.add(xx.set("something", 2, 0, 3)); // // // ofParameterGroup g; // g.setName("asdf 2"); // g.add(xx.set("something 2", 1, 0, 3)); // panel.add(g); // panel.add(label.setup(ofParameter<string>("", "hi there"))); // toggle.setup(ofParameter<bool>("tog", true)); // toggle.addListener(this, &ofApp::valChange); // // panel.add(&toggle); // panel.setPosition(200, 200); currentRenderType = NORMAL; currentPlate = NULL; showPanel = false; needsToRedrawPanel = false; noSelectionMode = false; connectMode = false; connecting = false; connectedPlate = NULL; noteToFigureManager = new PlateManagerMidi(); noteToFigureManager->setup(FIGURE_GRID_X, FIGURE_GRID_Y); for (int i = 1; i <= MAX_CHANNELS; i++) { playingPitches[i] = map<int,int>(); currentNotesPlaying[i] = 0; } // soundStream. // ofSoundStreamSetup(5, 0, 44100, 512, 2); soundStream.printDeviceList(); soundStream.setDeviceID(1); soundStream.setup(this, 2, 0, 44100, 512, 2); // plateManager->setup(10, 10); // initSnake(); // mode = SNAKE; // tempPanel.setup("tempPanel"); // tempPanel.add(spacing.set("spacing", 10, 0, 100)); // // loadImage(); }
static AtNode *MyGetNode(void *user_ptr, int i){ cout << "BEGIN GET NODE" << endl; const McdMiddleData* params = static_cast<McdMiddleData*>(user_ptr); const char* g_assetsPath = params->m_assetsPath; int g_agentID = params->m_agentID; int g_ppID = params->m_ppID; int g_geoID = params->m_geoID; int g_poly0_subd1 = params->m_poly0_subd1; int g_motionBlur = params->m_motionBlur; float g_motionShutter = params->m_motionShutter; const char* g_poseData = params->m_poseData; string agentFolder; string agentPath2,geoPath2,weightPath2; string currentLine; //long counter1; //long counter2; #ifdef WIN32 EnterCriticalSection(&g_cs1); #else pthread_mutex_lock( &cs_mutex ); #endif if (!have_Data) initAssets(params); #ifdef WIN32 LeaveCriticalSection(&g_cs1); #else pthread_mutex_unlock( &cs_mutex ); #endif #ifdef MiarmyDebug ofstream logFile("e:/logFile.txt"); #endif // agent file: // ///////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// bool motionBlurDef = false; float motionShutter = 0.0f; if (g_motionBlur == 1) { motionBlurDef = true; motionShutter = g_motionShutter; } vector<float> poseDataRaw; vector<float> poseDataRawNext; McdUtils utils; utils.getPoseRawData(poseDataRaw,poseDataRawNext, motionBlurDef, g_poseData); #ifdef MiarmyDebug logFile<<"pose data raw"<<endl; for (uint i = 0; i < poseDataRaw.size(); i++){ logFile<<poseDataRaw[i]<<" "; } #endif char tempBuf[10]; string ppIdStr, agentTypeIdStr, geoTypeIdStr; string assetsFolder(g_assetsPath); sprintf(tempBuf, "%d", g_ppID); ppIdStr = tempBuf; sprintf(tempBuf, "%d", g_agentID); agentTypeIdStr = tempBuf; sprintf(tempBuf, "%d", g_geoID); geoTypeIdStr = tempBuf; string geomStr = "geom"; geomStr = geomStr + ppIdStr; agentFolder = agentFolderPre + agentTypeIdStr; // d:/pp / McdAgentType0 / McdAgentMain.txt agentPath2= assetsFolder + slash + agentFolder + slash + agentFile2; // d:/pp / McdAgentType0 / McdGeoFiles / McdGeo 0 geoPath2= assetsFolder + slash + agentFolder + slash + geoFolder + slash + geoFilePre + geoTypeIdStr; // d:/pp / McdAgentType0 / McdGeoFiles / McdWeight 0 weightPath2= assetsFolder + slash + agentFolder + slash + geoFolder + slash + weightFilePre + geoTypeIdStr; // we already have agentPath2, geoPath2, and weightPath2, let's extract data: // get bone number and org pose vector<McdMatrix> orgPoseMatrixList; vector<McdMatrix> currentPoseMatrixList; vector<McdMatrix> nextPoseMatrixList; int nbBone = (int)(agentFiles_Data[g_agentID][0] + .1f); utils.getPoseMatrices( orgPoseMatrixList, currentPoseMatrixList, nextPoseMatrixList, agentFiles_Data, poseDataRaw, poseDataRawNext, nbBone, g_agentID, motionBlurDef); // now get the weights McdPointWeight weightList; int nbPoints = utils.getWeightsFromFile( weightList, weightPath2, weightFiles_Data, g_agentID, g_geoID ); /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // session 3: get the data from geo file ////////////////////////////////////////////////////////////////////// //bool startCollect = false; McdGeo geo; vector<float> currentPoints, nextPoints; // modified from points; vector<float> currentNormals, nextNormals; // modified from normals; utils.getGeoFromFile( geo, geoFiles_Data, currentNormals, nextNormals, g_geoID, g_agentID, motionBlurDef); // statistic final information: int nbNormalFromRib = geo.nidxs.size(); if (geo.points.size() / 3 != nbPoints) return 0; #ifdef MiarmyDebug logFile << "-----------> points number from pp exportor: >>>>" <<nbPoints<<endl; logFile << "-----------> normals number from rib: >>>>" <<nbNormalFromRib<<endl; #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // session 4: modify the data in vector /////////////////////////////////////////////////////////////////////// // modify points by skinning info #ifdef MiarmyDebug logFile << "*************start to deal with points********************************************"<<endl; #endif McdPoint currentPoint; McdPoint nextPoint; int nbWeights; int boneID; float weight; for (int i = 0; i < nbPoints; i++) { currentPoint.x = geo.points[i*3]; currentPoint.y = geo.points[i*3 + 1]; currentPoint.z = geo.points[i*3 + 2]; if (motionBlurDef) { nextPoint = currentPoint; } nbWeights = weightList.nbWeights[i]; #ifdef MiarmyDebug logFile<<"-------------------------------"<<endl; logFile << "point pre info: "<<currentPoint.x<<" "<<currentPoint.y<<" "<<currentPoint.z<<" "<<endl; #endif McdMatrix deformMat; deformMat = deformMat * 0.0f; // zero out McdMatrix deformMatNext; deformMatNext = deformMatNext * 0.0f; // zero out for (int j = 0; j < nbWeights; j++) { boneID = weightList.pointIdList[i][j]; weight = weightList.pointWeights[i][j]; #ifdef MiarmyDebug logFile <<"pointid: "<<i<<" boneId: "<<boneID<<" weight: "<<weight<<endl; #endif deformMat = deformMat + (orgPoseMatrixList[boneID] * currentPoseMatrixList[boneID]) * weight; if (motionBlurDef) { deformMatNext = deformMatNext + (orgPoseMatrixList[boneID] * nextPoseMatrixList[boneID]) * weight; } } currentPoint = currentPoint * deformMat; if (motionBlurDef) { nextPoint = nextPoint * deformMatNext; } // put result to points: currentPoints.push_back(currentPoint.x); currentPoints.push_back(currentPoint.y); currentPoints.push_back(currentPoint.z); if (motionBlurDef) { nextPoints.push_back(nextPoint.x); nextPoints.push_back(nextPoint.y); nextPoints.push_back(nextPoint.z); } #ifdef MiarmyDebug logFile << "result point info: "<<currentPoints[i*3]<<" "<<currentPoints[i*3+1]<<" "<<currentPoints[i*3+2]<<" "<<endl; if (motionBlurDef) logFile << "next point info: "<<nextPoints[i*3]<<" "<<nextPoints[i*3+1]<<" "<<nextPoints[i*3+2]<<" "<<endl; #endif } // modify normal by skinning info McdVector currentNormal, nextNormal; int normalPointID, normalID; for (int i = 0; i < nbNormalFromRib; i++){ normalID = geo.nidxs[i]; currentNormal.x = geo.normals[normalID*3]; currentNormal.y = geo.normals[normalID*3+1]; currentNormal.z = geo.normals[normalID*3+2]; if (motionBlurDef){ nextNormal.x = geo.normals[normalID*3]; nextNormal.y = geo.normals[normalID*3+1]; nextNormal.z = geo.normals[normalID*3+2]; } normalPointID = geo.vidxs[i]; nbWeights = weightList.nbWeights[normalPointID]; #ifdef MiarmyDebug logFile << "point normal info: "<<currentNormal.x<<" "<<currentNormal.y<<" "<<currentNormal.z<<" "<<endl; if (motionBlurDef){ logFile << "next point normal info: "<<nextNormal.x<<" "<<nextNormal.y<<" "<<nextNormal.z<<" "<<endl; } #endif McdMatrix deformMat; deformMat = deformMat * 0.0f; // zero out McdMatrix deformMatNext; deformMatNext = deformMatNext * 0.0f; // zero out for (int j = 0; j < nbWeights; j++){ boneID = weightList.pointIdList[normalPointID][j]; weight = weightList.pointWeights[normalPointID][j]; deformMat = deformMat + (orgPoseMatrixList[boneID] * currentPoseMatrixList[boneID]) * weight; if (motionBlurDef){ deformMat = deformMat + (orgPoseMatrixList[boneID] * nextPoseMatrixList[boneID]) * weight; } } currentNormal = currentNormal * deformMat; currentNormal.normalize(); if (motionBlurDef){ nextNormal = nextNormal * deformMatNext; nextNormal.normalize(); } // put result to normals: currentNormals[normalID*3] = currentNormal.x; currentNormals[normalID*3+1] = currentNormal.y; currentNormals[normalID*3+2] = currentNormal.z; if (motionBlurDef){ nextNormals[normalID*3] = nextNormal.x; nextNormals[normalID*3+1] = nextNormal.y; nextNormals[normalID*3+2] = nextNormal.z; } #ifdef MiarmyDebug logFile << "result normal info: "<<currentNormals[normalID*3]<<" "<<currentNormals[normalID*3+1]<<" "<<currentNormals[normalID*3+2]<<" "<<endl; if (motionBlurDef) logFile << "result next normal info: "<<nextNormals[normalID*3]<<" "<<nextNormals[normalID*3+1]<<" "<<nextNormals[normalID*3+2]<<" "<<endl; #endif } #ifdef MiarmyDebug logFile <<endl<< "----------------------- END -----------------------: "; logFile.close(); #endif AtArray *nsidesArray; AtArray *vidxsArray; AtArray *nidxsArray; AtArray *uvidxsArray; AtArray *vlistArray; AtArray *nlistArray; AtArray *uvlistArray; // proc geo: if (!motionBlurDef){ nsidesArray = AiArrayAllocate(geo.nsides.size(), 1, AI_TYPE_UINT); vidxsArray = AiArrayAllocate(geo.vidxs.size(), 1, AI_TYPE_UINT); nidxsArray = AiArrayAllocate(geo.nidxs.size(), 1, AI_TYPE_UINT); uvidxsArray = AiArrayAllocate(geo.uvidxs.size(), 1, AI_TYPE_UINT); vlistArray = AiArrayAllocate(geo.points.size() / 3, 1, AI_TYPE_POINT); nlistArray = AiArrayAllocate(geo.normals.size() / 3, 1, AI_TYPE_VECTOR); uvlistArray = AiArrayAllocate(geo.uvlist.size() / 2, 1, AI_TYPE_POINT2); uint i; AtPoint tempPoint; AtVector tempNormal; AtPoint2 tempPoint2; uint nbPnts = currentPoints.size() / 3; uint nbNormals = currentNormals.size() / 3; uint nbUVs = geo.uvlist.size() / 2; for (i = 0; i < geo.nsides.size(); i++) AiArraySetUInt(nsidesArray, i, geo.nsides[i]); for (i = 0; i < geo.vidxs.size(); i++) AiArraySetUInt(vidxsArray, i, geo.vidxs[i]); for (i = 0; i < geo.nidxs.size(); i++) AiArraySetUInt(nidxsArray, i, geo.nidxs[i]); for (i = 0; i < geo.uvidxs.size(); i++) AiArraySetUInt(uvidxsArray, i, geo.uvidxs[i]); for (i = 0; i < nbPnts; i++){ tempPoint.x = currentPoints[i*3]; tempPoint.y = currentPoints[i*3+1]; tempPoint.z = currentPoints[i*3+2]; AiArraySetPnt(vlistArray, i, tempPoint); } for (i = 0; i < nbNormals; i++){ tempNormal.x = currentNormals[i*3]; tempNormal.y = currentNormals[i*3+1]; tempNormal.z = currentNormals[i*3+2]; AiArraySetPnt(nlistArray, i, tempNormal); } for (i = 0; i < nbUVs; i++){ tempPoint2.x = geo.uvlist[i*2]; tempPoint2.y = geo.uvlist[i*2+1]; AiArraySetPnt2(uvlistArray, i, tempPoint2); } } else { nsidesArray = AiArrayAllocate(geo.nsides.size(), 1, AI_TYPE_UINT); vidxsArray = AiArrayAllocate(geo.vidxs.size(), 1, AI_TYPE_UINT); nidxsArray = AiArrayAllocate(geo.nidxs.size(), 1, AI_TYPE_UINT); uvidxsArray = AiArrayAllocate(geo.uvidxs.size(), 1, AI_TYPE_UINT); vlistArray = AiArrayAllocate(geo.points.size() / 3, 2, AI_TYPE_POINT); nlistArray = AiArrayAllocate(geo.normals.size() / 3, 2, AI_TYPE_VECTOR); uvlistArray = AiArrayAllocate(geo.uvlist.size() / 2, 1, AI_TYPE_POINT2); uint i; AtPoint tempPoint; AtVector tempNormal; AtPoint2 tempPoint2; uint nbPnts = currentPoints.size() / 3; uint nbNormals = currentNormals.size() / 3; uint nbUVs = geo.uvlist.size() / 2; for (i = 0; i < geo.nsides.size(); i++) AiArraySetUInt(nsidesArray, i, geo.nsides[i]); for (i = 0; i < geo.vidxs.size(); i++) AiArraySetUInt(vidxsArray, i, geo.vidxs[i]); for (i = 0; i < geo.nidxs.size(); i++) AiArraySetUInt(nidxsArray, i, geo.nidxs[i]); for (i = 0; i < geo.uvidxs.size(); i++) AiArraySetUInt(uvidxsArray, i, geo.uvidxs[i]); for (i = 0; i < nbPnts; i++){ tempPoint.x = currentPoints[i*3]; tempPoint.y = currentPoints[i*3+1]; tempPoint.z = currentPoints[i*3+2]; AiArraySetPnt(vlistArray, i, tempPoint); } for (i = 0; i < nbNormals; i++){ tempNormal.x = currentNormals[i*3]; tempNormal.y = currentNormals[i*3+1]; tempNormal.z = currentNormals[i*3+2]; AiArraySetPnt(nlistArray, i, tempNormal); } for (i = 0; i < nbPnts; i++){ tempPoint.x = nextPoints[i*3]; tempPoint.y = nextPoints[i*3+1]; tempPoint.z = nextPoints[i*3+2]; AiArraySetPnt(vlistArray, i+nbPnts, tempPoint); } for (i = 0; i < nbNormals; i++){ tempNormal.x = nextNormals[i*3]; tempNormal.y = nextNormals[i*3+1]; tempNormal.z = nextNormals[i*3+2]; AiArraySetPnt(nlistArray, i+nbNormals, tempNormal); } for (i = 0; i < nbUVs; i++){ tempPoint2.x = geo.uvlist[i*2]; tempPoint2.y = geo.uvlist[i*2+1]; AiArraySetPnt2(uvlistArray, i, tempPoint2); } } AtNode *meshNode = AiNode("polymesh"); AiNodeSetStr(meshNode, "name", geomStr.c_str()); AiNodeSetArray(meshNode, "nsides", nsidesArray); AiNodeSetArray(meshNode, "vidxs", vidxsArray); if (g_poly0_subd1 != 1) AiNodeSetArray(meshNode, "nidxs", nidxsArray); AiNodeSetArray(meshNode, "uvidxs", uvidxsArray); AiNodeSetArray(meshNode, "vlist", vlistArray); if (g_poly0_subd1 != 1) AiNodeSetArray(meshNode, "nlist", nlistArray); AiNodeSetArray(meshNode, "uvlist", uvlistArray); AiNodeSetBool(meshNode, "smoothing", true); if (g_poly0_subd1 == 1) AiNodeSetStr(meshNode, "subdiv_type", "catclark"); lockup = false; cout << "END GET NODE" << endl; return meshNode; }