Exemple #1
0
void TGLFunWidget::drawTriangle3D(TVertex3D* vertex)
{
    TVertex3D tmp;

    if (predicate.length())
    {
        if (fabs(vertex[0].u) < predicate.toFloat())
          vertex[0].u = 0;
        if (fabs(vertex[1].u) < predicate.toFloat())
          vertex[1].u = 0;
        if (fabs(vertex[2].u) < predicate.toFloat())
          vertex[2].u = 0;
    }
    vertex[0].c = getColorIndex(vertex[0].u);
    vertex[1].c = getColorIndex(vertex[1].u);
    vertex[2].c = getColorIndex(vertex[2].u);
    if ((vertex[0].c == vertex[1].c) && (vertex[1].c == vertex[2].c))
    {
        glBegin(GL_TRIANGLES);
            setColor(colorTable[vertex[0].c].red(),colorTable[vertex[0].c].green(),colorTable[vertex[0].c].blue(),params.alpha);
            vertex[0].setVertex();
            vertex[1].setVertex();
            vertex[2].setVertex();
        glEnd();
        return;
    }
    sort(vertex);
    if (vertex[2].u < vertex[1].u)
    {
        swap(vertex[2],vertex[1]);
        vertex[0].invertNormal();
        vertex[1].invertNormal();
        vertex[2].invertNormal();
    }
    if (vertex[0].c != vertex[1].c)
    {
        if (vertex[1].c != vertex[2].c)
        {
            createVertex(tmp,vertex[2],vertex[0],vertex[1].u);
            triangle1(vertex[0],tmp, vertex[1]);
            triangle2(tmp,vertex[1],vertex[2]);
        }
        else
            triangle1(vertex[0], vertex[2], vertex[1]);
    }
    else if (vertex[1].c != vertex[2].c)
        triangle2(vertex[0], vertex[1], vertex[2]);
}
TEST(TrapezoidalMotion, TriangleRampUp) {
	float posOut, speedOut;
	bool pathValid = triangle1(1, posOut, speedOut);
	EXPECT_EQ(pathValid, true);
	EXPECT_NEAR(posOut, 0.5*0.5, 0.001);
	EXPECT_NEAR(speedOut, 0.5, 0.001);
}
Exemple #3
0
int main(void){
	triangle1();
	printf("\n");
	triangle2();
	printf("\n");
	triangle3();
	printf("\n");
	triangle4();
	return 0;
}
TEST(TriangleTest, equality)
{
	double p_a_x = 0, p_a_y = 1, p_a_z = 2;
	double p_b_x = 3, p_b_y = 4, p_b_z = 5;
	double p_c_x = 6, p_c_y = 7, p_c_z = 8;
	Geom::Point3D p_a(p_a_x, p_a_y, p_a_z);
	Geom::Point3D p_b(p_b_x, p_b_y, p_b_z);
	Geom::Point3D p_c(p_c_x, p_c_y, p_c_z);

	Geom::Triangle triangle1(p_a, p_b, p_c);
	Geom::Triangle triangle2(p_a, p_b, p_c);
	EXPECT_EQ(triangle1, triangle2);

	Geom::Triangle triangle3(p_a, p_b, p_b);
	EXPECT_NE(triangle1, triangle3);
}
Exemple #5
0
TEST(KDTree, shouldSupportTriangles) {

  KDTree tree;
  vector<RTShape*> shapes;
  RTTriangle triangle0(Vector(0.1,0.1,0.1), Vector(1,1,1), Vector(0.1,2,0.1));
  RTTriangle triangle1(Vector(-0.1,-0.1,-0.1), Vector(-1,-1,-1), Vector(-0.1,-2,-0.1));
  shapes.push_back(&triangle0);
  shapes.push_back(&triangle1);

  BoundingBox box(Vector(-1,-2,-1), Vector(2,4,2));
  tree.setBoundingBox(box);
  tree.build(shapes, 0);
  
  CHECK_EQUAL( 1, tree.getLeft()->size() );
  CHECK_EQUAL( 1, tree.getRight()->size() );

}
Exemple #6
0
int main(void) {

  printf("<!-- hello.c -->\n");
  char name[MAX] = "henry";
  printf("hello %s!\n",name);

  printf("\n<!-- declare4Types.c -->\n");
  char c='A';
  int i = 1;
  float f = 12.0;
  double d = 12.12;
  printf("%c, %d, %f, %f\n",c,i,f,d);

  printf("\n<!-- circle.c -->\n");
  const float PI = 3.14159;
  int radius = 10;
  float area = PI * radius * radius;
  float circumference = 2 * PI * radius;
  printf("%f, %f\n", area, circumference );

  printf("\n<!-- operators.c -->\n");
  int a=17,b=5;
  printf("%d  %d  %d  %d\n", a+b, a-b, a*b, a/b);

  printf("\n<!-- inputName.c -->\n");
  char myName[MAX];
  int myAge;
  scanf("%s",myName);
  scanf("%d",&myAge);
  printf("%s is %d years old.\n", myName, myAge );

  printf("\n<!-- circle2.c -->\n");
  scanf("%d", &radius);
  printf("%f, %f\n", PI * radius * radius, 2 * PI * radius );

  printf("\n<!-- evenNum.c -->\n");
  int num[5];
  scanf("%d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4]);
  printf("even number: %d-%d-%d\n",num[0],num[2],num[4]);

  printf("\n<!-- string.c -->\n");
  char line1[MAX];
  char line2[MAX];
  char line3[MAX];
  scanf("%s",line1);
  scanf("%s",line2);
  scanf("%s",line3);
  printf("%s\n%s\n%s\n", line1,line2,line3);

  printf("\n<!-- charOfString.c -->\n");
  char charOfString[5];
  scanf("%s", charOfString);
  for (int i=0;i<5;i++){
    printf("%c-->", charOfString[i] );
  }
  printf("\n");

  printf("\n<!-- sumOfArray.c -->\n");
  int sumOfArray[2][3] = {{1,2,3},{4,5,6}};

  int result;
  for(int i=0;i<2;i++){
    result=0;
    for(int j=0;j<3;j++){
      result+=sumOfArray[i][j];
    }
    printf("%d\n", result);
  }
  int col[3]={0,0,0};
  for(int i=0;i<2;i++){
    for(int j=0;j<3;j++){
      col[j]+=sumOfArray[i][j];
    }
  }
  printf("%d %d %d\n",col[0],col[1],col[2]);

  printf("\n<!-- structScanf.c -->\n");
  struct person{
    char name[10];
    int age;
    float salary;
  };
  struct person teacher;
  scanf("%s",teacher.name);
  scanf("%d", &teacher.age);
  scanf("%f", &teacher.salary);
  printf("%s is %d years old. %f\n", teacher.name, teacher.age, teacher.salary);

  printf("\n<!-- unionScanf.c -->\n");
  union money{
    int student;
    double teacher;
  };

  union money henry;
  scanf("%d", &henry.student);
  scanf("%lf", &henry.teacher);
  printf("%d\n", henry.student);
  printf("%10.2lf\n", henry.teacher);

  printf("\n<!-- enumShow.c -->\n");
  enum color {
    white=100,
    red,
    blue,
    green,
    black
  };
  enum color ball;
  ball=white;
  printf("white: %d\n",ball);
  ball=green;
  printf("green: %d\n",ball);

  printf("\n<!-- structTypedefInput.c -->\n");
  // typedef struct {
  //     char name[10];
  //     int age;
  //     float salary;
  // } Person;
  Person teacher_lin;
  scanf("%s",teacher_lin.name);
  scanf("%d", &teacher_lin.age);
  scanf("%f", &teacher_lin.salary);
  printf("%s is %d years old. %f\n", teacher_lin.name, teacher_lin.age, teacher_lin.salary);

  printf("\n<!-- defineCircle.c -->\n");
  scanf("%d", &radius);
  printf("%f, %f\n", DEFINE_PI * radius * radius, 2 * DEFINE_PI * radius );

  printf("\n<!-- defineTypedef.c -->\n");
  printf("please see structTypedefInput.c\n");

  printf("\n<!-- triangle.c -->\n");
  triangle1();
  printf("\n");
  triangle2();
  printf("\n");
  triangle3();
  printf("\n");
  triangle4();

  printf("\n<!-- rectangle.c -->\n");
  int rectN,rectM,rectD;
  scanf("%d %d %d", &rectN, &rectM, &rectD );
  for (int i=1;i<=rectD;i++){
    for (int j=1;j<=rectN;j++){
      printf("%c", '*');
    }
    printf("\n");
  }
  for (int i=1;i<=rectM-rectD*2;i++){
    for (int j=1;j<=rectD;j++){
      printf("%c", '*');
    }
    for (int j=1;j<=rectN-rectD*2;j++){
      printf("%c", ' ');
    }
    for (int j=1;j<=rectD;j++){
      printf("%c", '*');
    }
    printf("\n");
  }
  for (int i=1;i<=rectD;i++){
    for (int j=1;j<=rectN;j++){
      printf("%c", '*');
    }
    printf("\n");
  }

  printf("\n<!-- rectangle_star.c -->\n");
  int rect_star_num=20;
  int rect_star_mod=0;
  while (rect_star_mod==0){
    printf("input odd:");
    scanf("%d",&rect_star_num);
    rect_star_mod=rect_star_num%2;
  }
  a=(rect_star_num+1)/2;
	for(int b=1;b<=a;b++)
	{
		for(int d=a-b;d>0;d--)
		{
		printf(" ");
		}
		for(int e=1;e<=2*b-1;e++)
		{
			printf("*");
		}
		printf("\n");
	}
	for(int b=a-1;b>0;b--)
	{
		for(int d=a-b;d>0;d--)
		{
			printf(" ");
		}
		for(int e=1;e<=2*b-1;e++)
		{
			printf("*");
		}
		printf("\n");//換行
	}

  printf("\n<!-- id.c -->\n");
  int isOK = parse_str("11111115");
  if (isOK) {
    printf("%s\n", "OK");
  } else {
    printf("%s\n", "nOK");
  }
  isOK = parse_int(22222220);
  if (isOK) {
    printf("%s\n", "OK");
  } else {
    printf("%s\n", "nOK");
  }


}
int ColorMapBulletNewApproachVolumeSampling(int argc, char** argv, boost::shared_ptr<ElVis::Model> model, unsigned int width, unsigned int height, const std::string& outFilePath)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(100, 100);
    glutCreateWindow("fake");

    boost::shared_ptr<ElVis::Scene> scene(new ElVis::Scene());
    scene->SetModel(model);

    boost::shared_ptr<ElVis::Cylinder> cylinder(new ElVis::Cylinder());
    cylinder->GetTransformationMatrix()[11] = 2.0;

    cylinder->GetTransformationMatrix()[0] = .10001f;
    cylinder->GetTransformationMatrix()[5] = .10001f;
    cylinder->GetTransformationMatrix()[10] = .4f;
   
    
    ElVis::PointLight* l = new ElVis::PointLight();
    ElVis::Color lightColor;
    lightColor.SetRed(.5);
    lightColor.SetGreen(.5);
    lightColor.SetBlue(.5);

    ElVis::WorldPoint lightPos(10.0, 0.0, 0.0);
    l->SetColor(lightColor);
    l->SetPosition(lightPos);
    scene->AddLight(l);

    ElVis::Color ambientColor;
    ambientColor.SetRed(.5);
    ambientColor.SetGreen(.5);
    ambientColor.SetBlue(.5);
    scene->SetAmbientLightColor(ambientColor);
    
    boost::shared_ptr<ElVis::Triangle> triangle1(new ElVis::Triangle());
    triangle1->SetP0(ElVis::WorldPoint(0, -1, 0));
    triangle1->SetP1(ElVis::WorldPoint(0, -1, 18));
    triangle1->SetP2(ElVis::WorldPoint(0, 1, 18));

    boost::shared_ptr<ElVis::Triangle> triangle2(new ElVis::Triangle());
    triangle2->SetP0(ElVis::WorldPoint(0, -1, 0));
    triangle2->SetP2(ElVis::WorldPoint(0, 1, 0));
    triangle2->SetP1(ElVis::WorldPoint(0, 1, 18));
  
    ElVis::Cylinder* cylinderToMap = new ElVis::Cylinder();
    cylinderToMap->GetTransformationMatrix()[11] = 0;

    cylinderToMap->GetTransformationMatrix()[0] = .1f;
    cylinderToMap->GetTransformationMatrix()[5] = .1f;
    cylinderToMap->GetTransformationMatrix()[10] = 20.0f;

    boost::shared_ptr<ElVis::PrimaryRayModule> primaryRayModule(new ElVis::PrimaryRayModule());
    boost::shared_ptr<ElVis::SampleVolumeSamplerObject> t1Sampler(new ElVis::SampleVolumeSamplerObject(triangle1));
    boost::shared_ptr<ElVis::SampleVolumeSamplerObject> t2Sampler(new ElVis::SampleVolumeSamplerObject(triangle2));
    //boost::shared_ptr<ElVis::SurfaceObject> cylinderSurface(new ElVis::SurfaceObject(cylinder));
    boost::shared_ptr<ElVis::SampleVolumeSamplerObject> cylinderSurface(new ElVis::SampleVolumeSamplerObject(cylinder));
    primaryRayModule->AddObject(t1Sampler);
    primaryRayModule->AddObject(t2Sampler);
    primaryRayModule->AddObject(cylinderSurface);

    boost::shared_ptr<ElVis::ColorMapperModule> colorMapperModule(new ElVis::ColorMapperModule());

    boost::shared_ptr<ElVis::TextureColorMap> textureColorMapper(new ElVis::TextureColorMap(ElVis::GetColorMapPath() + "/diverging257.cmap"));
    textureColorMapper->SetMin(-.12);
    textureColorMapper->SetMax(0);
    colorMapperModule->SetColorMap(textureColorMapper);
   
    
    ElVis::Camera c;

    // Zoomed to region of interest.
    //c.SetParameters(ElVis::WorldPoint(.5, 0, 1.5), ElVis::WorldPoint(0, 0, 1.5), ElVis::WorldVector(0, 1, 0));

    // Overall view
    //c.SetParameters(ElVis::WorldPoint(6, 0, 3.5), ElVis::WorldPoint(0, 0, 3.5), ElVis::WorldVector(0, 1, 0));

    //c.SetParameters(ElVis::WorldPoint(1.8, 1.2, 3.0), ElVis::WorldPoint(0, 0, 1), ElVis::WorldVector(0, 1, 0));
    c.SetParameters(ElVis::WorldPoint(1.8, .46, 3.7), ElVis::WorldPoint(0, 0, 2.7), ElVis::WorldVector(0, 1, 0));

    boost::shared_ptr<ElVis::SceneView> view(new ElVis::SceneView());
    view->SetCamera(c);
    
    boost::shared_ptr<ElVis::LightingModule> lighting(new ElVis::LightingModule());


    view->AddRenderModule(primaryRayModule);
    view->AddRenderModule(colorMapperModule);
    view->AddRenderModule(lighting);
    view->SetScene(scene);
    view->Resize(width, height);
    
    //view->GetScene()->SetEnableOptixTrace(true);
    //ElVis::Point<int, ElVis::TwoD> pixel1(10, 10);
    //view->GetScene()->SetOptixTracePixelIndex(pixel1);
    
    view->Draw();

    //std::cout << "Second pixel." << std::endl;
    //ElVis::Point<int, ElVis::TwoD> pixel(10, 1000-10-1);
    //view->GetScene()->SetOptixTracePixelIndex(pixel);
    //view->Draw();

    //ElVis::Point<int, ElVis::TwoD> pixel2(10, 1000-10-1);
    //view->GetScene()->SetOptixTracePixelIndex(pixel2);
    //view->GetScene()->SetEnableOptixTrace(true);
    //view->Draw();



    view->WriteColorBufferToFile(outFilePath.c_str());
    return 0;
}
void mainDriverShape(){
    
    int inputShape = 0;
    cout << "Choose the number below." << endl;
    cout << "1. Triangle" << endl;
    cout << "2. Rectangle" << endl;
    cin >> inputShape;
    
    int inputOperator;
    cout << "Choose the number below." << endl;
    cout << "1. Add operator OL" << endl;
    cout << "2. Deduct operator OL" << endl;
    cout << "3. Multiply operator OL" << endl;
    cout << "4. Divide operator OL" << endl;
    cin >> inputOperator;
    
    double inputHeight1;
    double inputWidth1;
    double inputHeight2;
    double inputWidth2;
    cout << "Enter the number for height of shape1 you chose." << endl;
    cin >> inputHeight1;
    cout << "Enter the number for width of shape1 you chose." << endl;
    cin >> inputWidth1;
    cout << "Enter the number for height of shape2 you chose." << endl;
    cin >> inputHeight2;
    cout << "Enter the number for width of shape2 you chose." << endl;
    cin >> inputWidth2;
    
    switch (inputShape) {
        case TRI:{
            Triangle triangle1(inputHeight1, inputWidth1);
            Triangle triangle2(inputHeight2, inputWidth2);
            switch (inputOperator) {
                case ADD:{
                    Triangle result = triangle1 + triangle2;
                    cout << result.getArea() << endl;
                    }
                    break;
                case SUB:{
                    Triangle result = triangle1 - triangle2;
                    cout << result.getArea() << endl;
                    }
                    
                    break;
                case MUITI:{
                    Triangle result = triangle1 * triangle2;
                    cout << result.getArea() << endl;
                    }
                    
                    break;
                case DIVIDE:{
                    Triangle result = triangle1 / triangle2;
                    cout << result.getArea() << endl;
                    }
                    break;
                    
                default:
                    break;
            }
            break;
        }
//        case REC:{
//            Rectangle rectangle1(inputHeight1, inputWidth1);
//            Rectangle rectangle2(inputHeight2, inputWidth2);
//            switch (inputOperator) {
//                case ADD:{
//                    Rectangle result = rectangle1 + rectangle2;
//                    cout << result.getArea() << endl;
//                }
//                    break;
//                case SUB:{
//                    Rectangle result = rectangle1 + rectangle2;
//                    cout << result.getArea() << endl;
//                }
//                    
//                    break;
//                case MUITI:{
//                    Rectangle result = rectangle1 + rectangle2;
//                    cout << result.getArea() << endl;
//                }
//                    
//                    break;
//                case DIVIDE:{
//                    Rectangle result = rectangle1 + rectangle2;
//                    cout << result.getArea() << endl;
//                }
//                    break;
//                    
//                default:
//                    break;
//            }
//            break;
//        }
        
        default:
        cout << "You have chosen wrong number for Shape: "<< inputShape <<endl;
            break;
    }
    
}
Exemple #9
0
qreal QGLBezierPatch::intersection
    (qreal result, int depth, const QRay3D& ray, bool anyIntersection,
     qreal xtex, qreal ytex, qreal wtex, qreal htex, QVector2D *tc)
{
    // Check the convex hull of the patch for an intersection.
    // If no intersection with the convex hull, then there is
    // no point subdividing this patch further.
    QBox3D box;
    for (int point = 0; point < 16; ++point)
        box.unite(points[point]);
    if (!box.intersects(ray))
        return result;

    // Are we at the lowest point of subdivision yet?
    if (depth <= 1) {
        // Divide the patch into two triangles and intersect with those.
        QTriangle3D triangle1(points[0], points[3], points[12]);
        qreal t = triangle1.intersection(ray);
        if (!qIsNaN(t)) {
            result = combineResults(result, t);
            if (result == t) {
                QVector2D uv = triangle1.uv(ray.point(t));
                QVector2D tp(xtex, ytex);
                QVector2D tq(xtex + wtex, ytex);
                QVector2D tr(xtex, ytex + htex);
                *tc = uv.x() * tp + uv.y() * tq + (1 - uv.x() - uv.y()) * tr;
            }
        } else {
            QTriangle3D triangle2(points[3], points[15], points[12]);
            qreal t = triangle2.intersection(ray);
            if (!qIsNaN(t)) {
                result = combineResults(result, t);
                if (result == t) {
                    QVector2D uv = triangle2.uv(ray.point(t));
                    QVector2D tp(xtex + wtex, ytex);
                    QVector2D tq(xtex + wtex, ytex + htex);
                    QVector2D tr(xtex, ytex + htex);
                    *tc = uv.x() * tp + uv.y() * tq + (1 - uv.x() - uv.y()) * tr;
                }
            }
        }
    } else {
        // Subdivide the patch to find the point of intersection.
        QGLBezierPatch patch1, patch2, patch3, patch4;
        subDivide(patch1, patch2, patch3, patch4);
        --depth;
        qreal hwtex = wtex / 2.0f;
        qreal hhtex = htex / 2.0f;
        result = patch1.intersection
            (result, depth, ray, anyIntersection,
             xtex, ytex, hwtex, hhtex, tc);
        if (anyIntersection && !qIsNaN(result))
            return result;
        result = patch2.intersection
            (result, depth, ray, anyIntersection,
             xtex + hwtex, ytex, hwtex, hhtex, tc);
        if (anyIntersection && !qIsNaN(result))
            return result;
        result = patch3.intersection
            (result, depth, ray, anyIntersection,
             xtex, ytex + hhtex, hwtex, hhtex, tc);
        if (anyIntersection && !qIsNaN(result))
            return result;
        result = patch4.intersection
            (result, depth, ray, anyIntersection,
             xtex + hwtex, ytex + hhtex, hwtex, hhtex, tc);
    }
    return result;
}