std::pair<Real, Real> Tri3::min_and_max_angle() const { Point v10 ( this->point(1) - this->point(0) ); Point v20 ( this->point(2) - this->point(0) ); Point v21 ( this->point(2) - this->point(1) ); const Real len_10=v10.size(), len_20=v20.size(), len_21=v21.size() ; const Real theta0=std::acos(( v10*v20)/len_10/len_20), theta1=std::acos((-v10*v21)/len_10/len_21), theta2=libMesh::pi - theta0 - theta1 ; libmesh_assert_greater (theta0, 0.); libmesh_assert_greater (theta1, 0.); libmesh_assert_greater (theta2, 0.); return std::make_pair(std::min(theta0, std::min(theta1,theta2)), std::max(theta0, std::max(theta1,theta2))); }
void MainWindow::autoMeshInternal(TriangleListPtr trianglesFront, TriangleListPtr trianglesBack, struct predgparam3f_s *param, double targetRadius, int component, double minU, double maxU, double minV, double maxV, int maxSubdivisions, int subdivision) { struct spin3f_s sp00, sp01, sp10, sp11; predgparam3f_eval(&sp00, param, minU, minV, component); predgparam3f_eval(&sp01, param, minU, maxV, component); predgparam3f_eval(&sp10, param, maxU, minV, component); predgparam3f_eval(&sp11, param, maxU, maxV, component); if (subdivision == maxSubdivisions || (projectedDistance(&sp00, &sp01) <= targetRadius && projectedDistance(&sp00, &sp10) <= targetRadius && projectedDistance(&sp00, &sp11) <= targetRadius && projectedDistance(&sp01, &sp10) <= targetRadius && projectedDistance(&sp01, &sp11) <= targetRadius && projectedDistance(&sp10, &sp11) <= targetRadius)) { QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0)); QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0)); QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0)); QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0)); trianglesFront->push_back(Triangle(v00, v01, v11)); trianglesFront->push_back(Triangle(v00, v11, v10)); trianglesBack->push_back(Triangle(v00, v11, v01)); trianglesBack->push_back(Triangle(v00, v10, v11)); } else { autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU, minU + 0.5 * (maxU - minU), minV, minV + 0.5 * (maxV - minV), maxSubdivisions, subdivision + 1); autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU, minU + 0.5 * (maxU - minU), minV + 0.5 * (maxV - minV), maxV, maxSubdivisions, subdivision + 1); autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU + 0.5 * (maxU - minU), maxU, minV, minV + 0.5 * (maxV - minV), maxSubdivisions, subdivision + 1); autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU + 0.5 * (maxU - minU), maxU, minV + 0.5 * (maxV - minV), maxV, maxSubdivisions, subdivision + 1); } }
Real Tri3::volume () const { // 3-node triangles have the following formula for computing the area Point v10 ( *(this->get_node(1)) - *(this->get_node(0)) ); Point v20 ( *(this->get_node(2)) - *(this->get_node(0)) ); return 0.5 * (v10.cross(v20)).size() ; }
void ValueTest::onEnter() { UnitTestDemo::onEnter(); Value v1; CCASSERT(v1.getType() == Value::Type::NONE, ""); CCASSERT(v1.isNull(), ""); Value v2(100); CCASSERT(v2.getType() == Value::Type::INTEGER, ""); CCASSERT(!v2.isNull(), ""); Value v3(101.4f); CCASSERT(v3.getType() == Value::Type::FLOAT, ""); CCASSERT(!v3.isNull(), ""); Value v4(106.1); CCASSERT(v4.getType() == Value::Type::DOUBLE, ""); CCASSERT(!v4.isNull(), ""); unsigned char byte = 50; Value v5(byte); CCASSERT(v5.getType() == Value::Type::BYTE, ""); CCASSERT(!v5.isNull(), ""); Value v6(true); CCASSERT(v6.getType() == Value::Type::BOOLEAN, ""); CCASSERT(!v6.isNull(), ""); Value v7("string"); CCASSERT(v7.getType() == Value::Type::STRING, ""); CCASSERT(!v7.isNull(), ""); Value v8(std::string("string2")); CCASSERT(v8.getType() == Value::Type::STRING, ""); CCASSERT(!v8.isNull(), ""); auto createValueVector = [&]() { ValueVector ret; ret.push_back(v1); ret.push_back(v2); ret.push_back(v3); return ret; }; Value v9(createValueVector()); CCASSERT(v9.getType() == Value::Type::VECTOR, ""); CCASSERT(!v9.isNull(), ""); auto createValueMap = [&]() { ValueMap ret; ret["aaa"] = v1; ret["bbb"] = v2; ret["ccc"] = v3; return ret; }; Value v10(createValueMap()); CCASSERT(v10.getType() == Value::Type::MAP, ""); CCASSERT(!v10.isNull(), ""); auto createValueMapIntKey = [&]() { ValueMapIntKey ret; ret[111] = v1; ret[222] = v2; ret[333] = v3; return ret; }; Value v11(createValueMapIntKey()); CCASSERT(v11.getType() == Value::Type::INT_KEY_MAP, ""); CCASSERT(!v11.isNull(), ""); }
int intersect(const TQuadratic &q, const TSegment &s, std::vector<DoublePair> &intersections, bool firstIsQuad) { int solutionNumber = 0; // Note the line `a*x+b*y+c = 0` we search for solutions // di a*x(t)+b*y(t)+c=0 in [0,1] double a = s.getP0().y - s.getP1().y, b = s.getP1().x - s.getP0().x, c = -(a * s.getP0().x + b * s.getP0().y); // se il segmento e' un punto if (0.0 == a && 0.0 == b) { double outParForQuad = q.getT(s.getP0()); if (areAlmostEqual(q.getPoint(outParForQuad), s.getP0())) { if (firstIsQuad) intersections.push_back(DoublePair(outParForQuad, 0)); else intersections.push_back(DoublePair(0, outParForQuad)); return 1; } return 0; } if (q.getP2() - q.getP1() == q.getP1() - q.getP0()) { // the second is a segment.... if (firstIsQuad) return intersect(TSegment(q.getP0(), q.getP2()), s, intersections); else return intersect(s, TSegment(q.getP0(), q.getP2()), intersections); } std::vector<TPointD> bez, pol; bez.push_back(q.getP0()); bez.push_back(q.getP1()); bez.push_back(q.getP2()); bezier2poly(bez, pol); std::vector<double> poly_1(3, 0), sol; poly_1[0] = a * pol[0].x + b * pol[0].y + c; poly_1[1] = a * pol[1].x + b * pol[1].y; poly_1[2] = a * pol[2].x + b * pol[2].y; if (!(rootFinding(poly_1, sol))) return 0; double segmentPar, solution; TPointD v10(s.getP1() - s.getP0()); for (UINT i = 0; i < sol.size(); ++i) { solution = sol[i]; if ((0.0 <= solution && solution <= 1.0) || areAlmostEqual(solution, 0.0, 1e-6) || areAlmostEqual(solution, 1.0, 1e-6)) { segmentPar = (q.getPoint(solution) - s.getP0()) * v10 / (v10 * v10); if ((0.0 <= segmentPar && segmentPar <= 1.0) || areAlmostEqual(segmentPar, 0.0, 1e-6) || areAlmostEqual(segmentPar, 1.0, 1e-6)) { TPointD p1 = q.getPoint(solution); TPointD p2 = s.getPoint(segmentPar); assert(areAlmostEqual(p1, p2, 1e-1)); if (firstIsQuad) intersections.push_back(DoublePair(solution, segmentPar)); else intersections.push_back(DoublePair(segmentPar, solution)); solutionNumber++; } } } return solutionNumber; }
void TestTupleList() { test_db_config::DbConfig config; bool bRet = config.Init(); assert( bRet == true ); occiwrapper::ConnectionInfo info( config.GetStrIp(), 1521, config.GetUserName(), config.GetPassword(), config.GetSid() ); occiwrapper::SessionFactory sf; occiwrapper::Session s = sf.Create( info ); string strErrMsg; struct tm objTm; objTm.tm_year = 2014 - 1900; objTm.tm_mon = 11; objTm.tm_mday = 30; objTm.tm_hour = 10; objTm.tm_min = 43; objTm.tm_sec = 0; s << strCreateTable, now, bRet, strErrMsg; // test 1 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int > t1[ 2 ]; t1[ 0 ] = make_tuple( 1 ); t1[ 1 ] = make_tuple( 2 ); list< tuple< int > > v1( t1, t1 + 2 ); s << "insert into tbl_test_tuple_elements( t1 ) values ( :1 )", batched_use( v1 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int > > v1Out; s << "select t1 from tbl_test_tuple_elements", into( v1Out ), now, bRet, strErrMsg; assert( bRet ); assert( v1Out.size() == 2 ); // test 2 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float > t2[ 2 ]; t2[ 0 ] = make_tuple( 1, 1.1 ); t2[ 1 ] = make_tuple( 2, 2.1 ); list< tuple< int, float > > v2( t2, t2 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2 ) values ( :1, :2 )", batched_use( v2 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float > > v2Out; s << "select t1, t2 from tbl_test_tuple_elements", into( v2Out ), now, bRet, strErrMsg; assert( bRet ); assert( v2Out.size() == 2 ); // test 3 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string > t3[ 2 ]; t3[ 0 ] = make_tuple( 1, 1.1, "str1" ); t3[ 1 ] = make_tuple( 2, 2.1, "str2" ); list< tuple< int, float, string > > v3( t3, t3 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3 ) values ( :1, :2, :3 )", batched_use( v3 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string > > v3Out; s << "select t1, t2, t3 from tbl_test_tuple_elements", into( v3Out ), now, bRet, strErrMsg; assert( bRet ); assert( v3Out.size() == 2 ); // test 4 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm > t4[ 2 ]; t4[ 0 ] = make_tuple( 1, 1.1, "str1", objTm ); t4[ 1 ] = make_tuple( 2, 2.1, "str2", objTm ); list< tuple< int, float, string, struct tm > > v4( t4, t4 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4 ) values ( :1, :2, :3, :4 )", batched_use( v4 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm > > v4Out; s << "select t1, t2, t3, t4 from tbl_test_tuple_elements", into( v4Out ), now, bRet, strErrMsg; assert( bRet ); assert( v4Out.size() == 2 ); // test 5 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm > t5[ 2 ]; t5[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm ); t5[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm ); list< tuple< int, float, string, struct tm, struct tm > > v5( t5, t5 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5 ) values ( :1, :2, :3, :4, :5 )", batched_use( v5 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm > > v5Out; s << "select t1, t2, t3, t4, t5 from tbl_test_tuple_elements", into( v5Out ), now, bRet, strErrMsg; assert( bRet ); assert( v5Out.size() == 2 ); // test 6 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double > t6[ 2 ]; t6[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2 ); t6[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2 ); list< tuple< int, float, string, struct tm, struct tm, double > > v6( t6, t6 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6 ) values ( :1, :2, :3, :4, :5, :6 )", batched_use( v6 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double > > v6Out; s << "select t1, t2, t3, t4, t5, t6 from tbl_test_tuple_elements", into( v6Out ), now, bRet, strErrMsg; assert( bRet ); assert( v6Out.size() == 2 ); // test 7 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double > t7[ 2 ]; t7[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1 ); t7[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2 ); list< tuple< int, float, string, struct tm, struct tm, double, double > > v7( t7, t7 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7 ) values ( :1, :2, :3, :4, :5, :6, :7 )", batched_use( v7 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double > > v7Out; s << "select t1, t2, t3, t4, t5, t6, t7 from tbl_test_tuple_elements", into( v7Out ), now, bRet, strErrMsg; assert( bRet ); assert( v7Out.size() == 2 ); // test 8 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double, string > t8[ 2 ]; t8[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1" ); t8[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2" ); list< tuple< int, float, string, struct tm, struct tm, double, double, string > > v8( t8, t8 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8 ) values ( :1, :2, :3, :4, :5, :6, :7, :8 )", batched_use( v8 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double, string > > v8Out; s << "select t1, t2, t3, t4, t5, t6, t7, t8 from tbl_test_tuple_elements", into( v8Out ), now, bRet, strErrMsg; assert( bRet ); assert( v8Out.size() == 2 ); // test 9 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double, string, string > t9[ 2 ]; t9[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1", "str9_1" ); t9[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2", "str9_2" ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string > > v9( t9, t9 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8, t9 ) values ( :1, :2, :3, :4, :5, :6, :7, :8, :9 )", batched_use( v9 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string > > v9Out; s << "select t1, t2, t3, t4, t5, t6, t7, t8, t9 from tbl_test_tuple_elements", into( v9Out ), now, bRet, strErrMsg; assert( bRet ); assert( v9Out.size() == 2 ); // test 10 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > t10[ 2 ]; t10[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1", "str9_1", "str10_1" ); t10[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2", "str9_2", "str10_2" ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > > v10( t10, t10 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ) values ( :1, :2, :3, :4, :5, :6, :7, :8, :9, :10 )", batched_use( v10 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > > v10Out; s << "select t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 from tbl_test_tuple_elements", into( v10Out ), now, bRet, strErrMsg; assert( bRet ); assert( v10Out.size() == 2 ); s << "drop table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); }
void MainWindow::simpleMesh(TriangleListPtr trianglesFront, TriangleListPtr trianglesBack, struct predgparam3f_s *param, double radius) { int number_of_components = predgparamtype3f_components(param->t); for (int c = 0; c < number_of_components; ++c) { for (double pu = 0; pu < 1 - radius; pu += radius) for (double pv = 0; pv < 1 - radius; pv += radius) { struct spin3f_s sp00, sp01, sp10, sp11; predgparam3f_eval(&sp00, param, pu, pv, c); predgparam3f_eval(&sp01, param, pu, pv + radius, c); predgparam3f_eval(&sp10, param, pu + radius, pv, c); predgparam3f_eval(&sp11, param, pu + radius, pv + radius, c); QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0)); QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0)); QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0)); QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0)); trianglesFront->push_back(Triangle(v00, v01, v11)); trianglesFront->push_back(Triangle(v00, v11, v10)); trianglesBack->push_back(Triangle(v00, v11, v01)); trianglesBack->push_back(Triangle(v00, v10, v11)); } // last u for (double pu = 0; pu < 1 - radius; pu += radius) { struct spin3f_s sp00, sp01, sp10, sp11; predgparam3f_eval(&sp00, param, pu, 1.0 - radius, c); predgparam3f_eval(&sp01, param, pu, 1.0, c); predgparam3f_eval(&sp10, param, pu + radius, 1.0 - radius, c); predgparam3f_eval(&sp11, param, pu + radius, 1.0, c); QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0)); QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0)); QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0)); QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0)); trianglesFront->push_back(Triangle(v00, v01, v11)); trianglesFront->push_back(Triangle(v00, v11, v10)); trianglesBack->push_back(Triangle(v00, v11, v01)); trianglesBack->push_back(Triangle(v00, v10, v11)); } // last v for (double pv = 0; pv < 1 - radius; pv += radius) { struct spin3f_s sp00, sp01, sp10, sp11; predgparam3f_eval(&sp00, param, 1.0 - radius, pv, c); predgparam3f_eval(&sp01, param, 1.0 - radius, pv + radius, c); predgparam3f_eval(&sp10, param, 1.0, pv, c); predgparam3f_eval(&sp11, param, 1.0, pv + radius, c); QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0)); QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0)); QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0)); QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0)); trianglesFront->push_back(Triangle(v00, v01, v11)); trianglesFront->push_back(Triangle(v00, v11, v10)); trianglesBack->push_back(Triangle(v00, v11, v01)); trianglesBack->push_back(Triangle(v00, v10, v11)); } // last uv { struct spin3f_s sp00, sp01, sp10, sp11; predgparam3f_eval(&sp00, param, 1.0 - radius, 1.0 - radius, c); predgparam3f_eval(&sp01, param, 1.0 - radius, 1.0, c); predgparam3f_eval(&sp10, param, 1.0, 1.0 - radius, c); predgparam3f_eval(&sp11, param, 1.0, 1.0, c); QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0)); QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0)); QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0)); QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0)); trianglesFront->push_back(Triangle(v00, v01, v11)); trianglesFront->push_back(Triangle(v00, v11, v10)); trianglesBack->push_back(Triangle(v00, v11, v01)); trianglesBack->push_back(Triangle(v00, v10, v11)); } } }
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); }
void CIcosahedron::init( float s ){ this->clearMesh(); float p = ((1.0 + sqrt(5.0))/2.0)*s; TVector3 v0(s,0.0,p); this->iVertices.push_back(v0); TVector3 v1(-s,0.0,p); this->iVertices.push_back(v1); TVector3 v2(s,0.0,-p); this->iVertices.push_back(v2); TVector3 v3(-s,0.0,-p); this->iVertices.push_back(v3); TVector3 v4(0.0,p,s); this->iVertices.push_back(v4); TVector3 v5(0,-p,s); this->iVertices.push_back(v5); TVector3 v6(0,p,-s); this->iVertices.push_back(v6); TVector3 v7(0.0,-p,-s); this->iVertices.push_back(v7); TVector3 v8(p,s,0.0); this->iVertices.push_back(v8); TVector3 v9(-p,s,0.0); this->iVertices.push_back(v9); TVector3 v10(p,-s,0.0); this->iVertices.push_back(v10); TVector3 v11(-p,-s,0.0); this->iVertices.push_back(v11); TTriangle t0(0,4,1); this->iTriangles.push_back(t0); TTriangle t1(0,1,5); this->iTriangles.push_back(t1); TTriangle t2(0,5,10); this->iTriangles.push_back(t2); TTriangle t3(0,10,8); this->iTriangles.push_back(t3); TTriangle t4(0,8,4); this->iTriangles.push_back(t4); TTriangle t5(4,8,6); this->iTriangles.push_back(t5); TTriangle t6(4,6,9); this->iTriangles.push_back(t6); TTriangle t7(4,9,1); this->iTriangles.push_back(t7); TTriangle t8(1,9,11); this->iTriangles.push_back(t8); TTriangle t9(1,11,5); this->iTriangles.push_back(t9); TTriangle t10(2,7,3); this->iTriangles.push_back(t10); TTriangle t11(2,3,6); this->iTriangles.push_back(t11); TTriangle t12(2,6,8); this->iTriangles.push_back(t12); TTriangle t13(2,8,10); this->iTriangles.push_back(t13); TTriangle t14(2,10,7); this->iTriangles.push_back(t14); TTriangle t15(7,10,5); this->iTriangles.push_back(t15); TTriangle t16(7,5,11); this->iTriangles.push_back(t16); TTriangle t17(7,11,3); this->iTriangles.push_back(t17); TTriangle t18(3,11,9); this->iTriangles.push_back(t18); TTriangle t19(3,9,6); this->iTriangles.push_back(t19); }
int main() { typedef make_variant_shrink_over< boost::mpl::vector<double,float,int,bool,char> >::type r1type; BOOST_MPL_ASSERT((boost::mpl::equal<r1type ,boost::variant<double,bool,char> > )); //BOOST_MPL_ASSERT((boost::is_same<r1type ,boost::variant<double,bool,char> > )); r1type val1(1.1); std::cout << val1 << std::endl; std::cout << val1.which() << std::endl; val1='a'; std::cout << val1 << std::endl; std::cout << val1.which() << std::endl; val1=false; std::cout << val1 << std::endl; std::cout << val1.which() << std::endl; typedef make_variant_shrink_over<boost::mpl::vector<double,float,int> >::type r2type; BOOST_MPL_ASSERT((boost::mpl::equal<r2type ,double > )); BOOST_MPL_ASSERT((boost::is_same<r2type ,double > )); r2type d1=1.1,d2=2.2; d2=d1+d2; std::cout << d2 << std::endl; typedef make_variant_shrink_over<boost::mpl::vector<bool,char,std::string> >::type r3type; BOOST_MPL_ASSERT((boost::mpl::equal<r3type ,boost::variant<bool,char,std::string> > )); //BOOST_MPL_ASSERT((boost::is_same<r3type ,boost::variant<bool,charstd::string> > )); r3type v3('a'); v3="v3"; //std::cout << v3<std::string > ; std::cout << v3 << std::endl; v3=false; std::cout << v3 << std::endl; typedef make_variant_shrink_over<boost::mpl::vector<int,double,double,char,char,std::string> >::type r4type; BOOST_MPL_ASSERT((boost::mpl::equal<r4type ,boost::variant<double,char,std::string> > )); r4type v4("v4"); std::cout << v4 << std::endl; std::cout << v4.which() << std::endl; //v4=false; //std::cout << v4 << std::endl; //std::cout << v4.which() << std::endl; v4='4'; std::cout << v4 << std::endl; std::cout << v4.which() << std::endl; v4=4.44; std::cout << v4 << std::endl; std::cout << v4.which() << std::endl; // v4=4; // std::cout << v4 << std::endl; // std::cout << v4.which() << std::endl; //v4=v4+v4; #if 1 typedef make_variant_shrink_over< boost::mpl::vector<double,float,bool,char> ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence< boost::mpl::vector<bool,char,std::string> //your prefer order >::type >::type r5type; BOOST_MPL_ASSERT((boost::mpl::equal<r5type ,boost::variant<char,double,float> > )); //BOOST_MPL_ASSERT((boost::is_same<r5type ,boost::variant<char,double,float> > )); #endif #if 1 typedef make_variant_shrink_over< boost::mpl::vector<char,int>//::type ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence< boost::mpl::vector<bool,char,int> //::type //your prefer order >::type >::type r6type; BOOST_MPL_ASSERT((boost::mpl::equal<r6type ,int > )); BOOST_MPL_ASSERT((boost::is_same<r6type ,int > )); r6type i1=1,i2=2; i2=i1+i2; #endif #if 1 typedef make_variant_shrink_over< boost::mpl::vector<char,std::string,double,int> ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence< boost::mpl::vector<bool,char,int,std::string> //your prefer order >::type >::type r7type; BOOST_MPL_ASSERT((boost::mpl::equal<r7type ,boost::variant<std::string,double> > )); r7type v7("v777"); std::cout << v7 << std::endl; std::cout << v7.which() << std::endl; //assert( v7.which() == 0 ); //v7=7.7777; //boost::get<double>(v7); //boost::get<int>(v7); //std::cout << v7<double> << std::endl; #endif #if 1 typedef make_variant_shrink_over< boost::mpl::vector<float,bool,boost::rational<long> > ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence< boost::mpl::vector< bool , int , long , boost::rational<int> , boost::rational<long> > //your prefer order >::type >::type r8type; BOOST_MPL_ASSERT((boost::mpl::equal<r8type ,boost::variant<boost::rational<long> ,float> > )); #endif #if 1 typedef make_variant_shrink_over< boost::mpl::vector< int , boost::rational<int> > ,generate_mpl_lambda_is_generalizable_to_from_type_order_sequence< boost::mpl::vector< bool , int , long , boost::rational<int> , boost::rational<long> > //your prefer order >::type >::type r9type; BOOST_MPL_ASSERT((boost::is_same<r9type ,boost::rational<int> > )); #endif typedef boost::mpl::lambda<is_generalizable_to_custom<boost::mpl::_1 , boost::mpl::_2 > >::type is_generalizable_to_custom_mpl_lambda; typedef make_variant_shrink_over< boost::mpl::vector<double,float,bool,char> ,is_generalizable_to_custom_mpl_lambda >::type r10type; BOOST_MPL_ASSERT((boost::mpl::equal<r10type ,boost::variant<double,char> >)); r10type v10(10.1); std::cout << v10 << std::endl; std::cout << v10.which() << std::endl; boost::get<double>(v10); //v10=10; v10='a'; std::cout << v10 << std::endl; std::cout << v10.which() << std::endl; boost::get<char>(v10); typedef make_variant_shrink_over< boost::mpl::vector<double,float> ,is_generalizable_to_custom_mpl_lambda >::type r11type; BOOST_MPL_ASSERT((boost::is_same<r11type ,double > )); }
/* Call functions through pointers and and check against expected results. */ void test (void) { CHECK_VOID_RESULT (v0 (), 1.0); CHECK_VOID_RESULT (v1 (1.0), 2.0); CHECK_VOID_RESULT (v5 (5.0, 6.0), 12.0); CHECK_VOID_RESULT (v9 (9.0, 10.0), 20.0); CHECK_VOID_RESULT (v2 (2.0), 3.0); CHECK_VOID_RESULT (v6 (6.0, 7.0), 14.0); CHECK_VOID_RESULT (v10 (10.0, 11.0), 22.0); CHECK_RESULT (f0 (), 1.0); CHECK_RESULT (f1 (1.0), 2.0); CHECK_RESULT (f5 (5.0, 6.0), 12.0); CHECK_RESULT (f9 (9.0, 10.0), 20.0); CHECK_RESULT (f2 (2.0), 3.0); CHECK_RESULT (f6 (6.0, 7.0), 14.0); CHECK_RESULT (f10 (10.0, 11.0), 22.0); CHECK_RESULT (d0 (), 1.0); CHECK_RESULT (d1 (1.0), 2.0); CHECK_RESULT (d5 (5.0, 6.0), 12.0); CHECK_RESULT (d9 (9.0, 10.0), 20.0); CHECK_RESULT (d2 (2.0), 3.0); CHECK_RESULT (d6 (6.0, 7.0), 14.0); CHECK_RESULT (d10 (10.0, 11.0), 22.0); CHECK_RESULT (cf0 (), 1.0 + 0.0i); CHECK_RESULT (cf1 (1.0), 2.0 + 1.0i); CHECK_RESULT (cf5 (5.0, 6.0), 12.0 + 5.0i); CHECK_RESULT (cf9 (9.0, 10.0), 20.0 + 9.0i); CHECK_RESULT (cf2 (2.0), 3.0 + 2.0i); CHECK_RESULT (cf6 (6.0, 7.0), 14.0 + 6.0i); CHECK_RESULT (cf10 (10.0, 11.0), 22.0 + 10.0i); CHECK_RESULT (cd0 (), 1.0 + 0.0i); CHECK_RESULT (cd1 (1.0), 2.0 + 1.0i); CHECK_RESULT (cd5 (5.0, 6.0), 12.0 + 5.0i); CHECK_RESULT (cd9 (9.0, 10.0), 20.0 + 9.0i); CHECK_RESULT (cd2 (2.0), 3.0 + 2.0i); CHECK_RESULT (cd6 (6.0, 7.0), 14.0 + 6.0i); CHECK_RESULT (cd10 (10.0, 11.0), 22.0 + 10.0i); CHECK_VOID_RESULT ((*pv0) (), 1.0); CHECK_VOID_RESULT ((*pv1) (1.0), 2.0); CHECK_VOID_RESULT ((*pv5) (5.0, 6.0), 12.0); CHECK_VOID_RESULT ((*pv9) (9.0, 10.0), 20.0); CHECK_VOID_RESULT ((*pv2) (2.0), 3.0); CHECK_VOID_RESULT ((*pv6) (6.0, 7.0), 14.0); CHECK_VOID_RESULT ((*pv10) (10.0, 11.0), 22.0); CHECK_RESULT ((*pf0) (), 1.0); CHECK_RESULT ((*pf1) (1.0), 2.0); CHECK_RESULT ((*pf5) (5.0, 6.0), 12.0); CHECK_RESULT ((*pf9) (9.0, 10.0), 20.0); CHECK_RESULT ((*pf2) (2.0), 3.0); CHECK_RESULT ((*pf6) (6.0, 7.0), 14.0); CHECK_RESULT ((*pf10) (10.0, 11.0), 22.0); CHECK_RESULT ((*pd0) (), 1.0); CHECK_RESULT ((*pd1) (1.0), 2.0); CHECK_RESULT ((*pd5) (5.0, 6.0), 12.0); CHECK_RESULT ((*pd9) (9.0, 10.0), 20.0); CHECK_RESULT ((*pd2) (2.0), 3.0); CHECK_RESULT ((*pd6) (6.0, 7.0), 14.0); CHECK_RESULT ((*pd10) (10.0, 11.0), 22.0); CHECK_RESULT ((*pcf0) (), 1.0 + 0.0i); CHECK_RESULT ((*pcf1) (1.0), 2.0 + 1.0i); CHECK_RESULT ((*pcf5) (5.0, 6.0), 12.0 + 5.0i); CHECK_RESULT ((*pcf9) (9.0, 10.0), 20.0 + 9.0i); CHECK_RESULT ((*pcf2) (2.0), 3.0 + 2.0i); CHECK_RESULT ((*pcf6) (6.0, 7.0), 14.0 + 6.0i); CHECK_RESULT ((*pcf10) (10.0, 11.0), 22.0 + 10.0i); CHECK_RESULT ((*pcd0) (), 1.0 + 0.0i); CHECK_RESULT ((*pcd1) (1.0), 2.0 + 1.0i); CHECK_RESULT ((*pcd5) (5.0, 6.0), 12.0 + 5.0i); CHECK_RESULT ((*pcd9) (9.0, 10.0), 20.0 + 9.0i); CHECK_RESULT ((*pcd2) (2.0), 3.0 + 2.0i); CHECK_RESULT ((*pcd6) (6.0, 7.0), 14.0 + 6.0i); CHECK_RESULT ((*pcd10) (10.0, 11.0), 22.0 + 10.0i); }
/*Build the MBTB_body and set to the initial postion.*/ void MBTB_BodyBuild(unsigned int numDS, const std::string& BodyName, double mass, SP::SiconosVector initPos, SP::SiconosVector modelCenterMass, SP::SimpleMatrix inertialMatrix, const std::string& pluginFextLib, const std::string& pluginFextFct, const std::string& pluginMextLib, const std::string& pluginMextFct, const std::string& pluginFintLib, const std::string& pluginFintFct, const std::string& pluginMintLib, const std::string& pluginMintFct, const std::string& pluginFintJacqLib, const std::string& pluginFintJacqFct, const std::string& pluginMintJacqLib, const std::string& pluginMintJacqFct, const std::string& pluginFintJacvLib, const std::string& pluginFintJacvFct, const std::string& pluginMintJacvLib, const std::string& pluginMintJacvFct, const std::string& pluginBoundaryConditionLib, const std::string& pluginBoundaryConditionFct, SP::IndexInt boundaryConditionIndex) { assert(sNbOfBodies > numDS &&"MBTB_BodyBuild numDS out of range."); unsigned int qDim=7; //unsigned int nDof = 3; unsigned int nDim = 6; SP::SiconosVector q10(new SiconosVector(qDim)); SP::SiconosVector v10(new SiconosVector(nDim)); _MBTB_BodyBuildComputeInitPosition(numDS,mass,initPos,modelCenterMass,inertialMatrix,q10,v10); MBTB_Body * p=0; p =new MBTB_Body(q10,v10,mass,inertialMatrix,modelCenterMass, BodyName, BodyName); // We fix a ds number just to be able to use postprocessing based on hdf5 file p->setNumber(numDS+1); // set external forces plugin if(pluginFextFct.length()>1) { p->setComputeFExtFunction(pluginFextLib,pluginFextFct); } if(pluginMextFct.length()>1) { p->setComputeMExtFunction(pluginMextLib,pluginMextFct); } // set internal forces plugin if(pluginFintFct.length()>1) { p->setComputeFIntFunction(pluginFintLib,pluginFintFct); if(pluginFintJacqFct.length()>1) { if (pluginFintJacqFct == "FiniteDifference") { std::cout <<"setComputeJacobianFIntqByFD(true)" <<std::endl; p->setComputeJacobianFIntqByFD(true); } else { p->setComputeJacobianFIntqFunction(pluginFintJacqLib,pluginFintJacqFct); } } if(pluginFintJacvFct.length()>1) { if (pluginFintJacvFct == "FiniteDifference") { std::cout <<"setComputeJacobianFIntvByFD(true)" <<std::endl; p->setComputeJacobianFIntvByFD(true); } else { p->setComputeJacobianFIntvFunction(pluginFintJacvLib,pluginFintJacvFct); } } } if(pluginMintFct.length()>1) { p->setComputeMIntFunction(pluginMintLib,pluginMintFct); if(pluginMintJacqFct.length()>1) { if (pluginMintJacqFct == "FiniteDifference") { std::cout <<"setComputeJacobianMIntqByFD(true)" <<std::endl; p->setComputeJacobianMIntqByFD(true); } else { p->setComputeJacobianMIntqFunction(pluginMintJacqLib,pluginMintJacqFct); } } if(pluginMintJacvFct.length()>1) { if (pluginMintJacvFct == "FiniteDifference") { std::cout <<"setComputeJacobianMIntvByFD(true)" <<std::endl; p->setComputeJacobianMIntvByFD(true); } else { p->setComputeJacobianMIntvFunction(pluginMintJacvLib,pluginMintJacvFct); } } } // set boundary condition if (pluginBoundaryConditionFct.length() >1) { //SP::IndexInt bdindex(new IndexInt(1)); //(*bdindex)[0] = 4; DEBUG_PRINT("################################################################\n"); DEBUG_PRINT("###\n"); DEBUG_PRINT("###\n"); DEBUG_PRINT("###\n"); DEBUG_PRINTF("Set boundary Condition for body numDs = %i\n", numDS); DEBUG_EXPR( for (std::vector<unsigned int>::iterator itindex = boundaryConditionIndex->begin() ; itindex != boundaryConditionIndex->end(); ++itindex) {std::cout << *itindex <<std::endl;}; );
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(); }