void ShapeTest::firstCollision() { Scene3D scene; ShapeGroup3D shapes; Object3D a(&scene); Shape<Shapes::Sphere3D> aShape(a, {{1.0f, -2.0f, 3.0f}, 1.5f}, &shapes); Object3D b(&scene); Shape<Shapes::Point3D> bShape(b, {{3.0f, -2.0f, 3.0f}}, &shapes); Object3D c(&scene); Shape<Shapes::Composition3D> cShape(c, &shapes); /* No collisions initially */ CORRADE_VERIFY(!shapes.firstCollision(aShape)); CORRADE_VERIFY(!shapes.firstCollision(bShape)); CORRADE_VERIFY(!shapes.isDirty()); /* Move point into sphere */ b.translate(Vector3::xAxis(-1.0f)); /* Collision */ CORRADE_VERIFY(shapes.isDirty()); CORRADE_VERIFY(shapes.firstCollision(aShape) == &bShape); CORRADE_VERIFY(shapes.firstCollision(bShape) == &aShape); CORRADE_VERIFY(!shapes.isDirty()); }
void ShapeTest::collision() { Scene3D scene; ShapeGroup3D shapes; Object3D a(&scene); Shape<Shapes::Sphere3D> aShape(a, {{1.0f, -2.0f, 3.0f}, 1.5f}, &shapes); { /* Collision with point inside the sphere */ Shape<Shapes::Point3D> aShape2(a, {{1.0f, -2.0f, 3.0f}}, &shapes); shapes.setClean(); const Collision3D collision = aShape.collision(aShape2); CORRADE_VERIFY(collision); CORRADE_COMPARE(collision.position(), Vector3(1.0f, -2.0f, 3.0f)); } { /* No collision with point inside the sphere, but not in the same group */ ShapeGroup3D shapes2; Shape<Shapes::Point3D> aShape3(a, {{1.0f, -2.0f, 3.0f}}, &shapes2); shapes2.setClean(); CORRADE_VERIFY(!aShape.collision(aShape3)); } { CORRADE_EXPECT_FAIL("Should cross-scene collision work or not?"); /* No collision with point inside the sphere, but not in the same scene */ Scene3D scene2; Object3D c(&scene2); Shape<Shapes::Point3D> cShape(c, {{1.0f, -2.0f, 3.0f}}, &shapes); shapes.setClean(); CORRADE_VERIFY(!aShape.collision(cShape)); } { /* No collision with point outside of the sphere */ Object3D b(&scene); Shape<Shapes::Point3D> bShape(b, {{3.0f, -2.0f, 3.0f}}, &shapes); shapes.setClean(); CORRADE_VERIFY(!aShape.collision(bShape)); /* Move point inside the sphere -- collision */ b.translate(Vector3::xAxis(-1.0f)); shapes.setClean(); const Collision3D collision = aShape.collision(bShape); CORRADE_VERIFY(collision); CORRADE_COMPARE(collision.position(), Vector3(2.0f, -2.0f, 3.0f)); } }