Exemple #1
0
void Bezier::split(double t, Bezier & left, Bezier & right) const
{
	// http://processingjs.nihongoresources.com/bezierinfo/sketchsource.php?sketch=CubicDeCasteljau

	// interpolate from 4 to 3 points
	QPointF p5((1-t)*m_endpoint0.x() + t*m_cp0.x(), (1-t)*m_endpoint0.y() + t*m_cp0.y());
	QPointF p6((1-t)*m_cp0.x() + t*m_cp1.x(), (1-t)*m_cp0.y() + t*m_cp1.y());
	QPointF p7((1-t)*m_cp1.x() + t*m_endpoint1.x(), (1-t)*m_cp1.y() + t*m_endpoint1.y());

	// interpolate from 3 to 2 points
	QPointF p8((1-t)*p5.x() + t*p6.x(), (1-t)*p5.y() + t*p6.y());
	QPointF p9((1-t)*p6.x() + t*p7.x(), (1-t)*p6.y() + t*p7.y());

	// interpolate from 2 points to 1 point
	QPointF p10((1-t)*p8.x() + t*p9.x(), (1-t)*p8.y() + t*p9.y());

	// we now have all the values we need to build the subcurves
	left.m_endpoint0 = m_endpoint0;
	left.m_cp0 = p5;
	left.m_cp1 = p8;
	right.m_endpoint0 = left.m_endpoint1 = p10;
	right.m_cp0 = p9;
	right.m_cp1 = p7;
	right.m_endpoint1 = m_endpoint1;
	left.m_isEmpty = right.m_isEmpty = false;
} 
void measurement_overhead() {
    printf("Measurement, 0, 0\n");

    PM("","RDTSC, "O_STR);

    #define FOR_MEAS for (int k = 0; k < 100; ++k) { ; }
    double m; uint64_t med, se, min, max;
    measure(FOR_MEAS,m,med,se,min,max,10000);
    printf("Loop, "O_STR, m/100, med/100, se/100, min/100, max/100);

    printf("Function Calls, 0, 0\n");

    PM_COUNT(p0(), "p0, "O_STR,1000000);

    PM_COUNT(p1(1), "p1, "O_STR,1000000);

    PM_COUNT(p2(1,2), "p2, "O_STR,1000000);

    PM_COUNT(p3(1,2,3), "p3, "O_STR,1000000);

    PM_COUNT(p4(1,2,3,4), "p4, "O_STR,1000000);

    PM_COUNT(p5(1,2,3,4,5), "p5, "O_STR,1000000);

    PM_COUNT(p6(1,2,3,4,5,6), "p6, "O_STR,1000000);

    PM_COUNT(p7(1,2,3,4,5,6,7), "p7, "O_STR,1000000);
}
Exemple #3
0
std::vector<Eigen::Vector2i> PathPlanner::getNeighbours(Eigen::Vector2i p)
{
    Eigen::Vector2i p0(p(0) + 1, p(1));
    Eigen::Vector2i p1(p(0) - 1, p(1));
    Eigen::Vector2i p2(p(0), p(1) + 1);
    Eigen::Vector2i p3(p(0), p(1) - 1);

    Eigen::Vector2i p4(p(0) + 1, p(1) + 1);
    Eigen::Vector2i p5(p(0) - 1, p(1) - 1);
    Eigen::Vector2i p6(p(0) - 1, p(1) + 1);
    Eigen::Vector2i p7(p(0) + 1, p(1) - 1);

    std::vector<Eigen::Vector2i> points;

    if(validPoint(p0))
        points.push_back(p0);
    if(validPoint(p1))
        points.push_back(p1);
    if(validPoint(p2))
        points.push_back(p2);
    if(validPoint(p3))
        points.push_back(p3);

    //Disallow walking through diagonal cracks
    if(validPoint(p4) && (validPoint(p0) || validPoint(p2)))
        points.push_back(p4);
    if(validPoint(p5) && (validPoint(p1) || validPoint(p3)))
        points.push_back(p5);
    if(validPoint(p6) && (validPoint(p1) || validPoint(p2)))
        points.push_back(p6);
    if(validPoint(p7) && (validPoint(p0) || validPoint(p3)))
        points.push_back(p7);

    return points;
}
Exemple #4
0
int main()
{
  // Construct an arrangement of seven intersecting line segments.
  Point_2 p1(1, 1), p2(1, 4), p3(2, 2), p4(3, 7), p5(4, 4), p6(7, 1), p7(9, 3);
  Ex_arrangement  arr;
  insert(arr, Segment_2(p1, p6));
  insert(arr, Segment_2(p1, p4));  insert(arr, Segment_2(p2, p6));
  insert(arr, Segment_2(p3, p7));  insert(arr, Segment_2(p3, p5));
  insert(arr, Segment_2(p6, p7));  insert(arr, Segment_2(p4, p7));

  // Create a mapping of the arrangement faces to indices.
  Face_index_map  index_map(arr);

  // Perform breadth-first search from the unbounded face, using the event
  // visitor to associate each arrangement face with its discover time.
  unsigned int    time = 0;
  boost::breadth_first_search(Dual_arrangement(arr), arr.unbounded_face(),
                              boost::vertex_index_map(index_map).visitor
                              (boost::make_bfs_visitor
                               (stamp_times(Face_property_map(), time,
                                            boost::on_discover_vertex()))));

  // Print the discover time of each arrangement face.
  Ex_arrangement::Face_iterator  fit;
  for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit) {
    std::cout << "Discover time " << fit->data() << " for ";
    if (fit != arr.unbounded_face()) {
      std::cout << "face ";
      print_ccb<Ex_arrangement>(fit->outer_ccb());
    }
    else std::cout << "the unbounded face." << std::endl;
  }
  return 0;
}
Exemple #5
0
    PrimitiveParts cubePrimitive(float width, float height, float depth)
    {
        float hx = width / 2;
        float hy = height / 2;
        float hz = depth / 2;

        // create the vertices
        Point3 p0(hx,hy,hz);
        Point3 p1(hx,hy,-hz);
        Point3 p2(-hx,hy,-hz);
        Point3 p3(-hx,hy,hz);
        Point3 p4(hx,-hy,hz);
        Point3 p5(hx,-hy,-hz);
        Point3 p6(-hx,-hy,-hz);
        Point3 p7(-hx,-hy,hz);

        QList<int> f0 = QList<int>() << 0 << 1 << 2 << 3;
        QList<int> f1 = QList<int>() << 4 << 5 << 1 << 0;
        QList<int> f2 = QList<int>() << 6 << 2 << 1 << 5;
        QList<int> f3 = QList<int>() << 7 << 3 << 2 << 6;
        QList<int> f4 = QList<int>() << 7 << 4 << 0 << 3;
        QList<int> f5 = QList<int>() << 4 << 7 << 6 << 5;

        PrimitiveParts parts;
        parts.points = QVector<Point3>() << p0 << p1 << p2 << p3 << p4 << p5 << p6 << p7;
        parts.faces = QVector<QList<int> >() << f0 << f1 << f2 << f3 << f4 << f5;
        return parts;
    }
Exemple #6
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	ChangeWindowMode(TRUE);
	if (DxLib_Init() == -1)
		return -1;

	p7();


	DxLib_End();
	return 0;
}
Exemple #7
0
void BBox::render()
{
	Vec3d p0(inf),
		p1(sup[0], inf[1], inf[2]),
		p2(sup[0], sup[1], inf[2]),
		p3(inf[0], sup[1], inf[2]),
		p4(inf[0], inf[1], sup[2]),
		p5(sup[0], inf[1], sup[2]),
		p6(sup),
		p7(inf[0], sup[1], sup[2]);
	glBegin(GL_LINES);

	glVertex3dv(&p0[0]);
	glVertex3dv(&p1[0]);

	glVertex3dv(&p1[0]);
	glVertex3dv(&p2[0]);

	glVertex3dv(&p2[0]);
	glVertex3dv(&p3[0]);

	glVertex3dv(&p3[0]);
	glVertex3dv(&p0[0]);

	glVertex3dv(&p4[0]);
	glVertex3dv(&p5[0]);

	glVertex3dv(&p5[0]);
	glVertex3dv(&p6[0]);

	glVertex3dv(&p6[0]);
	glVertex3dv(&p7[0]);

	glVertex3dv(&p7[0]);
	glVertex3dv(&p4[0]);

	glVertex3dv(&p0[0]);
	glVertex3dv(&p4[0]);

	glVertex3dv(&p1[0]);
	glVertex3dv(&p5[0]);

	glVertex3dv(&p2[0]);
	glVertex3dv(&p6[0]);

	glVertex3dv(&p3[0]);
	glVertex3dv(&p7[0]);

	glEnd();
}
void PE_IO::fire_PI()
{	
	token_type x0,x1,x2,x3,x4,x5,x6,x7;
	x0.re=(rand()%10000)/10000.0000; x0.im=(rand()%10000)/10000.0000;
	x1.re=(rand()%10000)/10000.0000; x1.im=(rand()%10000)/10000.0000;
	x2.re=(rand()%10000)/10000.0000; x2.im=(rand()%10000)/10000.0000;
	x3.re=(rand()%10000)/10000.0000; x3.im=(rand()%10000)/10000.0000;
	x4.re=(rand()%10000)/10000.0000; x4.im=(rand()%10000)/10000.0000;
	x5.re=(rand()%10000)/10000.0000; x5.im=(rand()%10000)/10000.0000;
	x6.re=(rand()%10000)/10000.0000; x6.im=(rand()%10000)/10000.0000;
	x7.re=(rand()%10000)/10000.0000; x7.im=(rand()%10000)/10000.0000;
	
	packet p0(x_, y_, 1, 0, x0);
	printf("Round %d:PI: send x0 %.4f+%.4fi to (%d,%d)\n",
		pifire,x0.re,x0.im, p0.dest_x, p0.dest_y);
	packet p1(x_, y_, 1, 2, x1);
	printf("Round %d:PI: send x1 %.4f+%.4fi to (%d,%d)\n",
		pifire,x1.re,x1.im, p1.dest_x, p1.dest_y);
	packet p2(x_, y_, 2, 1, x2);
	printf("Round %d:PI: send x2 %.4f+%.4fi to (%d,%d)\n",
		pifire,x2.re,x2.im, p2.dest_x, p2.dest_y);
	packet p3(x_, y_, 0, 1, x3);
	printf("Round %d:PI: send x3 %.4f+%.4fi to (%d,%d)\n",
		pifire,x3.re,x3.im, p3.dest_x, p3.dest_y);
	packet p4(x_, y_, 1, 0, x4);
	printf("Round %d:PI: send x4 %.4f+%.4fi to (%d,%d)\n",
		pifire,x4.re,x4.im, p4.dest_x, p4.dest_y);
	packet p5(x_, y_, 1, 2, x5);
	printf("Round %d:PI: send x5 %.4f+%.4fi to (%d,%d)\n",
		pifire,x5.re,x5.im, p5.dest_x, p5.dest_y);
	packet p6(x_, y_, 2, 1, x6);
	printf("Round %d:PI: send x6 %.4f+%.4fi to (%d,%d)\n",
		pifire,x6.re,x6.im, p6.dest_x, p6.dest_y);
	packet p7(x_, y_, 0, 1, x7);
	printf("Round %d:PI: send x7 %.4f+%.4fi to (%d,%d)\n",
		pifire,x7.re,x7.im, p7.dest_x, p7.dest_y);
	out_queue_.push_back(p0);
	out_queue_.push_back(p1);
	out_queue_.push_back(p2);
	out_queue_.push_back(p3);
	out_queue_.push_back(p4);
	out_queue_.push_back(p5);
	out_queue_.push_back(p6);
	out_queue_.push_back(p7);
	
	pifire++;
}
int main(int argc, char* argv[]) {
  chain<ReqGenerator, ReqParser, ReqPrinter> p2;
  p2();

  chain<ReqGenerator, ReqParser2, ReqPrinter> p3;
  p3();

  chain<ReqGenerator, ReqParser, ReqParser2, ReqPrinter> p4;
  p4();

  chain<ReqGenerator, ReqParser, ReqPrinter2> p5;
  p5();

  chain<ReqGenerator, ReqParser2, ReqPrinter2> p6;
  p6();

  chain<ReqGenerator, ReqParser3, ReqPrinter2, ReqPrinter3> p7;
  p7();
}
/**
 * Load a predefined set of double-click gestures patterns.
 * Theses patterns are manualy recorded @ 20FPS
 * If the framerate changes the patterns wont be relevant anymore.
 */
void DoubleClickFilter::loadDoubleClickPatterns()
{
    cv::Mat p1( sizeof(doubleClickPattern_1)/sizeof(float), 1, CV_32F, doubleClickPattern_1 );
    cv::Mat p2( sizeof(doubleClickPattern_2)/sizeof(float), 1, CV_32F, doubleClickPattern_2 );
    cv::Mat p3( sizeof(doubleClickPattern_3)/sizeof(float), 1, CV_32F, doubleClickPattern_3 );
    cv::Mat p4( sizeof(doubleClickPattern_4)/sizeof(float), 1, CV_32F, doubleClickPattern_4 );
    cv::Mat p5( sizeof(doubleClickPattern_5)/sizeof(float), 1, CV_32F, doubleClickPattern_5 );
    cv::Mat p6( sizeof(doubleClickPattern_6)/sizeof(float), 1, CV_32F, doubleClickPattern_6 );
    cv::Mat p7( sizeof(doubleClickPattern_7)/sizeof(float), 1, CV_32F, doubleClickPattern_7 );
    cv::Mat p8( sizeof(doubleClickPattern_8)/sizeof(float), 1, CV_32F, doubleClickPattern_8 );

    addPattern( p1 );
    addPattern( p2 );
    addPattern( p3 );
    addPattern( p4 );
    addPattern( p5 );
    addPattern( p6 );
    addPattern( p7 );
    addPattern( p8 );
}
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;

    Player p1("Emma", 4);
    Player p2("Emma", 4);
    Player p3("Emma", 4);
    Player p4("Emma", 4);
    Player p5("Emma", 4);
    Player p6("Emma", 4);
    Player p7("Emma", 4);
    Player p8("Emma", 4);
    Player p9("Emma", 4);
    Player p10("Emma", 4);
    Player p11("Emma", 4);
    Player p12("Emma", 4);
    Match m(3);

    engine.rootContext()->setContextProperty("player1", &p1);
    engine.rootContext()->setContextProperty("player2", &p2);
    engine.rootContext()->setContextProperty("player3", &p3);
    engine.rootContext()->setContextProperty("player4", &p4);
    engine.rootContext()->setContextProperty("player5", &p5);
    engine.rootContext()->setContextProperty("player6", &p6);
    engine.rootContext()->setContextProperty("player7", &p7);
    engine.rootContext()->setContextProperty("player8", &p8);
    engine.rootContext()->setContextProperty("player9", &p9);
    engine.rootContext()->setContextProperty("player10", &p10);
    engine.rootContext()->setContextProperty("player11", &p11);
    engine.rootContext()->setContextProperty("player12", &p12);
    engine.rootContext()->setContextProperty("match", &m);

    QCoreApplication::setApplicationName("Lab2");
    QCoreApplication::setOrganizationName("EMMA");
    QCoreApplication::setOrganizationDomain(".fourThompson");

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
Exemple #12
0
std::vector<Triangle> triangulationCube(int rayon){

	std::vector<Triangle> listeTriangle;
	
	
	Point p0(-rayon, rayon, - rayon); //en haut à gauche
	Point p1(rayon, rayon,  - rayon); //en haut à droite
	Point p2(rayon,  - rayon,  - rayon); //en bas à droite
	Point p3(- rayon, - rayon,  - rayon); //en bas à gauche
	
	Point p4( - rayon,  rayon,  rayon);
	Point p5( rayon,  rayon, rayon);
	Point p6( rayon,  - rayon, rayon);
	Point p7( - rayon, - rayon, rayon);
	
	
	listeTriangle.push_back(Triangle(p0,p1,p2));
	listeTriangle.push_back(Triangle(p0,p2,p3));
	
	/*
	listeTriangle.push_back(Triangle(p4,p5,p6));
	listeTriangle.push_back(Triangle(p4,p6,p7));
	
	listeTriangle.push_back(Triangle(p0,p4,p5));
	listeTriangle.push_back(Triangle(p0,p5,p1));
	
	listeTriangle.push_back(Triangle(p1,p5,p6));
	listeTriangle.push_back(Triangle(p1,p6,p2));
	
	listeTriangle.push_back(Triangle(p6,p2,p3));
	listeTriangle.push_back(Triangle(p6,p3,p7));
	
	listeTriangle.push_back(Triangle(p0,p4,p7));
	listeTriangle.push_back(Triangle(p0,p7,p3));
*/

	return listeTriangle;

}
Exemple #13
0
void setup(MeshType & mesh, viennagrid::hexahedron_tag)
{
  typedef typename viennagrid::result_of::point<MeshType>::type               PointType;
  typedef typename viennagrid::result_of::vertex_handle<MeshType>::type       VertexHandleType;

  PointType p0(0.0, 0.0, 0.0);
  PointType p1(1.0, 0.0, 0.0);
  PointType p2(1.0, 1.0, 0.0);
  PointType p3(0.0, 1.0, 0.0);
  PointType p4(0.0, 0.0, 1.0);
  PointType p5(1.0, 0.0, 1.0);
  PointType p6(1.0, 1.0, 1.0);
  PointType p7(0.0, 1.0, 1.0);
  PointType p8(2.0, 0.0, 0.0);
  PointType p9(2.0, 1.0, 0.0);
  PointType p10(2.0, 0.0, 1.0);
  PointType p11(2.0, 1.0, 1.0);

  std::cout << "Adding vertices to segment:" << std::endl;


  VertexHandleType vh0 = viennagrid::make_vertex( mesh, p0 );
  VertexHandleType vh1 = viennagrid::make_vertex( mesh, p1 );
  VertexHandleType vh2 = viennagrid::make_vertex( mesh, p2 );
  VertexHandleType vh3 = viennagrid::make_vertex( mesh, p3 );
  VertexHandleType vh4 = viennagrid::make_vertex( mesh, p4 );
  VertexHandleType vh5 = viennagrid::make_vertex( mesh, p5 );
  VertexHandleType vh6 = viennagrid::make_vertex( mesh, p6 );
  VertexHandleType vh7 = viennagrid::make_vertex( mesh, p7 );
  VertexHandleType vh8 = viennagrid::make_vertex( mesh, p8 );
  VertexHandleType vh9 = viennagrid::make_vertex( mesh, p9 );
  VertexHandleType vh10 = viennagrid::make_vertex( mesh, p10 );
  VertexHandleType vh11 = viennagrid::make_vertex( mesh, p11 );


  viennagrid::make_hexahedron( mesh, vh0, vh1, vh3, vh2, vh4, vh5, vh7, vh6 );
  viennagrid::make_hexahedron( mesh, vh1, vh8, vh2, vh9, vh5, vh10, vh6, vh11 );
}
bool test(bool is_kernel_exact = true)
{
	// types
  typedef typename K::FT FT;
  typedef typename K::Line_3 Line;
  typedef typename K::Point_3 Point;
  typedef typename K::Segment_3 Segment;
  typedef typename K::Ray_3 Ray;
  typedef typename K::Line_3 Line;
  typedef typename K::Triangle_3 Triangle;

  /* -------------------------------------
  // Test data is something like that (in t supporting plane)
  // Triangle is (p1,p2,p3)
  //
  //       +E          +1
  //                 /   \
  //        +C     6+  +8  +4      +B
  //              /   9++7  \
  //            3+-------+5--+2
  //     
  //         +F        +A      
  ------------------------------------- */
  
  Point p1(FT(1.), FT(0.), FT(0.));
  Point p2(FT(0.), FT(1.), FT(0.));
  Point p3(FT(0.), FT(0.), FT(1.));
  
  Triangle t(p1,p2,p3);
  
  // Edges of t 
  Segment s12(p1,p2);
  Segment s21(p2,p1);
  Segment s13(p1,p3);
  Segment s23(p2,p3);
  Segment s32(p3,p2);
  Segment s31(p3,p1);
  
  bool b = test_aux(is_kernel_exact,t,s12,"t-s12",s12);
  b &= test_aux(is_kernel_exact,t,s21,"t-s21",s21);
  b &= test_aux(is_kernel_exact,t,s13,"t-s13",s13);
  b &= test_aux(is_kernel_exact,t,s23,"t-s23",s23);

  // Inside points
  Point p4(FT(0.5), FT(0.5), FT(0.));
  Point p5(FT(0.), FT(0.75), FT(0.25));
  Point p6(FT(0.5), FT(0.), FT(0.5));
  Point p7(FT(0.25), FT(0.625), FT(0.125));
  Point p8(FT(0.5), FT(0.25), FT(0.25));
  
  Segment s14(p1,p4);
  Segment s41(p4,p1);
  Segment s24(p2,p4);
  Segment s42(p4,p2);
  Segment s15(p1,p5);
  Segment s25(p2,p5);
  Segment s34(p3,p4);
  Segment s35(p3,p5);
  Segment s36(p3,p6);
  Segment s45(p4,p5);
  Segment s16(p1,p6);
  Segment s26(p2,p6);
  Segment s62(p6,p2);
  Segment s46(p4,p6);
  Segment s48(p4,p8);
  Segment s56(p5,p6);
  Segment s65(p6,p5);
  Segment s64(p6,p4);
  Segment s17(p1,p7);
  Segment s67(p6,p7);
  Segment s68(p6,p8);
  Segment s86(p8,p6);
  Segment s78(p7,p8);
  Segment s87(p8,p7);
  
  b &= test_aux(is_kernel_exact,t,s14,"t-s14",s14);
  b &= test_aux(is_kernel_exact,t,s41,"t-s41",s41);
  b &= test_aux(is_kernel_exact,t,s24,"t-s24",s24);
  b &= test_aux(is_kernel_exact,t,s42,"t-s42",s42);
  b &= test_aux(is_kernel_exact,t,s15,"t-s15",s15);
  b &= test_aux(is_kernel_exact,t,s25,"t-s25",s25);
  b &= test_aux(is_kernel_exact,t,s34,"t-s34",s34);
  b &= test_aux(is_kernel_exact,t,s35,"t-s35",s35);
  b &= test_aux(is_kernel_exact,t,s36,"t-s36",s36);
  b &= test_aux(is_kernel_exact,t,s45,"t-s45",s45);
  b &= test_aux(is_kernel_exact,t,s16,"t-s16",s16);
  b &= test_aux(is_kernel_exact,t,s26,"t-s26",s26);
  b &= test_aux(is_kernel_exact,t,s62,"t-s62",s62);
  b &= test_aux(is_kernel_exact,t,s46,"t-s46",s46);
  b &= test_aux(is_kernel_exact,t,s65,"t-s65",s65);
  b &= test_aux(is_kernel_exact,t,s64,"t-s64",s64);
  b &= test_aux(is_kernel_exact,t,s48,"t-s48",s48);
  b &= test_aux(is_kernel_exact,t,s56,"t-s56",s56);
  b &= test_aux(is_kernel_exact,t,s17,"t-t17",s17);
  b &= test_aux(is_kernel_exact,t,s67,"t-t67",s67);
  b &= test_aux(is_kernel_exact,t,s68,"t-s68",s68);
  b &= test_aux(is_kernel_exact,t,s86,"t-s86",s86);
  b &= test_aux(is_kernel_exact,t,s78,"t-t78",s78);
  b &= test_aux(is_kernel_exact,t,s87,"t-t87",s87);
  
  // Outside points (in triangle plane)
  Point pA(FT(-0.5), FT(1.), FT(0.5));
  Point pB(FT(0.5), FT(1.), FT(-0.5));
  Point pC(FT(0.5), FT(-0.5), FT(1.));
  Point pE(FT(1.), FT(-1.), FT(1.));
  Point pF(FT(-1.), FT(0.), FT(2.));
  
  Segment sAB(pA,pB);
  Segment sBC(pB,pC);
  Segment s2E(p2,pE);
  Segment sE2(pE,p2);
  Segment s2A(p2,pA);
  Segment s6E(p6,pE);
  Segment sB8(pB,p8);
  Segment sC8(pC,p8);
  Segment s8C(p8,pC);
  Segment s1F(p1,pF);
  Segment sF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,sAB,"t-sAB",p2);
  b &= test_aux(is_kernel_exact,t,sBC,"t-sBC",s46);
  b &= test_aux(is_kernel_exact,t,s2E,"t-s2E",s26);
  b &= test_aux(is_kernel_exact,t,sE2,"t-sE2",s62);
  b &= test_aux(is_kernel_exact,t,s2A,"t-s2A",p2);
  b &= test_aux(is_kernel_exact,t,s6E,"t-s6E",p6);
  b &= test_aux(is_kernel_exact,t,sB8,"t-sB8",s48);
  b &= test_aux(is_kernel_exact,t,sC8,"t-sC8",s68);
  b &= test_aux(is_kernel_exact,t,s8C,"t-s8C",s86);
  b &= test_aux(is_kernel_exact,t,s1F,"t-s1F",s13);
  b &= test_aux(is_kernel_exact,t,sF6,"t-sF6",s36);
  
  // Outside triangle plane
  Point pa(FT(0.), FT(0.), FT(0.));
  Point pb(FT(2.), FT(0.), FT(0.));
  Point pc(FT(1.), FT(0.), FT(1.));
  Point pe(FT(1.), FT(0.5), FT(0.5));
  
  Segment sab(pa,pb);
  Segment sac(pa,pc);
  Segment sae(pa,pe);
  Segment sa8(pa,p8);
  Segment sb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,sab,"t-sab",p1);
  b &= test_aux(is_kernel_exact,t,sac,"t-sac",p6);
  b &= test_aux(is_kernel_exact,t,sae,"t-sae",p8);
  b &= test_aux(is_kernel_exact,t,sa8,"t-sa8",p8);
  b &= test_aux(is_kernel_exact,t,sb2,"t-sb2",p2);
  
  // -----------------------------------
  // ray queries
  // -----------------------------------
  // Edges of t 
  Ray r12(p1,p2);
  Ray r21(p2,p1);
  Ray r13(p1,p3);
  Ray r23(p2,p3);
  
  b &= test_aux(is_kernel_exact,t,r12,"t-r12",s12);
  b &= test_aux(is_kernel_exact,t,r21,"t-r21",s21);
  b &= test_aux(is_kernel_exact,t,r13,"t-r13",s13);
  b &= test_aux(is_kernel_exact,t,r23,"t-r23",s23);
  
  // In triangle
  Point p9_(FT(0.), FT(0.5), FT(0.5));
  Point p9(FT(0.25), FT(0.375), FT(0.375));
  
  Ray r14(p1,p4);
  Ray r41(p4,p1);
  Ray r24(p2,p4);
  Ray r42(p4,p2);
  Ray r15(p1,p5);
  Ray r25(p2,p5);
  Ray r34(p3,p4);
  Ray r35(p3,p5);
  Ray r36(p3,p6);
  Ray r45(p4,p5);
  Ray r16(p1,p6);
  Ray r26(p2,p6);
  Ray r62(p6,p2);
  Ray r46(p4,p6);
  Ray r48(p4,p8);
  Ray r56(p5,p6);
  Ray r47(p4,p7);
  Ray r89(p8,p9);
  Ray r86(p8,p6);
  Ray r68(p6,p8);
  Segment r89_res(p8,p9_);
  
  b &= test_aux(is_kernel_exact,t,r14,"t-r14",s12);
  b &= test_aux(is_kernel_exact,t,r41,"t-r41",s41);
  b &= test_aux(is_kernel_exact,t,r24,"t-r24",s21);
  b &= test_aux(is_kernel_exact,t,r42,"t-r42",s42);
  b &= test_aux(is_kernel_exact,t,r15,"t-r15",s15);
  b &= test_aux(is_kernel_exact,t,r25,"t-r25",s23);
  b &= test_aux(is_kernel_exact,t,r34,"t-r34",s34);
  b &= test_aux(is_kernel_exact,t,r35,"t-r35",s32);
  b &= test_aux(is_kernel_exact,t,r36,"t-r36",s31);
  b &= test_aux(is_kernel_exact,t,r45,"t-r45",s45);
  b &= test_aux(is_kernel_exact,t,r16,"t-r16",s13);
  b &= test_aux(is_kernel_exact,t,r26,"t-r26",s26);
  b &= test_aux(is_kernel_exact,t,r62,"t-r62",s62);
  b &= test_aux(is_kernel_exact,t,r46,"t-r46",s46);
  b &= test_aux(is_kernel_exact,t,r48,"t-r48",s46);
  b &= test_aux(is_kernel_exact,t,r56,"t-r56",s56);
  b &= test_aux(is_kernel_exact,t,r47,"t-r47",s45);
  b &= test_aux(is_kernel_exact,t,r89,"t-t89",r89_res);
  b &= test_aux(is_kernel_exact,t,r68,"t-r68",s64);
  b &= test_aux(is_kernel_exact,t,r86,"t-r86",s86);
  
  
  // Outside points (in triangre prane)
  Ray rAB(pA,pB);
  Ray rBC(pB,pC);
  Ray r2E(p2,pE);
  Ray rE2(pE,p2);
  Ray r2A(p2,pA);
  Ray r6E(p6,pE);
  Ray rB8(pB,p8);
  Ray rC8(pC,p8);
  Ray r8C(p8,pC);
  Ray r1F(p1,pF);
  Ray rF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,rAB,"t-rAB",p2);
  b &= test_aux(is_kernel_exact,t,rBC,"t-rBC",s46);
  b &= test_aux(is_kernel_exact,t,r2E,"t-r2E",s26);
  b &= test_aux(is_kernel_exact,t,rE2,"t-rE2",s62);
  b &= test_aux(is_kernel_exact,t,r2A,"t-r2A",p2);
  b &= test_aux(is_kernel_exact,t,r6E,"t-r6E",p6);
  b &= test_aux(is_kernel_exact,t,rB8,"t-rB8",s46);
  b &= test_aux(is_kernel_exact,t,rC8,"t-rC8",s64);
  b &= test_aux(is_kernel_exact,t,r8C,"t-r8C",s86);
  b &= test_aux(is_kernel_exact,t,r1F,"t-r1F",s13);
  b &= test_aux(is_kernel_exact,t,rF6,"t-rF6",s31);
  
  // Outside triangle plane
  Ray rab(pa,pb);
  Ray rac(pa,pc);
  Ray rae(pa,pe);
  Ray ra8(pa,p8);
  Ray rb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,rab,"t-rab",p1);
  b &= test_aux(is_kernel_exact,t,rac,"t-rac",p6);
  b &= test_aux(is_kernel_exact,t,rae,"t-rae",p8);
  b &= test_aux(is_kernel_exact,t,ra8,"t-ra8",p8);
  b &= test_aux(is_kernel_exact,t,rb2,"t-rb2",p2);
  
  // -----------------------------------
  // Line queries
  // -----------------------------------
  // Edges of t 
  Line l12(p1,p2);
  Line l21(p2,p1);
  Line l13(p1,p3);
  Line l23(p2,p3);
  
  b &= test_aux(is_kernel_exact,t,l12,"t-l12",s12);
  b &= test_aux(is_kernel_exact,t,l21,"t-l21",s21);
  b &= test_aux(is_kernel_exact,t,l13,"t-l13",s13);
  b &= test_aux(is_kernel_exact,t,l23,"t-l23",s23);
  
  // In triangle
  Line l14(p1,p4);
  Line l41(p4,p1);
  Line l24(p2,p4);
  Line l42(p4,p2);
  Line l15(p1,p5);
  Line l25(p2,p5);
  Line l34(p3,p4);
  Line l35(p3,p5);
  Line l36(p3,p6);
  Line l45(p4,p5);
  Line l16(p1,p6);
  Line l26(p2,p6);
  Line l62(p6,p2);
  Line l46(p4,p6);
  Line l48(p4,p8);
  Line l56(p5,p6);
  Line l47(p4,p7);
  Line l89(p8,p9);
  Line l86(p8,p6);
  Line l68(p6,p8);
  Segment l89_res(p1,p9_);

  
  b &= test_aux(is_kernel_exact,t,l14,"t-l14",s12);
  b &= test_aux(is_kernel_exact,t,l41,"t-l41",s21);
  b &= test_aux(is_kernel_exact,t,l24,"t-l24",s21);
  b &= test_aux(is_kernel_exact,t,l42,"t-l42",s12);
  b &= test_aux(is_kernel_exact,t,l15,"t-l15",s15);
  b &= test_aux(is_kernel_exact,t,l25,"t-l25",s23);
  b &= test_aux(is_kernel_exact,t,l34,"t-l34",s34);
  b &= test_aux(is_kernel_exact,t,l35,"t-l35",s32);
  b &= test_aux(is_kernel_exact,t,l36,"t-l36",s31);
  b &= test_aux(is_kernel_exact,t,l45,"t-l45",s45);
  b &= test_aux(is_kernel_exact,t,l16,"t-l16",s13);
  b &= test_aux(is_kernel_exact,t,l26,"t-l26",s26);
  b &= test_aux(is_kernel_exact,t,l62,"t-l62",s62);
  b &= test_aux(is_kernel_exact,t,l46,"t-l46",s46);
  b &= test_aux(is_kernel_exact,t,l48,"t-l48",s46);
  b &= test_aux(is_kernel_exact,t,l56,"t-l56",s56);
  b &= test_aux(is_kernel_exact,t,l47,"t-l47",s45);
  b &= test_aux(is_kernel_exact,t,l89,"t-t89",l89_res);
  b &= test_aux(is_kernel_exact,t,l68,"t-l68",s64);
  b &= test_aux(is_kernel_exact,t,l86,"t-l86",s46);

  
  // Outside points (in triangle plane)
  Line lAB(pA,pB);
  Line lBC(pB,pC);
  Line l2E(p2,pE);
  Line lE2(pE,p2);
  Line l2A(p2,pA);
  Line l6E(p6,pE);
  Line lB8(pB,p8);
  Line lC8(pC,p8);
  Line l8C(p8,pC);
  Line l1F(p1,pF);
  Line lF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,lAB,"t-lAB",p2);
  b &= test_aux(is_kernel_exact,t,lBC,"t-lBC",s46);
  b &= test_aux(is_kernel_exact,t,l2E,"t-l2E",s26);
  b &= test_aux(is_kernel_exact,t,lE2,"t-lE2",s62);
  b &= test_aux(is_kernel_exact,t,l2A,"t-l2A",p2);
  b &= test_aux(is_kernel_exact,t,l6E,"t-l6E",s26);
  b &= test_aux(is_kernel_exact,t,lB8,"t-lB8",s46);
  b &= test_aux(is_kernel_exact,t,lC8,"t-lC8",s64);
  b &= test_aux(is_kernel_exact,t,l8C,"t-l8C",s46);
  b &= test_aux(is_kernel_exact,t,l1F,"t-l1F",s13);
  b &= test_aux(is_kernel_exact,t,lF6,"t-lF6",s31);
  
  // Outside triangle plane
  Line lab(pa,pb);
  Line lac(pa,pc);
  Line lae(pa,pe);
  Line la8(pa,p8);
  Line lb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,lab,"t-lab",p1);
  b &= test_aux(is_kernel_exact,t,lac,"t-lac",p6);
  b &= test_aux(is_kernel_exact,t,lae,"t-lae",p8);
  b &= test_aux(is_kernel_exact,t,la8,"t-la8",p8);
  b &= test_aux(is_kernel_exact,t,lb2,"t-lb2",p2);
  
  
	return b;
}
Exemple #15
0
int main() {
  printf("P7: %d", p7());
}
Exemple #16
0
int main(int argc, char **argv)
{
  plan_tests(92);

  // test constructor
  GeoPoint p1(Angle::Degrees(345.32), Angle::Degrees(-6.332));
  ok1(p1.IsValid());
  ok1(equals(p1, -6.332, 345.32));

  // test normalize()
  p1.Normalize();
  ok1(p1.IsValid());
  ok1(equals(p1, -6.332, -14.68));

  // test parametric()
  GeoPoint p2(Angle::Degrees(2), Angle::Degrees(1));
  GeoPoint p3 = p1.Parametric(p2, 5);
  ok1(p2.IsValid());
  ok1(p3.IsValid());
  ok1(equals(p3, -1.332, -4.68));

  // test interpolate
  GeoPoint p4 = p1.Interpolate(p3, 0.5);
  ok1(p4.IsValid());
  ok1(equals(p4, -3.832, -9.68));

  GeoPoint p5 = p1.Interpolate(p3, 0.25);
  ok1(p5.IsValid());
  ok1(equals(p5, -5.082, -12.18));

  // test *
  GeoPoint p6 = p2 * 3.5;
  ok1(p6.IsValid());
  ok1(equals(p6, 3.5, 7));

  // test +
  p6 = p6 + p2;
  ok1(p6.IsValid());
  ok1(equals(p6, 4.5, 9));

  // test +=
  p6 += p2;
  ok1(p6.IsValid());
  ok1(equals(p6, 5.5, 11));

  // test -
  p6 = p6 - p2;
  ok1(p6.IsValid());
  ok1(equals(p6, 4.5, 9));

  // for large and short distance testing
  GeoPoint p11(Angle::Degrees(0.00001), Angle::Degrees(0.00001));
  GeoPoint p12(Angle::Degrees(179), Angle::Degrees(0));

  p11 += p1;
  p12 += p1;

  ok1(p11.IsValid());
  ok1(equals(p11, -6.33199, -14.67999));

  ok1(p12.IsValid());
  ok1(equals(p12, -6.332, 164.32));

  // test sort()
  ok1(!p1.Sort(p3));
  ok1(p3.Sort(p1));
  ok1(!p1.Sort(p4));
  ok1(p4.Sort(p1));
  ok1(!p1.Sort(p5));
  ok1(p5.Sort(p1));
  ok1(!p4.Sort(p3));
  ok1(p3.Sort(p4));
  ok1(!p5.Sort(p3));
  ok1(p3.Sort(p5));
  ok1(!p5.Sort(p4));
  ok1(p4.Sort(p5));

  // test distance()
  //
  // note: distance between p1 and p4 and between p3 and p4 is not
  // the same due to linear interpolation instead of real geographic
  // intermediate point calculation
  ok1(equals(p2.Distance(p6), 869146.334126));
  ok1(equals(p6.Distance(p2), 869146.334126));
  ok1(equals(p1.Distance(p5), 309506.275043));
  ok1(equals(p1.Distance(p4), 619486.719361));
  ok1(equals(p1.Distance(p3), 1240403.22926));
  ok1(equals(p3.Distance(p4), 620924.169000));
  ok1(equals(p1.Distance(p11), 1.561761));
  ok1(equals(p1.Distance(p12), 18599361.600));

  ok1(equals(p2.DistanceS(p6), 869326.653160));
  ok1(equals(p6.DistanceS(p2), 869326.653160));
  ok1(equals(p1.DistanceS(p5), 309562.219016));
  ok1(equals(p1.DistanceS(p4), 619603.149273));
  ok1(equals(p1.DistanceS(p3), 1240649.267606));
  ok1(equals(p3.DistanceS(p4), 621053.760625));
  ok1(equals(p1.DistanceS(p11), 1.568588));
  ok1(equals(p1.DistanceS(p12), 18602548.701));

  // test bearing()
  //
  // note: the bearings p1 -> p5, p5 -> p4 and so on are not the same due to
  // linear interpolation instead of real geographic intermediate point
  // calculation
  ok1(equals(p2.Bearing(p6), 63.425773));
  ok1(equals(p6.Bearing(p2), 243.762198));
  ok1(equals(p1.Bearing(p5), 63.601900));
  ok1(equals(p1.Bearing(p4), 63.735395));
  ok1(equals(p1.Bearing(p3), 63.937616));
  ok1(equals(p5.Bearing(p4), 63.619712));
  ok1(equals(p5.Bearing(p3), 63.799336));
  ok1(equals(p4.Bearing(p3), 63.694155));
  ok1(equals(p5.Bearing(p6), 66.126880));
  ok1(equals(p2.Bearing(p3), 250.886912));

  ok1(equals(p2.BearingS(p6), 63.272424));
  ok1(equals(p6.BearingS(p2), 243.608847));
  ok1(equals(p1.BearingS(p5), 63.449343));
  ok1(equals(p1.BearingS(p4), 63.582620));
  ok1(equals(p1.BearingS(p3), 63.784526));
  ok1(equals(p5.BearingS(p4), 63.466726));
  ok1(equals(p5.BearingS(p3), 63.646072));
  ok1(equals(p4.BearingS(p3), 63.540756));
  ok1(equals(p5.BearingS(p6), 65.982854));
  ok1(equals(p2.BearingS(p3), 250.786774));

  // test distance_bearing()
  // note: should be the same output as bearing() and distance()
  GeoVector v = p2.DistanceBearing(p6);
  ok1(equals(v.distance, 869146.334126));
  ok1(equals(v.bearing, 63.425773));

  v = p2.DistanceBearingS(p6);
  ok1(equals(v.distance, 869326.653160));
  ok1(equals(v.bearing, 63.272424));

  // test intermediate_point()
  GeoPoint p7(Angle::Zero(), Angle::Zero());
  ok1(p7.IsValid());
  GeoPoint p8 = p7.IntermediatePoint(p2, 100000);
  ok1(p8.IsValid());
  ok1(equals(p8, 0.402361, 0.804516));
  ok1(equals(p8.Distance(p7), 100000));
  GeoPoint p9 = p7.IntermediatePoint(p2, 100000000);
  ok1(p9.IsValid());
  ok1(equals(p9, p2));

  // test projected_distance()
  ok1(equals(p8.ProjectedDistance(p7, p2), 100000));
  ok1(equals(p4.ProjectedDistance(p1, p3), 619494.517917));
  ok1(equals((p2 * 2).ProjectedDistance(p2, p6), 248511.833322));

  // Tests moved here from test_fixed.cpp
  GeoPoint l1(Angle::Zero(), Angle::Zero());
  ok1(l1.IsValid());
  GeoPoint l2(Angle::Degrees(-0.3), Angle::Degrees(1.0));
  ok1(l2.IsValid());
  GeoPoint l3(Angle::Degrees(0.00001), Angle::Zero());
  ok1(l3.IsValid());
  GeoPoint l4(Angle::Degrees(10), Angle::Zero());
  ok1(l4.IsValid());
  l4.SetInvalid();
  ok1(!l4.IsValid());

  bool find_lat_lon_okay = true;
  for (Angle bearing = Angle::Zero(); bearing < Angle::FullCircle();
      bearing += Angle::Degrees(5)) {
    GeoPoint p_test = FindLatitudeLongitude(p1, bearing, 50000);
    find_lat_lon_okay = equals(p_test.Distance(p1), 50000) && find_lat_lon_okay;
  }
  ok1(find_lat_lon_okay);

  v = l1.DistanceBearing(l2);
  // 116090 @ 343

  v = l1.DistanceBearing(l3);
  ok(v.distance > 0 && v.distance < 2, "earth distance short", 0);

  GeoPoint p10(GeoPoint::Invalid());
  ok1(!p10.IsValid());


  return exit_status();
}
TEST(FloatRectTest, SquaredDistanceToTest)
{

    //
    //  O--x
    //  |
    //  y
    //
    //     FloatRect.x()   FloatRect.maxX()
    //            |          |
    //        1   |    2     |  3
    //      ======+==========+======   --FloatRect.y()
    //        4   |    5(in) |  6
    //      ======+==========+======   --FloatRect.maxY()
    //        7   |    8     |  9
    //

    FloatRect r1(100, 100, 250, 150);

    // `1` case
    FloatPoint p1(80, 80);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p1), 800.f);

    FloatPoint p2(-10, -10);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p2), 24200.f);

    FloatPoint p3(80, -10);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p3), 12500.f);

    // `2` case
    FloatPoint p4(110, 80);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p4), 400.f);

    FloatPoint p5(150, 0);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p5), 10000.f);

    FloatPoint p6(180, -10);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p6), 12100.f);

    // `3` case
    FloatPoint p7(400, 80);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p7), 2900.f);

    FloatPoint p8(360, -10);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p8), 12200.f);

    // `4` case
    FloatPoint p9(80, 110);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p9), 400.f);

    FloatPoint p10(-10, 180);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p10), 12100.f);

    // `5`(& In) case
    FloatPoint p11(100, 100);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p11), 0.f);

    FloatPoint p12(150, 100);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p12), 0.f);

    FloatPoint p13(350, 100);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p13), 0.f);

    FloatPoint p14(350, 150);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p14), 0.f);

    FloatPoint p15(350, 250);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p15), 0.f);

    FloatPoint p16(150, 250);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p16), 0.f);

    FloatPoint p17(100, 250);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p17), 0.f);

    FloatPoint p18(100, 150);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p18), 0.f);

    FloatPoint p19(150, 150);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p19), 0.f);

    // `6` case
    FloatPoint p20(380, 150);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p20), 900.f);

    // `7` case
    FloatPoint p21(80, 280);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p21), 1300.f);

    FloatPoint p22(-10, 300);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p22), 14600.f);

    // `8` case
    FloatPoint p23(180, 300);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p23), 2500.f);

    // `9` case
    FloatPoint p24(450, 450);
    EXPECT_PRED_FORMAT2(GeometryTest::AssertAlmostEqual, r1.squaredDistanceTo(p24), 50000.f);
}
Exemple #18
0
// Create mesh
void Chunk::CreateMesh()
{
	if (m_pMesh == NULL)
	{
		m_pMesh = m_pRenderer->CreateMesh(OGLMeshType_Textured);
	}

	int *l_merged;
	l_merged = new int[CHUNK_SIZE_CUBED];

	for (unsigned int j = 0; j < CHUNK_SIZE_CUBED; j++)
	{
		l_merged[j] = MergedSide_None;
	}

	float r = 1.0f;
	float g = 1.0f;
	float b = 1.0f;
	float a = 1.0f;

	for (int x = 0; x < CHUNK_SIZE; x++)
	{
		for (int y = 0; y < CHUNK_SIZE; y++)
		{
			for (int z = 0; z < CHUNK_SIZE; z++)
			{
				if (GetActive(x, y, z) == false)
				{
					continue;
				}
				else
				{
					GetColour(x, y, z, &r, &g, &b, &a);

					a = 1.0f;

					vec3 p1(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					vec3 p2(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					vec3 p3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					vec3 p4(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					vec3 p5(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					vec3 p6(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					vec3 p7(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					vec3 p8(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);

					vec3 n1;
					unsigned int v1, v2, v3, v4;
					unsigned int t1, t2, t3, t4;

					bool doXPositive = (IsMergedXPositive(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE) == false);
					bool doXNegative = (IsMergedXNegative(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE) == false);
					bool doYPositive = (IsMergedYPositive(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE) == false);
					bool doYNegative = (IsMergedYNegative(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE) == false);
					bool doZPositive = (IsMergedZPositive(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE) == false);
					bool doZNegative = (IsMergedZNegative(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE) == false);

					// Front
					if (doZPositive && ((z == CHUNK_SIZE - 1) || z < CHUNK_SIZE - 1 && GetActive(x, y, z + 1) == false))
					{
						bool addSide = true;

						if ((z == CHUNK_SIZE - 1))
						{
							Chunk* pChunk = m_pChunkManager->GetChunk(m_gridX, m_gridY, m_gridZ + 1);
							if (pChunk == NULL || pChunk->IsSetup())
							{
								addSide = pChunk != NULL && (pChunk->GetActive(x, y, 0) == false);
							}
						}

						if (addSide)
						{
							int endX = (x / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;
							int endY = (y / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;

							if (m_pChunkManager->GetFaceMerging())
							{
								UpdateMergedSide(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE, &p1, &p2, &p3, &p4, x, y, endX, endY, true, true, false, false);
							}

							n1 = vec3(0.0f, 0.0f, 1.0f);
							v1 = m_pRenderer->AddVertexToMesh(p1, n1, r, g, b, a, m_pMesh);
							t1 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 0.0f, m_pMesh);
							v2 = m_pRenderer->AddVertexToMesh(p2, n1, r, g, b, a, m_pMesh);
							t2 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 0.0f, m_pMesh);
							v3 = m_pRenderer->AddVertexToMesh(p3, n1, r, g, b, a, m_pMesh);
							t3 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 1.0f, m_pMesh);
							v4 = m_pRenderer->AddVertexToMesh(p4, n1, r, g, b, a, m_pMesh);
							t4 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 1.0f, m_pMesh);

							m_pRenderer->AddTriangleToMesh(v1, v2, v3, m_pMesh);
							m_pRenderer->AddTriangleToMesh(v1, v3, v4, m_pMesh);
						}
					}

					p1 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p2 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p3 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p4 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p5 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p6 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p7 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p8 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);

					// Back
					if (doZNegative && ((z == 0) || (z > 0 && GetActive(x, y, z - 1) == false)))
					{
						bool addSide = true;

						if ((z == 0))
						{
							Chunk* pChunk = m_pChunkManager->GetChunk(m_gridX, m_gridY, m_gridZ - 1);
							if (pChunk == NULL || pChunk->IsSetup())
							{
								addSide = pChunk != NULL && (pChunk->GetActive(x, y, CHUNK_SIZE - 1) == false);
							}
						}

						if (addSide)
						{
							int endX = (x / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;
							int endY = (y / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;

							if (m_pChunkManager->GetFaceMerging())
							{
								UpdateMergedSide(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE, &p6, &p5, &p8, &p7, x, y, endX, endY, false, true, false, false);
							}

							n1 = vec3(0.0f, 0.0f, -1.0f);
							v1 = m_pRenderer->AddVertexToMesh(p5, n1, r, g, b, a, m_pMesh);
							t1 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 0.0f, m_pMesh);
							v2 = m_pRenderer->AddVertexToMesh(p6, n1, r, g, b, a, m_pMesh);
							t2 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 0.0f, m_pMesh);
							v3 = m_pRenderer->AddVertexToMesh(p7, n1, r, g, b, a, m_pMesh);
							t3 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 1.0f, m_pMesh);
							v4 = m_pRenderer->AddVertexToMesh(p8, n1, r, g, b, a, m_pMesh);
							t4 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 1.0f, m_pMesh);

							m_pRenderer->AddTriangleToMesh(v1, v2, v3, m_pMesh);
							m_pRenderer->AddTriangleToMesh(v1, v3, v4, m_pMesh);
						}
					}

					p1 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p2 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p3 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p4 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p5 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p6 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p7 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p8 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);

					// Right
					if (doXPositive && ((x == CHUNK_SIZE - 1) || (x < CHUNK_SIZE - 1 && GetActive(x + 1, y, z) == false)))
					{
						bool addSide = true;

						if ((x == CHUNK_SIZE - 1))
						{
							Chunk* pChunk = m_pChunkManager->GetChunk(m_gridX + 1, m_gridY, m_gridZ);
							if (pChunk == NULL || pChunk->IsSetup())
							{
								addSide = pChunk != NULL && (pChunk->GetActive(0, y, z) == false);
							}
						}

						if (addSide)
						{
							int endX = (z / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;
							int endY = (y / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;

							if (m_pChunkManager->GetFaceMerging())
							{
								UpdateMergedSide(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE, &p5, &p2, &p3, &p8, z, y, endX, endY, true, false, true, false);
							}

							n1 = vec3(1.0f, 0.0f, 0.0f);
							v1 = m_pRenderer->AddVertexToMesh(p2, n1, r, g, b, a, m_pMesh);
							t1 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 0.0f, m_pMesh);
							v2 = m_pRenderer->AddVertexToMesh(p5, n1, r, g, b, a, m_pMesh);
							t2 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 0.0f, m_pMesh);
							v3 = m_pRenderer->AddVertexToMesh(p8, n1, r, g, b, a, m_pMesh);
							t3 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 1.0f, m_pMesh);
							v4 = m_pRenderer->AddVertexToMesh(p3, n1, r, g, b, a, m_pMesh);
							t4 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 1.0f, m_pMesh);

							m_pRenderer->AddTriangleToMesh(v1, v2, v3, m_pMesh);
							m_pRenderer->AddTriangleToMesh(v1, v3, v4, m_pMesh);
						}
					}

					p1 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p2 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p3 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p4 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p5 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p6 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p7 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p8 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);

					// Left
					if (doXNegative && ((x == 0) || (x > 0 && GetActive(x - 1, y, z) == false)))
					{
						bool addSide = true;

						if ((x == 0))
						{
							Chunk* pChunk = m_pChunkManager->GetChunk(m_gridX - 1, m_gridY, m_gridZ);
							if (pChunk == NULL || pChunk->IsSetup())
							{
								addSide = pChunk != NULL && (pChunk->GetActive(CHUNK_SIZE - 1, y, z) == false);
							}
						}

						if (addSide)
						{
							int endX = (z / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;
							int endY = (y / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;

							if (m_pChunkManager->GetFaceMerging())
							{
								UpdateMergedSide(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE, &p6, &p1, &p4, &p7, z, y, endX, endY, false, false, true, false);
							}

							n1 = vec3(-1.0f, 0.0f, 0.0f);
							v1 = m_pRenderer->AddVertexToMesh(p6, n1, r, g, b, a, m_pMesh);
							t1 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 0.0f, m_pMesh);
							v2 = m_pRenderer->AddVertexToMesh(p1, n1, r, g, b, a, m_pMesh);
							t2 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 0.0f, m_pMesh);
							v3 = m_pRenderer->AddVertexToMesh(p4, n1, r, g, b, a, m_pMesh);
							t3 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 1.0f, m_pMesh);
							v4 = m_pRenderer->AddVertexToMesh(p7, n1, r, g, b, a, m_pMesh);
							t4 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 1.0f, m_pMesh);

							m_pRenderer->AddTriangleToMesh(v1, v2, v3, m_pMesh);
							m_pRenderer->AddTriangleToMesh(v1, v3, v4, m_pMesh);
						}
					}

					p1 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p2 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p3 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p4 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p5 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p6 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p7 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p8 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);

					// Top
					if (doYPositive && ((y == CHUNK_SIZE - 1) || (y < CHUNK_SIZE - 1 && GetActive(x, y + 1, z) == false)))
					{
						bool addSide = true;

						if ((y == CHUNK_SIZE - 1))
						{
							Chunk* pChunk = m_pChunkManager->GetChunk(m_gridX, m_gridY + 1, m_gridZ);
							if (pChunk == NULL || pChunk->IsSetup())
							{
								addSide = pChunk != NULL && (pChunk->GetActive(x, 0, z) == false);
							}
						}

						if (addSide)
						{
							int endX = (x / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;
							int endY = (z / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;

							if (m_pChunkManager->GetFaceMerging())
							{
								UpdateMergedSide(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE, &p7, &p8, &p3, &p4, x, z, endX, endY, true, false, false, true);
							}

							n1 = vec3(0.0f, 1.0f, 0.0f);
							v1 = m_pRenderer->AddVertexToMesh(p4, n1, r, g, b, a, m_pMesh);
							t1 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 0.0f, m_pMesh);
							v2 = m_pRenderer->AddVertexToMesh(p3, n1, r, g, b, a, m_pMesh);
							t2 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 0.0f, m_pMesh);
							v3 = m_pRenderer->AddVertexToMesh(p8, n1, r, g, b, a, m_pMesh);
							t3 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 1.0f, m_pMesh);
							v4 = m_pRenderer->AddVertexToMesh(p7, n1, r, g, b, a, m_pMesh);
							t4 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 1.0f, m_pMesh);

							m_pRenderer->AddTriangleToMesh(v1, v2, v3, m_pMesh);
							m_pRenderer->AddTriangleToMesh(v1, v3, v4, m_pMesh);
						}
					}

					p1 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p2 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p3 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p4 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z + BLOCK_RENDER_SIZE);
					p5 = vec3(x + BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p6 = vec3(x - BLOCK_RENDER_SIZE, y - BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p7 = vec3(x - BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);
					p8 = vec3(x + BLOCK_RENDER_SIZE, y + BLOCK_RENDER_SIZE, z - BLOCK_RENDER_SIZE);

					// Bottom
					if (doYNegative && ((y == 0) || (y > 0 && GetActive(x, y - 1, z) == false)))
					{
						bool addSide = true;

						if ((y == 0))
						{
							Chunk* pChunk = m_pChunkManager->GetChunk(m_gridX, m_gridY - 1, m_gridZ);
							if (pChunk == NULL || pChunk->IsSetup())
							{
								addSide = pChunk != NULL && (pChunk->GetActive(x, CHUNK_SIZE - 1, z) == false);
							}
						}

						if (addSide)
						{
							int endX = (x / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;
							int endY = (z / CHUNK_SIZE) * CHUNK_SIZE + CHUNK_SIZE;

							if (m_pChunkManager->GetFaceMerging())
							{
								UpdateMergedSide(l_merged, x, y, z, CHUNK_SIZE, CHUNK_SIZE, &p6, &p5, &p2, &p1, x, z, endX, endY, false, false, false, true);
							}

							n1 = vec3(0.0f, -1.0f, 0.0f);
							v1 = m_pRenderer->AddVertexToMesh(p6, n1, r, g, b, a, m_pMesh);
							t1 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 0.0f, m_pMesh);
							v2 = m_pRenderer->AddVertexToMesh(p5, n1, r, g, b, a, m_pMesh);
							t2 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 0.0f, m_pMesh);
							v3 = m_pRenderer->AddVertexToMesh(p2, n1, r, g, b, a, m_pMesh);
							t3 = m_pRenderer->AddTextureCoordinatesToMesh(1.0f, 1.0f, m_pMesh);
							v4 = m_pRenderer->AddVertexToMesh(p1, n1, r, g, b, a, m_pMesh);
							t4 = m_pRenderer->AddTextureCoordinatesToMesh(0.0f, 1.0f, m_pMesh);

							m_pRenderer->AddTriangleToMesh(v1, v2, v3, m_pMesh);
							m_pRenderer->AddTriangleToMesh(v1, v3, v4, m_pMesh);
						}
					}
				}
			}
		}
	}

	// Delete the merged array
	delete l_merged;
}
Exemple #19
0
int main()
{
  Point p1(-253.357, -123.36);
  Point p2(-190.03, 216.606);
  Point p3(-343.349, 286.6);
  Point p4(141.604, 279.934);
  Point p5(276.591, -46.7012);
  Point p6(251.593, -263.347);
  Point p7(-3.38184, -343.339);
  Point p8(-380.012, -173.355);
  Point p9(-98.3726, 39.957);
  Point p10(133.271, 124.949);
  Point p11(289.923, 301.598);
  Point p12(421.577, 23.292);
  Point p13(79.9434, -93.3633);
  Point p14(-40.0449, 366.592);
  Point p15(311.587, 374.924);
  Point p16(431.576, 214.94);
  Point p17(426.576, -131.693);
  Point p18(-265.023, -285.011);
  Point p19(369.915, 89.9521);
  Point p20(368.249, -15.0376);
  Point p21(484.904, 18.2925);
  Point p22(-411.675, 283.267);
  Point p23(-250.024, 124.949);
  Point p24(-80.041, -78.3647);
  Point p25(-360.014, 31.6245);
  Point p26(-305.019, 356.593);
  
  // built Delaunay triangulation
  PS.insert(p1); PS.insert(p2); PS.insert(p3); PS.insert(p4);
  PS.insert(p5); PS.insert(p6); PS.insert(p7); PS.insert(p8);  
  PS.insert(p9); PS.insert(p10); PS.insert(p11); PS.insert(p12);
  PS.insert(p13); PS.insert(p14); PS.insert(p15); PS.insert(p16);  
  PS.insert(p17); PS.insert(p18); PS.insert(p19); PS.insert(p20);
  PS.insert(p21); PS.insert(p22); PS.insert(p23); PS.insert(p24);
  PS.insert(p25); PS.insert(p26);
  
  std::list<Vertex_handle> LV;
  
  bool correct = true;
  
  // circle emptiness check
  Circle cs1(Point(-23.3799, 108.284), 1124.78);
  check_empty checker(cs1);
  
  CGAL::range_search(PS,cs1,std::back_inserter(LV),checker,true);
   
  if (checker.get_result()) {
    std::cout << "circle not empty !\n";
    std::cout <<  "this is an error !\n"; correct=false;
  }
  else std::cout << "circle was empty !\n";  
  
  Circle cs2(Point(-255.024, -100.029), 23551);
  check_empty checker2(cs2);
  
  CGAL::range_search(PS,cs2,std::back_inserter(LV),checker2,true);
   
  if (checker2.get_result()) std::cout << "circle not empty !\n";
  else {
    std::cout << "circle was empty !\n";   
    std::cout <<  "this is an error !\n"; correct=false;
  } 
  
  // triangle check
  Triangle t1(Point(-21.7134, -123.36), Point(84.9429, 74.9536), Point(209.931, -161.69)); 
  Triangle t2(Point(-61.7095, 164.945), Point(-88.3735, 101.618), Point(49.9463, 101.618));
  
  check_empty_triangle tchecker1(t1);
  CGAL::range_search(PS,t1.vertex(0),t1.vertex(1),t1.vertex(2),std::back_inserter(LV),tchecker1,true);
   
  if (tchecker1.get_result()) std::cout << "triangle not empty !\n";
  else {
    std::cout << "triangle was empty !\n";   
    std::cout <<  "this is an error !\n"; correct=false;
  }
  
  check_empty_triangle tchecker2(t2);
  CGAL::range_search(PS,t2.vertex(0),t2.vertex(1),t2.vertex(2),std::back_inserter(LV),tchecker2,true);
   
  if (tchecker2.get_result()) {
     std::cout << "triangle not empty !\n";
     std::cout <<  "this is an error !\n"; correct=false;
  }
  else std::cout << "triangle was empty !\n";   
  
  // rectangle check
  Rectangle_2 r1(-290.021, -175.022, -125.037, -35.0356);       
  Rectangle_2 r2(-48.3774, 136.614, -23.3799, 251.603);   

  check_empty_rectangle rchecker1(r1);
  CGAL::range_search(PS,r1.vertex(0),r1.vertex(1),r1.vertex(2),r1.vertex(3),std::back_inserter(LV),rchecker1,true);
   
  if (rchecker1.get_result()) std::cout << "rectangle not empty !\n";
  else {
    std::cout << "rectangle was empty !\n";
    std::cout <<  "this is an error !\n"; correct=false;
  }
   
  check_empty_rectangle rchecker2(r2);
  CGAL::range_search(PS,r2.vertex(0),r2.vertex(1),r2.vertex(2),r2.vertex(3),std::back_inserter(LV),rchecker2,true);
   
  if (rchecker2.get_result()) {
    std::cout << "rectangle not empty !\n";
    std::cout <<  "this is an error !\n"; correct=false;
  }
  else std::cout << "rectangle was empty !\n";
 
  if (correct) return 0;
  
  return 1;
}
void update_mission_brief_point(
        interfaceItemType *dataItem, long whichBriefPoint, const Scenario* scenario,
        coordPointType *corner, long scale, Rect *bounds, vector<inlinePictType>& inlinePict,
        Rect& highlight_rect, vector<pair<Point, Point> >& lines, String& text) {
    if (whichBriefPoint < kMissionBriefPointOffset) {
        // No longer handled here.
        return;
    }

    whichBriefPoint -= kMissionBriefPointOffset;

    Rect hiliteBounds;
    long            headerID, headerNumber, contentID;
    BriefPoint_Data_Get(whichBriefPoint, scenario, &headerID, &headerNumber, &contentID,
            &hiliteBounds, corner, scale, 16, 32, bounds);
    hiliteBounds.offset(bounds->left, bounds->top);

    // TODO(sfiera): catch exception.
    Resource rsrc("text", "txt", contentID);
    text.assign(macroman::decode(rsrc.data()));
    short textHeight = GetInterfaceTextHeightFromWidth(text, dataItem->style, kMissionDataWidth);
    if (hiliteBounds.left == hiliteBounds.right) {
        dataItem->bounds.left = (bounds->right - bounds->left) / 2 - (kMissionDataWidth / 2) + bounds->left;
        dataItem->bounds.right = dataItem->bounds.left + kMissionDataWidth;
        dataItem->bounds.top = (bounds->bottom - bounds->top) / 2 - (textHeight / 2) + bounds->top;
        dataItem->bounds.bottom = dataItem->bounds.top + textHeight;
    } else {
        if ((hiliteBounds.left + (hiliteBounds.right - hiliteBounds.left) / 2) >
                (bounds->left + (bounds->right - bounds->left) / 2)) {
            dataItem->bounds.right = hiliteBounds.left - kMissionDataHBuffer;
            dataItem->bounds.left = dataItem->bounds.right - kMissionDataWidth;
        } else {
            dataItem->bounds.left = hiliteBounds.right + kMissionDataHBuffer;
            dataItem->bounds.right = dataItem->bounds.left + kMissionDataWidth;
        }

        dataItem->bounds.top = hiliteBounds.top + (hiliteBounds.bottom - hiliteBounds.top) / 2 -
                                textHeight / 2;
        dataItem->bounds.bottom = dataItem->bounds.top + textHeight;
        if (dataItem->bounds.top < (bounds->top + kMissionDataTopBuffer)) {
            dataItem->bounds.top = bounds->top + kMissionDataTopBuffer;
            dataItem->bounds.bottom = dataItem->bounds.top + textHeight;
        }
        if (dataItem->bounds.bottom > (bounds->bottom - kMissionDataBottomBuffer)) {
            dataItem->bounds.bottom = bounds->bottom - kMissionDataBottomBuffer;
            dataItem->bounds.top = dataItem->bounds.bottom - textHeight;
        }

        if (dataItem->bounds.left < (bounds->left + kMissionDataVBuffer)) {
            dataItem->bounds.left = bounds->left + kMissionDataVBuffer;
            dataItem->bounds.right = dataItem->bounds.left + kMissionDataWidth;
        }
        if (dataItem->bounds.right > (bounds->right - kMissionDataVBuffer)) {
            dataItem->bounds.right = bounds->right - kMissionDataVBuffer;
            dataItem->bounds.left = dataItem->bounds.right - kMissionDataWidth;
        }

        hiliteBounds.right++;
        hiliteBounds.bottom++;
        highlight_rect = hiliteBounds;
        Rect newRect;
        GetAnyInterfaceItemGraphicBounds(*dataItem, &newRect);
        lines.clear();
        if (dataItem->bounds.right < hiliteBounds.left) {
            Point p1(hiliteBounds.left, hiliteBounds.top);
            Point p2(newRect.right + kMissionLineHJog, hiliteBounds.top);
            Point p3(newRect.right + kMissionLineHJog, newRect.top);
            Point p4(newRect.right + 2, newRect.top);
            lines.push_back(make_pair(p1, p2));
            lines.push_back(make_pair(p2, p3));
            lines.push_back(make_pair(p3, p4));

            Point p5(hiliteBounds.left, hiliteBounds.bottom - 1);
            Point p6(newRect.right + kMissionLineHJog, hiliteBounds.bottom - 1);
            Point p7(newRect.right + kMissionLineHJog, newRect.bottom - 1);
            Point p8(newRect.right + 2, newRect.bottom - 1);
            lines.push_back(make_pair(p5, p6));
            lines.push_back(make_pair(p6, p7));
            lines.push_back(make_pair(p7, p8));
        } else {
            Point p1(hiliteBounds.right, hiliteBounds.top);
            Point p2(newRect.left - kMissionLineHJog, hiliteBounds.top);
            Point p3(newRect.left - kMissionLineHJog, newRect.top);
            Point p4(newRect.left - 3, newRect.top);
            lines.push_back(make_pair(p1, p2));
            lines.push_back(make_pair(p2, p3));
            lines.push_back(make_pair(p3, p4));

            Point p5(hiliteBounds.right, hiliteBounds.bottom - 1);
            Point p6(newRect.left - kMissionLineHJog, hiliteBounds.bottom - 1);
            Point p7(newRect.left - kMissionLineHJog, newRect.bottom - 1);
            Point p8(newRect.left - 3, newRect.bottom - 1);
            lines.push_back(make_pair(p5, p6));
            lines.push_back(make_pair(p6, p7));
            lines.push_back(make_pair(p7, p8));
        }
    }
    dataItem->item.labeledRect.label.stringID = headerID;
    dataItem->item.labeledRect.label.stringNumber = headerNumber;
    Rect newRect;
    GetAnyInterfaceItemGraphicBounds(*dataItem, &newRect);
    populate_inline_picts(dataItem->bounds, text, dataItem->style, inlinePict);
}
Exemple #21
0
int main(int argc, char **argv)
{
  plan_tests(46);

  // test constructor
  GeoPoint p1(Angle::Degrees(fixed(345.32)), Angle::Degrees(fixed(-6.332)));
  ok1(equals(p1, -6.332, 345.32));

  // test normalize()
  p1.Normalize();
  ok1(equals(p1, -6.332, -14.68));

  // test parametric()
  GeoPoint p2(Angle::Degrees(fixed_two), Angle::Degrees(fixed_one));
  GeoPoint p3 = p1.Parametric(p2, fixed(5));
  ok1(equals(p3, -1.332, -4.68));

  // test interpolate
  GeoPoint p4 = p1.Interpolate(p3, fixed_half);
  ok1(equals(p4, -3.832, -9.68));

  GeoPoint p5 = p1.Interpolate(p3, fixed(0.25));
  ok1(equals(p5, -5.082, -12.18));

  // test *
  GeoPoint p6 = p2 * fixed(3.5);
  ok1(equals(p6, 3.5, 7));

  // test +
  p6 = p6 + p2;
  ok1(equals(p6, 4.5, 9));

  // test +=
  p6 += p2;
  ok1(equals(p6, 5.5, 11));

  // test -
  p6 = p6 - p2;
  ok1(equals(p6, 4.5, 9));

  // test sort()
  ok1(!p1.Sort(p3));
  ok1(p3.Sort(p1));
  ok1(!p1.Sort(p4));
  ok1(p4.Sort(p1));
  ok1(!p1.Sort(p5));
  ok1(p5.Sort(p1));
  ok1(!p4.Sort(p3));
  ok1(p3.Sort(p4));
  ok1(!p5.Sort(p3));
  ok1(p3.Sort(p5));
  ok1(!p5.Sort(p4));
  ok1(p4.Sort(p5));

  // test distance()
  //
  // note: distance between p1 and p4 and between p3 and p4 is not
  // the same due to linear interpolation instead of real geographic
  // intermediate point calculation
  ok1(equals(p2.Distance(p6), 869326.653160));
  ok1(equals(p6.Distance(p2), 869326.653160));
  ok1(equals(p1.Distance(p5), 309562.219016));
  ok1(equals(p1.Distance(p4), 619603.149273));
  ok1(equals(p1.Distance(p3), 1240649.267606));
  ok1(equals(p3.Distance(p4), 621053.760625));

  // test bearing()
  //
  // note: the bearings p1 -> p5, p5 -> p4 and so on are not the same due to
  // linear interpolation instead of real geographic intermediate point
  // calculation
  ok1(equals(p2.Bearing(p6), 63.272424));
  ok1(equals(p6.Bearing(p2), 243.608847));
  ok1(equals(p1.Bearing(p5), 63.449343));
  ok1(equals(p1.Bearing(p4), 63.582620));
  ok1(equals(p1.Bearing(p3), 63.784526));
  ok1(equals(p5.Bearing(p4), 63.466726));
  ok1(equals(p5.Bearing(p3), 63.646072));
  ok1(equals(p4.Bearing(p3), 63.540756));
  ok1(equals(p5.Bearing(p6), 65.982854));
  ok1(equals(p2.Bearing(p3), 250.786774));

  // test distance_bearing()
  // note: should be the same output as bearing() and distance()
  GeoVector v = p2.DistanceBearing(p6);
  ok1(equals(v.distance, 869326.653160));
  ok1(equals(v.bearing, 63.272424));

  // test intermediate_point()
  GeoPoint p7(Angle::Degrees(fixed_zero), Angle::Degrees(fixed_zero));
  GeoPoint p8 = p7.IntermediatePoint(p2, fixed(100000));
  ok1(equals(p8, 0.402274, 0.804342));
  ok1(equals(p8.Distance(p7), 100000));
  GeoPoint p9 = p7.IntermediatePoint(p2, fixed(100000000));
  ok1(equals(p9, p2));

  // test projected_distance()
  ok1(equals(p8.ProjectedDistance(p7, p2), 100000));
  ok1(equals(p4.ProjectedDistance(p1, p3), 619599.304393));
  ok1(equals((p2 * fixed_two).ProjectedDistance(p2, p6), 248567.832772));

  // Tests moved here from test_fixed.cpp
  GeoPoint l1(Angle::Zero(), Angle::Zero());
  GeoPoint l2(Angle::Degrees(fixed(-0.3)), Angle::Degrees(fixed(1.0)));
  GeoPoint l3(Angle::Degrees(fixed(0.00001)), Angle::Degrees(fixed_zero));
  GeoPoint l4(Angle::Degrees(fixed(10)), Angle::Degrees(fixed_zero));

  v = l1.DistanceBearing(l2);
  printf("Dist %g bearing %d\n",
         FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees()));
  // 116090 @ 343

  v = l1.DistanceBearing(l3);
  printf("Dist %g bearing %d\n",
         FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees()));
  ok(positive(v.distance) && v.distance < fixed_two, "earth distance short", 0);

  v = l1.DistanceBearing(l4);
  printf("Dist %g bearing %d\n",
         FIXED_DOUBLE(v.distance), FIXED_INT(v.bearing.Degrees()));

  return exit_status();
}
Exemple #22
0
bool UniformGrid::intersectsCell(const Model& model, const CellCoord& coord) {
  // Left side
  // Bottom left point
  Point3D p0 = pointAt(coord);
  Point3D p1(p0[0], p0[1] + cellSize, p0[2]);
  Point3D p2(p0[0], p0[1] + cellSize, p0[2] + cellSize);
  Point3D p3(p0[0], p0[1], p0[2] + cellSize);

  // Right side
  Point3D p4(p0[0] + cellSize, p0[1], p0[2]);
  Point3D p5(p0[0] + cellSize, p0[1] + cellSize, p0[2]);
  Point3D p6(p0[0] + cellSize, p0[1] + cellSize, p0[2] + cellSize);
  Point3D p7(p0[0] + cellSize, p0[1], p0[2] + cellSize);

  const std::vector<Point3D> pts = {p0, p1, p2, p3, p4, p5, p6, p7};

  auto cellMat = translationMatrix(p0[0], p0[1], p0[2]) * cellSizeScaleMatrix;
  // But we need the inverse of course
  cellMat = cellMat.invert();

  // Check if a pt is in the cell
  auto inCell = [&] (const Point3D& pt) -> bool {
    return p0[0] <= pt[0] && pt[0] <= (p0[0] + cellSize) &&
           p0[1] <= pt[1] && pt[1] <= (p0[1] + cellSize) &&
           p0[2] <= pt[2] && pt[2] <= (p0[2] + cellSize);
  };

  // First, we need to get the 8 points of the bounding box
  auto bbox = model.getBoundingBox();

  auto inBoundingBox = [&bbox] (const Point3D& pt) -> bool {
    // We are in the box if we are in between all the opposite parallel planes
    const auto c1 = bbox[0]; // Bottom back left corner
    const auto v1a = bbox[1] - c1; // Bottom back left to bottom back right
    const auto v1b = bbox[3] - c1; // Bottom back left to top back left
    const auto v1c = bbox[4] - c1; // Bottom back left to bottom front left
    const auto n1 = v1a.cross(v1b); // Back face
    const auto n2 = v1b.cross(v1c); // Left face
    const auto n3 = v1c.cross(v1a); // Bottom face

    const auto c2 = bbox[6]; // Top front right corner
    const auto v2a = bbox[5] - c2; // Top front right to bottom front right
    const auto v2b = bbox[7] - c2; // Top front right to top front left
    const auto v2c = bbox[2] - c2; // Top front right to top back right
    // We want this to be opposite sign (i.e. not pointing inwards)
    // so we do the opposite cross as above
    const auto n4 = v2b.cross(v2a); // Front face
    const auto n5 = v2c.cross(v2b); // Top face
    const auto n6 = v2a.cross(v2c); // Right face

    return betweenPlanes(n1, c1, n4, c2, pt) &&
           betweenPlanes(n2, c1, n6, c2, pt) &&
           betweenPlanes(n3, c1, n5, c2, pt);
  };

  // A corner of the bbox being inside the cell implies an intersection
  // between the bbox and the cell.
  for (const auto& pt : bbox) {
    if (inCell(pt)) {
      return true;
    }
  }

  // Similarly, a corner of cell inside bbox implies intersection
  for (const auto& pt : pts) {
    if (inBoundingBox(pt)) {
      return true;
    }
  }

  // Check if any of the 12 lines from bbox intersect this cell
  HitRecord hr;
  for (size_t i = 0; i < 8; ++i) {
    // This is the vector of one edge
    Vector3D v = bbox[(i % 4 == 0) ? i + 3 : i - 1] - bbox[i];
    Ray ray(bbox[i] - v, bbox[i]);
    if (utilityCube.intersects(ray, &hr, cellMat) && 1 <= hr.t && hr.t <= 2) {
      // This edge of the bounding box intersects our cell cube.
      return true;
    }
  }
  for (size_t i = 0; i < 4; ++i) {
    Vector3D v = bbox[i + 4] - bbox[i];
    Ray ray(bbox[i] - v, bbox[i]);
    if (utilityCube.intersects(ray, &hr, cellMat) && 1 <= hr.t && hr.t <= 2) {
      // This edge of the bounding box intersects our cell cube.
      return true;
    }
  }

  // Now check if any of the 12 lines from this cell intersect the model
  for (size_t i = 0; i < pts.size(); ++i) {
    Vector3D v = pts[(i % 4 == 0) ? i + 3 : i - 1] - pts[i];
    // Note: We are doing pts[i] - v and checking for t between 1 and 2.
    // This is equivalent to checking between 0 and 1 without doing the
    // subtraction, *but* we have an epsilon check in the intersects code.
    // For this case, we do *not* want to bother with epsilon check, so we
    // will check from 1 to 2 to avoid it.
    if (model.intersects(Ray(pts[i] - v, pts[i]), &hr)) {
      if (1 <= hr.t && hr.t <= 2) {
        return true;
      }
    }
  }

  // Now we have to check the struts between the two sides
  for (size_t i = 0; i < 4; ++i) {
    Vector3D v = pts[i + 4] - pts[i];
    if (model.intersects(Ray(pts[i] - v, pts[i]), &hr)) {
      if (1 <= hr.t && hr.t <= 2) {
        return true;
      }
    }
  }

  return false;
}
Exemple #23
0
void BGcubeD_D::BGdraw() {
    glPushMatrix();
    
    const dReal* pos = dGeomGetPosition(boxGeom_m);
    glColor3f(r_m/255, g_m/255, b_m/255);
    
    tex1.activate();
   
    
    // THIS IS WHERE THE DRAWING HAPPENS!
    // The front face :)
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1); p5(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1); p8(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0); p7(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0); p6(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Right face
    tex2.activate();
    
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1);p8(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1);p4(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0);p3(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0);p7(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Left face
    tex3.activate();
    
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1);p5(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1);p6(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0);p2(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0);p1(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Top face
    tex4.activate();
    
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1);p6(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1);p7(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0);p3(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0);p2(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Bottom face
    tex5.activate();
    
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1); p4(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1); p8(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0); p5(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0); p1(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Back face
    tex6.activate();
    
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1); p1(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1); p2(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0); p3(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0); p4(pos[0],pos[1],pos[2],h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    glPopMatrix();
}
Exemple #24
0
void cubeD_D::draw() {
    glPushMatrix();

    orient_body_in_opengl(boxBody_m);

    glColor3f(r_m/255, g_m/255, b_m/255);
    tex1.activate();
    // THIS IS WHERE THE DRAWING HAPPENS!
    // The front face :)
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1); p5(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1); p8(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0); p7(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0); p6(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Right face
    tex2.activate();
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1);p8(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1);p4(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0);p3(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0);p7(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    // Left face
    tex3.activate();
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1);p5(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1);p6(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0);p2(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0);p1(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.

    // Top face
    tex4.activate();
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1);p6(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1);p7(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0);p3(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0);p2(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.

    // Bottom face
    tex5.activate();
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1); p4(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1); p8(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0); p5(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0); p1(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.

    // Back face
    tex6.activate();
    glBegin(GL_QUADS); // All OpenGL drawing begins with a glBegin.
    glTexCoord2f(0, 1); p1(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 1); p2(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(1, 0); p3(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glTexCoord2f(0, 0); p4(0,0,0,h_m,w_m,d_m,r_m,g_m,b_m);
    glEnd(); // All OpenGL drawing ends with a glEnd.
    
    glPopMatrix();
}
Exemple #25
0
    virtual void on_draw()
    {
        pixfmt pf(rbuf_window());
        renderer_base ren_base(pf);
        ren_base.clear(agg::rgba(1.0, 1.0, 0.95));
        renderer_scanline ren(ren_base);

        rasterizer_scanline ras;
        scanline sl;

        // Pattern source. Must have an interface:
        // width() const
        // height() const
        // pixel(int x, int y) const
        // Any agg::renderer_base<> or derived
        // is good for the use as a source.
        //-----------------------------------
        pattern_src_brightness_to_alpha p1(rbuf_img(0));
        pattern_src_brightness_to_alpha p2(rbuf_img(1));
        pattern_src_brightness_to_alpha p3(rbuf_img(2));
        pattern_src_brightness_to_alpha p4(rbuf_img(3));
        pattern_src_brightness_to_alpha p5(rbuf_img(4));
        pattern_src_brightness_to_alpha p6(rbuf_img(5));
        pattern_src_brightness_to_alpha p7(rbuf_img(6));
        pattern_src_brightness_to_alpha p8(rbuf_img(7));
        pattern_src_brightness_to_alpha p9(rbuf_img(8));

        agg::pattern_filter_bilinear_rgba<color_type> fltr;           // Filtering functor

        // agg::line_image_pattern is the main container for the patterns. It creates
        // a copy of the patterns extended according to the needs of the filter.
        // agg::line_image_pattern can operate with arbitrary image width, but if the 
        // width of the pattern is power of 2, it's better to use the modified
        // version agg::line_image_pattern_pow2 because it works about 15-25 percent
        // faster than agg::line_image_pattern (because of using simple masking instead 
        // of expensive '%' operation). 
        typedef agg::line_image_pattern<agg::pattern_filter_bilinear_rgba<color_type> > pattern_type;
        typedef agg::renderer_base<pixfmt> base_ren_type;
        typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_type;
        typedef agg::rasterizer_outline_aa<renderer_type>                rasterizer_type;

        //-- Create with specifying the source
        //pattern_type patt(fltr, src);   

        //-- Create uninitialized and set the source
        pattern_type patt(fltr);        
        renderer_type ren_img(ren_base, patt);
        rasterizer_type ras_img(ren_img);

        draw_curve(patt, ras_img, ren_img, p1, m_curve1.curve());
        draw_curve(patt, ras_img, ren_img, p2, m_curve2.curve());
        draw_curve(patt, ras_img, ren_img, p3, m_curve3.curve());
        draw_curve(patt, ras_img, ren_img, p4, m_curve4.curve());
        draw_curve(patt, ras_img, ren_img, p5, m_curve5.curve());
        draw_curve(patt, ras_img, ren_img, p6, m_curve6.curve());
        draw_curve(patt, ras_img, ren_img, p7, m_curve7.curve());
        draw_curve(patt, ras_img, ren_img, p8, m_curve8.curve());
        draw_curve(patt, ras_img, ren_img, p9, m_curve9.curve());

        agg::render_ctrl(ras, sl, ren_base, m_curve1);
        agg::render_ctrl(ras, sl, ren_base, m_curve2);
        agg::render_ctrl(ras, sl, ren_base, m_curve3);
        agg::render_ctrl(ras, sl, ren_base, m_curve4);
        agg::render_ctrl(ras, sl, ren_base, m_curve5);
        agg::render_ctrl(ras, sl, ren_base, m_curve6);
        agg::render_ctrl(ras, sl, ren_base, m_curve7);
        agg::render_ctrl(ras, sl, ren_base, m_curve8);
        agg::render_ctrl(ras, sl, ren_base, m_curve9);

        agg::render_ctrl(ras, sl, ren_base, m_scale_x);
        agg::render_ctrl(ras, sl, ren_base, m_start_x);
    }
Exemple #26
0
void CContainers::prepareMemBuffers()
{
	memout=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p("!data",memout);
	memmap.insert(p);

	memout_words=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p2("!!!words",memout_words);
	memmap.insert(p2);

	memout_letters=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p3("!!letters",memout_letters);
	memmap.insert(p3);

	memout_num=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p4("!num",memout_num);
	memmap.insert(p4);

	memout_year=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p5("!year",memout_year);
	memmap.insert(p5);

	memout_date=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p6("!date",memout_date);
	memmap.insert(p6);

	memout_words2=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p7("!!!words2",memout_words2);
	memmap.insert(p7);

	memout_words3=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p8("!!!words3",memout_words3);
	memmap.insert(p8);

	memout_words4=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p9("!!!words4",memout_words4);
	memmap.insert(p9);

	memout_pages=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p10("!pages",memout_pages);
	memmap.insert(p10);

	memout_num2=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p11("!num2",memout_num2);
	memmap.insert(p11);

	memout_num3=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p12("!num3",memout_num3);
	memmap.insert(p12);

	memout_num4=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p13("!num4",memout_num4);
	memmap.insert(p13);

	memout_remain=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p14("!remain",memout_remain);
	memmap.insert(p14);

	memout_date2=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p15("!date2",memout_date2);
	memmap.insert(p15);

	memout_date3=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p16("!date3",memout_date3);
	memmap.insert(p16);

	memout_num2b=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p17("!num2b",memout_num2b);
	memmap.insert(p17);

	memout_num3b=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p18("!num3b",memout_num3b);
	memmap.insert(p18);

	memout_num4b=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p19("!num4b",memout_num4b);
	memmap.insert(p19);

	memout_numb=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p20("!numb",memout_numb);
	memmap.insert(p20);

	memout_num2c=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p21("!num2c",memout_num2c);
	memmap.insert(p21);

	memout_num3c=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p22("!num3c",memout_num3c);
	memmap.insert(p22);

	memout_num4c=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p23("!num4c",memout_num4c);
	memmap.insert(p23);

	memout_numc=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p24("!numc",memout_numc);
	memmap.insert(p24);

	memout_time=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p25("!time",memout_time);
	memmap.insert(p25);

	memout_remain2=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p26("!remain2",memout_remain2);
	memmap.insert(p26);

	memout_ip=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p27("!ip",memout_ip);
	memmap.insert(p27);

	memout_hm=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p28("!hm",memout_hm);
	memmap.insert(p28);

	memout_hms=new CMemoryBuffer();
	std::pair<std::string,CMemoryBuffer*> p29("!hms",memout_hms);
	memmap.insert(p29);
}
Exemple #27
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bound_Ptr_Test"));


  // =========================================================================
  // The following test uses the ACE_Strong_Bound_Ptr in a single
  // thread of control, hence we use the ACE_Null_Mutex

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) performing synchronous test...\n")));

  Parent *parent1 = 0;
  ACE_NEW_RETURN (parent1,
                  Parent,
                  -1);
  ACE_Weak_Bound_Ptr<Parent, ACE_Null_Mutex> p8;
  {
    // Must get the pointer from the parent object's weak_self_ member.
    ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p(parent1->weak_self_);
    ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p1(p);
    ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p2(p);
    ACE_Weak_Bound_Ptr<Parent, ACE_Null_Mutex> p3(p);
    ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p4(p);
    ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p5 = p2;
    ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p6 = p3;
    ACE_Weak_Bound_Ptr<Parent, ACE_Null_Mutex> p7(p1);
    p8 = p2;
    p->child_->do_something ();
  }
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) Parent instance count is %d, expecting 0\n"),
              Parent::instance_count_));
  if (Parent::instance_count_ != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("(%t) parent instance count not 0...\n")),
                         -1);
    }
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) Child instance count is %d, expecting 0\n"),
              Child::instance_count_));
  if (Child::instance_count_ != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("(%t) child instance count not 0...\n")),
                         -1);
    }
  // Weak pointer should now be set to null.
  if(!p8.null ())
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("(%t) p8 not nill...\n")),
                         -1);
    }

  Printer *printer1 = 0;
  ACE_NEW_RETURN (printer1,
                  Printer ("I am printer 1"),
                  -1);
  ACE_Weak_Bound_Ptr<Printer, ACE_Null_Mutex> r9;
  {
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r(printer1);
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r1(r);
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r2(r);
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r3(r);
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r4(r);
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r5 = r2;
    ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r6 = r1;
    ACE_Weak_Bound_Ptr<Printer, ACE_Null_Mutex> r7(r1);
    ACE_Weak_Bound_Ptr<Printer, ACE_Null_Mutex> r8 = r2;
    r9 = r3;
    r9->print ();
  }
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) Printer instance count is %d, expecting 0\n"),
              Printer::instance_count_));
  if (Printer::instance_count_ != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("(%t) Printer instance count not 0...\n")),
                         -1);
    }
  // Weak pointer should now be set to null.
  if (!r9.null ())
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("(%t) r9 not nill...\n")),
                         -1);
    }

#if defined (ACE_HAS_THREADS)

  // =========================================================================
  // The following test uses the ACE_Strong_Bound_Ptr in multiple
  // threads of control.

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) performing asynchronous test...\n")));

  Scheduler *scheduler_ptr = 0;

  // Create active objects..
  ACE_NEW_RETURN (scheduler_ptr,
                  Scheduler (),
                  -1);

  ACE_Strong_Bound_Ptr<Scheduler, ACE_Null_Mutex> scheduler(scheduler_ptr);

  if (scheduler->open () == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("(%t) Scheduler open failed...\n")),
                         -1);
    }

  {
    Printer *printer2 = 0;
    ACE_NEW_RETURN (printer2,
                    Printer ("I am printer 2"),
                    -1);

    // Ownership is transferred from the auto_ptr to the strong pointer.
    auto_ptr<Printer> a (printer2);
    Printer_var r (a);

    for (int i = 0; i < n_loops; i++)
      // Spawn off the methods, which run in a separate thread as
      // active object invocations.
      scheduler->print (r);
  }

  // Close things down.
  scheduler->end ();

  scheduler->wait ();

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) Printer instance count is %d, expecting 0\n"),
              Printer::instance_count_));
  if (Printer::instance_count_ != 0)
    return -1;

#endif /* ACE_HAS_THREADS */
  ACE_END_TEST;

  return 0;
}
Exemple #28
0
void Render ()
{
   LoadFPS (60);
   glClearColor (250/255.0, 245/255.0, 245/255.0, 1);
   srand (time (NULL) );
   //at global scope
   static float currentRayAngle = 0;
   currentRayAngle += 6;
   //calculate points of ray


   b2Vec2 p1 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) ); //center of scene
   b2Vec2 p2 = p1 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle  ) ),
                                        cosf ( DEGTORAD * (currentRayAngle ) ) );

   b2Vec2 p3 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) );
   b2Vec2 p4 = p3 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle + 90) ),
                                        cosf ( DEGTORAD * (currentRayAngle + 90) ) );

   b2Vec2 p5 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) ); //center of scene
   b2Vec2 p6 = p5 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle + 180) ),
                                        cosf ( DEGTORAD * (currentRayAngle + 180) ) );

   b2Vec2 p7 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) );
   b2Vec2 p8 = p7 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle + 270 ) ),
                                        cosf ( DEGTORAD * (currentRayAngle + 270 ) ) );
   b2Vec2 p9 =  b2Vec2 (agent->body->GetPosition ().x ,
                        agent->body->GetPosition ().y  - 4 ) ;
   b2Vec2 p10 = b2Vec2 (agent->body->GetPosition ().x ,
                        agent->body->GetPosition ().y - 4 )  + rayLength / 2.0 * b2Vec2 (sinf ( (
                                 agent->angle + 1.57) ),
                              cosf ( ( agent->angle + 1.57  ) ) );

   b2Vec2 p11 =  b2Vec2 (agent->body->GetPosition ().x ,
                         agent->body->GetPosition ().y + 4  ) ;
   b2Vec2 p12 = b2Vec2 (agent->body->GetPosition ().x,
                        agent->body->GetPosition ().y + 4   )  + rayLength / 2.0  * b2Vec2 (sinf ( (
                                 agent->angle + 1.57) ),
                              cosf ( ( agent->angle + 1.57 ) ) );

   b2RayCastInput input;
   input.p1 = p1;
   input.p2 = p2;
   input.maxFraction = rayLength / 50.0;

   b2RayCastInput input2;
   input2.p1 = p3;
   input2.p2 = p4;
   input2.maxFraction = rayLength / 50.0;

   b2RayCastInput input3;
   input3.p1 = p5;
   input3.p2 = p6;
   input3.maxFraction = rayLength / 50.0 ;

   b2RayCastInput input4;
   input4.p1 = p7;
   input4.p2 = p8;
   input4.maxFraction = rayLength / 50.0;

   b2RayCastInput input5;
   input5.p1 = p9;
   input5.p2 = p10;
   input5.maxFraction = rayLength / 50.0;

   b2RayCastInput input6;
   input6.p1 = p11;
   input6.p2 = p12;
   input6.maxFraction = rayLength / 50.0;

   //check every fixture of every body to find closest
   float closestFraction = rayLength / 50.0; //start with end of line as p2
   float closestFraction2 = rayLength / 50.0 ;
   float closestFraction3 =  rayLength / 50.0;
   float closestFraction4 =  rayLength / 50.0;
   float closestFraction5 = rayLength / 50.0;
   float closestFraction6 = rayLength / 50.0;
   static int timer = 0;
   timer++;
   b2Vec2 intersectionNormal (0, 0);

   bool isObstacle[5] = {0} ;
   static int freeAngle[5] = {0};
   freeAngle[1] = agent->angle;
   static int count = 0 ;
   /*
    * Raycasting is done here, there are 6 ray here
   */
   for (b2Body * b = myWorld.GetBodyList (); b; b = b->GetNext () )
   {
      if (100 == (int) b->GetUserData () )
      { break; }
      for (b2Fixture * f = b->GetFixtureList (); f; f = f->GetNext () )
      {
         b2RayCastOutput output;

         if ( f->RayCast ( &output, input, 0 ) )
         {
            if ( output.fraction < closestFraction )
            {
               isObstacle[1] = 1;

               count = 0 ;
               closestFraction = output.fraction;
               intersectionNormal = output.normal;
               b2Vec2 intersectionPoint = p1 + closestFraction * (p2 - p1);
               b2Vec2 diff1  =  agent->body->GetPosition () - intersectionPoint;

               int x = diff1.x / (800 / 80.0) ;
               int y = diff1.y / (600 / 60.0) ;
               carCollisionMap[20 - y][20 - x] = 1;
            }
         }

         b2RayCastOutput output2;
         if (f->RayCast (&output2, input2, 0) )
         {
            if (output2.fraction < closestFraction)
            {
               isObstacle[2] = 1;
               closestFraction2 = output2.fraction;
               b2Vec2 intersectionPoint2 = p3 + closestFraction2 * (p4 - p3);

               b2Vec2 diff2 =  agent->body->GetPosition () - intersectionPoint2;
               int x = diff2.x / (800 / 80.0) ;
               int y = diff2.y / (600 / 60.0) ;
               carCollisionMap[20 - y][20 - x] = 1;
            }

         }
         b2RayCastOutput output3;
         if (f->RayCast (&output3, input3, 0) )
         {
            if (output3.fraction < closestFraction3)
            {
               isObstacle[3] = 1;
               closestFraction3 = output3.fraction;
               b2Vec2 intersectionPoint3 = p5 + closestFraction3 * (p6 - p5);

               b2Vec2 diff2 =  agent->body->GetPosition () - intersectionPoint3;
               int x = diff2.x / (800 / 80.0) ;
               int y = diff2.y / (600 / 60.0) ;
               carCollisionMap[20 - y][20 - x] = 1;
            }
         }

         b2RayCastOutput output4;
         if (f->RayCast (&output4, input4, 0) )
         {
            if (output4.fraction < closestFraction4)
            {
               isObstacle[4] = 1;
               closestFraction4 = output4.fraction;
               b2Vec2 intersectionPoint4 = p7 + closestFraction4 * (p8 - p7);

               b2Vec2 diff2 =  agent->body->GetPosition () - intersectionPoint4;
               int x = diff2.x / (800 / 80.0) ;
               int y = diff2.y / (600 / 60.0) ;
               carCollisionMap[20 - y][20 - x] = 1;
            }
         }

         b2RayCastOutput output5;
         if (f->RayCast (&output5, input5, 0) )
         {
            if (output5.fraction < closestFraction5)
            {
               closestFraction5 = output5.fraction;
               b2Vec2 intersectionPoint5 = p9 + closestFraction5 * (p10 - p9);

               b2Vec2 diff2 =  agent->body->GetPosition () - intersectionPoint5;
               int x = diff2.x / (800 / 80.0) ;
               int y = diff2.y / (600 / 60.0) ;
               carCollisionMap[20 - y][20 - x] = 1;
               agent->frontObstacle = 1;
            }
         }
         b2RayCastOutput output6;
         if (f->RayCast (&output6, input6, 0) )
         {
            if (output6.fraction < closestFraction6)
            {
               closestFraction6 = output6.fraction;
               b2Vec2 intersectionPoint6 = p11 + closestFraction6 * (p12 - p11);

               b2Vec2 diff2 =  agent->body->GetPosition () - intersectionPoint6;
               int x = diff2.x / (800 / 80.0) ;
               int y = diff2.y / (600 / 60.0) ;
               carCollisionMap[20 - y][20 - x] = 1;
               agent->frontObstacle = 1;
            }
         }
      }
   }

   static float timetem= glutGet(GLUT_ELAPSED_TIME);
   if(glutGet(GLUT_ELAPSED_TIME)-timetem > 1000)
   for (int i = 1 ; i <= 4; ++i)
   {
      if (isObstacle[i] == false)
      {
         float tempAngle;
         tempAngle = (int) (currentRayAngle + 90 * (i - 1) ) % 360;

         if (tempAngle >= converToDegree (agent->angle) && tempAngle <= (int) (converToDegree (agent->angle) + 180) % 360)
         {
            if (agent->nearestAngle[RIGHT_SIDE] > tempAngle - converToDegree (agent->angle) )
            {
               agent->nearestAngle[RIGHT_SIDE] = tempAngle - converToDegree (agent->angle) ;

            }
            else
            { isObstacle[i] = true; }
         }
         else
         {
            if (agent->nearestAngle[LEFT_SIDE] > (360 - tempAngle) - converToDegree (agent->angle) )
            { agent->nearestAngle[LEFT_SIDE] = fabs ( (360 - tempAngle) - converToDegree (agent->angle) ); }
            else
            { isObstacle[i] = true; }
         }

      }
      timetem= glutGet(GLUT_ELAPSED_TIME);
   }


// if no obstacle is infront of behicle and destination is set, then head for the destination
// this is done by changing vehicle angle to face the destination



   b2Vec2 intersectionPoint  = p1  + closestFraction  * (p2 - p1);
   b2Vec2 intersectionPoint2 = p3  + closestFraction2 * (p4 - p3);
   b2Vec2 intersectionPoint3 = p5  + closestFraction3 * (p6 - p5);
   b2Vec2 intersectionPoint4 = p7  + closestFraction4 * (p8 - p7);
   b2Vec2 intersectionPoint5 = p9  + closestFraction4 * (p10 - p9);
   b2Vec2 intersectionPoint6 = p11 + closestFraction4 * (p12 - p11);
   float dist = (agent->body->GetPosition().x - intersectionPoint5.x) * (agent->body->GetPosition().x - intersectionPoint5.x)
               + (agent->body->GetPosition().y - intersectionPoint5.y) * (agent->body->GetPosition().x - intersectionPoint5.y);
   //draw a line
   glColor3f (255, 0, 0); //white
   glBegin (GL_LINES);
   glVertex2f ( p1.x, p1.y );
   glVertex2f ( intersectionPoint.x, intersectionPoint.y );
   glEnd ();

   SetRenderColor (0, 0, 0, 255);
   if (isObstacle[1] == false)
   { SetRenderColor (255, 0, 255, 255); }
   //draw a point at the intersection point
   glPointSize (10);

   glBegin (GL_POINTS);
   glVertex2f ( intersectionPoint.x, intersectionPoint.y );
   glEnd ();

   SetRenderColor (255, 34, 25, 255);
   glBegin (GL_POINTS);
   glVertex2f ( destination.x, destination.y );
   glEnd ();

   glBegin (GL_LINES);
   glVertex2f ( p3.x, p3.y );
   glVertex2f ( intersectionPoint2.x, intersectionPoint2.y );
   glEnd ();

   glBegin (GL_LINES);
   glVertex2f ( p5.x, p5.y );
   glVertex2f ( intersectionPoint3.x, intersectionPoint3.y );
   glEnd ();

   glBegin (GL_LINES);
   glVertex2f ( p7.x, p7.y );
   glVertex2f ( intersectionPoint4.x, intersectionPoint4.y );
   glEnd ();

   glBegin (GL_LINES);
   glVertex2f ( p9.x, p9.y );
   glVertex2f ( intersectionPoint5.x, intersectionPoint5.y );
   glEnd ();
   glBegin (GL_POINTS);
   glVertex2f ( intersectionPoint5.x, intersectionPoint5.y );
   glEnd ();
   glBegin (GL_LINES);
   glVertex2f ( p11.x, p11.y );
   glVertex2f ( intersectionPoint6.x, intersectionPoint6.y );
   glEnd ();

   glBegin (GL_POINTS);
   glVertex2f ( intersectionPoint6.x, intersectionPoint6.y );
   glEnd ();
   SetRenderColor (0, 0, 0, 255);
   if (isObstacle[2] == false)
   { SetRenderColor (255, 0, 255, 255); }
   glPointSize (10);
   glBegin (GL_POINTS);
   glVertex2f ( intersectionPoint2.x, intersectionPoint2.y );
   glEnd ();


   SetRenderColor (0, 0, 0, 255);
   if (isObstacle[3] == false)
   { SetRenderColor (255, 0, 255, 255); }
   glBegin (GL_POINTS);
   glVertex2f ( intersectionPoint3.x, intersectionPoint3.y );
   glEnd ();


   SetRenderColor (0, 0, 0, 255);
   if (isObstacle[4] == false)
   { SetRenderColor (255, 0, 255, 255); }

   glBegin (GL_POINTS);
   glVertex2f ( intersectionPoint4.x, intersectionPoint4.y );
   glEnd ();

//   glBegin (GL_LINES);
//   glVertex2f ( agent->body->GetPosition ().x, agent->body->GetPosition ().y );
//   glVertex2f ( agent->body->GetPosition ().x + sin (agent->angle + 1.57) * 100,
//                agent->body->GetPosition ().y + cos (agent->angle + 1.57) * 100);
//   glEnd ();

   static float posx = 0;
   posx = posx + .1;
// we are drawing collision array here
   for (int i = 0; i < 40; ++i)
      for (int j = 0; j < 40; ++j)
      {
         if (carCollisionMap[i][j] == 1)
         {
            glPointSize (5);
            glBegin (GL_POINTS);
            glVertex2f (agent->body->GetPosition ().x -  (20 - j) * 10 ,
                        agent->body->GetPosition ().y -  (20 - i) * 10 );

            glEnd ();
         }
      }

   turnToDestination();
   turnToNearestAngle ();
   agent->isCollision = 0;

//  checking collision here, not so important now
   for (int i = 1; i < 15; ++i)
   {
      float x = 20  + (i * 2) * sinf (agent->angle + 1.57) ;
      float y = 20  +  (i * 2) * cosf (agent->angle + 1.57);
      if (x < 40 && y < 40)
         if (carCollisionMap[ (int) y][ (int) x] == 1)
         {
//               printf ("obstacle found\n");
            agent->isCollision = 1;
            static float timerT = glutGet (GLUT_ELAPSED_TIME);
            bool safe = 1;
            safe = rand () % 2;
            if (!agent->frontObstacle)
               if (agent->nearestAngle[LEFT_SIDE] != 1000 || agent->nearestAngle[RIGHT_SIDE] != 1000)
               {
//                  if (glutGet (GLUT_ELAPSED_TIME) - timerT > 500)
                  {
                     if (agent->nearestAngle[LEFT_SIDE] < agent->nearestAngle[RIGHT_SIDE])
                     {
                        printf ("Left side wins %f\n", agent->nearestAngle[LEFT_SIDE]);
                        agent->angle = agent->angle - .2;
                        agent->foundNearestAngle = true;
//                  agent->nearestAngle[RIGHT_SIDE] = 1000;
                     }
                     else
                     {
                        printf ("Right side wins %f\n", agent->nearestAngle[RIGHT_SIDE]);
                        agent->foundNearestAngle = true;
//                  agent->nearestAngle[LEFT_SIDE] = 1000;
                        agent->angle = agent->angle + .2;
                     }
                 timerT = glutGet (GLUT_ELAPSED_TIME);
                  }
               }
//            if (glutGet (GLUT_ELAPSED_TIME) - timerT > 1000)
//            {
//
//               if (safe == 1)
//                  for (int j = 0; j < 10; ++j)
//                  {
//                     float x = 20 + ( (j ) * sinf (agent->angle + 1.57 + .3) ) ;
//                     float y = 20 + ( (j ) * cosf (agent->angle + 1.57 + .3) ) ;
//
//                     if (carCollisionMap[ (int) y][ (int) x] == 1)
//                     {
//                        safe = 0;
//                        break;
//                     }
//                  }
//               if (safe == 1)
//               { agent->angle = agent->angle + .3; }
//               {
//                  memset (carCollisionMap, 0, sizeof (carCollisionMap) );
//               }
//               if (safe == 0)
//               {
//                  safe = 1;
//                  for (int j = 0; j < 10; ++j)
//                  {
//                     float x = 20 + ( (j ) * sinf (agent->angle + 1.57 - .3) ) ;
//                     float y = 20 + ( (j ) * cosf (agent->angle + 1.57 - .3) ) ;
//                     if (carCollisionMap[ (int) y][ (int) x] == 1)
//                     {
//                        safe = 0;
//                        break;
//                     }
//                  }
//                  if (safe == 1)
//                  {
//                     agent->angle = agent->angle - .3;
//                     memset (carCollisionMap, 0, sizeof (carCollisionMap) );
//                  }
//               }
//               timerT = glutGet (GLUT_ELAPSED_TIME);
//            }

         }
   }

   agent->moveForward ();
   SetRenderColor (0, 0, 0, 255);

   RenderBitmapText (60, 550, GLUT_BITMAP_9_BY_15, "ctrl + left click to add obstacle, alt + left click to add a destination");

   sprintf (fps, "%f", GetFps () );
   SetRenderColor (255, 0, 255, 255);
   RenderBitmapText (10, 590, GLUT_BITMAP_9_BY_15, fps);

   myWorld.DrawDebugData ();

}
Exemple #29
0
void GfxMesh::addCube(float _size, Vec3f _pos, Vec4f _color, bool _front, bool _back, bool _right, bool _left, bool _top, bool _bottom)
{
	_size /= 2.0f;

	Vec3f p0(_pos.x - _size, _pos.y - _size, _pos.z + _size);
	Vec3f p1(_pos.x + _size, _pos.y - _size, _pos.z + _size);
	Vec3f p2(_pos.x + _size, _pos.y + _size, _pos.z + _size);
	Vec3f p3(_pos.x - _size, _pos.y + _size, _pos.z + _size);
	Vec3f p4(_pos.x + _size, _pos.y - _size, _pos.z - _size);
	Vec3f p5(_pos.x - _size, _pos.y - _size, _pos.z - _size);
	Vec3f p6(_pos.x - _size, _pos.y + _size, _pos.z - _size);
	Vec3f p7(_pos.x + _size, _pos.y + _size, _pos.z - _size);

	Vec3f n;

	unsigned int v0, v1, v2, v3, v4, v5, v6, v7;

	// Front
	if (_front)
	{
		n = Vec3f(0.0f, 0.0f, 1.0f);

		v0 = addVertex(p0, n, _color);
		v1 = addVertex(p1, n, _color);
		v2 = addVertex(p2, n, _color);
		v3 = addVertex(p3, n, _color);

		addTriangle(v0, v1, v2);
		addTriangle(v0, v2, v3);
	}

	// Back
	if (_back)
	{
		n = Vec3f(0.0f, 0.0f, -1.0f);

		v4 = addVertex(p4, n, _color);
		v5 = addVertex(p5, n, _color);
		v6 = addVertex(p6, n, _color);
		v7 = addVertex(p7, n, _color);

		addTriangle(v4, v5, v6);
		addTriangle(v4, v6, v7);
	}

	// Right
	if (_right)
	{
		n = Vec3f(1.0f, 0.0f, 0.0f);

		v1 = addVertex(p1, n, _color);
		v4 = addVertex(p4, n, _color);
		v7 = addVertex(p7, n, _color);
		v2 = addVertex(p2, n, _color);

		addTriangle(v1, v4, v7);
		addTriangle(v1, v7, v2);
	}

	// Left
	if (_left)
	{
		n = Vec3f(-1.0f, 0.0f, 0.0f);

		v5 = addVertex(p5, n, _color);
		v0 = addVertex(p0, n, _color);
		v3 = addVertex(p3, n, _color);
		v6 = addVertex(p6, n, _color);

		addTriangle(v5, v0, v3);
		addTriangle(v5, v3, v6);
	}

	// Top
	if (_top)
	{
		n = Vec3f(0.0f, 1.0f, 0.0f);

		v3 = addVertex(p3, n, _color);
		v2 = addVertex(p2, n, _color);
		v7 = addVertex(p7, n, _color);
		v6 = addVertex(p6, n, _color);

		addTriangle(v3, v2, v7);
		addTriangle(v3, v7, v6);
	}

	// Bottom
	if (_bottom)
	{
		n = Vec3f(0.0f, -1.0f, 0.0f);

		v5 = addVertex(p5, n, _color);
		v4 = addVertex(p4, n, _color);
		v1 = addVertex(p1, n, _color);
		v0 = addVertex(p0, n, _color);

		addTriangle(v5, v4, v1);
		addTriangle(v5, v1, v0);
	}
}
/**
@SYMTestCaseID			SYSLIB-SQL-CT-1628
@SYMTestCaseDesc		GetFirstSqlStmt() test
						Tests the GetFirstSqlStmt() behaviour with a set of various SQL statements.
@SYMTestPriority		High
@SYMTestActions			GetFirstSqlStmt() test
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ5792
                        REQ5793
*/	
void TestGetFirstSqlStmt()
	{
	TPtrC res;

	TBuf<1> b2; b2.Append(TChar(0));
	TPtr p2(PTR_ARG(b2));
	res.Set(GetFirstSqlStmt(p2));
	//Expected result: res = "\x0", p2 is NULL
	TEST(res == b2);
	TEST(!p2.Ptr());
		
	TBuf<2> b3; b3.Append(TChar(' ')); b3.Append(TChar(0));
	TPtr p3(PTR_ARG(b3));
	res.Set(GetFirstSqlStmt(p3));
	//Expected result: res = " \x0", p3 is NULL
	TEST(res == b3);
	TEST(!p3.Ptr());
	
	TBuf<7> b4(_L(";; ;  ")); b4.Append(TChar(0));
	TPtr p4(PTR_ARG(b4));
	res.Set(GetFirstSqlStmt(p4));
	//Expected result: res = "\x0", p4 = "; ;  \x0"
	TEST(res.Length() == 1 && (TInt)res[0] == 0);
	TInt accLen = res.Length();
	TEST(p4 == b4.Right(b4.Length() - accLen));

	res.Set(GetFirstSqlStmt(p4));
	//Expected result: res = "\x0", p4 = " ;  \x0"
	TEST(res.Length() == 1 && (TInt)res[0] == 0);
	accLen += res.Length();
	TEST(p4 == b4.Right(b4.Length() - accLen));
	
	res.Set(GetFirstSqlStmt(p4));
	//Expected result: res = " \x0", p4 = "  \x0"
	TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == 0);
	accLen += res.Length();
	TEST(p4 == b4.Right(b4.Length() - accLen));
	
	res.Set(GetFirstSqlStmt(p4));
	//Expected result: res = "  \x0", p4 is NULL
	TEST((TInt)res[0] == (TInt)TChar(' ') && (TInt)res[1] == (TInt)TChar(' ') && (TInt)res[2] == 0);
	TEST(!p4.Ptr());
	
	TBuf<20> b5(_L("SELECT * FROM A")); b5.Append(TChar(0));
	TPtr p5(PTR_ARG(b5));
	res.Set(GetFirstSqlStmt(p5));
	//Expected result: res = "SELECT * FROM A\x0", p5 is NULL
	TEST(res == b5);
	TEST(!p5.Ptr());
	
	TBuf<20> b6(_L("SELECT * FROM A;")); b6.Append(TChar(0));
	TPtr p6(PTR_ARG(b6));
	res.Set(GetFirstSqlStmt(p6));
	//Expected result: res = "SELECT * FROM A\x0", p6 = "\x0"
	TEST(res == b6.Left(b6.Length() - 1));
	TEST(p6.Length() == 1 && p6[0] == 0);

	TBuf<40> b7(_L("/** Comment */ SELECT * FROM A;")); b7.Append(TChar(0));
	TPtr p7(PTR_ARG(b7));
	res.Set(GetFirstSqlStmt(p7));
	//Expected result: res = "/** Comment */ SELECT * FROM A\x0", p7 = "\x0"
	TEST(res == b7.Left(b7.Length() - 1));
	TEST(p7.Length() == 1 && p7[0] == 0);

	TBuf<40> b8(_L(" SELECT * FROM --Comment \r\n A;")); b8.Append(TChar(0));
	TPtr p8(PTR_ARG(b8));
	res.Set(GetFirstSqlStmt(p8));
	//Expected result: res = " SELECT * FROM --Comment \r\n A\x0", p8 = "\x0"
	TEST(res == b8.Left(b8.Length() - 1));
	TEST(p8.Length() == 1 && p8[0] == 0);

	TBuf<40> b9(_L("SELECT * FROM A; SELECT * FROM B")); b9.Append(TChar(0));
	TPtr p9(PTR_ARG(b9));
	res.Set(GetFirstSqlStmt(p9));
	//Expected result: res = "SELECT * FROM A\x0", p9 = " SELECT * FROM B\x0"
	TEST(res.Left(res.Length() - 1) == b9.Left(res.Length() - 1) && (TInt)res[res.Length() - 1] == 0);
	accLen = res.Length();
	TEST(p9 == b9.Right(b9.Length() - accLen));

	res.Set(GetFirstSqlStmt(p9));
	//Expected result: res = " SELECT * FROM B\x0", p9 is NULL
	TEST(res == b9.Right(b9.Length() - accLen));
	TEST(!p9.Ptr());

	//Defect INC113060	
	TBuf<255> b10(_L("UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473"));
	TPtr p10(PTR_ARG(b10));
	res.Set(GetFirstSqlStmt(p10));
	//Expected results: res= original string
	TEST(res.Compare(b10)==0);
	TEST(!p10.Ptr());
	
	TBuf<255> firstStmt(_L("SELECT * FROM PlayList"));firstStmt.Append(TChar(0));
	TBuf<255> b11(_L("SELECT * FROM PlayList;UPDATE Playlist SET Name=';',Time='2007-09-20 12:31:33' WHERE UniqueId=640397473"));
	TPtr p11(PTR_ARG(b11));
	res.Set(GetFirstSqlStmt(p11));
	TEST(res.Compare(firstStmt)==0);
	TEST(p11.Compare(b10)==0);
	}