| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_RENDERING_DRAWABLE_H |
| 7 |
#define AVOGADRO_RENDERING_DRAWABLE_H |
| 8 |
|
| 9 |
#include "avogadrorenderingexport.h" |
| 10 |
|
| 11 |
#include "avogadrorendering.h" |
| 12 |
#include "primitive.h" |
| 13 |
|
| 14 |
#include <avogadro/core/array.h> |
| 15 |
#include <avogadro/core/vector.h> |
| 16 |
|
| 17 |
#include <map> |
| 18 |
|
| 19 |
namespace Avogadro { |
| 20 |
namespace Rendering { |
| 21 |
|
| 22 |
class Camera; |
| 23 |
class GeometryNode; |
| 24 |
class Visitor; |
| 25 |
|
| 26 |
/** |
| 27 |
* @class Drawable drawable.h <avogadro/rendering/drawable.h> |
| 28 |
* @brief The base class for all drawable geometry and types. |
| 29 |
* @author Marcus D. Hanwell |
| 30 |
* |
| 31 |
* This class provides the common API for drawable objects on the scene. It is |
| 32 |
* not a Node object, and can only be attached to GeometryNode objects in the |
| 33 |
* Scene. |
| 34 |
*/ |
| 35 |
|
| 36 |
class AVOGADRORENDERING_EXPORT Drawable |
| 37 |
{ |
| 38 |
public: |
| 39 |
Drawable(); |
| 40 |
Drawable(const Drawable& other); |
| 41 |
virtual ~Drawable(); |
| 42 |
|
| 43 |
Drawable& operator=(Drawable); |
| 44 |
friend void swap(Drawable& lhs, Drawable& rhs); |
| 45 |
|
| 46 |
/** |
| 47 |
* Accept a visit from our friendly visitor. |
| 48 |
*/ |
| 49 |
virtual void accept(Visitor&); |
| 50 |
|
| 51 |
/** |
| 52 |
* @brief Get a pointer to the drawable object's parent. |
| 53 |
* @return Pointer to the parent node, nullptr if no parent. |
| 54 |
*/ |
| 55 |
const GeometryNode* parent() const { return m_parent; } |
| 56 |
GeometryNode* parent() { return m_parent; } |
| 57 |
|
| 58 |
/** |
| 59 |
* @brief Set the visibility of the drawable object. |
| 60 |
* @param visibility True if the drawable is visible, false if invisible. |
| 61 |
*/ |
| 62 |
void setVisible(bool visibility) { m_visible = visibility; } |
| 63 |
|
| 64 |
/** |
| 65 |
* @brief Get the current visibility of the drawable. |
| 66 |
* @return True if visible. |
| 67 |
*/ |
| 68 |
bool isVisible() const { return m_visible; } |
| 69 |
|
| 70 |
/** |
| 71 |
* The render pass in which this drawable should be rendered. |
| 72 |
* @sa Rendering::RenderPass |
| 73 |
* @{ |
| 74 |
*/ |
| 75 |
void setRenderPass(RenderPass pass) { m_renderPass = pass; } |
| 76 |
RenderPass renderPass() const { return m_renderPass; } |
| 77 |
/** @} */ |
| 78 |
|
| 79 |
/** |
| 80 |
* @brief Render the contents of the drawable. |
| 81 |
* @param camera The current Camera. |
| 82 |
*/ |
| 83 |
virtual void render(const Camera& camera); |
| 84 |
|
| 85 |
/** |
| 86 |
* Get the identifier for the object, this stores the parent Molecule and |
| 87 |
* the type represented by the geometry. |
| 88 |
*/ |
| 89 |
Identifier& identifier() { return m_identifier; } |
| 90 |
const Identifier& identifier() const { return m_identifier; } |
| 91 |
|
| 92 |
/** |
| 93 |
* Return the primitives that are hit by the ray. |
| 94 |
* @param rayOrigin Origin of the ray. |
| 95 |
* @param rayEnd End point of the ray. |
| 96 |
* @param rayDirection Normalized direction of the ray. |
| 97 |
* @return Sorted collection of primitives that were hit. |
| 98 |
*/ |
| 99 |
virtual std::multimap<float, Identifier> hits( |
| 100 |
const Vector3f& rayOrigin, const Vector3f& rayEnd, |
| 101 |
const Vector3f& rayDirection) const; |
| 102 |
|
| 103 |
/** |
| 104 |
* Return the primitives within the supplied area. |
| 105 |
* @param f The frustrum defining the area highlighted. |
| 106 |
* @return Collection of primitives in the area. |
| 107 |
*/ |
| 108 |
virtual Core::Array<Identifier> areaHits(const Frustrum& f) const; |
| 109 |
|
| 110 |
/** |
| 111 |
* Clear the contents of the node. |
| 112 |
*/ |
| 113 |
virtual void clear(); |
| 114 |
|
| 115 |
protected: |
| 116 |
friend class GeometryNode; |
| 117 |
|
| 118 |
/** |
| 119 |
* @brief Set the parent node for the node. |
| 120 |
* @param parent The parent, a value of nullptr denotes no parent node. |
| 121 |
*/ |
| 122 |
void setParent(GeometryNode* parent); |
| 123 |
|
| 124 |
GeometryNode* m_parent; |
| 125 |
bool m_visible; |
| 126 |
RenderPass m_renderPass; |
| 127 |
Identifier m_identifier; |
| 128 |
}; |
| 129 |
|
| 130 |
inline Drawable& Drawable::operator=(Drawable rhs) |
| 131 |
{ |
| 132 |
using std::swap; |
| 133 |
swap(*this, rhs); |
| 134 |
return *this; |
| 135 |
} |
| 136 |
|
| 137 |
inline void swap(Drawable& lhs, Drawable& rhs) |
| 138 |
{ |
| 139 |
using std::swap; |
| 140 |
swap(lhs.m_parent, rhs.m_parent); |
| 141 |
swap(lhs.m_visible, rhs.m_visible); |
| 142 |
swap(lhs.m_renderPass, rhs.m_renderPass); |
| 143 |
swap(lhs.m_identifier, rhs.m_identifier); |
| 144 |
} |
| 145 |
|
| 146 |
} // End namespace Rendering |
| 147 |
} // End namespace Avogadro |
| 148 |
|
| 149 |
#endif // AVOGADRO_RENDERING_SPHERENODE_H |