/* main function in embree namespace */ int main(int argc, char** argv) { /* for best performance set FTZ and DAZ flags in MXCSR control and status register */ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); /* initialize ray tracing core and force bvh4.triangle4v hierarchy for triangles */ rtcInit("tri_accel=bvh4.triangle4v"); /* set error handler */ rtcSetErrorFunction(error_handler); /* create scene */ g_scene = rtcNewScene(RTC_SCENE_STATIC,RTC_INTERSECT1); addCube(g_scene,Vec3fa(-1,0,0)); addCube(g_scene,Vec3fa(1,0,0)); addCube(g_scene,Vec3fa(0,0,-1)); addCube(g_scene,Vec3fa(0,0,1)); addHair(g_scene); addGroundPlane(g_scene); rtcCommit (g_scene); /* print triangle BVH */ print_bvh(g_scene); /* cleanup */ rtcDeleteScene (g_scene); rtcExit(); return 0; }
void CubeValidator::addScan(std::vector<Cube> cubes) { numOfScans++; for (std::vector<Cube>::iterator it = cubes.begin(); it != cubes.end(); it++) addCube(*it); cleanup(); }
/* called by the C++ code for initialization */ extern "C" void device_init (char* cfg) { /* create new Embree device */ g_device = rtcNewDevice(cfg); error_handler(nullptr,rtcDeviceGetError(g_device)); /* set error handler */ rtcDeviceSetErrorFunction2(g_device,error_handler,nullptr); /* create scene */ RTCAlgorithmFlags aflags; if (g_mode == MODE_NORMAL) aflags = RTC_INTERSECT1; else aflags = RTC_INTERSECT1 | RTC_INTERSECT_STREAM; g_scene = rtcDeviceNewScene(g_device, RTC_SCENE_STATIC | RTC_SCENE_HIGH_QUALITY,aflags); /* add cube */ addCube(g_scene,Vec3fa(0.0f,0.0f,0.0f),Vec3fa(10.0f,1.0f,1.0f),45.0f); //addSubdivCube(g_scene); /* add ground plane */ addGroundPlane(g_scene); /* commit changes to scene */ rtcCommit (g_scene); /* set start render mode */ if (g_mode == MODE_NORMAL) renderTile = renderTileStandard; else renderTile = renderTileStandardStream; key_pressed_handler = device_key_pressed_default; }
/* called by the C++ code for initialization */ extern "C" void device_init (int8* cfg) { /* initialize ray tracing core */ rtcInit(cfg); /* set error handler */ rtcSetErrorFunction(error_handler); /* create scene */ g_scene = rtcNewScene(RTC_SCENE_DYNAMIC | RTC_SCENE_ROBUST,RTC_INTERSECT1); /* add cube */ addCube(g_scene); /* add ground plane */ addGroundPlane(g_scene); /* commit changes to scene */ #if !defined(PARALLEL_COMMIT) rtcCommit (g_scene); #else launch[ getNumHWThreads() ] parallelCommit(g_scene); #endif /* set start render mode */ renderPixel = renderPixelStandard; }
/* called by the C++ code for initialization */ extern "C" void device_init (char* cfg) { /* create new Embree device */ g_device = rtcNewDevice(cfg); /* configure the size of the software cache used for subdivision geometry */ rtcDeviceSetParameter1i(g_device,RTC_SOFTWARE_CACHE_SIZE,100*1024*1024); /* set error handler */ rtcDeviceSetErrorFunction(g_device,error_handler); /* create scene */ g_scene = rtcDeviceNewScene(g_device,RTC_SCENE_DYNAMIC | RTC_SCENE_ROBUST,RTC_INTERSECT1 | RTC_INTERPOLATE); /* add ground plane */ addGroundPlane(g_scene); /* add cube */ addCube(g_scene); /* commit changes to scene */ rtcCommit (g_scene); /* set start render mode */ renderPixel = renderPixelStandard; key_pressed_handler = device_key_pressed_default; }
static void makeCubes(std::vector<cube> &cubes, MString &name, MStatus *stat) { MFnMesh fnMesh; MObject result; MFloatPointArray points; MIntArray faceCounts; MIntArray faceConnects; int index_offset = 0; for (std::vector<cube>::iterator cit = cubes.begin(); cit != cubes.end(); ++cit) { point3 diag = cit->diagonal(); float scale = diag.x; point3 pos = cit->start + (diag * .5f); MFloatVector mpos(pos.x, pos.y, pos.z); addCube(scale, mpos, index_offset * (8), points, faceCounts, faceConnects); index_offset += 1; } unsigned int vtx_cnt = points.length(); unsigned int face_cnt = faceCounts.length(); MObject newMesh = fnMesh.create( /* numVertices */ vtx_cnt, /* numFaces */ face_cnt, points, faceCounts, faceConnects, MObject::kNullObj, stat); /* Harden all edges. */ int n_edges = fnMesh.numEdges(stat); for (int i = 0; i < n_edges; ++i) { fnMesh.setEdgeSmoothing(i, false); } fnMesh.cleanupEdgeSmoothing(); /* Must be called after editing edges. */ fnMesh.updateSurface(); /* Assign Shader. */ MSelectionList sel_list; if (!MFAIL(sel_list.add("initialShadingGroup"))) { MObject set_obj; sel_list.getDependNode(0, set_obj); MFnSet set(set_obj); set.addMember(newMesh); } /* Give it a swanky name. */ MFnDagNode parent(fnMesh.parent(0)); name = parent.setName("polyMengerSponge", false, stat); }
/* Top */ addLine(pOcc, x, y + h, z + d, x, y, z + d, x, y, z + d - .1f); addLine(pOcc, x + w, y + h, z + d, x, y + h, z + d, x, y + h, z + d - .1f); addLine(pOcc, x + w, y, z + d, x + w, y + h, z + d, x + w, y + h, z + d - .1f); addLine(pOcc, x, y, z + d, x + w, y, z + d, x + w, y, z + d - .1f); addLine(pOcc, x, y, z + d, x, y + h, z + d, x + .1f, y, z + d); addLine(pOcc, x, y + h, z + d, x + w, y + h, z + d, x, y + h - .1f, z + d); addLine(pOcc, x + w, y + h, z + d, x + w, y, z + d, x + w - .1f, y + h, z + d); addLine(pOcc, x + w, y, z + d, x, y, z + d, x + w, y + .1f, z + d); } #if 0 /* No longer used */ void addCubeCentered(Occluder * pOcc, float x, float y, float z, float w, float h, float d) { x -= w / 2.0f; y -= h / 2.0f; z -= d / 2.0f; addCube(pOcc, x, y, z, w, h, d); }
/** * Draw a bounding box centered at (0,0,0) and translate and rotate it accordingly */ void visualization::DetectionVisualizer::visualizeBox(const detection::BoundingBox &box, const string id, const Vec3f &translation, const Eigen::Quaternionf &rotation) { removeShape(id); addCube(translation, rotation, box.getSize3D()[0], box.getSize3D()[1], box.getSize3D()[2], id); }
void Viewport::display() { processEvents(); // 处理鼠标、键盘事件等相关回调 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清空当前Viewport中的缓冲 glLoadIdentity(); // 重置为单位矩阵 // 初始化相机的基本属性 glRotatef(camera.rotation.x, 1, 0, 0); glRotatef(camera.rotation.y, 0, 1, 0); glRotatef(camera.rotation.z, 0, 0, 1); // 设置平移矩阵变换 glTranslatef(-camera.position.x, -camera.position.y, camera.position.z); // 绘制一个三角形 glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex3f(-1, 0, -3); glColor3f(0.0, 1.0, -3); glVertex3f(0, 2, -3); glColor3f(0.0, 0.0, 1.0); glVertex3f(1, 0, -3); glEnd(); addCube(); // 绘制一个立方体 // Resources::load(); glBindTexture(GL_TEXTURE_2D, Resources::tex->textureID); // 绑定材质 glBegin(GL_QUADS); glColor3f(1, 1, 1); glTexCoord2f(100, 100); glVertex3f(100, 0, 100); glTexCoord2f(100, -100); glVertex3f(-100, 0, 100); glTexCoord2f(-100, -100); glVertex3f(-100, 0, -100); glTexCoord2f(-100, 100); glVertex3f(100, 0, -100); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); // 结束绑定 glutSwapBuffers(); // 双缓冲显示模式 }
void NGLScene::keyPressEvent(QKeyEvent *_event) { // this method is called every time the main window recives a key event. // we then switch on the key value and set the camera in the NGLScene switch (_event->key()) { // escape key to quite case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break; // turn on wirframe rendering case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; // turn off wire frame case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; // show full screen case Qt::Key_F : showFullScreen(); break; // show windowed case Qt::Key_N : showNormal(); break; case Qt::Key_Space : m_car->reset(); break; case Qt::Key_X : stepAnimation(); break; case Qt::Key_1 : addCube(); break; case Qt::Key_2 : addSphere(); break; case Qt::Key_3 : addCapsule(); break; case Qt::Key_4 : addCylinder(); break; case Qt::Key_5 : addCone(); break; case Qt::Key_6 : addMesh(TEAPOT); break; case Qt::Key_7 : addMesh(APPLE); break; /* case Qt::Key_Left : m_physics->addImpulse(ngl::Vec3(-5,0.0f,0.0f)); break; case Qt::Key_Right : m_physics->addImpulse(ngl::Vec3(5.0f,0.0f,0.0f)); break; case Qt::Key_Up : m_physics->addImpulse(ngl::Vec3(0.0f,5.0f,0.0f)); break; case Qt::Key_Down : m_physics->addImpulse(ngl::Vec3(0.0f,-5.0f,0.0f)); break; */ case Qt::Key_Left : m_car->left(); break; case Qt::Key_Right : m_car->right(); break; case Qt::Key_Up : m_car->accelerate(); break; case Qt::Key_Down : m_car->stop(); break; case Qt::Key_B : toggleBBox(); break; case Qt::Key_R : toggleRandomPlace(); break; case Qt::Key_0 : resetSim(); break; default : break; } // finally update the GLWindow and re-draw //if (isExposed()) renderNow(); }
/* called by the C++ code for initialization */ extern "C" void device_init (char* cfg) { /* create scene */ g_scene = rtcNewScene(g_device); rtcSetSceneFlags(g_scene,RTC_SCENE_FLAG_ROBUST); /* add ground plane */ addGroundPlane(g_scene); /* add cube */ addCube(g_scene); /* commit changes to scene */ rtcCommitScene (g_scene); /* set start render mode */ renderTile = renderTileStandard; key_pressed_handler = device_key_pressed_default; }
/* called by the C++ code for initialization */ extern "C" void device_init (int8* cfg) { /* initialize ray tracing core */ rtcInit(cfg); /* create scene */ g_scene = rtcNewScene(RTC_SCENE_STATIC,RTC_INTERSECT1); /* add cube */ addCube(g_scene); /* add ground plane */ addGroundPlane(g_scene); /* commit changes to scene */ rtcCommit (g_scene); /* set start render mode */ renderPixel = renderPixelStandard; }
/* called by the C++ code for initialization */ extern "C" void device_init (int8* cfg) { /* initialize ray tracing core */ rtcInit(cfg); /* set error handler */ rtcSetErrorFunction(error_handler); /* create scene */ g_scene = rtcNewScene(RTC_SCENE_DYNAMIC | RTC_SCENE_ROBUST,RTC_INTERSECT1); /* add cube */ addCube(g_scene); /* add ground plane */ addGroundPlane(g_scene); /* set start render mode */ renderPixel = renderPixelStandard; }
Renderer::Renderer(CubemapSource* cubemapSource) : al::OmniApp("AlloPlayer", false, 2048), resizeCtx(nullptr), cubemapSource(cubemapSource), cubemap(nullptr), newCubemap(false) { nav().smooth(0.8); // set up cube cube.color(1,1,1,1); cube.primitive(al::Graphics::TRIANGLES); addCube(cube); for (int i = 0; i < cube.vertices().size(); ++i) { float f = (float)i / cube.vertices().size(); cube.color(al::Color(al::HSV(f, 1 - f, 1), 1)); } cube.generateNormals(); // set up sphere sphere.primitive(al::Graphics::TRIANGLES); addSphere(sphere, 1.0, 32, 32); for (int i = 0; i < sphere.vertices().size(); ++i) { float f = (float)i / sphere.vertices().size(); sphere.color(al::Color(al::HSV(f, 1 - f, 1), 1)); } sphere.generateNormals(); // set up light light.ambient(al::Color(0.4, 0.4, 0.4, 1.0)); light.pos(5, 5, 5); std::function<void (CubemapSource*, StereoCubemap*)> callback = boost::bind(&Renderer::onNextCubemap, this, _1, _2); cubemapSource->setOnNextCubemap(callback); }
void Chunk::build() { Batch batch; batch.start(); for (uint8_t x = 0; x < 16 ; x++) { for (uint8_t y = 0; y < 16; y++) { for (uint8_t z = 0; z < 16; z++) { if (getBlockId(x, y, z) == 0) continue; if (getBlockId(x + 1, y, z) != 0 && getBlockId(x, y + 1, z) != 0 && getBlockId(x, y, z + 1) != 0 && getBlockId(x - 1, y, z) != 0 && getBlockId(x, y - 1, z) != 0 && getBlockId(x, y, z - 1) != 0) continue; addCube(batch, x, y, z); } } } mesh_.generateMesh(batch); }
Cube *Molecule::addCube() { Q_D(const Molecule); return addCube(d->cubes.size()); }
void InstancedSponge::makeSponge( unsigned recursion, const vector<float> & position, float size) { if (recursion == 0) { addCube(position, size); } else { recursion-=1; size/=3.0f; float trans = size*2; // TOP makeSponge(recursion, {position[0], position[1]+trans, position[2]+trans}, size); makeSponge(recursion, {position[0]-trans, position[1]+trans, position[2]}, size); makeSponge(recursion, {position[0], position[1]+trans, position[2]-trans}, size); makeSponge(recursion, {position[0]+trans, position[1]+trans, position[2]}, size); makeSponge(recursion, {position[0]+trans, position[1]+trans, position[2]+trans}, size); makeSponge(recursion, {position[0]+trans, position[1]+trans, position[2]-trans}, size); makeSponge(recursion, {position[0]-trans, position[1]+trans, position[2]+trans}, size); makeSponge(recursion, {position[0]-trans, position[1]+trans, position[2]-trans}, size); // MIDDLE makeSponge(recursion, {position[0]+trans, position[1], position[2]+trans}, size); makeSponge(recursion, {position[0]+trans, position[1], position[2]-trans}, size); makeSponge(recursion, {position[0]-trans, position[1], position[2]+trans}, size); makeSponge(recursion, {position[0]-trans, position[1], position[2]-trans}, size); // BOTTOM makeSponge(recursion, {position[0], position[1]-trans, position[2]+trans}, size); makeSponge(recursion, {position[0], position[1]-trans, position[2]-trans}, size); makeSponge(recursion, {position[0]+trans, position[1]-trans, position[2]}, size); makeSponge(recursion, {position[0]-trans, position[1]-trans, position[2]}, size); makeSponge(recursion, {position[0]+trans, position[1]-trans, position[2]+trans}, size); makeSponge(recursion, {position[0]+trans, position[1]-trans, position[2]-trans}, size); makeSponge(recursion, {position[0]-trans, position[1]-trans, position[2]+trans}, size); makeSponge(recursion, {position[0]-trans, position[1]-trans, position[2]-trans}, size); } }
void GeometryTerrain::addLight(glm::vec3& position_) { sm_singleton->lightPosition = glm::vec4(position_, 1); addCube(position_, 1); }