int main() { // Create a mapper and actor VTK_CREATE(vtkDataSetMapper, mapper); vtkSmartPointer<vtkStructuredGrid> g = createGrid(6,10); #if VTK_MAJOR_VERSION <= 5 mapper->SetInputConnection(g->GetProducerPort()); #else mapper->SetInputData(g); #endif VTK_CREATE(vtkActor, g_actor); g_actor->SetMapper(mapper); g_actor->GetProperty()->SetRepresentationToWireframe(); VTK_CREATE(vtkRenderer, ren); ren->AddActor(g_actor); ren->SetBackground(.1,.2,.3); VTK_CREATE(vtkRenderWindow, renw); renw->AddRenderer(ren); VTK_CREATE(vtkInteractorStyleTrackballCamera, style); VTK_CREATE(vtkRenderWindowInteractor, iren); iren->SetRenderWindow(renw); iren->SetInteractorStyle(style); iren->Initialize(); iren->Start(); return 0; }
// 初始化插件,传进来的worldEditor是世界编辑器的接口 bool AxisGridPlugin::init(IWorldEditor *worldEditor) { if(m_inited) return true; m_worldEditor = worldEditor; // 创建网格对象 m_gridObject = createGrid(128 , 128 , 1); // 显示之 m_gridNode = m_worldEditor->getDisplaySystem()->getMainSceneMgr()->getRootSceneNode()->createChildSceneNode("GridNode"); m_gridNode->attachObject(m_gridObject); m_axisRTT = new AxisRTT(); m_axisRTT->init(worldEditor); m_axisRTT->setEnabled(true); // 创建坐标轴 createAxisOverlay(); // 创建统计界面 createStatOverlay(); m_worldEditor->getMainFrame()->addChildViewListener(this); activate(); m_inited = true; return m_inited; }
AnimatedScene::AnimatedScene( const dp::math::Vec2f& gridSize, const dp::math::Vec2i& objectCount ) : m_gridSize( gridSize ) , m_objectCount( objectCount ) { m_root = dp::sg::core::Group::create(); m_scene = dp::sg::core::Scene::create(); m_scene->setRootNode( m_root ); m_effectSpec = dp::sg::core::getStandardMaterialSpec(); m_primitive = dp::sg::generator::createSphere( 5, 5, 1.5 ); //m_primitive = dp::sg::generator::createCube(); m_itColors = m_effectSpec->findParameterGroupSpec( std::string("standardMaterialParameters") ); dp::util::FileFinder fileFinder; fileFinder.addSearchPath( dp::home() + "/media/dpfx" ); fileFinder.addSearchPath( dp::home() + "/media/textures" ); dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/carpaint.xml", fileFinder ); dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/phong.xml", fileFinder ); dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/standard_material.xml", fileFinder ); dp::fx::EffectLibrary::instance()->loadEffects( dp::home() + "/media/effects/xml/thinglass.xml", fileFinder ); m_carpaint = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData("carpaint") ); m_phong = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData("phong") ); m_standard_material = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData("standardMaterial") ); m_thinglass = dp::sg::core::EffectData::create( dp::fx::EffectLibrary::instance()->getEffectData("thinglass") ); m_animationTime = std::shared_ptr<AnimationTime>(new AnimationTime()); DP_ASSERT( m_carpaint ); DP_ASSERT( m_phong ); DP_ASSERT( m_standard_material ); DP_ASSERT( m_thinglass ); createGrid( ); }
int main(int argc, char* argv[]) { if (argc != 4) { printHelp(argv); return 1; } // QUADRATURE RULE if (strlen(argv[1]) > 1) { printHelp(argv); return 2; } QuadratureFactory* factory = createFactory(argv[1][0]); // FUNCTION TO BE USED/TESTED int functionIndex = atoi(argv[2]); if (functionIndex == 0) { printHelp(argv); return 3; } fptr func = chooseFunc(functionIndex); // INTEGRATION GRID IntegrationGrid grid = createGrid(argv[3]); //grid.print(); CompositeIntegrator integrator(func, factory, grid); printf("performing integration\n"); integrator.integrate(); printf("result of integrating function %d = %5.3lf\n", functionIndex, integrator.getResult()); return 0; }
void Quad::setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo) { deleteGrid(); if (x == 0 || y == 0) { gridTimer = 0; xDivs = 0; yDivs = 0; doUpdateGrid = false; } else { this->drawGridOffsetX = dgox; this->drawGridOffsetY = dgoy; this->drawGridModX = dgmx; this->drawGridModY = dgmy; this->drawGridTimeMultiplier = dgtm; drawGridOut = dgo; xDivs = x; yDivs = y; createGrid(x, y); gridTimer = 0; doUpdateGrid = true; } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); createGrid(grid, ROWS, COLS); return a.exec(); }
bool LensDistortOverlayInteract::draw( const OFX::DrawArgs& args ) { typedef boost::gil::point2<Scalar> Point2; static const float lineWidth = 2.0; bool displaySomething = false; // debug drawing if( _plugin->_debugDisplayRoi->getValue() ) { glLineWidth( lineWidth ); displaySomething = true; glColor3f( 1.0f, 0.0f, 0.0f ); overlay::displayRect( _plugin->_dstRoi, -1 ); glColor3f( 0.0f, 1.0f, 0.0f ); overlay::displayRect( _plugin->_srcRoi, 1 ); glColor3f( 0.0f, 0.0f, 1.0f ); overlay::displayRect( _plugin->_srcRealRoi, 1 ); } displaySomething |= _interactScene.draw( args ); // drawing if( _plugin->_gridOverlay->getValue() && _plugin->_clipSrc->isConnected() ) { displaySomething = true; static const unsigned int steps = 10; // get the project size OfxRectD srcRod = _plugin->_clipSrc->getCanonicalRod( args.time ); if( _plugin->_srcRefClip->isConnected() ) srcRod = _plugin->_srcRefClip->getCanonicalRod( args.time ); const Point2 imgSize( srcRod.x2 - srcRod.x1, srcRod.y2 - srcRod.y1 ); const OfxRectD outputRod = _plugin->_clipDst->getCanonicalRod( args.time ); //parameters const Point2 gridCenter( ofxToGil( _plugin->_gridCenter->getValue() ) ); const Point2 gridScale( ofxToGil( _plugin->_gridScale->getValue() ) ); std::vector<std::vector<Point2> > grid = createGrid( srcRod, steps, gridScale, gridCenter ); if( !_plugin->_displaySource->getValue() ) { LensDistortProcessParams<Scalar> params; static const double pixelAspectRatio = 1.0; // here the pixel aspect ratio is 1.0 because we work in canonical coordinates params = _plugin->getProcessParams( srcRod, srcRod, pixelAspectRatio, true ); // work in output clip coordinates transformValuesApply( _plugin->getLensType(), params, grid ); } Point2 rodCorner( srcRod.x1, srcRod.y1 ); shiftGrid( grid, rodCorner ); // to move in RoW coordinates glLineWidth( lineWidth ); glColor3f( 1.0f, 1.0f, 0.0f ); overlay::drawCurves( grid ); } return displaySomething; }
/** * @see GridContainer::GridContainer() */ grid::SimpleGridContainer::SimpleGridContainer(asagi::Grid::Type type, bool isArray, unsigned int hint, unsigned int levels) : GridContainer(type, isArray, hint, levels) { m_grids = new grid::Grid*[m_levels]; for (unsigned int i = 0; i < levels; i++) m_grids[i] = createGrid(hint, i); }
//-------------------------------------------------------------- void elementWarp::increaseYgrid() { if (bViewGrid) { yRes++; if (yRes>MAX_RESOLUTION) yRes=MAX_RESOLUTION; createGrid(xRes, yRes); } }
//-------------------------------------------------------------- void elementWarp::load() { loadXML(xRes, yRes, &vertici[0], nPoints, &texVert[0], nPoints, &screenPos[0], nPoints, &mainVertici[0], 4, &mainIndex[0], 4); createGrid(xRes, yRes); loadXML(xRes, yRes, &vertici[0], nPoints, &texVert[0], nPoints, &screenPos[0], nPoints, &mainVertici[0], 4, &mainIndex[0], 4); quadWarp.setTopLeftCornerPosition(ofPoint(mainVertici[0].x, mainVertici[0].y)); quadWarp.setTopRightCornerPosition(ofPoint(mainVertici[1].x, mainVertici[1].y)); quadWarp.setBottomRightCornerPosition(ofPoint(mainVertici[2].x, mainVertici[2].y)); quadWarp.setBottomLeftCornerPosition(ofPoint(mainVertici[3].x, mainVertici[3].y)); }
//-------------------------------------------------------------- void elementWarp::decreaseYgrid() { // if (bWarpActive) if (bViewGrid) { yRes--; if (yRes<2) yRes=2; createGrid(xRes, yRes); } }
//-------------------------------------------------------------- void elementWarp::decreaseXgrid() { if (bViewGrid) { xRes--; if (xRes<2) xRes=2; createGrid(xRes, yRes); } }
int main(int argc, char** argv) { float s; clock_t t; char inner = 0; float k = 0; if (argc!=5) { printf("Usage: levelSet <pdb File> <gridSize> <probeSize> <inner caves(1) or outer surface(0)\n"); return 1; } t = clock(); mol = loadMolecule(argv[1]); catrace = loadCATrace(argv[1]); printf("Number of CA atoms = %d\n",catrace->npoints); printf("Molecule loading time %f seconds\n",(clock()-t)/(float)CLOCKS_PER_SEC); N = (short)atoi(argv[2]); PR = (float)atof(argv[3]); inner = argv[4][0]-'0'; printf("Number of atoms: %d\n",mol->npoints); t = clock(); ttime = clock(); s = centerMolecule(mol, catrace); printf("Molecule centering time %f seconds\n",(clock()-t)/(float)CLOCKS_PER_SEC); PR = PR*s; t = clock(); grid = createGrid(N); printf("Grid creation time %f seconds\n",(clock()-t)/(float)CLOCKS_PER_SEC); t = clock(); signDistanceGridMol(grid,mol,PR); printf("Grid initialization time %f seconds\n",(clock()-t)/(float)CLOCKS_PER_SEC); t = clock(); shrink(grid,PR); /* c = findProbesMol(grid,PR); printf("There are %d probes.\n",c); printf("ProbesMol time %f seconds.\n",(clock()-t)/(float)CLOCKS_PER_SEC); */ printf("Shrinking time %f seconds.\n",(clock()-t)/(float)CLOCKS_PER_SEC); t = clock(); k = s/(512/N); k = k * k * k; printf("Total cavity/molecule volume = %f\n",fastMarching(grid,inner)/k); printf("Fast marching time %f seconds\n",(clock()-t)/(float)CLOCKS_PER_SEC); init(); return 0; }
/** * @see GridContainer::GridContainer() */ grid::SimpleGridContainer::SimpleGridContainer(unsigned int count, unsigned int blockLength[], unsigned long displacements[], asagi::Grid::Type types[], unsigned int hint, unsigned int levels) : GridContainer(count, blockLength, displacements, types, hint, levels) { m_grids = new grid::Grid*[m_levels]; for (unsigned int i = 0; i < levels; i++) m_grids[i] = createGrid(hint, i); }
void ParticleGrid::clear() { if (cellSizes != NULL) { int n = gridSize.x * gridSize.y; for (int i = 0; i < n; ++i) { cellSizes[i] = 0; } } else { createGrid(); } }
//constructor .. e apelat cand e instantiata clasa Laborator(){ //setari pentru desenare, clear color seteaza culoarea de clear pentru ecran (format R,G,B,A) glClearColor(0.8,0.8,0.8,1); glClearDepth(1); //clear depth si depth test (nu le studiem momentan, dar avem nevoie de ele!) glEnable(GL_DEPTH_TEST); //sunt folosite pentru a determina obiectele cele mai apropiate de camera (la curs: algoritmul pictorului, algoritmul zbuffer) //initializari timp = 0.0f; amplitudine = 1.5f; frecventa = glm::pi<float>() /15; // 2pi/lungime --- lungime e 30 faza = frecventa /2 ;// viteza * frecventa ---- viteza = 0.5 directional = 0; circular = 0; // unde directie = glm::vec3(1, 0, 1); centru.x = 150; centru.z = 10; drawable = 0; //incarca un shader din fisiere si gaseste locatiile matricilor relativ la programul creat gl_program_shader_gouraud = lab::loadShader("shadere\\shader_gouraud_vertex.glsl", "shadere\\shader_gouraud_fragment.glsl"); //incarca o sfera lab::loadObj("resurse\\sphere.obj",mesh_vao_sphere, mesh_vbo_sphere, mesh_ibo_sphere, mesh_num_indices_sphere); //incarca un plan //lab::loadObj("resurse\\plane.obj",mesh_vao_ground, mesh_vbo_ground, mesh_ibo_ground, mesh_num_indices_ground); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { ver.push_back(lab::VertexFormat(i, 0, -j, 0, 1, 0)); } } for (int i = 0; i < 99; i++) { for (int j = 0; j < 99; j++) { ind.push_back(glm::uvec3(i * 100 + j, (i + 1) * 100 + j, (i + 1) * 100 + j + 1)); ind.push_back(glm::uvec3(i * 100 + j, (i + 1) * 100 + j + 1, i * 100 + j + 1)); } } // create grid createGrid(); //lumina & material eye_position = glm::vec3(50, 25, 0); FPS.set(glm::vec3(50, 25, 0), glm::vec3(50, 0, -15), glm::vec3(0, 1, 0)); light_position = glm::vec3(50,10,-50); material_shininess = 30; material_kd = 0.5; material_ks = 0.5; //matrici de modelare si vizualizare model_matrix = glm::mat4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1); //desenare wireframe glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); }
//----------------------------------------------------------------- void elementWarp::setup(int _outputWidth, int _outputHeight, string _name) { gridFactorW=1; gridFactorH=1; //set texture w & h width=_outputWidth; height=_outputHeight; //allocate texture text.allocate(width, height, GL_RGBA); //file name for save/load settings xmlName=_name+".xml"; cout << "XML FILE: " + xmlName << endl; // QUAD WARPER INIT bWarpActive=true; mainVertici[0]=ofPoint(0,0); //top left mainVertici[1]=ofPoint(text.getWidth(),0); //top right mainVertici[2]=ofPoint(text.getWidth(),text.getHeight()); //bottom right mainVertici[3]=ofPoint(0,text.getHeight()); //bottom left quadWarp.setSourceRect( ofRectangle( 0, 0, text.getWidth(), text.getHeight() ) ); quadWarp.setTopLeftCornerPosition(ofPoint(mainVertici[0].x, mainVertici[0].y)); quadWarp.setTopRightCornerPosition(ofPoint(mainVertici[1].x, mainVertici[1].y)); quadWarp.setBottomRightCornerPosition(ofPoint(mainVertici[2].x, mainVertici[2].y)); quadWarp.setBottomLeftCornerPosition(ofPoint(mainVertici[3].x, mainVertici[3].y)); // GRID WARPER INIT //default grid= 4x4 control points xRes=4; yRes=4; //create grid coordinates bViewGrid=true; createGrid(xRes, yRes); //start with everything deactivated bWarpActive=false; bViewGrid=false; bSposta=false; bHoldSelection=false; bMela=false; bSpeedUp=false; //auto-load last warp settings on startup load(); }
int main(void) { /* Initialization players */ srand(time(0)); int playerNumber = ( rand() % 2 ) + 1;; int *p_playerNumber = &playerNumber; /* Initilization MAP */ double posX = marginWidth + circleSize * 2 + 57; double posY = 420 + marginHight; double *p_posX = &posX; double *p_posY = &posY; int map[45], i, j = 3, posMap = 1, keyPressed; int *p_posMap = &posMap; for (i = 1 ; i <= 42 ; i++){ map[i] = j; j++; } /* Draw the grid */ createGrid(); update_graphics(); /* Take deplacement with key until ESCAPE is pressed*/ while (gameStat(map) == 0) { if (keyPressed == key_ESCAPE) exit(1); keyPressed = get_key(); moveCase(p_posX, p_posY, p_posMap, map, p_playerNumber, keyPressed); update_graphics(); } set_drawing_color(color_BLUE); if (gameStat(map) == 100) draw_printf(5, 5, "Result: match nul"); else draw_printf(5, 1, "Winner: player %d", gameStat(map)); update_graphics(); get_key(); return EXIT_SUCCESS; }
//Init int init (unsigned int _m, unsigned int _n) { //Open log file m = _m; n = _n; remove ("log_old.txt"); rename ("log.txt", "log_old.txt"); //reroute stdout to print to log.txt freopen("log.txt", "a", stdout); printf( "##########################################\nProgram started\n\n"); //Create the grid createGrid(m,n); return 0; }
void ECPComponentBuilder::addSemiLocal(xmlNodePtr cur) { GridType* grid_semilocal=0; RealType rmax= pp_nonloc->Rmax; cur=cur->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "grid") { grid_semilocal=createGrid(cur); rmax=grid_semilocal->rmax(); } else if(cname == "vps") { //should be able to overwrite rmax int l=angMon[(const char*)xmlGetProp(cur,(const xmlChar*)"l")]; Lmax = std::max(l,Lmax); xmlNodePtr cur1=cur->children; while(cur1 != NULL) { string cname1((const char*)cur1->name); if(cname1 == "basisGroup") { pp_nonloc->add(l,createVrWithBasisGroup(cur1,grid_semilocal)); } //else if(cname1 == "data") //{ // pp_nonloc->add(l,createVrWithData(cur1,grid_semilocal)); //} cur1=cur1->next; } NumNonLocal++; } cur=cur->next; } pp_nonloc->lmax=Lmax; pp_nonloc->Rmax=rmax; }
/** \brief Create the Grid by reading a file * * \param char* : name of a file * \param grid[][] : array of Cell * */ void createFullGrid(char *nameFile, Cell grid[N][N]) { FILE* readFile = NULL; int i; char charFile[16]; char c; // open the file in reading mode readFile = fopen(nameFile, "r"); if (readFile != NULL) { i = 0; do { c = getc(readFile); if (c != '\n') { charFile[i] = c; i++; } } while (c != EOF); // close file fclose(readFile); initGrid(grid); createGrid(grid, charFile); setBonus(grid); } else { // reading file failed printf("File not found"); exit(1); } }
void AbstractGrid::initializeGrid(uint width, uint height, Wrapping wrapping) { if ((width * height) != (m_width * m_height)) { qDeleteAll(m_cells); m_cells.clear(); for (uint index = 0; index < width*height; ++index) { m_cells.append(newCell(index)); } } m_width = width; m_height = height; m_isWrapped = wrapping; createGrid(); while(hasUnneededCables() || solutionCount() != 1) { // the grid is invalid: create a new one createGrid(); } m_minimumMoves = 0; const int shuffleLimit = cellCount() * minCellRatio; QList<int> notShuffledCells; for (int i = 0; i < cellCount(); ++i) notShuffledCells.append(i); // select a random cell that is not yet shuffled // rotate such that initial and final states are not same // repeat above two steps until minimum moves equal to shuffle limit while(m_minimumMoves < shuffleLimit) { // selecting a random index int index = qrand() % notShuffledCells.count(); int cellNo = notShuffledCells[index]; // removing the selected index so that it must not be used again notShuffledCells.removeAt(index); AbstractCell *cell = m_cells[cellNo]; Directions dir = cell->cables(); // excludes None(Empty cell) if (dir == None) { continue; } // if straight line rotate once // cant rotate twice(it will be back on its initial state) else if ((dir == (Up | Down)) || (dir == (Left | Right))) { m_minimumMoves += 1; cell->rotateClockwise(); } // for every other case rotate 1..3 times else { int rotation = qrand() % 3 + 1; // 1..3 // cant rotate twice when m_minimumMoves == shuffleLimit - 1 if (m_minimumMoves == shuffleLimit - 1 && rotation == 2){ rotation = (qrand() % 2)? 1 : 3; // 1 or 3 } m_minimumMoves += (rotation == 3) ? 1 : rotation; while(rotation--) { cell->rotateClockwise(); } } } updateConnections(); }
void Element::setElementEffectByIndex(int eidx) { deleteGrid(); setBlendType(RenderObject::BLEND_DEFAULT); alpha.stop(); alpha = 1; elementEffectIndex = eidx; ElementEffect e = dsq->getElementEffectByIndex(eidx); switch(e.type) { case EFX_SEGS: { setSegs(e.segsx, e.segsy, e.segs_dgox, e.segs_dgoy, e.segs_dgmx, e.segs_dgmy, e.segs_dgtm, e.segs_dgo); setStatic(false); } break; case EFX_ALPHA: { setBlendType(e.blendType); alpha = e.alpha; setStatic(false); } break; case EFX_WAVY: { /* char buf[256]; sprintf(buf, "setting wavy segsy: %d radius: %d min: %d max: %d", e.segsy, e.wavy_radius, e.wavy_min, e.wavy_max); debugLog(buf); */ wavy.resize(e.segsy); float bity = float(getHeight())/float(e.segsy); for (int i = 0; i < wavy.size(); i++) { wavy[i] = Vector(0, -(i*bity)); } //wavySave = wavy; wavyRadius = e.wavy_radius; wavyFlip = e.wavy_flip; wavyMin = bity; wavyMax = bity*1.2f; //wavyRadius = 8; createGrid(2, e.segsy); setGridFromWavy(); //createGrid(8,8); /* wavyMin = e.wavy_min; wavyMax = e.wavy_max; */ setStatic(false); } break; default: setStatic(true); break; } elementEffectType = e.type; }
Map::Map(char* p_filePath) { _cm = new ConfigurationManager(p_filePath); loadImage(_cm->GetMapFilePath().c_str()); blowImage(_cm->GetRobotSize(),_cm->GetMapResolutionCM()); createGrid(getGridResolutionPix()); }
//-------------------------------------------------------------- void ofxMtlMapping2D::update() { ofxMtlMapping2DControls::mapping2DControls()->update(); // ---- save mapping to xml if(ofxMtlMapping2DControls::mapping2DControls()->saveMapping()) { ofxMtlMapping2DControls::mapping2DControls()->resetSaveMapping(); saveShapesList(); } // ---- load mapping from xml if(ofxMtlMapping2DControls::mapping2DControls()->loadMapping()) { ofxMtlMapping2DControls::mapping2DControls()->resetLoadMapping(); loadShapesList(); } // ---- // Editing or not !? if(!ofxMtlMapping2DControls::mapping2DControls()->editShapes()) return; // ---- // Create a new shape if(ofxMtlMapping2DControls::mapping2DControls()->createNewQuad()) { ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape(); createQuad(1020/2, 720/2); return; } if(ofxMtlMapping2DControls::mapping2DControls()->createNewGrid()) { ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape(); createGrid(1020/2, 720/2); return; } if(ofxMtlMapping2DControls::mapping2DControls()->createNewTriangle()) { ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape(); createTriangle(1020/2, 720/2); return; } if(ofxMtlMapping2DControls::mapping2DControls()->createNewMask()) { ofxMtlMapping2DControls::mapping2DControls()->resetCreateNewShape(); createMask(1020/2, 720/2); return; } // ---- // Selected shape with UI if(ofxMtlMapping2DControls::mapping2DControls()->selectedShapeChanged()) { ofxMtlMapping2DControls::mapping2DControls()->resetSelectedShapeChangedFlag(); list<ofxMtlMapping2DShape*>::iterator it = iteratorForShapeWithId(ofxMtlMapping2DControls::mapping2DControls()->selectedShapeId()); if(it != ofxMtlMapping2DShapes::pmShapes.end()) { ofxMtlMapping2DShape* shape = *it; shape->setAsActiveShape(true); // Put active shape at the top of the list ofxMtlMapping2DShapes::pmShapes.push_front(shape); ofxMtlMapping2DShapes::pmShapes.erase(it); } } // ---- // We changed of mode - Output / Input if(ofxMtlMapping2DControls::mapping2DControls()->mappingModeChanged()) { ofxMtlMapping2DControls::mapping2DControls()->resetMappingChangedFlag(); // ---- OUTPUT MODE if(ofxMtlMapping2DControls::mapping2DControls()->mappingMode() == MAPPING_MODE_OUTPUT) { list<ofxMtlMapping2DShape*>::iterator it; for (it=ofxMtlMapping2DShapes::pmShapes.begin(); it!=ofxMtlMapping2DShapes::pmShapes.end(); it++) { ofxMtlMapping2DShape* shape = *it; shape->enable(); if(shape->inputPolygon) { // If this Shape is textured and has an 'inputPolygon' shape->inputPolygon->setAsIdle(); } } // ---- INPUT MODE } else if (ofxMtlMapping2DControls::mapping2DControls()->mappingMode() == MAPPING_MODE_INPUT) { list<ofxMtlMapping2DShape*>::iterator it; for (it=ofxMtlMapping2DShapes::pmShapes.begin(); it!=ofxMtlMapping2DShapes::pmShapes.end(); it++) { ofxMtlMapping2DShape* shape = *it; shape->setAsIdle(); shape->inputPolygon->enable(); } } } // ---- // Update the Shapes list<ofxMtlMapping2DShape*>::iterator it; for (it=ofxMtlMapping2DShapes::pmShapes.begin(); it!=ofxMtlMapping2DShapes::pmShapes.end(); it++) { ofxMtlMapping2DShape* shape = *it; shape->update(); } }
Grid* Grid::setSize(int size) { this->size = size; createGrid(); return this; }
Grid* Grid::setBlockSize(D3DXVECTOR2 size) { this->block_size = size; createGrid(); return this; }
//---------------------------------------------------------------------------------------------------------------------- // This method should be overridden in user defined nodes. // Recompute the given output based on the nodes inputs. // The plug represents the data value that needs to be recomputed, and the data block holds the storage // for all of the node'_scale attributes. //---------------------------------------------------------------------------------------------------------------------- MStatus OceanNode::compute( const MPlug &_plug , MDataBlock &_data ){ MStatus status; // see if we get the output plug if( _plug == m_output){ MDataHandle dataHandle; dataHandle = _data.inputValue(m_resolution, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for resolution plug"); if (m_res != dataHandle.asInt()){ switch(dataHandle.asInt()){ case 0: m_ocean->setResolution(128); MGlobal::displayInfo("Resolution: 128"); break; case 1: m_ocean->setResolution(256); MGlobal::displayInfo("Resolution: 256"); break; case 2: m_ocean->setResolution(512); MGlobal::displayInfo("Resolution: 512"); break; case 3: m_ocean->setResolution(1024); MGlobal::displayInfo("Resolution: 1024"); break; default: break; } m_res = dataHandle.asInt(); } dataHandle = _data.inputValue( m_amplitude , &status ); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for amplitude plug" ); // now get the value for the data handle as a double double amp = dataHandle.asDouble(); m_ocean->setAmplitude(amp); dataHandle = _data.inputValue(m_frequency, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get handle for \"frequency\" plug"); double freq = dataHandle.asDouble(); m_ocean->setFrequency(freq); dataHandle = _data.inputValue(m_windDirectionX, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionX plug"); // now get value for data handle double wdx = dataHandle.asDouble(); dataHandle = _data.inputValue(m_windDirectionZ, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionY plug"); // now get value for data handle double wdz = dataHandle.asDouble(); m_ocean->setWindVector(make_float2(wdx, wdz)); dataHandle = _data.inputValue(m_windSpeed, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windSpeed plug"); // now get value for data handle double ws = dataHandle.asDouble(); m_ocean->setWindSpeed(ws); // Only create a new frequency domain if either amplitude or the wind vecotr has changed if (m_amp != amp || m_wdx != wdx || m_wdz != wdz || m_ws != ws ){ MGlobal::displayInfo("here"); m_ocean->createH0(); m_amp = amp; m_wdx = wdx; m_wdz = wdz; m_ws = ws; } dataHandle = _data.inputValue(m_choppiness, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for the choppiness plug"); double choppiness = dataHandle.asDouble(); dataHandle = _data.inputValue(m_time, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for time plug"); MTime time = dataHandle.asTime(); MDataHandle outputData = _data.outputValue(m_output, &status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for output plug" ); MFnMeshData mesh; MObject outputObject = mesh.create(&status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to create output mesh"); // Find the current frame number we're on and create the grid based on this MAnimControl anim; anim.setMinTime(time); createGrid((int)pow(2.0, m_res+7), anim.currentTime().value()/24, choppiness, outputObject, status); CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to to create grid"); outputData.set(outputObject); // clean the output plug, ie unset it from dirty so that maya does not re-evaluate it _data.setClean( _plug ); return MStatus::kSuccess; } return MStatus::kUnknownParameter; }
void ParticleViewerWindow::load(char* file) { g_System.LoadSystem(file); createGrid(); updateScene(); }
int main(void) { //Set the error callback glfwSetErrorCallback(error_callback); //Initialize GLFW if (!glfwInit()) { exit(EXIT_FAILURE); } //Set the GLFW window creation hints - these are optional //glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //Request a specific OpenGL version //glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //Request a specific OpenGL version //glfwWindowHint(GLFW_SAMPLES, 4); //Request 4x antialiasing //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //Create a window and create its OpenGL context window = glfwCreateWindow(960, 720, "Test Window", NULL, NULL); //If the window couldn't be created if (!window) { fprintf(stderr, "Failed to open GLFW window.\n"); glfwTerminate(); //exit(EXIT_FAILURE); } //This function makes the context of the specified window current on the calling thread. glfwMakeContextCurrent(window); //Sets the key callback glfwSetKeyCallback(window, key_callback); //Initialize GLEW GLenum err = glewInit(); //If GLEW hasn't initialized if (err != GLEW_OK) { fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); return -1; } //Set a background color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glfwSetCursorPos(window, 1024 / 2, 768 / 2); GLuint VertexArrayID; glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); // Create and compile our GLSL program from the shaders GLuint red = LoadShaders("SimpleTransform.vertexshader", "SingleColorRed.fragmentshader"); GLuint grid = LoadShaders("SimpleTransform.vertexshader", "SingleColorGrid.fragmentshader"); glBindFragDataLocation(red, 0, "red"); glBindFragDataLocation(grid, 1, "grid"); // Get a handle for our "MVP" uniform GLuint MatrixID = glGetUniformLocation(red, "MVP"); // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 1000.0f); // Or, for an ortho camera : //glm::mat4 Projection = glm::ortho(-10.0f,10.0f,-10.0f,10.0f,0.0f,100.0f); // In world coordinates // Camera matrix glm::mat4 View = glm::lookAt( glm::vec3(4, 3, 3), // Camera is at (4,3,3), in World Space glm::vec3(0, 0, 0), // and looks at the origin glm::vec3(0, 1, 0) // Head is up (set to 0,-1,0 to look upside-down) ); static const GLfloat g_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; static const GLushort g_element_buffer_data[] = { 0, 1, 2 }; GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); static const GLfloat g_triangle_buffer_data[] = { -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, }; GLuint triangle; glGenBuffers(1, &triangle); glBindBuffer(GL_ARRAY_BUFFER, triangle); glBufferData(GL_ARRAY_BUFFER, sizeof(g_triangle_buffer_data), g_triangle_buffer_data, GL_STATIC_DRAW); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_SMOOTH);//OPENGL INSTANTIATION HRESULT hr; NUI_IMAGE_FRAME depthFrame; HANDLE hDepth; INuiSensor* pNuiSensor = NULL; int iSensorCount = 0; hr = NuiGetSensorCount(&iSensorCount); if (FAILED(hr)) return hr; for (int i = 0; i < iSensorCount; i++) { INuiSensor* tempSensor; hr = NuiCreateSensorByIndex(i, &tempSensor); if (FAILED(hr)) continue; hr = tempSensor->NuiStatus(); if (S_OK == hr) { pNuiSensor = tempSensor; break; } tempSensor->Release(); } for (int i = 0; i < 2048; i++) { depthLookUp[i] = rawDepthToMeters(i); } rotation = getRotationMatrix(theta, psi, fi); pNuiSensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH); pNuiSensor->NuiImageStreamOpen( NUI_IMAGE_TYPE_DEPTH, NUI_IMAGE_RESOLUTION_320x240, 0, 2, NULL, &hDepth);//KINECT INSTANTIATION cout << "Starting Main Loop"; static double lastTime = glfwGetTime(); //Main Loop do { double currentTime = glfwGetTime(); float deltaTime = float(currentTime - lastTime); //Clear color buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(grid); modelMatrix(MatrixID); hr = pNuiSensor->NuiImageStreamGetNextFrame(hDepth, 0, &depthFrame); if (!FAILED(hr)) { INuiFrameTexture* pTexture; NUI_LOCKED_RECT LockedRect; hr = pNuiSensor->NuiImageFrameGetDepthImagePixelFrameTexture( hDepth, &depthFrame, false, &pTexture); if (FAILED(hr)) { pNuiSensor->NuiImageStreamReleaseFrame(hDepth, &depthFrame); continue; } pTexture->LockRect(0, &LockedRect, NULL, 0);//Kinect Image Grab int skipX = 1; int skipY = 1; float scalar = 4.0f; if (LockedRect.Pitch != 0) { for (int x = 0; x < width; x += skipX) { for (int y = 0; y < height; y += skipY) { const NUI_DEPTH_IMAGE_PIXEL * pBufferRun = reinterpret_cast<const NUI_DEPTH_IMAGE_PIXEL *>(LockedRect.pBits) + x + y * width; //float depth = (float)(pBufferRun->depth); //glm::vec3 location = realWorld(depth, height - y, x, 500.0f, 1000.0f); //createCube(0.006f, location); Vector4 locationDepth = NuiTransformDepthImageToSkeleton(x, y, (short)(pBufferRun->depth << 3)); glm::vec3 locationDepthxyz = glm::vec3(locationDepth.x * scalar, locationDepth.y * scalar, locationDepth.z * scalar); createCube(0.009f, locationDepthxyz); } } } pTexture->UnlockRect(0); pTexture->Release(); pNuiSensor->NuiImageStreamReleaseFrame(hDepth, &depthFrame); } createGrid(); //Test drawings /* glUseProgram(red); modelMatrix(MatrixID); //createCube(0.05f, glm::vec3(1.0f,1.0f,1.0f)); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); //createObject(vertexbuffer, GL_TRIANGLES, 3); //createObject(triangle, GL_TRIANGLES, 3); glDisableVertexAttribArray(0); */ //Swap buffers glfwSwapBuffers(window); //Get and organize events, like keyboard and mouse input, window resizing, etc... glfwPollEvents(); std::string title = "Title | DELTA TIME " + std::to_string(1.0f/deltaTime); const char* pszConstString = title.c_str(); glfwSetWindowTitle(window, pszConstString); lastTime = currentTime; } //Check if the ESC key had been pressed or if the window had been closed while (!glfwWindowShouldClose(window)); //Close OpenGL window and terminate GLFW glfwDestroyWindow(window); //Finalize and clean up GLFW glfwTerminate(); exit(EXIT_SUCCESS); }