Skip to content

Additional Geometric Primitives #2290

@morphogencc

Description

@morphogencc

The geom:: namespace seems to have a pretty complete listing of GPU representations of shapes, but there's very few of the corresponding classes in the ci:: namespace. There's ci::Rect<T>, ci::Sphere, and ci::AxisAlignedBox, and I'm not sure there's much else...

For 2D Shapes it'd be great if they had a similar interface to Rect:

        void		transform( const Mat3T &matrix );
        RectT	transformed( const Mat3T &matrix ) const;
        bool	contains( const glm::tvec2<Y, glm::defaultp> &pt ) const
        bool	contains( const Vec2T &pt ) const	
        bool	intersects( const RectT &rect ) const;
        T		distance( const Vec2T &pt ) const;
        T		distanceSquared( const Vec2T &pt ) const;

and for 3D Shapes if they followed the Sphere interface:

	bool	intersects( const AxisAlignedBox &box ) const;
	bool	intersects( const Ray &ray ) const;
	int		intersect( const Ray &ray, float *intersection ) const;
	int		intersect( const Ray &ray, float *min, float *max ) const;
	vec3	closestPoint( const Ray &ray ) const;
	Sphere	transformed( const mat4 &transform ) const;

I'm imagining that these would be useful for hit-testing in various applications, where perhaps you don't want an entire physics system just to figure out if objects overlap / intersect / contain a point.

Based off of some threads I've read here, it seems that other primitives are missing mostly because they haven't been a priority / need for anyone yet, not because anyone is against them existing -- if this is correct, then I may go ahead and build a few for a current project and add them.

It'd be great to collate thoughts on what the consistent interface might be across multiples of these objects (and if perhaps they should inherit from a parent class that defines this interface?).

A preliminary list of ideas:

2D Shapes

  • ci::Circle
  • ci::RotatedRect
  • ci::Triangle

3D Shapes

  • ci::Box
  • ci::Capsule
  • ci::Cylinder

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions