57 #include "ClippingNode.hh" 59 #include <ACG/GL/IRenderer.hh> 61 #include <OpenMesh/Core/Utils/vector_cast.hh> 81 position_ = _position;
87 if (slice_width_ == 0.0)
89 plane0_[0] = normal_[0];
90 plane0_[1] = normal_[1];
91 plane0_[2] = normal_[2];
92 plane0_[3] = -(normal_|position_);
99 float d = -(normal_|position_);
100 if (d > 0) { normal_ = -normal_; d = -d; }
102 plane0_[0] = normal_[0];
103 plane0_[1] = normal_[1];
104 plane0_[2] = normal_[2];
105 plane0_[3] = d + 0.5f*slice_width_;
107 plane1_[0] = -normal_[0];
108 plane1_[1] = -normal_[1];
109 plane1_[2] = -normal_[2];
110 plane1_[3] = -(d - 0.5f*slice_width_);
126 offset_plane0_[0] = plane0_[0];
127 offset_plane0_[1] = plane0_[1];
128 offset_plane0_[2] = plane0_[2];
129 offset_plane0_[3] = plane0_[3] - offset_;
131 offset_plane1_[0] = plane1_[0];
132 offset_plane1_[1] = plane1_[1];
133 offset_plane1_[2] = plane1_[2];
134 offset_plane1_[3] = plane1_[3] + offset_;
144 if (slice_width_ == 0.0)
146 glClipPlane(GL_CLIP_PLANE0, offset_plane0_);
153 glClipPlane(GL_CLIP_PLANE0, offset_plane0_);
155 glClipPlane(GL_CLIP_PLANE1, offset_plane1_);
167 if (slice_width_ > 0.0)
194 ClippingNode::ClippingShaderModifier::ClippingShaderModifier(
int _numClipPlanes)
195 : numClipPlanes_(_numClipPlanes)
203 for (
int i = 0; i < numClipPlanes_; ++i)
204 _shader->
addUniform(QString(
"vec4 g_SlicePlane%1").arg(i));
210 for (
int i = 0; i < numClipPlanes_; ++i)
211 _code->push_back(QString(
"gl_ClipDistance[%1] = dot(inverse(g_mWV) * sg_vPosVS, g_SlicePlane%1);").arg(i));
216 ClippingNode::ClippingObjectModifier::ClippingObjectModifier(
const ClippingNode* _node)
229 _obj->clipDistanceMask |= 0x1;
231 unsigned int shaderModID = shaderMod1_.
getID();
233 if (node_->slice_width() > 0.0f)
237 _obj->clipDistanceMask |= 0x2;
239 shaderModID = shaderMod2_.
getID();
243 _obj->
shaderDesc.shaderMods.push_back(shaderModID);
246 _obj->
shaderDesc.clipDistanceMask = _obj->clipDistanceMask;
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
void apply(RenderObject *_obj)
apply the modifier
virtual void removeRenderObjectModifier(RenderObjectModifier *_mod)
Callback for the scenegraph nodes, which removes a render object modifier from the renderer...
Namespace providing different geometric functions concerning angles.
Interface for modifying render objects.
VectorT< float, 4 > Vec4f
ShaderGenDesc shaderDesc
Drawmode and other shader params.
unsigned int getID()
Returns the modifier ID.
void enter(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawmode) override
enable clipping plane
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
void leave(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawmode) override
disable clipping plane
void addUniform(QString _uniform, QString _comment="")
Add one GLSL uniform specifier.
virtual void addRenderObjectModifier(RenderObjectModifier *_mod)
Callback for the scenegraph nodes, which adds a render object modifier to the renderer via this funct...
void modifyVertexEndCode(QStringList *_code)
Append code the the vertex shader.
static unsigned int registerModifier(ShaderModifier *_modifier)
Shader modifiers have to be registered before they can be used. They also must remain allocated for t...
void modifyVertexIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the vertex shader.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Interface class between scenegraph and renderer.
void set_plane(const Vec3f &_position, const Vec3f &_normal, float _eps=0.0)
set position and normal of plane
void set_offset(float _dist)
sweep plane along normal by _dist