/// create node Graph::Node& Graph::add(int value) { nodes.push_back(Node(value)); return nodes.back(); }
//------------------------------------------------------------------------------ //! void BIH::create( const Vector<AABBoxf*>& bboxes, const Vector<Vec3f>& centers, Vector<uint>* ids, uint leafSize, uint maxDepth ) { CHECK( bboxes.size() == centers.size() ); DBG_BLOCK( os_bih, "Start computing BIH..." ); DBG( Timer timer ); // Initialization. DBG_MSG( os_bih, "# of elements: " << bboxes.size() << " " << centers.size() << "\n" ); // 1. Init maximum recursion level. if( maxDepth == 0 ) { maxDepth = (int)CGM::log2( float(centers.size()) ) * 2 + 1; } _maxDepth = CGM::min( maxDepth, (uint)100 ); // 2. Init ids. if( ids == 0 ) { _ids.resize( centers.size() ); for( uint i = 0; i < _ids.size(); ++i ) { _ids[i] = i; } } else { _ids.swap( *ids ); } Vector<uint> remap( centers.size() ); for( uint i = 0; i < remap.size(); ++i ) { remap[i] = i; } // 3. Init nodes and root. //_nodes.reserve(); _nodes.resize(1); // 4. Compute bounding box. AABBoxf nodeBox = AABBoxf::empty(); for( uint i = 0; i < bboxes.size(); ++i ) { nodeBox |= *bboxes[i]; } AABBoxf splitBox = nodeBox; // 5. Stack. Vector<BuildStackNode> stack( maxDepth ); uint stackID = 0; uint maxPrim = 0; uint maxD = 0; // Construct BIH. uint begin = 0; uint end = uint(_ids.size()); uint depth = 1; uint node = 0; while( 1 ) { // Do we have a root node? if( (end - begin <= leafSize) || depth >= maxDepth ) { // Root node. _nodes[node]._index = (begin << 3) + 3; _nodes[node]._numElements = end-begin; maxPrim = CGM::max( maxPrim, end-begin ); maxD = CGM::max( maxD, depth ); // Are we done? if( stackID == 0 ) { break; } stack[--stackID].get( node, begin, end, depth, nodeBox, splitBox ); } else { // Compute split plane and axis. uint axis = splitBox.longestSide(); float splitPlane = splitBox.center( axis ); // Partition primitives. AABBoxf leftNodeBox = AABBoxf::empty(); AABBoxf rightNodeBox = AABBoxf::empty(); uint pivot = begin; for( uint i = begin; i < end; ++i ) { if( centers[remap[i]](axis) < splitPlane ) { leftNodeBox |= (*bboxes[remap[i]]); CGM::swap( remap[i], remap[pivot] ); CGM::swap( _ids[i], _ids[pivot++] ); } else { rightNodeBox |= (*bboxes[remap[i]]); } } // Construct node. ++depth; // No left node. if( pivot == begin ) { uint childNode = uint(_nodes.size()); // Current node. _nodes[node]._index = (childNode << 3) + 4 + axis; _nodes[node]._plane[0] = rightNodeBox.min( axis ); _nodes[node]._plane[1] = rightNodeBox.max( axis ); // Create nodes. _nodes.pushBack( Node() ); // Child node. node = childNode; nodeBox = rightNodeBox; splitBox.slab( axis )(0) = CGM::max( splitPlane, rightNodeBox.min( axis ) ); } // No right node. else if( pivot == end ) { uint childNode = uint(_nodes.size()); // Current node. _nodes[node]._index = (childNode << 3) + 4 + axis; _nodes[node]._plane[0] = leftNodeBox.min( axis ); _nodes[node]._plane[1] = leftNodeBox.max( axis ); // Create nodes. _nodes.pushBack( Node() ); // Child node. node = childNode; nodeBox = leftNodeBox; splitBox.slab( axis )(1) = CGM::min( splitPlane, leftNodeBox.max( axis ) ); } // Left and right node. else { uint leftNode = uint(_nodes.size()); // Current node. _nodes[node]._index = (leftNode << 3) + axis; _nodes[node]._plane[0] = leftNodeBox.max( axis ); _nodes[node]._plane[1] = rightNodeBox.min( axis ); // Create nodes. _nodes.pushBack( Node() ); _nodes.pushBack( Node() ); // Right node. AABBoxf rsplitBox( splitBox ); rsplitBox.slab( axis )(0) = splitPlane; stack[stackID++].set( leftNode+1, pivot, end, depth, rightNodeBox, rsplitBox ); // Left node. node = leftNode; end = pivot; nodeBox = leftNodeBox; splitBox.slab( axis )(1) = splitPlane; } } } DBG( double time = timer.elapsed() ); DBG_MSG( os_bih, "...finish in " << time << " sec." ); DBG_MSG( os_bih, "# of nodes: " << _nodes.size() ); DBG_MSG( os_bih, "# of indices: " << _ids.size() ); DBG_MSG( os_bih, "max primitives in a leaf: " << maxPrim ); DBG_MSG( os_bih, "max depth: " << maxD << " " << maxDepth ); }
bool isBoxAppl (Tree t) { return t->node() == Node(gGlobal->BOXAPPL); }
void CArena::free (void* vp) { if (vp == 0) // // Allow calls with NULL as allowed by C++ delete. // return; // // `vp' had better be in the busy list. // NL::iterator busy_it = m_busylist.find(Node(vp,0)); BL_ASSERT(!(busy_it == m_busylist.end())); BL_ASSERT(m_freelist.find(*busy_it) == m_freelist.end()); // // Put free'd block on free list and save iterator to insert()ed position. // std::pair<NL::iterator,bool> pair_it = m_freelist.insert(*busy_it); BL_ASSERT(pair_it.second == true); NL::iterator free_it = pair_it.first; void* freeblock = static_cast<char*>((*busy_it).block()); BL_ASSERT(free_it != m_freelist.end() && (*free_it).block() == freeblock); // // And remove from busy list. // m_busylist.erase(busy_it); // // Coalesce freeblock(s) on lo and hi side of this block. // if (!(free_it == m_freelist.begin())) { NL::iterator lo_it = free_it; --lo_it; void* addr = static_cast<char*>((*lo_it).block()) + (*lo_it).size(); if (addr == (*free_it).block()) { // // This cast is needed as iterators to set return const values; // i.e. we can't legally change an element of a set. // In this case I want to change the size() of a block // in the freelist. Since size() is not used in the ordering // relations in the set, this won't effect the order; // i.e. it won't muck up the ordering of elements in the set. // I don't want to have to remove the element from the set and // then reinsert it with a different size() as it'll just go // back into the same place in the set. // Node* node = const_cast<Node*>(&(*lo_it)); BL_ASSERT(!(node == 0)); node->size((*lo_it).size() + (*free_it).size()); m_freelist.erase(free_it); free_it = lo_it; } } NL::iterator hi_it = free_it; void* addr = static_cast<char*>((*free_it).block()) + (*free_it).size(); if (++hi_it != m_freelist.end() && addr == (*hi_it).block()) { // // Ditto the above comment. // Node* node = const_cast<Node*>(&(*free_it)); BL_ASSERT(!(node == 0)); node->size((*free_it).size() + (*hi_it).size()); m_freelist.erase(hi_it); } }
//---------------------------------------------------------------------------- void CollisionsBoundTree::CreateScene () { // The root of the scene will have two cylinders as children. mScene = new0 Node(); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); mCullState = new0 CullState(); mCullState->Enabled = false; mRenderer->SetOverrideCullState(mCullState); // Create a texture image to be used by both cylinders. Texture2D* texture = new0 Texture2D(Texture::TF_A8R8G8B8, 2, 2, 1); unsigned int* data = (unsigned int*)texture->GetData(0); data[0] = Color::MakeR8G8B8(0, 0, 255); // blue data[1] = Color::MakeR8G8B8(0, 255, 255); // cyan data[2] = Color::MakeR8G8B8(255, 0, 0); // red data[3] = Color::MakeR8G8B8(255, 255, 0); // yellow Texture2DEffect* effect = new0 Texture2DEffect(Shader::SF_LINEAR); // Create two cylinders, one short and thick, one tall and thin. VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); StandardMesh sm(vformat); VertexBufferAccessor vba; int i; mCylinder0 = sm.Cylinder(8, 16, 1.0f, 2.0f, false); vba.ApplyTo(mCylinder0); for (i = 0; i < vba.GetNumVertices(); ++i) { vba.TCoord<Float2>(0, i) = mBlueUV; } mCylinder0->SetEffectInstance(effect->CreateInstance(texture)); mScene->AttachChild(mCylinder0); mCylinder1 = sm.Cylinder(16,8,0.25,4.0,false); vba.ApplyTo(mCylinder1); for (i = 0; i < vba.GetNumVertices(); ++i) { vba.TCoord<Float2>(0, i) = mRedUV; } mCylinder1->SetEffectInstance(effect->CreateInstance(texture)); mScene->AttachChild(mCylinder1); mScene->Update(); // Set up the collision system. Record0 handles the collision response. // Record1 is not given a callback so that 'double processing' of the // events does not occur. CTree* tree0 = new0 CTree(mCylinder0, 1, false); CRecord* record0 = new0 CRecord(tree0, 0, Response, this); CTree* tree1 = new0 CTree(mCylinder1, 1, false); CRecord* record1 = new0 CRecord(tree1, 0, 0, 0); mGroup = new0 CGroup(); mGroup->Add(record0); mGroup->Add(record1); ResetColors(); mGroup->TestIntersection(); }
//---------------------------------------------------------------------------- void Terrains::CreateScene () { // Create the root of the scene. mScene = new0 Node(); // Load and initialize the sky dome. It follows the camera. std::string skyMeshName = Environment::GetPathR("SkyDomePNT2.wmvf"); Visual::PrimitiveType type; VertexFormat* vformat; VertexBuffer* vbuffer; IndexBuffer* ibuffer; Visual::LoadWMVF(skyMeshName, type, vformat, vbuffer, ibuffer); mSkyDome = new0 TriMesh(vformat, vbuffer, ibuffer); mScene->AttachChild(mSkyDome); APoint skyPosition = mCamera->GetPosition(); skyPosition[2] = 0.0f; mSkyDome->LocalTransform.SetTranslate(skyPosition); mSkyDome->LocalTransform.SetUniformScale(mCamera->GetDMax()); Texture2DEffect* skyEffect = new0 Texture2DEffect( Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT); std::string skyTextureName = Environment::GetPathR("SkyDome.wmtf"); Texture2D* skyTexture = Texture2D::LoadWMTF(skyTextureName); skyTexture->GenerateMipmaps(); mSkyDome->SetEffectInstance(skyEffect->CreateInstance(skyTexture)); // Load the height field and create the terrain. vformat = VertexFormat::Create(3, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 1); // For lower-resolution terrain, change the paths to Height64/Color64 or // Height32/Color32. std::string heightName = ThePath + "Data/Height128/height"; std::string colorName = ThePath + "Data/Color128/color"; mTerrain = new0 Terrain(heightName, vformat, mCamera); mScene->AttachChild(mTerrain); // The effect that is shared across all pages. std::string effectFile = Environment::GetPathR("BaseMulDetailFogExpSqr.wmfx"); TerrainEffect* terrainEffect = new0 TerrainEffect(effectFile); std::string detailName = Environment::GetPathR("Detail.wmtf"); Texture2D* detailTexture = Texture2D::LoadWMTF(detailName); detailTexture->GenerateMipmaps(); ShaderFloat* fogColorDensity = new0 ShaderFloat(1); (*fogColorDensity)[0] = 0.5686f; (*fogColorDensity)[1] = 0.7255f; (*fogColorDensity)[2] = 0.8353f; (*fogColorDensity)[3] = 0.0015f; // Attach an effect to each page. Preload all resources to video memory. // This will avoid frame rate stalls when new terrain pages are // encountered as the camera moves. const int numRows = mTerrain->GetRowQuantity(); const int numCols = mTerrain->GetColQuantity(); for (int r = 0; r < numRows; ++r) { for (int c = 0; c < numCols; ++c) { TerrainPage* page = mTerrain->GetPage(r, c); char suffix[32]; sprintf(suffix, ".%d.%d.wmtf", r, c); std::string colorTextureName = colorName + std::string(suffix); Texture2D* colorTexture = Texture2D::LoadWMTF(colorTextureName); colorTexture->GenerateMipmaps(); VisualEffectInstance* instance = terrainEffect->CreateInstance( colorTexture, detailTexture, fogColorDensity); page->SetEffectInstance(instance); mRenderer->Bind(page->GetVertexBuffer()); mRenderer->Bind(page->GetVertexFormat()); mRenderer->Bind(page->GetIndexBuffer()); mRenderer->Bind(colorTexture); } } }
bool fill(const FileNode &root) { // cascade properties static const char *const SC_STAGE_TYPE = "stageType"; static const char *const SC_BOOST = "BOOST"; static const char *const SC_FEATURE_TYPE = "featureType"; static const char *const SC_ICF = "ICF"; static const char *const SC_ORIG_W = "width"; static const char *const SC_ORIG_H = "height"; static const char *const SC_OCTAVES = "octaves"; static const char *const SC_TREES = "trees"; static const char *const SC_FEATURES = "features"; static const char *const SC_INTERNAL = "internalNodes"; static const char *const SC_LEAF = "leafValues"; static const char *const SC_SHRINKAGE = "shrinkage"; static const char *const FEATURE_FORMAT = "featureFormat"; // only Ada Boost supported std::string stageTypeStr = (string)root[SC_STAGE_TYPE]; CV_Assert(stageTypeStr == SC_BOOST); std::string fformat = (string)root[FEATURE_FORMAT]; bool useBoxes = (fformat == "BOX"); // only HOG-like integral channel features supported string featureTypeStr = (string)root[SC_FEATURE_TYPE]; CV_Assert(featureTypeStr == SC_ICF); origObjWidth = (int)root[SC_ORIG_W]; origObjHeight = (int)root[SC_ORIG_H]; shrinkage = (int)root[SC_SHRINKAGE]; FileNode fn = root[SC_OCTAVES]; if (fn.empty()) return false; // for each octave FileNodeIterator it = fn.begin(), it_end = fn.end(); for (int octIndex = 0; it != it_end; ++it, ++octIndex) { FileNode fns = *it; Octave octave(octIndex, cv::Size(origObjWidth, origObjHeight), fns); CV_Assert(octave.weaks > 0); octaves.push_back(octave); FileNode ffs = fns[SC_FEATURES]; if (ffs.empty()) return false; fns = fns[SC_TREES]; if (fn.empty()) return false; FileNodeIterator st = fns.begin(), st_end = fns.end(); for (; st != st_end; ++st ) { weaks.push_back(Weak(*st)); fns = (*st)[SC_INTERNAL]; FileNodeIterator inIt = fns.begin(), inIt_end = fns.end(); for (; inIt != inIt_end;) nodes.push_back(Node(features.size(), inIt)); fns = (*st)[SC_LEAF]; inIt = fns.begin(), inIt_end = fns.end(); for (; inIt != inIt_end; ++inIt) leaves.push_back((float)(*inIt)); } st = ffs.begin(), st_end = ffs.end(); for (; st != st_end; ++st ) features.push_back(Feature(*st, useBoxes)); } return true; }
//---------------------------------------------------------------------------- void IntersectConvexPolyhedra::CreateScene () { mScene = new0 Node(); mMotionObject = mScene; VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); // Attach a dummy intersection mesh. If the intersection is nonempty, // the Culling flag will be modified to CULL_DYNAMIC. The intersection // is drawn as a solid. mMeshIntersection = StandardMesh(vformat).Tetrahedron(); VertexBufferAccessor vba(mMeshIntersection); Float3 green(0.0f, 1.0f, 0.0f); int i, j; for (i = 0; i < vba.GetNumVertices(); ++i) { vba.Color<Float3>(0, i) = green; } mMeshIntersection->SetEffectInstance( VertexColor3Effect::CreateUniqueInstance()); mMeshIntersection->Culling = Spatial::CULL_ALWAYS; mScene->AttachChild(mMeshIntersection); // The first polyhedron is an ellipsoid. ConvexPolyhedronf::CreateEggShape(Vector3f::ZERO, 1.0f, 1.0f, 2.0f, 2.0f, 4.0f, 4.0f, 3, mWorldPoly0); // Build the corresponding mesh. int numVertices = mWorldPoly0.GetNumVertices(); int numTriangles = mWorldPoly0.GetNumTriangles(); int numIndices = 3*numTriangles; VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, vstride); IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int)); Float3 red(1.0f, 0.0f, 0.0f); vba.ApplyTo(vformat, vbuffer); for (i = 0; i < numVertices; ++i) { vba.Position<Vector3f>(i) = mWorldPoly0.Point(i); vba.Color<Float3>(0,i) = red; } int* indices = (int*)ibuffer->GetData(); for (i = 0; i < numTriangles; ++i) { const MTTriangle& triangle = mWorldPoly0.GetTriangle(i); for (j = 0; j < 3; ++j) { indices[3*i + j] = mWorldPoly0.GetVLabel(triangle.GetVertex(j)); } } mMeshPoly0 = new0 TriMesh(vformat, vbuffer, ibuffer); VisualEffectInstance* instance = VertexColor3Effect::CreateUniqueInstance(); instance->GetEffect()->GetWireState(0, 0)->Enabled = true; mMeshPoly0->SetEffectInstance(instance); mMeshPoly0->LocalTransform.SetTranslate(APoint(0.0f, 2.0f, 0.0f)); mScene->AttachChild(mMeshPoly0); // The second polyhedron is egg shaped. ConvexPolyhedronf::CreateEggShape(Vector3f::ZERO, 2.0f, 2.0f, 4.0f, 4.0f, 5.0f, 3.0f, 4, mWorldPoly1); // Build the corresponding mesh. numVertices = mWorldPoly1.GetNumVertices(); numTriangles = mWorldPoly1.GetNumTriangles(); numIndices = 3*numTriangles; vbuffer = new0 VertexBuffer(numVertices, vstride); ibuffer = new0 IndexBuffer(numIndices, sizeof(int)); Float3 blue(0.0f, 0.0f, 1.0f); vba.ApplyTo(vformat, vbuffer); for (i = 0; i < numVertices; ++i) { vba.Position<Vector3f>(i) = mWorldPoly1.Point(i); vba.Color<Float3>(0, i) = blue; } indices = (int*)ibuffer->GetData(); for (i = 0; i < numTriangles; ++i) { const MTTriangle& triangle = mWorldPoly1.GetTriangle(i); for (j = 0; j < 3; ++j) { indices[3*i + j] = mWorldPoly1.GetVLabel(triangle.GetVertex(j)); } } mMeshPoly1 = new0 TriMesh(vformat, vbuffer, ibuffer); instance = VertexColor3Effect::CreateUniqueInstance(); instance->GetEffect()->GetWireState(0, 0)->Enabled = true; mMeshPoly1->SetEffectInstance(instance); mMeshPoly1->LocalTransform.SetTranslate(APoint(0.0f, -2.0f, 0.0f)); mScene->AttachChild(mMeshPoly1); ComputeIntersection(); }
int main() { glfwInit(); Window testWindow(50, 50, WINDOW_WIDTH, WINDOW_HEIGHT, "Deferred Shading"); glfwMakeContextCurrent(testWindow.getWindow()); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // You have to set a camera name cam.setName("PilotviewCam"); cam.setPosition(glm::vec4(0.0, 0.5, 3.0, 1.0)); cam.setNearFar(0.01f, 100.0f); iH.setAllInputMaps(cam); iH.changeActiveInputMap("Pilotview"); //Callback glfwSetKeyCallback(testWindow.getWindow(), key_callback); glewInit(); //our shader VertexShader vsGBuffer(loadShaderSource(SHADERS_PATH + std::string("/GBuffer/GBuffer.vert"))); FragmentShader fsGBuffer(loadShaderSource(SHADERS_PATH + std::string("/GBuffer/GBuffer.frag"))); ShaderProgram shaderGBuffer(vsGBuffer, fsGBuffer); //load shader here VertexShader vsDsLighting(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsLighting.vert"))); FragmentShader fsDsLighting(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsLighting.frag"))); ShaderProgram shaderDsLightingShader(vsDsLighting, fsDsLighting); VertexShader vsDsCompositing(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsFinalCompositing.vert"))); FragmentShader fsDsCompositing(loadShaderSource(SHADERS_PATH + std::string("/DeferredShading/dsFinalCompositing.frag"))); ShaderProgram shaderDsCompositingShader(vsDsCompositing, fsDsCompositing); VertexShader vsSfq(loadShaderSource(SHADERS_PATH + std::string("/ScreenFillingQuad/ScreenFillingQuad.vert"))); FragmentShader fsSfq(loadShaderSource(SHADERS_PATH + std::string("/ScreenFillingQuad/ScreenFillingQuad.frag"))); ShaderProgram shaderSFQ(vsSfq, fsSfq); //our renderer OpenGL3Context context; Renderer renderer(context); FBO fboGBuffer(WINDOW_WIDTH, WINDOW_HEIGHT, 3, true, false); FBO fboDeferredShading(WINDOW_WIDTH, WINDOW_HEIGHT, 3, true, false); FBO fboCompositing(WINDOW_WIDTH, WINDOW_HEIGHT, 3, false, false); //our object Cube cube; Teapot teapot; Rect plane; Rect screenFillingQuad; screenFillingQuad.loadBufferData(); //our textures Texture bricks((char*)RESOURCES_PATH "/bricks_diffuse.png"); Texture bricks_normal((char*)RESOURCES_PATH "/bricks_normal.png"); Texture bricks_height((char*)RESOURCES_PATH "/bricks_height.png"); Texture chrome((char*)RESOURCES_PATH "/chrome.jpg"); Texture cvLogo((char*)RESOURCES_PATH "/cv_logo.bmp"); //Scene creation Level testLevel("testLevel"); Scene testScene("testScene"); testLevel.addScene(&testScene); testLevel.changeScene("testScene"); //Add Camera to scenegraph testScene.getScenegraph()->addCamera(&cam); testScene.getScenegraph()->getCamera("PilotviewCam"); testScene.getScenegraph()->setActiveCamera("PilotviewCam"); Rect rect; Node cube1("cube1"); cube1.addGeometry(&cube); cube1.addTexture(&bricks); cube1.addNormalMap(&bricks_normal); cube1.addHeightMap(&bricks_height); cube1.setModelMatrix(glm::translate(cube1.getModelMatrix(), glm::vec3(-1.0, 0.5, -0.5))); cube1.setModelMatrix(glm::scale(cube1.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node cube2("cube2"); cube2.addGeometry(&cube); cube2.addTexture(&bricks); cube2.addNormalMap(&bricks_normal); cube2.setModelMatrix(glm::translate(cube2.getModelMatrix(), glm::vec3(-1, 0.5, 0.5))); cube2.setModelMatrix(glm::scale(cube2.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node cube3("cube3"); cube3.addGeometry(&cube); cube3.addTexture(&bricks); cube3.setModelMatrix(glm::translate(cube3.getModelMatrix(), glm::vec3(0, 0.5, -0.5))); cube3.setModelMatrix(glm::scale(cube3.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node cube4("cube4"); cube4.addGeometry(&cube); cube4.addTexture(&bricks); cube4.addNormalMap(&bricks_normal); cube4.addHeightMap(&bricks_height,0.07,0.1,true); cube4.setModelMatrix(glm::translate(cube4.getModelMatrix(), glm::vec3(0, 0.5, 0.5))); cube4.setModelMatrix(glm::scale(cube4.getModelMatrix(), glm::vec3(0.7, 0.7, 0.7))); Node wallNode1("wall1"); wallNode1.addGeometry(&plane); wallNode1.addTexture(&cvLogo); wallNode1.setModelMatrix(glm::translate(wallNode1.getModelMatrix(), glm::vec3(0.0, 0.1, 0.2))); wallNode1.setModelMatrix(glm::rotate(wallNode1.getModelMatrix(), 90.0f, glm::vec3(1.0, 0.0, 0.0))); wallNode1.setModelMatrix(glm::scale(wallNode1.getModelMatrix(), glm::vec3(10.5, 10.5, 10.5))); Node teaNode("teaNode"); teaNode.addGeometry(&teapot); teaNode.addTexture(&chrome); teaNode.setModelMatrix(glm::translate(teaNode.getModelMatrix(), glm::vec3(0.2, 0.4, 0.7))); teaNode.setModelMatrix(glm::scale(teaNode.getModelMatrix(), glm::vec3(0.5, 0.5, 0.5))); //Creating a scenegraph testScene.getScenegraph()->getRootNode()->addChildrenNode(&wallNode1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube1); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube2); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube3); testScene.getScenegraph()->getRootNode()->addChildrenNode(&cube4); //testScene.getScenegraph()->getRootNode()->addChildrenNode(&teaNode); double startTime = glfwGetTime(); //Renderloop //create Light spheres for DS Node lights = Node("Root"); Sphere lightSphere = Sphere(); for (int i = -4; i < 4; i++) for (int j = -4; j < 4; j++) { Node *newLight = new Node(std::string("Node_"+std::to_string(i)+std::to_string(j))); newLight->addGeometry(&lightSphere); newLight->setModelMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(i*1.5, 1.0f, j*1.5))); //newLight.setModelMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, 1, 1.0f))); newLight->setModelMatrix(glm::scale(newLight->getModelMatrix(), glm::vec3(2.0, 2.0, 2.0))); lights.addChildrenNode(newLight); } int outputFPS = 0; while (!glfwWindowShouldClose(testWindow.getWindow())) { // You have to compute the delta time float deltaTime = glfwGetTime() - startTime; cam.setSensitivity(deltaTime); //if (!(outputFPS % 20)) //std::cout << "FPS: " << static_cast<int>(1 / (glfwGetTime() - startTime)) << std::endl; std::cout << "FPS: " << static_cast<double>(glfwGetTime() - startTime) * 100 << std::endl; outputFPS++; startTime = glfwGetTime(); //update Model Matrix lights.setModelMatrix(glm::rotate(lights.getModelMatrix(), 10.0f * deltaTime, glm::vec3(0.0, 1.0, 0.0))); fboGBuffer.bind(); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderGBuffer.bind(); shaderGBuffer.sendMat4("viewMatrix", cam.getViewMatrix()); shaderGBuffer.sendMat4("projectionMatrix", cam.getProjectionMatrix()); testScene.render(shaderGBuffer); shaderGBuffer.unbind(); fboGBuffer.unbind(); //DEFERRED SHADING TEIL============================ fboDeferredShading.bind(); glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderDsLightingShader.bind(); shaderDsLightingShader.sendMat4("viewMatrix", cam.getViewMatrix()); shaderDsLightingShader.sendMat4("projectionMatrix", cam.getProjectionMatrix()); shaderDsLightingShader.sendSampler2D("positionMap", fboGBuffer.getColorTexture(0),0); shaderDsLightingShader.sendSampler2D("normalMap", fboGBuffer.getColorTexture(1),1); shaderDsLightingShader.sendInt("windowWidth", testWindow.getWidth()); shaderDsLightingShader.sendInt("windowHeight", testWindow.getHeight()); shaderDsLightingShader.sendVec3("lightColor", glm::fvec3(0.7f,0.7f,0.4f)); lights.render(shaderDsLightingShader); glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glClearColor(1.0, 1.0, 1.0, 0.0); shaderDsLightingShader.unbind(); fboDeferredShading.unbind(); //COMPOSITING TEIL =============================== fboCompositing.bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderDsCompositingShader.bind(); shaderDsCompositingShader.sendSampler2D("colorMap", fboGBuffer.getColorTexture(2),0); shaderDsCompositingShader.sendSampler2D("lightMap", fboDeferredShading.getColorTexture(2),1); screenFillingQuad.renderGeometry(); shaderDsCompositingShader.unbind(); fboCompositing.unbind(); //================================================ //ScreenFillingQuad Render Pass shaderSFQ.bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (glfwGetKey(testWindow.getWindow(), GLFW_KEY_F1)) shaderSFQ.sendSampler2D("fboTexture", fboDeferredShading.getColorTexture(2)); else shaderSFQ.sendSampler2D("fboTexture", fboCompositing.getColorTexture(2)); screenFillingQuad.renderGeometry(); shaderSFQ.unbind(); glfwSwapBuffers(testWindow.getWindow()); glfwPollEvents(); } glfwDestroyWindow(testWindow.getWindow()); glfwTerminate(); return 0; }
void ClusterMgr::configure(Uint32 nodeId, const ndb_mgm_configuration* config) { ndb_mgm_configuration_iterator iter(* config, CFG_SECTION_NODE); for(iter.first(); iter.valid(); iter.next()){ Uint32 nodeId = 0; if(iter.get(CFG_NODE_ID, &nodeId)) continue; // Check array bounds + don't allow node 0 to be touched assert(nodeId > 0 && nodeId < MAX_NODES); trp_node& theNode = theNodes[nodeId]; theNode.defined = true; unsigned type; if(iter.get(CFG_TYPE_OF_SECTION, &type)) continue; switch(type){ case NODE_TYPE_DB: theNode.m_info.m_type = NodeInfo::DB; break; case NODE_TYPE_API: theNode.m_info.m_type = NodeInfo::API; break; case NODE_TYPE_MGM: theNode.m_info.m_type = NodeInfo::MGM; break; default: type = type; break; } } /* Mark all non existing nodes as not defined */ for(Uint32 i = 0; i<MAX_NODES; i++) { if (iter.first()) continue; if (iter.find(CFG_NODE_ID, i)) theNodes[i]= Node(); } #if 0 print_nodes("init"); #endif // Configure arbitrator Uint32 rank = 0; iter.first(); iter.find(CFG_NODE_ID, nodeId); // let not found in config mean rank=0 iter.get(CFG_NODE_ARBIT_RANK, &rank); if (rank > 0) { // The arbitrator should be active if (!theArbitMgr) theArbitMgr = new ArbitMgr(* this); theArbitMgr->setRank(rank); Uint32 delay = 0; iter.get(CFG_NODE_ARBIT_DELAY, &delay); theArbitMgr->setDelay(delay); } else if (theArbitMgr) { // No arbitrator should be started theArbitMgr->doStop(NULL); delete theArbitMgr; theArbitMgr= NULL; } }
Pacman::ViewDirection Pacman::getNextDirection(unsigned int startIndex, unsigned int searchIndex, unsigned int ignoreCell) { std::list<Node> OpenNodeList; std::list<Node> ClosedNodeList; // Guardamos en la lista de Nodos Abiertos el Nodo correspondiente a startIndex OpenNodeList.push_back(Node()); OpenNodeList.back().Index = startIndex; OpenNodeList.back().Range = abs((startIndex % m_mapSize.x) - (searchIndex % m_mapSize.x)) + abs(floor(startIndex / m_mapSize.y) - floor(searchIndex / m_mapSize.y)); if(ignoreCell == m_mapNullCell) { // Guardamos en la lista de Nodos Cerrados el Nodo correspondiente a la casilla a ignorar ClosedNodeList.push_back(Node()); ClosedNodeList.back().Index = ignoreCell; } Node* preferentNode = &OpenNodeList.back(); // Hasta que no encuentre el destino o la lista de nodos abiertos se vacíe (no haya caminos posibles)... while (preferentNode->Index != searchIndex && !OpenNodeList.empty()) { // Si el nodo preferente está en la lista de nodos cerrados... for (auto closedNode : ClosedNodeList) { if (closedNode.Index == preferentNode->Index) { preferentNode = &OpenNodeList.back(); // Elegimos el primer nodo más preferente de la lista de nodos abiertos for (auto openNodeIt = OpenNodeList.begin(); openNodeIt != OpenNodeList.end(); ++openNodeIt) //for (auto openNode : OpenNodeList) { if ((preferentNode->Range + preferentNode->Cost) > (openNodeIt->Range + openNodeIt->Cost)) { preferentNode = &*openNodeIt; } } break; } } // Guardamos el nodo preferente en la lista de Nodos cerrados y lo eliminamos de la lista de nodos abiertos for (auto openNodeIt = OpenNodeList.begin(); openNodeIt != OpenNodeList.end(); ++openNodeIt) { if (openNodeIt->Index == preferentNode->Index) { ClosedNodeList.push_back(*preferentNode); // Actualizamos los punteros for (Node openNode : OpenNodeList) { if(openNode.ParentNode == preferentNode) { openNode.ParentNode = &ClosedNodeList.back(); } } preferentNode = &ClosedNodeList.back(); OpenNodeList.erase(openNodeIt); break; } } std::vector<unsigned int> nextIndex; // Añadimos a nextIndex CADA UNA de las 4 direcciones si es posible su tránsito if (!checkCollision(preferentNode->Index, ViewDirection::Left, false)) { nextIndex.push_back(getMapIndex(preferentNode->Index, ViewDirection::Left)); } if (!checkCollision(preferentNode->Index, ViewDirection::Right, false)) { nextIndex.push_back(getMapIndex(preferentNode->Index, ViewDirection::Right)); } if (!checkCollision(preferentNode->Index, ViewDirection::Up, false)) { nextIndex.push_back(getMapIndex(preferentNode->Index, ViewDirection::Up)); } if (!checkCollision(preferentNode->Index, ViewDirection::Down, false)) { nextIndex.push_back(getMapIndex(preferentNode->Index, ViewDirection::Down)); } if (!nextIndex.empty()) { Node* previousNode = preferentNode; for (unsigned int Index : nextIndex) { bool isValid = true; // Miramos si existe en la lista de nodos abiertos for (Node openNode : OpenNodeList) { if (openNode.Index == Index) { isValid = false; break; } } if (!isValid) { continue; } // Miramos si existe en la lista de nodos cerrados for (Node closedNode : ClosedNodeList) { if (closedNode.Index == Index) { isValid = false; break; } } if (!isValid) { continue; } // Si NO existe en ninguna de las listas anteriores, añadimos el nodo a la lista de nodos abiertos OpenNodeList.push_back(Node()); OpenNodeList.back().Index = Index; OpenNodeList.back().ParentNode = previousNode; OpenNodeList.back().Cost = (previousNode->Cost + 1); OpenNodeList.back().Range = abs((int)(Index % m_mapSize.x) - (int)(searchIndex % m_mapSize.x)) + abs(floor(Index / m_mapSize.y) - floor(searchIndex / m_mapSize.y)); // ... y actualizamos preferentNode si así fuera el caso if ((preferentNode->Range + preferentNode->Cost) > (OpenNodeList.back().Range + OpenNodeList.back().Cost)) { preferentNode = &OpenNodeList.back(); } } } } // Si el ultimo nodo preferente encontró el destino... if (preferentNode->Index == searchIndex) { // Localizamos el nodo con la siguiente casilla a desplazarse desde el nodo destino while (preferentNode->ParentNode->Index != startIndex) { preferentNode = preferentNode->ParentNode; } // Nos movemos en una dirección segun el nodo posterior al nodo origen if (preferentNode->Index == (startIndex - 1)) { return ViewDirection::Left; } else if (preferentNode->Index == (startIndex + 1)) { return ViewDirection::Right; } else if (preferentNode->Index == (startIndex + m_mapSize.x)) { return ViewDirection::Down; } else { return ViewDirection::Up; } } else { return getRandomDirection(startIndex, ignoreCell); } }
/// Returns the cell (represented as a Node object) at the specified point. Node Game::pointToNode(const QPointF &point){ return Node(point.x()/cellSize_,point.y()/cellSize_); }
bool IFindObserver<span>::contains(KmerType kmer) { kmer = std::min(kmer, revcomp(kmer, this->_find->kmer_size())); Node node = Node(Node::Value(kmer)); return this->_find->graph_contains(node); }
// --------------------------------------------------------------------------- // CIAUpdateContentOperation::OperationProgress // // --------------------------------------------------------------------------- // void CIAUpdateContentOperation::OperationProgress( TInt aProgress, TInt aMaxProgress ) { Observer().ContentOperationProgress( Node(), aProgress, aMaxProgress ); }
//---------------------------------------------------------------------------- void BillboardNodes::CreateScene () { mScene = new0 Node(); mCullState = new0 CullState(); mRenderer->SetOverrideCullState(mCullState); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); // All triangle meshes have this common vertex format. Use StandardMesh // to create these meshes. VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); StandardMesh stdMesh(vformat); // Create the ground. It covers a square with vertices (1,1,0), (1,-1,0), // (-1,1,0), and (-1,-1,0). Multiply the texture coordinates by a factor // to enhance the wrap-around. mGround = stdMesh.Rectangle(2, 2, 16.0f, 16.0f); VertexBufferAccessor vba(mGround); int i; for (i = 0; i < vba.GetNumVertices(); ++i) { Float2& tcoord = vba.TCoord<Float2>(0, i); tcoord[0] *= 128.0f; tcoord[1] *= 128.0f; } // Create a texture effect for the ground. std::string path = Environment::GetPathR("Horizontal.wmtf"); Texture2D* texture = Texture2D::LoadWMTF(path); VisualEffectInstance* instance = Texture2DEffect::CreateUniqueInstance( texture, Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT); mGround->SetEffectInstance(instance); mScene->AttachChild(mGround); // Create a rectangle mesh. The mesh is in the xy-plane. Do not apply // local transformations to the mesh. Use the billboard node transforms // to control the mesh location and orientation. mRectangle = stdMesh.Rectangle(2, 2, 0.125f, 0.25f); // Create a texture effect for the rectangle and for the torus. Texture2DEffect* geomEffect = new0 Texture2DEffect(Shader::SF_LINEAR); path = Environment::GetPathR("RedSky.wmtf"); texture = Texture2D::LoadWMTF(path); mRectangle->SetEffectInstance(geomEffect->CreateInstance(texture)); // Create a billboard node that causes a rectangle to always be facing // the camera. This is the type of billboard for an avatar. mBillboard0 = new0 BillboardNode(mCamera); mBillboard0->AttachChild(mRectangle); mScene->AttachChild(mBillboard0); // The billboard rotation is about its model-space up-vector (0,1,0). In // this application, world-space up is (0,0,1). Locally rotate the // billboard so it's up-vector matches the world's. mBillboard0->LocalTransform.SetTranslate(APoint(-0.25f, 0.0f, 0.25f)); mBillboard0->LocalTransform.SetRotate(HMatrix(AVector::UNIT_X, Mathf::HALF_PI)); // Create a torus mesh. Do not apply local transformations to the mesh. // Use the billboard node transforms to control the mesh location and // orientation. mTorus = StandardMesh(vformat, false).Torus(16, 16, 1.0f, 0.25f); mTorus->LocalTransform.SetUniformScale(0.1f); // Create a texture effect for the torus. It uses the RedSky image that // the rectangle uses. mTorus->SetEffectInstance(geomEffect->CreateInstance(texture)); // Create a billboard node that causes an object to always be oriented // the same way relative to the camera. mBillboard1 = new0 BillboardNode(mCamera); mBillboard1->AttachChild(mTorus); mScene->AttachChild(mBillboard1); // The billboard rotation is about its model-space up-vector (0,1,0). In // this application, world-space up is (0,0,1). Locally rotate the // billboard so it's up-vector matches the world's. mBillboard1->LocalTransform.SetTranslate(APoint(0.25f, 0.0f, 0.25f)); mBillboard1->LocalTransform.SetRotate(HMatrix(AVector::UNIT_X, Mathf::HALF_PI)); #ifdef DEMONSTRATE_VIEWPORT_BOUNDING_RECTANGLE // The screen camera is designed to map (x,y,z) in [0,1]^3 to (x',y,'z') // in [-1,1]^2 x [0,1]. mSSCamera = new0 Camera(false); mSSCamera->SetFrustum(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); mSSCamera->SetFrame(APoint::ORIGIN, AVector::UNIT_Z, AVector::UNIT_Y, AVector::UNIT_X); // Create a semitransparent screen rectangle. VertexFormat* ssVFormat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT4, 0); int ssVStride = ssVFormat->GetStride(); VertexBuffer* ssVBuffer = new0 VertexBuffer(4, ssVStride); VertexBufferAccessor ssVba(ssVFormat, ssVBuffer); Float4 ssColor(0.0f, 0.0f, 1.0f, 0.25f); ssVba.Position<Float3>(0) = Float3(0.0f, 0.0f, 0.0f); ssVba.Position<Float3>(1) = Float3(1.0f, 0.0f, 0.0f); ssVba.Position<Float3>(2) = Float3(1.0f, 1.0f, 0.0f); ssVba.Position<Float3>(3) = Float3(0.0f, 1.0f, 0.0f); ssVba.Color<Float4>(0, 0) = ssColor; ssVba.Color<Float4>(0, 1) = ssColor; ssVba.Color<Float4>(0, 2) = ssColor; ssVba.Color<Float4>(0, 3) = ssColor; IndexBuffer* ssIBuffer = new0 IndexBuffer(6, sizeof(int)); int* indices = (int*)ssIBuffer->GetData(); indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; mSSRectangle = new0 TriMesh(ssVFormat, ssVBuffer, ssIBuffer); mSSRectangle->Update(); // Create a vertex color effect for the screen rectangle. VertexColor4Effect* ssEffect = new0 VertexColor4Effect(); mSSRectangle->SetEffectInstance(ssEffect->CreateInstance()); // Alpha blending must be enabled to obtain the semitransparency. ssEffect->GetAlphaState(0, 0)->BlendEnabled = true; #endif }
//--------------------------------------------------------------------------- Node Node::operator+ ( Node node ) { return Node( x + node.x, y + node.y, z + node.z ); }
//---------------------------------------------------------------------------- void ClodMeshes::CreateScene () { mScene = new0 Node(); mTrnNode = new0 Node(); mScene->AttachChild(mTrnNode); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); // Load the face model. #ifdef WM5_LITTLE_ENDIAN std::string path = Environment::GetPathR("FacePN.wmof"); #else std::string path = Environment::GetPathR("FacePN.be.wmof"); #endif InStream inStream; inStream.Load(path); TriMeshPtr mesh = StaticCast<TriMesh>(inStream.GetObjectAt(0)); VertexBufferAccessor vba0(mesh); // Remove the normals and add texture coordinates. VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0); int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(vba0.GetNumVertices(), vstride); VertexBufferAccessor vba1(vformat, vbuffer); float xmin = Mathf::MAX_REAL, xmax = -Mathf::MAX_REAL; float ymin = Mathf::MAX_REAL, ymax = -Mathf::MAX_REAL; int i; for (i = 0; i < vba0.GetNumVertices(); ++i) { Float3 position = vba0.Position<Float3>(i); vba1.Position<Float3>(i) = position; float x = position[0]; float y = position[2]; vba1.TCoord<Float2>(0, i) = Float2(x, y); if (x < xmin) { xmin = x; } if (x > xmax) { xmax = x; } if (y < ymin) { ymin = y; } if (y > ymax) { ymax = y; } } float xmult = 1.0f/(xmax - xmin); float ymult = 1.0f/(ymax - ymin); for (i = 0; i < vba1.GetNumVertices(); ++i) { Float2 tcoord = vba1.TCoord<Float2>(0, i); vba1.TCoord<Float2>(0,i) = Float2( (tcoord[0] - xmin)*xmult, (tcoord[1] - ymin)*ymult); } mesh->SetVertexFormat(vformat); mesh->SetVertexBuffer(vbuffer); // Create a texture for the face. Use the generated texture coordinates. Texture2DEffect* effect = new0 Texture2DEffect(Shader::SF_LINEAR); path = Environment::GetPathR("Magician.wmtf"); Texture2D* texture = Texture2D::LoadWMTF(path); #ifdef USE_CLOD_MESH // Create the collapse records to be shared by two CLOD meshes. int numRecords = 0; CollapseRecord* records = 0; CreateClodMesh ccm(mesh, numRecords, records); CollapseRecordArray* recordArray = new0 CollapseRecordArray(numRecords, records); mClod[0] = new0 ClodMesh(mesh, recordArray); mClod[0]->LocalTransform = mesh->LocalTransform; mClod[0]->LocalTransform.SetTranslate(mesh->LocalTransform.GetTranslate() - 150.0f*AVector::UNIT_X); mClod[0]->SetEffectInstance(effect->CreateInstance(texture)); mTrnNode->AttachChild(mClod[0]); mClod[1] = new0 ClodMesh(mesh, recordArray); mClod[1]->LocalTransform = mesh->LocalTransform; mClod[1]->LocalTransform.SetTranslate(mesh->LocalTransform.GetTranslate() + 150.0f*AVector::UNIT_X - 100.0f*AVector::UNIT_Y); mClod[1]->SetEffectInstance(effect->CreateInstance(texture)); mTrnNode->AttachChild(mClod[1]); mActive = mClod[0]; #else IndexBuffer* ibuffer = mesh->GetIndexBuffer(); TriMesh* face = new0 TriMesh(vformat, vbuffer,ibuffer); face->LocalTransform = mesh->LocalTransform; face->LocalTransform.SetTranslate(mesh->LocalTransform.GetTranslate() - 150.0f*AVector::UNIT_X); face->SetEffectInstance(effect->CreateInstance(texture)); mTrnNode->AttachChild(face); face = new0 TriMesh(vformat, vbuffer, ibuffer); face->LocalTransform = mesh->LocalTransform; face->LocalTransform.SetTranslate(mesh->LocalTransform.GetTranslate() + 150.0f*AVector::UNIT_X); face->SetEffectInstance(effect->CreateInstance(texture)); mTrnNode->AttachChild(face); #endif }
//--------------------------------------------------------------------------- Node Node::operator- ( Node node ) { return Node( x - node.x, y - node.y, z - node.z ); }
//---------------------------------------------------------------------------- void Fluids3D::CreateScene () { // Get fluid solver parameters. const int bound0M1 = mSmoke->GetIMax(); const int bound1M1 = mSmoke->GetJMax(); const int bound2M1 = mSmoke->GetKMax(); const int bound0 = bound0M1 + 1; const int bound1 = bound1M1 + 1; const int bound2 = bound2M1 + 1; const int quantity = bound0*bound1*bound2; const float* x = mSmoke->GetX(); const float* y = mSmoke->GetY(); const float* z = mSmoke->GetZ(); #ifdef USE_PARTICLES // Create the vertex format. VertexFormat* vformat = VertexFormat::Create(3, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT4, 0); #else VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT4, 0); #endif // Create the vertex buffer for the cube. #ifdef USE_PARTICLES const int numVertices = 4*quantity; #else const int numVertices = quantity; #endif int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, vstride); int i0, i1, i2, index; #ifdef USE_PARTICLES const float delta = mSmoke->GetDx(); Float4* posSize = new1<Float4>(quantity); for (i2 = 0, index = 0; i2 < bound2; ++i2) { for (i1 = 0; i1 < bound1; ++i1) { for (i0 = 0; i0 < bound0; ++i0, ++index) { posSize[index] = Float4(x[i0], y[i1], z[i2], delta); } } } mCube = new0 Particles(vformat, vbuffer, 4, posSize, 1.0f); UpdateVertexBuffer(); IndexBuffer* ibuffer = mCube->GetIndexBuffer(); #else VertexBufferAccessor vba(vformat, vbuffer); for (i2 = 0, index = 0; i2 < bound2; ++i2) { for (i1 = 0; i1 < bound1; ++i1) { for (i0 = 0; i0 < bound0; ++i0, ++index) { vba.Position<Float3>(index) = Float3(x[i0], y[i1], z[i2]); } } } // Create the index buffer for the cube. const int numIndices = 6*bound0M1*bound1M1*bound2 + 6*bound0M1*bound1*bound2M1 + 6*bound0*bound1M1*bound2M1; IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int)); int* indices = (int*)ibuffer->GetData(); const int bound01 = bound0*bound1; int j0, j1, j2, j3; for (i2 = 0; i2 < bound2; ++i2) { for (i1 = 0; i1 < bound1M1; ++i1) { for (i0 = 0; i0 < bound0M1; ++i0) { j0 = i0 + bound0*(i1 + bound1*i2); j1 = j0 + 1; j2 = j1 + bound0; j3 = j2 - 1; *indices++ = j0; *indices++ = j1; *indices++ = j2; *indices++ = j0; *indices++ = j2; *indices++ = j3; } } } for (i1 = 0; i1 < bound1; ++i1) { for (i2 = 0; i2 < bound2M1; ++i2) { for (i0 = 0; i0 < bound0M1; ++i0) { j0 = i0 + bound0*(i1 + bound1*i2); j1 = j0 + 1; j2 = j1 + bound01; j3 = j2 - 1; *indices++ = j0; *indices++ = j1; *indices++ = j2; *indices++ = j0; *indices++ = j2; *indices++ = j3; } } } for (i0 = 0; i0 < bound0; ++i0) { for (i1 = 0; i1 < bound1M1; ++i1) { for (i2 = 0; i2 < bound2M1; ++i2) { j0 = i0 + bound0*(i1 + bound1*i2); j1 = j0 + bound0; j2 = j1 + bound01; j3 = j2 - bound0; *indices++ = j0; *indices++ = j1; *indices++ = j2; *indices++ = j0; *indices++ = j2; *indices++ = j3; } } } mCube = new0 TriMesh(vformat, vbuffer, ibuffer); UpdateVertexBuffer(); #endif mNumIndices = ibuffer->GetNumElements(); mIndices = new1<int>(mNumIndices); memcpy(mIndices, ibuffer->GetData(), mNumIndices*sizeof(int)); // Create the cube effect. #ifdef USE_PARTICLES std::string path = Environment::GetPathR("Disk.wmtf"); Texture2D* texture = Texture2D::LoadWMTF(path); VisualEffectInstance* instance = VertexColor4TextureEffect::CreateUniqueInstance(texture, Shader::SF_NEAREST, Shader::SC_CLAMP_EDGE, Shader::SC_CLAMP_EDGE); #else VertexColor4Effect* effect = new0 VertexColor4Effect(); VisualEffectInstance* instance = effect->CreateInstance(); #endif const VisualPass* pass = instance->GetPass(0); AlphaState* astate = pass->GetAlphaState(); astate->BlendEnabled = true; CullState* cstate = pass->GetCullState(); cstate->Enabled = false; DepthState* dstate = pass->GetDepthState(); dstate->Enabled = false; dstate->Writable = false; mCube->SetEffectInstance(instance); mScene = new0 Node(); mScene->AttachChild(mCube); }
//--------------------------------------------------------------------------- Node Node::operator* ( Node node ) { return Node( x * node.x, y * node.y, z * node.z ); }
void* CArena::alloc (size_t nbytes) { nbytes = Arena::align(nbytes == 0 ? 1 : nbytes); // // Find node in freelist at lowest memory address that'll satisfy request. // NL::iterator free_it = m_freelist.begin(); for ( ; free_it != m_freelist.end(); ++free_it) if ((*free_it).size() >= nbytes) break; void* vp = 0; if (free_it == m_freelist.end()) { const size_t N = nbytes < m_hunk ? m_hunk : nbytes; vp = ::operator new(N); m_used += N; m_alloc.push_back(vp); if (nbytes < m_hunk) { // // Add leftover chunk to free list. // // Insert with a hint -- should be largest block in the set. // void* block = static_cast<char*>(vp) + nbytes; m_freelist.insert(m_freelist.end(), Node(block, m_hunk-nbytes)); } } else { BL_ASSERT((*free_it).size() >= nbytes); BL_ASSERT(m_busylist.find(*free_it) == m_busylist.end()); vp = (*free_it).block(); if ((*free_it).size() > nbytes) { // // Insert remainder of free block back into freelist. // // Insert with a hint -- right after the current block being split. // Node freeblock = *free_it; freeblock.size(freeblock.size() - nbytes); freeblock.block(static_cast<char*>(vp) + nbytes); m_freelist.insert(free_it, freeblock); } m_freelist.erase(free_it); } m_busylist.insert(Node(vp, nbytes)); BL_ASSERT(!(vp == 0)); return vp; }
//--------------------------------------------------------------------------- Node Node::operator/ ( Node node ) { return Node( x / node.x, y / node.y, z / node.z ); }
int Ndb_cluster_connection_impl::init_nodes_vector(Uint32 nodeid, const ndb_mgm_configuration &config) { DBUG_ENTER("Ndb_cluster_connection_impl::init_nodes_vector"); ndb_mgm_configuration_iterator iter(config, CFG_SECTION_CONNECTION); for(iter.first(); iter.valid(); iter.next()) { Uint32 nodeid1, nodeid2, remoteNodeId, group= 5; const char * remoteHostName= 0, * localHostName= 0; if(iter.get(CFG_CONNECTION_NODE_1, &nodeid1)) continue; if(iter.get(CFG_CONNECTION_NODE_2, &nodeid2)) continue; if(nodeid1 != nodeid && nodeid2 != nodeid) continue; remoteNodeId = (nodeid == nodeid1 ? nodeid2 : nodeid1); iter.get(CFG_CONNECTION_GROUP, &group); { const char * host1= 0, * host2= 0; iter.get(CFG_CONNECTION_HOSTNAME_1, &host1); iter.get(CFG_CONNECTION_HOSTNAME_2, &host2); localHostName = (nodeid == nodeid1 ? host1 : host2); remoteHostName = (nodeid == nodeid1 ? host2 : host1); } Uint32 type = ~0; if(iter.get(CFG_TYPE_OF_SECTION, &type)) continue; switch(type){ case CONNECTION_TYPE_SHM:{ break; } case CONNECTION_TYPE_SCI:{ break; } case CONNECTION_TYPE_TCP:{ // connecting through localhost // check if config_hostname is local if (SocketServer::tryBind(0,remoteHostName)) group--; // upgrade group value break; } } if (m_impl.m_all_nodes.push_back(Node(group,remoteNodeId))) { DBUG_RETURN(-1); } DBUG_PRINT("info",("saved %d %d", group,remoteNodeId)); for (int i= m_impl.m_all_nodes.size()-2; i >= 0 && m_impl.m_all_nodes[i].group > m_impl.m_all_nodes[i+1].group; i--) { Node tmp= m_impl.m_all_nodes[i]; m_impl.m_all_nodes[i]= m_impl.m_all_nodes[i+1]; m_impl.m_all_nodes[i+1]= tmp; } } int i; Uint32 cur_group, i_group= 0; cur_group= ~0; for (i= (int)m_impl.m_all_nodes.size()-1; i >= 0; i--) { if (m_impl.m_all_nodes[i].group != cur_group) { cur_group= m_impl.m_all_nodes[i].group; i_group= i+1; } m_impl.m_all_nodes[i].next_group= i_group; } cur_group= ~0; for (i= 0; i < (int)m_impl.m_all_nodes.size(); i++) { if (m_impl.m_all_nodes[i].group != cur_group) { cur_group= m_impl.m_all_nodes[i].group; i_group= i; } m_impl.m_all_nodes[i].this_group= i_group; } #if 0 for (i= 0; i < (int)m_impl.m_all_nodes.size(); i++) { fprintf(stderr, "[%d] %d %d %d %d\n", i, m_impl.m_all_nodes[i].id, m_impl.m_all_nodes[i].group, m_impl.m_all_nodes[i].this_group, m_impl.m_all_nodes[i].next_group); } do_test(); #endif DBUG_RETURN(0); }
//--------------------------------------------------------------------------- Node Node::operator* ( double m ) { return Node( x * m, y * m, z * m ); }
MSTableColumnGroup &MSTableColumnGroup::operator<<(MSTableColumnGroup &tableColumnGroup_) { if (isOkToAdd(tableColumnGroup_)==MSTrue) _nodeList<<Node(tableColumnGroup_); return *this; }
//--------------------------------------------------------------------------- Node Node::operator/ ( double d ) { return Node( x / d, y / d, z / d ); }
bool isBoxAbstr (Tree t) { return t->node() == Node(gGlobal->BOXABSTR); }
void eraseAllProperties(Tree t) { cerr << "begin eraseAllProperties" << endl; eraseProperties(tree(Node(unique("erase_"))), t); cerr << "end eraseAllProperties" << endl; }
bool isBoxIdent(Tree t) { return t->node() == Node(gGlobal->BOXIDENT); }
//---------------------------------------------------------------------------- Node* RoughPlaneSolidBox::CreateBox () { mBox = new0 Node(); float xExtent = (float)mModule.XLocExt; float yExtent = (float)mModule.YLocExt; float zExtent = (float)mModule.ZLocExt; VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); StandardMesh sm(vformat); VertexColor3Effect* effect = new0 VertexColor3Effect(); VertexBufferAccessor vba; Transform transform; TriMesh* face; int i; // +z face Float3 red(1.0f, 0.0f, 0.0f); transform.SetTranslate(APoint(0.0f, 0.0f, zExtent)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, xExtent, yExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = red; vba.Color<Float3>(0, 1) = red; vba.Color<Float3>(0, 2) = red; vba.Color<Float3>(0, 3) = red; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // -z face Float3 darkRed(0.5f, 0.0f, 0.0f); transform.SetTranslate(APoint(0.0f, 0.0f, -zExtent)); transform.SetRotate(HMatrix(AVector::UNIT_Y, AVector::UNIT_X, -AVector::UNIT_Z, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, yExtent, xExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = darkRed; vba.Color<Float3>(0, 1) = darkRed; vba.Color<Float3>(0, 2) = darkRed; vba.Color<Float3>(0, 3) = darkRed; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // +y face Float3 green(0.0f, 1.0f, 0.0f); transform.SetTranslate(APoint(0.0f, yExtent, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_Z, AVector::UNIT_X, AVector::UNIT_Y, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, zExtent, xExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = green; vba.Color<Float3>(0, 1) = green; vba.Color<Float3>(0, 2) = green; vba.Color<Float3>(0, 3) = green; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // -y face Float3 darkGreen(0.0f, 1.0f, 0.0f); transform.SetTranslate(APoint(0.0f, -yExtent, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_X, AVector::UNIT_Z, -AVector::UNIT_Y, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, xExtent, zExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = darkGreen; vba.Color<Float3>(0, 1) = darkGreen; vba.Color<Float3>(0, 2) = darkGreen; vba.Color<Float3>(0, 3) = darkGreen; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // +x face Float3 blue(0.0f, 0.0f, 1.0f); transform.SetTranslate(APoint(xExtent, 0.0f, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_Y, AVector::UNIT_Z, AVector::UNIT_X, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, yExtent, zExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = blue; vba.Color<Float3>(0, 1) = blue; vba.Color<Float3>(0, 2) = blue; vba.Color<Float3>(0, 3) = blue; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // -x face Float3 darkBlue(0.0f, 0.0f, 1.0f); transform.SetTranslate(APoint(-xExtent, 0.0f, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_Z, AVector::UNIT_Y, -AVector::UNIT_X, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, zExtent, yExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = darkBlue; vba.Color<Float3>(0, 1) = darkBlue; vba.Color<Float3>(0, 2) = darkBlue; vba.Color<Float3>(0, 3) = darkBlue; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); MoveBox(); return mBox; }