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)); } }
void ShapeTest::clean() { Scene3D scene; ShapeGroup3D shapes; Object3D a(&scene); auto shape = new Shapes::Shape<Shapes::Point3D>(a, {{1.0f, -2.0f, 3.0f}}, &shapes); a.scale(Vector3(-2.0f)); Object3D b(&scene); new Shapes::Shape<Shapes::Point3D>(b, &shapes); /* Everything is dirty at the beginning */ CORRADE_VERIFY(shapes.isDirty()); CORRADE_VERIFY(a.isDirty()); CORRADE_VERIFY(b.isDirty()); /* Cleaning object will not clean anything other */ a.setClean(); CORRADE_VERIFY(shapes.isDirty()); CORRADE_VERIFY(!a.isDirty()); CORRADE_VERIFY(b.isDirty()); /* Verify that the feature was actually cleaned */ CORRADE_COMPARE(shape->transformedShape().position(), Vector3(-2.0f, 4.0f, -6.0f)); /* Setting group clean will clean whole group */ a.setDirty(); shapes.setClean(); CORRADE_VERIFY(!shapes.isDirty()); CORRADE_VERIFY(!a.isDirty()); CORRADE_VERIFY(!b.isDirty()); /* Setting object dirty will set also the group, but not other objects */ b.setDirty(); CORRADE_VERIFY(shapes.isDirty()); CORRADE_VERIFY(!a.isDirty()); CORRADE_VERIFY(b.isDirty()); }