double ComputeCylinderRadius (const Point3d & p1, const Point3d & p2, const Point3d & p3, const Point3d & p4) { Vec3d v12(p1, p2); Vec3d v13(p1, p3); Vec3d v14(p1, p4); Vec3d n1 = Cross (v12, v13); Vec3d n2 = Cross (v14, v12); double n1l = n1.Length(); double n2l = n2.Length(); n1 /= n1l; n2 /= n2l; double v12len = v12.Length(); double h1 = n1l / v12len; double h2 = n2l / v12len; /* (*testout) << "n1 = " << n1 << " n2 = " << n2 << "h1 = " << h1 << " h2 = " << h2 << endl; */ return ComputeCylinderRadius (n1, n2, h1, h2); }
bool Line::Shortest(const Line& l2, Line& lshort, double& t1, double& t2)const { /* Calculate the line segment PaPb that is the shortest route between two lines P1P2 and P3P4. Calculate also the values of mua and mub where Pa = P1 + t1 (P2 - P1) Pb = P3 + t2 (P4 - P3) Return FALSE if no solution exists. P Bourke method. Input this 1st line Input l2 2nd line Output lshort shortest line between lines (if lshort.ok == false, the line intersect at a point lshort.p0) Output t1 parameter at intersection on 1st Line Output t2 parameter at intersection on 2nd Line */ Vector3d v13(l2.p0, this->p0); if(this->ok == false || l2.ok == false) return false; double d1343 = v13 * l2.v; // dot products double d4321 = l2.v * this->v; double d1321 = v13 * this->v; double d4343 = l2.v * l2.v; double d2121 = this->v * this->v; double denom = d2121 * d4343 - d4321 * d4321; if(fabs(denom) < 1.0e-09) return false; double numer = d1343 * d4321 - d1321 * d4343; t1 = numer / denom; t2 = (d1343 + d4321 * t1) / d4343; lshort = Line(t1* this->v + this->p0, t2 * l2.v + l2.p0); t1 *= this->length; t2 *= l2.length; // parameter in line length for tolerance checking return true; }
void DragRect::TrackPoint3(const DPoint& pt3) { // pt1 fixed, v01 direction locked DPoint pt1 = v01_.add(pt0_); Vec2d v13(pt1, pt3); v01_ = v01_.unit().scale(-v01_.project(v13)); pt0_ = v01_.flip180().add(pt1); v02_ = Vec2d(pt0_, v01_.add(pt3)); }
void DragRect::TrackPoints13(const DPoint& pt1, const DPoint& pt3) { // width variable, height variable, theta constant double fdy = v02_.project(v01_) / v02_.mag(); double fdx = Vec2d(v02_.unit().scale(v02_.mag() * fdy).add(pt0_), v01_.add(pt0_)).mag() / v02_.mag(); Vec2d v13(pt1, pt3); DPoint ptT = v13.unit().scale(v13.mag() * fdy).add(pt1); DPoint pt0 = v13.flip90().unit().scale(v13.mag() * fdx).add(ptT); pt0_ = pt0; v01_ = Vec2d(pt0, pt1); v02_ = Vec2d(pt0, v01_.add(pt3)); }
Real Pyramid5::volume () const { // The pyramid with a bilinear base has volume given by the // formula in: "Calculation of the Volume of a General Hexahedron // for Flow Predictions", AIAA Journal v.23, no.6, 1984, p.954- Node * node0 = this->get_node(0); Node * node1 = this->get_node(1); Node * node2 = this->get_node(2); Node * node3 = this->get_node(3); Node * node4 = this->get_node(4); // Construct Various edge and diagonal vectors Point v40 ( *node0 - *node4 ); Point v13 ( *node3 - *node1 ); Point v02 ( *node2 - *node0 ); Point v03 ( *node3 - *node0 ); Point v01 ( *node1 - *node0 ); // Finally, ready to return the volume! return (1./6.)*(v40*(v13.cross(v02))) + (1./12.)*(v02*(v01.cross(v03))); }
void Scene::init(){ primitives = new Primitive*[25]; nrOfPrimitives = 0; //wall at0,0,1 Vec3 v121( 0,0, 1 ); primitives[nrOfPrimitives] = new PlanePrim( v121, -13.0f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f); Color c121( 1,1,1 ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c121); //wall at 0 0 -1 Vec3 v12( 0,0, -1 ); primitives[nrOfPrimitives] = new PlanePrim( v12, 13.0f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f); Color c12( 0.3f,0.3f,0.7f ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c12); //- //the ground Vec3 v1( 0,1, 0 ); primitives[nrOfPrimitives] = new CheckerBoard( v1, 3.4f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.7f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(0.0f); Color c1( 0.3f, 0.3f, 0.7f ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c1); // // 0 -1 0 Vec3 v13( 0,-1, 0 ); primitives[nrOfPrimitives] = new PlanePrim( v13, -3.4f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse()); Color c13( 1,1,1 ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c13); // //middle sphere Vec3 v2( 0, 1, 8 ); primitives[nrOfPrimitives] = new Sphere( v2, 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.2 ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse()); Color c2( 1,1,1); primitives[nrOfPrimitives++]->getMaterial()->setColor( c2 ); //- //left sphere Vec3 v3( -5.5f, -0.5, 7 ); Color c3( 0.7f, 0.7f, 0 ); primitives[nrOfPrimitives] = new Sphere( v3, 2 ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.6f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.9f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse()); primitives[nrOfPrimitives++]->getMaterial()->setColor( c3 ); //- //right sphere Vec3 v31( 5.5f, -0.5, 7 ); Color c31( 0.7f, 0.0f, 0 ); primitives[nrOfPrimitives] = new Sphere( v31, 2 ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.6f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.9f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f); primitives[nrOfPrimitives++]->getMaterial()->setColor( c31 ); //- //a light Vec3 v4( 3, 2.5f, 3 ); Color c4(0.7f,0.7f,0.7f); primitives[nrOfPrimitives] = new Sphere( v4, 0.5f ); primitives[nrOfPrimitives]->isLight = true; primitives[nrOfPrimitives++]->getMaterial()->setColor( c4 ); //-- //another light Vec3 v5( 0, 5, 10 ); Color c5( 0.6f, 0.6f, 0.8f ); primitives[nrOfPrimitives] = new Sphere( v5, 0.5f ); primitives[nrOfPrimitives]->isLight = true; primitives[nrOfPrimitives++]->getMaterial()->setColor( c5 ); //-- }
void Hud::Draw (Zeni::Time::Second_Type elapsedTime) { HeroComponent & hero = HeroComponent::GetInstance(); double heroHealth = hero.GetHealth(); double heroShields = hero.GetShields(); double healthWidth = 200.0f; double healthHeight = 30.0f; Zeni::Point2f bgPosition1 (590.0f, 40.0f); Zeni::Point2f bgPosition2 (bgPosition1.x, bgPosition1.y + healthHeight); Zeni::Point2f bgPosition3 (bgPosition1.x + healthWidth, bgPosition1.y + healthHeight); Zeni::Point2f bgPosition4 (bgPosition1.x + healthWidth, bgPosition1.y); Zeni::Point2f healthPosition1 = bgPosition1; Zeni::Point2f healthPosition2 = bgPosition2; Zeni::Point2f healthPosition3 (bgPosition1.x + healthWidth * heroHealth / 1000.0f, bgPosition1.y + healthHeight); Zeni::Point2f healthPosition4 (bgPosition1.x + healthWidth * heroHealth / 1000.0f, bgPosition1.y); Zeni::Point2f shieldPosition1 = bgPosition1; Zeni::Point2f shieldPosition2 = bgPosition2; Zeni::Point2f shieldPosition3 (bgPosition1.x + healthWidth * heroShields / 100.0f, bgPosition1.y + healthHeight); Zeni::Point2f shieldPosition4 (bgPosition1.x + healthWidth * heroShields / 100.0f, bgPosition1.y); int score = hero.GetScore(); std::stringstream ss4; ss4 << score; Zeni::get_Fonts()["score"].render_text (ss4.str(), Zeni::Point2f (20.0f, 550.0f), Zeni::get_Colors()["score"]); ++frameCount; std::stringstream ss ("FPS: "); ss << fps; //Zeni::get_Fonts()["fps"].render_text (ss.str(), Zeni::Point2f(), Zeni::get_Colors()["fps"]); const std::vector<ProjectileFactory*>& heroWeapons = hero.GetWeapons(); size_t numWeapons = heroWeapons.size(); int selectedWeapon = hero.GetSelectedWeaponIndex(); double corner = 800.0f - 30.0f * numWeapons; Zeni::Color enabled = Zeni::get_Colors()["weapon_enabled"]; Zeni::Color disabled = Zeni::get_Colors()["weapon_disabled"]; for (int i = 0; i < numWeapons; ++i) { Zeni::Vertex2f_Texture vertex1 (Zeni::Point2f(corner + 30.0f * i, 0.0f), Zeni::Point2f(0.0f, 0.0f)); Zeni::Vertex2f_Texture vertex2 (Zeni::Point2f(corner + 30.0f * i, 30.0f), Zeni::Point2f(0.0f, 1.0f)); Zeni::Vertex2f_Texture vertex3 (Zeni::Point2f(corner + 30.0f * (i + 1), 30.0f), Zeni::Point2f(1.0f, 1.0f)); Zeni::Vertex2f_Texture vertex4 (Zeni::Point2f(corner + 30.0f * (i + 1), 0.0f), Zeni::Point2f(1.0f, 0.0f)); Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q (vertex1, vertex2, vertex3, vertex4); Zeni::Material backing(i == selectedWeapon ? "selected_weapon" : "weapon"); q.lend_Material (&backing); Zeni::get_Video().render (q); double r = selectedWeapon == i ? weaponRotation : 0.0f; Zeni::render_image ( heroWeapons[i]->GetTexture(), Zeni::Point2f(corner + 30 * i + 5.0f, 5.0f), Zeni::Point2f(corner + 30 * (i + 1.0f) - 5.0f, 25.0), r, 1.0f, Zeni::Point2f(corner + 30 * i + 15.0f, 15.0f), false, heroWeapons[i]->IsReady() ? enabled : disabled); } int heroAmmo = heroWeapons[selectedWeapon]->GetAmmo(); std::stringstream ss3; ss3 << heroAmmo; Zeni::get_Fonts()["ammo"].render_text (ss3.str(), Zeni::Point2f(corner - 5.0f, 0.0f), Zeni::get_Colors()["ammo"], Zeni::ZENI_RIGHT); Zeni::Vertex2f_Texture v9 (bgPosition1, Zeni::Point2f (0.0f, 0.0f)); Zeni::Vertex2f_Texture v10 (bgPosition2, Zeni::Point2f (0.0f, 1.0f)); Zeni::Vertex2f_Texture v11 (bgPosition3, Zeni::Point2f (1.0f, 1.0f)); Zeni::Vertex2f_Texture v12 (bgPosition4, Zeni::Point2f (1.0f, 0.0f)); Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q3 (v9, v10, v11, v12); Zeni::Material healthbar1("healthbar1"); q3.lend_Material (&healthbar1); Zeni::get_Video().render (q3); Zeni::Vertex2f_Texture v13 (healthPosition1, Zeni::Point2f (0.0f, 0.0f)); Zeni::Vertex2f_Texture v14 (healthPosition2, Zeni::Point2f (0.0f, 1.0f)); Zeni::Vertex2f_Texture v15 (healthPosition3, Zeni::Point2f (heroHealth / 1000.0f, 1.0f)); Zeni::Vertex2f_Texture v16 (healthPosition4, Zeni::Point2f (heroHealth / 1000.0f, 0.0f)); Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q4 (v13, v14, v15, v16); Zeni::Material healthbar2("healthbar2"); q4.lend_Material (&healthbar2); Zeni::get_Video().render (q4); Zeni::Vertex2f_Texture v17 (shieldPosition1, Zeni::Point2f (0.0f, 0.0f)); Zeni::Vertex2f_Texture v18 (shieldPosition2, Zeni::Point2f (0.0f, 1.0f)); Zeni::Vertex2f_Texture v19 (shieldPosition3, Zeni::Point2f (heroShields / 100.0f, 1.0f)); Zeni::Vertex2f_Texture v20 (shieldPosition4, Zeni::Point2f (heroShields / 100.0f, 0.0f)); Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q5 (v17, v18, v19, v20); Zeni::Material healthbar3("healthbar3"); q5.lend_Material (&healthbar3); Zeni::get_Video().render (q5); double timeRemaining = GameTimer::GetInstance().GetRemainingTime(); Zeni::Color timerTextColor = timeRemaining < 10.0f ? Zeni::get_Colors()["low_time"] : Zeni::get_Colors()["time"]; Zeni::render_image ( "Timer", Zeni::Point2f (620.0f, 540.0f), Zeni::Point2f (670.0f, 590.0f), false, timerTextColor); std::stringstream ss2; int minutes = (int)timeRemaining / 60; ss2 << minutes << ":" << std::fixed << std::setprecision(2) << timeRemaining - minutes * 60; Zeni::get_Fonts()["time"].render_text (ss2.str(), Zeni::Point2f(680.0f, 550.0f), timerTextColor); }
osg::Drawable *ReverseTileNode::createReverseTile(void) const { // Get the tile ReverseTile* tile = static_cast<ReverseTile*>(_lego); // Get tile color QColor color = tile->getColor(); // Get integer sizes int width = tile->getWidth(); int length = tile->getLength(); int height = 3; // Get real position, according to tile size double mw = (-width)*Lego::length_unit/2; double pw = (width)*Lego::length_unit/2; double mwp = (-width+2)*Lego::length_unit/2; double ml = (-length)*Lego::length_unit/2; double pl = (length)*Lego::length_unit/2; double mh = (-height)*Lego::height_unit/2; double ph = (height)*Lego::height_unit/2; double phm = (height-1)*Lego::height_unit/2; // Create 14 vertices osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; osg::Vec3 v0(mw, ml, mh); osg::Vec3 v1(mw, pl, mh); osg::Vec3 v2(mwp, pl, mh); osg::Vec3 v3(mwp, ml, mh); osg::Vec3 v4(pw, ml, phm); osg::Vec3 v5(pw, pl, phm); osg::Vec3 v6(pw, pl, ph); osg::Vec3 v7(pw, ml, ph); osg::Vec3 v8(mw, ml, ph); osg::Vec3 v9(mw, pl, ph); osg::Vec3 v10(mwp, ml, phm); osg::Vec3 v11(mwp, ml, ph); osg::Vec3 v12(mwp, pl, ph); osg::Vec3 v13(mwp, pl, phm); // Create 10 faces, 8 faces are quads splitted into two triangles // NB: Down face is transparent, we don't even create it // Front face t1 vertices->push_back(v4); vertices->push_back(v5); vertices->push_back(v6); // Front face t2 vertices->push_back(v4); vertices->push_back(v6); vertices->push_back(v7); // Back face t1 vertices->push_back(v0); vertices->push_back(v1); vertices->push_back(v8); // Back face t2 vertices->push_back(v1); vertices->push_back(v8); vertices->push_back(v9); // Top face t1 vertices->push_back(v6); vertices->push_back(v7); vertices->push_back(v9); // Top face t2 vertices->push_back(v7); vertices->push_back(v8); vertices->push_back(v9); // Slop face t1 vertices->push_back(v2); vertices->push_back(v3); vertices->push_back(v5); // Slop face t2 vertices->push_back(v3); vertices->push_back(v4); vertices->push_back(v5); // Right triangle face vertices->push_back(v2); vertices->push_back(v13); vertices->push_back(v5); // Right quad face t1 vertices->push_back(v13); vertices->push_back(v12); vertices->push_back(v6); // Right quad face t2 vertices->push_back(v13); vertices->push_back(v6); vertices->push_back(v5); // Right quad face down t1 vertices->push_back(v1); vertices->push_back(v9); vertices->push_back(v12); // Right quad face down t2 vertices->push_back(v1); vertices->push_back(v2); vertices->push_back(v12); // Left triangle face vertices->push_back(v3); vertices->push_back(v4); vertices->push_back(v10); // Left quad face t1 vertices->push_back(v4); vertices->push_back(v10); vertices->push_back(v11); // Left quad face t2 vertices->push_back(v4); vertices->push_back(v7); vertices->push_back(v11); // Left quad face down t1 vertices->push_back(v0); vertices->push_back(v3); vertices->push_back(v8); // Left quad face down t2 vertices->push_back(v3); vertices->push_back(v8); vertices->push_back(v11); // Create tile geometry osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry; // Match vertices tileGeometry->setVertexArray(vertices); // Add color (each rectangle has the same color except for the down one which is transparent) osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; // Every face has the same color, so there is only one color colors->push_back(osgColor); // Match color tileGeometry->setColorArray(colors); tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); // Create normals osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array; normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(0, 0, 1)); normals->push_back(osg::Vec3(0, 0, 1)); double w = pw - mwp; double h = phm - mh; double norm = std::sqrt(w*w + h*h); normals->push_back(osg::Vec3(h/norm, 0, -w/norm)); normals->push_back(osg::Vec3(h/norm, 0, -w/norm)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); // Match normals tileGeometry->setNormalArray(normals); tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); // Define tile 18 GL_TRIANGLES with 20*3 vertices tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3)); // Return the tile whithout plot return tileGeometry.release(); }
osg::Drawable *ClampNode::createBrick(void) const { // Get the brick Clamp* clamp = static_cast<Clamp*>(_lego); // Get brick color QColor color = clamp->getColor(); // Get clamp bounding box clamp->calculateBoundingBox(); BoundingBox bb = clamp->getBoundingBox(); // Get integer sizes int width = bb.getWidth(); int length = bb.getLength(); int height = bb.getHeight(); // Get real position, according to tile size double mw = (-width)*Lego::length_unit/2; double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2; double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit; double pw = (width)*Lego::length_unit/2; double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2; double ml = (-length)*Lego::length_unit/2; double mlp = (-length+0.5)*Lego::length_unit/2; double pl = (length)*Lego::length_unit/2; double plm = (length-0.5)*Lego::length_unit/2; double mh = (-height)*Lego::height_unit/2; double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height; double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height; double phm = (height)*Lego::height_unit/2-Lego::height_unit/2; double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2; // Create 3 vertices osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; osg::Vec3 v0(ml, mw, mh); osg::Vec3 v1(pl, mw, mh); osg::Vec3 v2(pl, pw, mh); osg::Vec3 v3(ml, pw, mh); osg::Vec3 v4(ml, pw, mhp); osg::Vec3 v5(pl, pw, mhp); osg::Vec3 v6(pl, mw, mhp); osg::Vec3 v7(ml, mw, mhp); osg::Vec3 v8(mlp, mw, mhp); osg::Vec3 v9(mlp, mw, phm); osg::Vec3 v10(ml, mw, phm); osg::Vec3 v11(ml, mwp, phmp); osg::Vec3 v12(mlp, mwp, phmp); osg::Vec3 v13(mlp, pw, mhp); osg::Vec3 v14(plm, mw, mhp); osg::Vec3 v15(plm, mw, phm); osg::Vec3 v16(pl, mw, phm); osg::Vec3 v17(pl, mwp, phmp); osg::Vec3 v18(plm, mwp, phmp); osg::Vec3 v19(plm, pw, mhp); osg::Vec3 v20(mlp, mwpm, mh); osg::Vec3 v21(plm, mwpm, mh); osg::Vec3 v22(plm, pwm, mh); osg::Vec3 v23(mlp, pwm, mh); osg::Vec3 v24(mlp, mwpm, mhpm); osg::Vec3 v25(plm, mwpm, mhpm); osg::Vec3 v26(plm, pwm, mhpm); osg::Vec3 v27(mlp, pwm, mhpm); // Create 1 faces, 0 faces are quads splitted into two triangles // NB: Down face is transparent, we don't even create it // Bottom vertices->push_back(v3); vertices->push_back(v2); vertices->push_back(v1); vertices->push_back(v0); // Bottom hole vertices->push_back(v20); vertices->push_back(v21); vertices->push_back(v22); vertices->push_back(v23); // Bottom far vertices->push_back(v24); vertices->push_back(v25); vertices->push_back(v26); vertices->push_back(v27); // Front face vertices->push_back(v2); vertices->push_back(v3); vertices->push_back(v4); vertices->push_back(v5); // Back face vertices->push_back(v0); vertices->push_back(v1); vertices->push_back(v6); vertices->push_back(v7); // Left bottom face vertices->push_back(v0); vertices->push_back(v3); vertices->push_back(v4); vertices->push_back(v7); // Right bottom face vertices->push_back(v1); vertices->push_back(v2); vertices->push_back(v5); vertices->push_back(v6); // Top face vertices->push_back(v4); vertices->push_back(v5); vertices->push_back(v6); vertices->push_back(v7); // Left part back vertices->push_back(v7); vertices->push_back(v8); vertices->push_back(v9); vertices->push_back(v10); // Left part left ext vertices->push_back(v4); vertices->push_back(v7); vertices->push_back(v10); vertices->push_back(v11); // Left part front vertices->push_back(v4); vertices->push_back(v11); vertices->push_back(v12); vertices->push_back(v13); // Left part left int vertices->push_back(v8); vertices->push_back(v9); vertices->push_back(v12); vertices->push_back(v13); // Right part back vertices->push_back(v6); vertices->push_back(v14); vertices->push_back(v15); vertices->push_back(v16); // Left part left ext vertices->push_back(v5); vertices->push_back(v6); vertices->push_back(v16); vertices->push_back(v17); // Left part front vertices->push_back(v5); vertices->push_back(v17); vertices->push_back(v18); vertices->push_back(v19); // Left part left int vertices->push_back(v14); vertices->push_back(v15); vertices->push_back(v18); vertices->push_back(v19); // Bottom front vertices->push_back(v20); vertices->push_back(v21); vertices->push_back(v25); vertices->push_back(v24); // Bottom right vertices->push_back(v21); vertices->push_back(v22); vertices->push_back(v26); vertices->push_back(v25); // Bottom back vertices->push_back(v22); vertices->push_back(v23); vertices->push_back(v27); vertices->push_back(v26); // Bottom left vertices->push_back(v23); vertices->push_back(v20); vertices->push_back(v24); vertices->push_back(v27); // Create tile geometry osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry; // Match vertices clampGeometry->setVertexArray(vertices); // Create colors osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; // Every face has the same color, so there is only one color colors->push_back(osgColor); // Match color clampGeometry->setColorArray(colors); clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); // Create normals osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0, 0, -1)); normals->push_back(osg::Vec3(0, 0, -1)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(0, 0, 1)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); double w = pw - mwp; double h = phmp - mhp; double norm = std::sqrt(w*w + h*h); normals->push_back(osg::Vec3(0, h/norm, w/norm)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(1, 0, 0)); normals->push_back(osg::Vec3(0, h/norm, w/norm)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(0, 1, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(0, -1, 0)); normals->push_back(osg::Vec3(1, 0, 0)); // Match normals clampGeometry->setNormalArray(normals); clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4)); // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4)); // Retesslate to create hole osgUtil::Tessellator tesslator; tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD); tesslator.retessellatePolygons(*clampGeometry); // Create 17 GL_QUADS, i.e. 18*4 vertices clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4)); // Return the tile whithout plot return clampGeometry.release(); }