TEST(SphereRayIntersection, SimpleRay2)
{
    shapes::Sphere shape(1.0);
    bodies::Body* sphere = new bodies::Sphere(&shape);
    sphere->setScale(1.05);

    Eigen::Vector3d ray_o(5, 0, 0);
    Eigen::Vector3d ray_d(1, 0, 0);
    EigenSTL::vector_Vector3d p;
    bool intersect = sphere->intersectsRay(ray_o, ray_d, &p);

    delete sphere;
    EXPECT_FALSE(intersect);
    EXPECT_EQ(0, (int)p.size());
}
Beispiel #2
0
Intersection Cube::SampleLight( float a, float b, float c ){

    glm::vec3 ray_o( 0.f );
    glm::vec3 ray_d( 0.f );

    a -= .5f;
    b -= .5f;

    int hit_face( c * 6.f );

    switch ( hit_face ) {
    case 0:
        //--- x+ ---
        ray_o = glm::vec3( 1.f, a, b );
        ray_d = glm::vec3( -1.f, 0.f, 0.f );
        break;
    case 1:
        //--- x- ---
        ray_o = glm::vec3( -1.f, a, b );
        ray_d = glm::vec3( 1.f, 0.f, 0.f );
        break;
    case 2:
        //--- y+ ---
        ray_o = glm::vec3( a, 1.f, b );
        ray_d = glm::vec3( 0.f, -1.f, 0.f );
        break;
    case 3:
        //--- y- ---
        ray_o = glm::vec3( a, -1.f, b );
        ray_d = glm::vec3( 0.f, 1.f, 0.f );
        break;
    case 4:
        //--- z+ ---
        ray_o = glm::vec3( a, b, 1.f );
        ray_d = glm::vec3( 0.f, 0.f, -1.f );
        break;
    case 5:
        //--- z- ---
        ray_o = glm::vec3( a, b, -1.f );
        ray_d = glm::vec3( 0.f, 0.f, 1.f );
        break;
    }

    Ray ray( ray_o, ray_d );

    return GetIntersection( ray.GetTransformedCopy( transform.T() ) );
}
Beispiel #3
0
Intersection Sphere::SampleLight( float a, float b, float c ){

    float phi( PI * a );
    float u( cosf( phi ) );
    float theta( TWO_PI * b );

    float x( sqrt( 1 - u * u ) * cosf( theta ) );
    float y( sqrt( 1 - u * u ) * sinf( theta ) );
    float z( u );

    glm::vec3 ray_o( x * .6f, y * .6f, z * .6f );
    glm::vec3 ray_d( -x, -y, -z );

    Ray ray( ray_o, ray_d );

    return GetIntersection( ray.GetTransformedCopy( transform.T() ) );
}
TEST(SphereRayIntersection, SimpleRay1)
{
    shapes::Sphere shape(1.0);
    bodies::Body* sphere = new bodies::Sphere(&shape);
    sphere->setScale(1.05);

    Eigen::Vector3d ray_o(5, 0, 0);
    Eigen::Vector3d ray_d(-1, 0, 0);
    EigenSTL::vector_Vector3d p;
    bool intersect = sphere->intersectsRay(ray_o, ray_d, &p);

    delete sphere;
    EXPECT_TRUE(intersect);
    EXPECT_EQ(2, (int)p.size());
    EXPECT_NEAR(p[0].x(), 1.05, 1e-6);
    EXPECT_NEAR(p[1].x(), -1.05, 1e-6);
}
TEST(BoxRayIntersection, SimpleRay1)
{
    shapes::Box shape(1.0, 1.0, 3.0);
    bodies::Body* box = new bodies::Box(&shape);
    box->setScale(0.95);

    Eigen::Vector3d ray_o(10, 0.449, 0);
    Eigen::Vector3d ray_d(-1, 0, 0);
    EigenSTL::vector_Vector3d p;

    bool intersect = box->intersectsRay(ray_o, ray_d, &p);

    //    for (unsigned int i = 0; i < p.size() ; ++i)
    //        printf("intersection at %f, %f, %f\n", p[i].x(), p[i].y(), p[i].z());

    delete box;
    EXPECT_TRUE(intersect);
}