63 #include "ClippingNode.hh" 65 #include <ACG/GL/IRenderer.hh> 67 #include <OpenMesh/Core/Utils/vector_cast.hh> 87 position_ = _position;
93 if (slice_width_ == 0.0)
95 plane0_[0] = normal_[0];
96 plane0_[1] = normal_[1];
97 plane0_[2] = normal_[2];
98 plane0_[3] = -(normal_|position_);
105 float d = -(normal_|position_);
106 if (d > 0) { normal_ = -normal_; d = -d; }
108 plane0_[0] = normal_[0];
109 plane0_[1] = normal_[1];
110 plane0_[2] = normal_[2];
111 plane0_[3] = d + 0.5f*slice_width_;
113 plane1_[0] = -normal_[0];
114 plane1_[1] = -normal_[1];
115 plane1_[2] = -normal_[2];
116 plane1_[3] = -(d - 0.5f*slice_width_);
132 offset_plane0_[0] = plane0_[0];
133 offset_plane0_[1] = plane0_[1];
134 offset_plane0_[2] = plane0_[2];
135 offset_plane0_[3] = plane0_[3] - offset_;
137 offset_plane1_[0] = plane1_[0];
138 offset_plane1_[1] = plane1_[1];
139 offset_plane1_[2] = plane1_[2];
140 offset_plane1_[3] = plane1_[3] + offset_;
150 if (slice_width_ == 0.0)
152 glClipPlane(GL_CLIP_PLANE0, offset_plane0_);
159 glClipPlane(GL_CLIP_PLANE0, offset_plane0_);
161 glClipPlane(GL_CLIP_PLANE1, offset_plane1_);
173 if (slice_width_ > 0.0)
200 ClippingNode::ClippingShaderModifier::ClippingShaderModifier(
int _numClipPlanes)
201 : numClipPlanes_(_numClipPlanes)
207 void ClippingNode::ClippingShaderModifier::modifyVertexIO(
ShaderGenerator* _shader)
209 for (
int i = 0; i < numClipPlanes_; ++i)
210 _shader->
addUniform(QString(
"vec4 g_SlicePlane%1").arg(i));
216 for (
int i = 0; i < numClipPlanes_; ++i)
217 _code->push_back(QString(
"gl_ClipDistance[%1] = dot(SG_INPUT_POSOS, g_SlicePlane%1);").arg(i));
222 ClippingNode::ClippingObjectModifier::ClippingObjectModifier(
const ClippingNode* _node)
229 void ClippingNode::ClippingObjectModifier::apply(
RenderObject* _obj)
235 _obj->clipDistanceMask |= 0x1;
237 unsigned int shaderModID = shaderMod1_.
getID();
239 if (node_->slice_width() > 0.0f)
243 _obj->clipDistanceMask |= 0x2;
245 shaderModID = shaderMod2_.
getID();
249 _obj->
shaderDesc.shaderMods.push_back(shaderModID);
void set_offset(float _dist)
sweep plane along normal by _dist
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.
VectorT< float, 4 > Vec4f
void leave(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawmode)
disable clipping plane
Interface for modifying render objects.
void enter(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawmode)
enable clipping plane
static void enable(GLenum _cap)
replaces glEnable, but supports locking
virtual void removeRenderObjectModifier(RenderObjectModifier *_mod)
Callback for the scenegraph nodes, which removes a render object modifier from the renderer...
void setUniform(const char *_name, GLint _value)
set values for int uniforms
void modifyVertexBeginCode(QStringList *_code)
Append code the the vertex shader.
void set_plane(const Vec3f &_position, const Vec3f &_normal, float _eps=0.0)
set position and normal of plane
static void disable(GLenum _cap)
replaces glDisable, but supports locking
Namespace providing different geometric functions concerning angles.
void addUniform(QString _uniform, QString _comment="")
Add one GLSL uniform specifier.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
virtual void addRenderObjectModifier(RenderObjectModifier *_mod)
Callback for the scenegraph nodes, which adds a render object modifier to the renderer via this funct...
Interface class between scenegraph and renderer.
static unsigned int registerModifier(ShaderModifier *_modifier)
Shader modifiers have to be registered before they can be used. They also must remain allocated for t...
ShaderGenDesc shaderDesc
Drawmode and other shader params.
unsigned int getID()
Returns the modifier ID.