void cameraCollision(void) { if (Camera_Mode != humanIndex) return; const Frame &playerFrame = Player_List[humanIndex]->frame; Ray r = rayFromTo(playerFrame.position, camera.eye); MatrixCoord testCoord = worldSpaceToTileSpace(playerFrame.position, Tilesize); const MatrixCoord testcoords[] = { testCoord + MatrixCoord( 0, 1), testCoord + MatrixCoord( 0,-1), testCoord + MatrixCoord( 1, 0), testCoord + MatrixCoord(-1, 0), testCoord + MatrixCoord( 1, 1), testCoord + MatrixCoord(-1, 1), testCoord + MatrixCoord(-1,-1), testCoord + MatrixCoord( 1,-1), }; // std::cout << "ray = " << r << std::endl; float near = INFINITY; float nearest = INFINITY; for (unsigned int i=0; i<8; ++i) { if (tileSpace[testcoords[i]] != TILESPACE_CHAR) continue; //bool x = intersection(r, glmaze.aabb[testcoords[i]], &near, NULL); bool x = intersection(r, AABB(glmaze.aabb[testcoords[i]].xyz-glm::vec3(0.3f), glmaze.aabb[testcoords[i]].XYZ+glm::vec3(0.3f)), &near, NULL); // std::cout << "box coord(" << testcoords[i] << ") intersection collision" << " min = " << min << " max = " << max << " return = " << x << std::endl; nearest = (x && near < nearest) ? near : nearest; } cameraDistance = nearest < defaultCameraDistance ? nearest : defaultCameraDistance; }
TEST_F(LensTest, ray_passing_thru_the_center_at_an_angle_should_pass_through) { Vector ORIGIN{-3, 2, 0}; Vector DEST{-ORIGIN[0], -ORIGIN[1], Z_DISTANCE * 2}; auto central = rayFromTo(ORIGIN, DEST); auto refracted = lens.refract(central); EXPECT_THAT(refracted, RayPassesThrough(DEST, EPS)); EXPECT_THAT(refracted, RayHasDirection(central.getDirection(), EPS)); EXPECT_THAT(central, RayPassesThrough(refracted.getOrigin(), EPS)); }
TEST_F(LensTest, rays_passing_though_the_focal_point_should_become_parallel) { Point destinationPoints[]{ {1, 2, Z_DISTANCE}, {-3, 4, Z_DISTANCE}, {4, 1, Z_DISTANCE}}; for (auto& to : destinationPoints) { auto ray = rayFromTo(FOCAL_POINT, to); auto refracted = lens.refract(ray); EXPECT_THAT(refracted, RayHasDirection(-DIR_Z, EPS)); EXPECT_NEAR(to[0], refracted.getOrigin()[0], EPS); EXPECT_NEAR(to[1], refracted.getOrigin()[1], EPS); EXPECT_NEAR(to[2], refracted.getOrigin()[2], EPS); } }