void drawFrustum(RenderingContext & rc, const Geometry::Frustum & frustum, const Util::Color4f & color, float lineWidth) { static Util::Reference<Mesh> mesh; if (mesh.isNull()) { VertexDescription vertexDescription; vertexDescription.appendPosition3D(); mesh = new Mesh(vertexDescription, 8, 16); mesh->setDrawMode(Mesh::DRAW_LINE_STRIP); MeshIndexData & id = mesh->openIndexData(); uint32_t * indices = id.data(); indices[0] = 0; indices[1] = 2; indices[2] = 3; indices[3] = 1; indices[4] = 5; indices[5] = 7; indices[6] = 6; indices[7] = 4; indices[8] = 0; indices[9] = 1; indices[10] = 3; indices[11] = 7; indices[12] = 5; indices[13] = 4; indices[14] = 6; indices[15] = 2; id.updateIndexRange(); } MeshVertexData & vd = mesh->openVertexData(); float * vertices = reinterpret_cast<float *>(vd.data()); for (uint_fast8_t c = 0; c < 8; ++c) { const Geometry::Vec3 & corner = frustum[static_cast<Geometry::corner_t> (c)]; *vertices++ = corner.getX(); *vertices++ = corner.getY(); *vertices++ = corner.getZ(); } vd.updateBoundingBox(); vd.markAsChanged(); rc.pushAndSetLine(lineWidth); rc.pushAndSetLighting(LightingParameters(false)); rc.pushAndSetColorMaterial(color); rc.displayMesh(mesh.get()); rc.popMaterial(); rc.popLighting(); rc.popLine(); }
void Demo::onGraphics(RenderDevice* rd) { debugAssert(GLCaps::supports_two_sided_stencil()); app->renderDevice->setProjectionAndCameraMatrix(app->debugCamera); // Can now render from the texture // Cyan background app->renderDevice->setColorClearValue(Color3(.1f, .5f, 1)); app->renderDevice->clear(); if (app->sky.notNull()) { app->sky->render(rd, LightingParameters(G3D::toSeconds(10,00,00, AM))); } rd->pushState(); rd->enableLighting(); //Configure ambient light rd->setAmbientLightColor(Color3::white() * .25); for (int m = 0; m < models.size(); ++m) { models[m]->render(rd); } GLight light = GLight::directional(Vector3(0,1,0), Color3::white() * 0.5); rd->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE); rd->setStencilTest(RenderDevice::STENCIL_EQUAL); rd->setStencilConstant(0); rd->setAmbientLightColor(Color3::black()); rd->setDepthTest(RenderDevice::DEPTH_LEQUAL); rd->setLight(0, light); for (int m = 0; m < models.size(); ++m) { models[m]->render(rd); } rd->popState(); GApplet::onGraphics(rd); }
void drawCamera(RenderingContext & rc, const Util::Color4f & color) { static Util::Reference<Mesh> mesh; if (mesh.isNull()) { std::deque<Mesh *> meshes; std::deque<Geometry::Matrix4x4f> transformations; { VertexDescription vertexDescription; vertexDescription.appendPosition3D(); vertexDescription.appendNormalFloat(); Geometry::Box box(Geometry::Vec3f(0.0f, 0.0f, 0.1f), 0.2f, 0.5f, 0.8f); meshes.push_back(MeshUtils::MeshBuilder::createBox(vertexDescription, box)); transformations.push_back(Geometry::Matrix4x4()); } { // Lens meshes.push_back(MeshUtils::MeshBuilder::createConicalFrustum(0.1f, 0.25f, 0.2f, 16)); Geometry::Matrix4x4f mat; mat.translate(0.0f, 0.0f, -0.3f); mat.rotate_deg(90.0f, 0.0f, 1.0f, 0.0f); transformations.push_back(mat); } { // Lens cap meshes.push_back(MeshUtils::MeshBuilder::createDiscSector(0.25f, 16)); Geometry::Matrix4x4f mat; mat.translate(0.0f, 0.0f, -0.5f); mat.rotate_deg(-90.0f, 0.0f, 1.0f, 0.0f); transformations.push_back(mat); } { // First film reel meshes.push_back(MeshUtils::MeshBuilder::createConicalFrustum(0.2f, 0.2f, 0.1f, 16)); Geometry::Matrix4x4f mat; mat.translate(-0.05f, 0.45f, -0.1f); transformations.push_back(mat); } { meshes.push_back(MeshUtils::MeshBuilder::createDiscSector(0.2f, 16)); Geometry::Matrix4x4f mat; mat.translate(-0.05f, 0.45f, -0.1f); transformations.push_back(mat); } { meshes.push_back(MeshUtils::MeshBuilder::createDiscSector(0.2f, 16)); Geometry::Matrix4x4f mat; mat.translate(0.05f, 0.45f, -0.1f); mat.rotate_deg(180.0f, 0.0f, 1.0f, 0.0f); transformations.push_back(mat); } { // Second film reel meshes.push_back(MeshUtils::MeshBuilder::createConicalFrustum(0.2f, 0.2f, 0.1f, 16)); Geometry::Matrix4x4f mat; mat.translate(-0.05f, 0.45f, 0.3f); transformations.push_back(mat); } { meshes.push_back(MeshUtils::MeshBuilder::createDiscSector(0.2f, 16)); Geometry::Matrix4x4f mat; mat.translate(-0.05f, 0.45f, 0.3f); transformations.push_back(mat); } { meshes.push_back(MeshUtils::MeshBuilder::createDiscSector(0.2f, 16)); Geometry::Matrix4x4f mat; mat.translate(0.05f, 0.45f, 0.3f); mat.rotate_deg(180.0f, 0.0f, 1.0f, 0.0f); transformations.push_back(mat); } mesh = MeshUtils::combineMeshes(meshes, transformations); } rc.pushAndSetLighting(LightingParameters(false)); rc.pushAndSetColorMaterial(Util::Color4f(color)); rc.displayMesh(mesh.get()); rc.popMaterial(); rc.popLighting(); }