// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include #include #include #include #include namespace anki { /// @addtogroup scene /// @{ /// Spatial component. It is used by scene nodes that need to be placed inside the visibility structures. class SpatialComponent : public SceneComponent { ANKI_SCENE_COMPONENT(SpatialComponent) public: SpatialComponent(SceneNode* node); ~SpatialComponent(); void setObbWorldSpace(const Obb& obb) { m_obb = obb; m_collisionObjectType = obb.CLASS_TYPE; m_markedForUpdate = true; } void setAabbWorldSpace(const Aabb& aabb) { m_aabb = aabb; m_collisionObjectType = aabb.CLASS_TYPE; m_markedForUpdate = true; } void setSphereWorldSpace(const Sphere& sphere) { m_sphere = sphere; m_collisionObjectType = sphere.CLASS_TYPE; m_markedForUpdate = true; } void setConvexHullWorldSpace(const ConvexHullShape& hull); template const T& getCollisionShape() const { ANKI_ASSERT(T::CLASS_TYPE == m_collisionObjectType); return *reinterpret_cast(&m_anyShape); } CollisionShapeType getCollisionShapeType() const { return m_collisionObjectType; } const Aabb& getAabbWorldSpace() const { ANKI_ASSERT(!m_alwaysVisible); return m_derivedAabb; } const SceneNode& getSceneNode() const { return *m_node; } SceneNode& getSceneNode() { return *m_node; } /// Used for sorting spatials. In most object the origin is the center of mass but for cameras the origin is the /// eye point. const Vec3& getSpatialOrigin() const { ANKI_ASSERT(m_origin.x() != MAX_F32); return m_origin; } /// See getSpatialOrigin() void setSpatialOrigin(const Vec3& origin) { m_origin = origin; } /// Update the "actual scene bounds" of the octree or not. void setUpdateOctreeBounds(Bool update) { m_updateOctreeBounds = update; } /// Make it or not always visible. void setAlwaysVisible(Bool alwaysVisible) { m_alwaysVisible = alwaysVisible; } /// See if it's always visible or not. Bool getAlwaysVisible() const { return m_alwaysVisible; } ANKI_USE_RESULT Error update(SceneNode& node, Second prevTime, Second crntTime, Bool& updated) override; private: SceneNode* m_node; union { Obb m_obb; Aabb m_aabb; Sphere m_sphere; ConvexHullShape m_hull; U8 m_anyShape; }; DynamicArray m_convexHullPoints; CollisionShapeType m_collisionObjectType = CollisionShapeType::COUNT; Aabb m_derivedAabb; ///< A faster shape Vec3 m_origin = Vec3(MAX_F32); OctreePlaceable m_octreeInfo; Bool m_markedForUpdate : 1; Bool m_placed : 1; Bool m_updateOctreeBounds : 1; Bool m_alwaysVisible : 1; }; /// @} } // end namespace anki