Closed mosra closed 11 years ago
From user's point of view I'd appreciate more solution 1.1. I find differentiating between general shapes and physics shapes bit confusing. Ideally user should be able to pass general shape and let framework decide (at compile time) whether it is related to debug drawing, collision detection, physics computation etc. depending on context. But I have no idea about implementation.
Could you please describe issue with ShapeGroup
in 1.1?
Thoughts:
%
and composition operatorsPhysics
namespace
Shapes
and Physics
this is how it is currently - ShapeGroup
which can contain one or more shapes, but the only advantage is the "universal" type, querying the contents is almost impossible. The shapes actually behave like monoids and you have to specify the type only during creation of single shapes, not for the result:
auto shape = Physics::Point2D({}) || Physics::Sphere2D({3.0f, 1.0f}, 0.5f);
Nice thing would be to have something like the following to avoid specifying the resulting type altogether to follow the monoids idea, maybe C++17 will be able to do it?:
new Shapes::Shape<auto>(object, shape);
Otherwise, to avoid explicit type specification, we must resort to some makeShape()
function as described above.
Shapes
and Physics
, sure.In current "terminology", primitive is mesh data (vertices, faces, normals...) of some basic object (circle, line, arrow, crosshair, monkey...) to ease up prototyping, shape is (simplified) description of some subspace (which doesn't even need to encapsulate any mesh, e.g. trigger volumes) used for collision detection (primarily not for rendering). User's line of thoughs should be like this:
I'd like to have a box object:
auto box = new Object3D(scene);
I'd like to have it collidable, thus I need to assign Shape
feature to it and somehow describe its erm... shape, possibly using Shapes::Box3D
:
auto shape = new Shapes::Shape<???>(box, Shapes::Box3D(...));
I'd like to visualize the box somehow. I have two options, assign Drawable
feature to it and render a mesh (possibly created from pre-made Primitives::Cube
) using some shader (possibly with stock Shaders::Phong
). Or, because I have assigned the collision shape already, I can use DebugTools::ShapeRenderer
, which will visualize just the shape with wireframe, it will look ugly, but I can do it better later:
new DebugTools::ShapeRenderer3D(shape, ...);
Done in 06d707f25c517a237d301ae7422309e7a4a81c0e.
Why?
Current reimplementation state
ShapeGroup
stores the shapes in flat array, making it easy for user to query the contents and possibly save a reference to particular shape. It also saves some allocations compared to previous solution, but the internals more complicated. Nothing for user to worry about, the API is the the same as before:Adding shapes as references to original objects is not possible though, they need to be extracted back after creating the group:
ObjectShape
is now templated on shape, stores two instances of it (original and transformed one) and common functionality is in abstract baseAbstractObjectShape
. It is now actually usable, compare previous, whereObjectShape
wasn't useful for anything:With current:
ShapeGroup
andObjectShape
. It is good because it doesn't add confusing wrappers to the user (except one additional "internal" header file with no public documentation and no need for user to include it). Has it any downsides? Will the user need the polymorphism anywhere?Issue 1
The above code is not intuitive, becasuse the user might not immediately know that result of
a || b
isShapeGroup
. Even if he would, this is a lot of unnecessary typing, because the shape type is known from the arguments (unlike in above examples). Two considered (but unsufficient) solutions:ShapeGroup
into specializedObjectShape
, e.g.ObjectShapeHierarchy
? Will result in having the internal polymorphic wrappers in only one place (hopefully), which is good, but removes the possibility to operate onShapeGroup
alone without scene graph. HasShapeGroup
any use without scene graph?Provide some convenience function similar to
std::make_tuple
which removes the need for explicit type specification, e.g.:It would save typing also in some other cases, but what should this function return? Pointer to object created on heap? Object by value? Both have valid use cases and having both
makeObjectShape()
andmakeObjectShapePtr()
is ugly.Issue 2
The user can't intuitively tell what's the difference between
ObjectShapeGroup
andShapeGroup
, thus they should be renamed to something more meaningful. Also why not to move everything to different namespace soPhysics
can be saved for other things like rigid bodies and particle systems? LinkingPhysics
library just because one needs to click menus seems like overkill. But on the other hand, will collision detection be large enough to be in separate library?Physics
namespace toShapes
(CollisionDetection
is too long?)ShapeGroup
toHierarchy
. Because it will always be written asShapes::Hierarchy
it will be obvious what is going on. Better name?ObjectShape
toShape
andObjectShapeGroup
toShapeGroup
(Object
was redundant). Is it descriptive enough for scene graph feature (Collidable
sounds to Java-ish)? Physics itself will containRigidBody
.