Commit 0d8bb0a6 authored by Zain Selman's avatar Zain Selman 💬

adds parameter that controls sphere radius for vertex picking

parent b5a6cc73
......@@ -51,9 +51,8 @@
#include "PlaneNode.hh"
#include <ACG/GL/ShaderGenerator.hh>
#include <ACG/GL/ShaderCache.hh>
#include <ACG/GL/ShaderGenerator.hh>
//== IMPLEMENTATION ==========================================================
......@@ -220,20 +219,29 @@ void PlaneNode::draw(
//----------------------------------------------------------------
void PlaneNode::pick(ACG::GLState& _state,
ACG::SceneGraph::PickTarget _target) {
ACG::SceneGraph::PickTarget _target) {
/// original intention: our application could do custom radius picking
/// however we dont call this method directly, but rather the scenegraphpicker
/// does so this doesnt really do anything. todo anyways: change picking
/// radius to be constant in screenspace
/// we will do slightly larger sphere radii anyways
pick(_state, _target, 0.1);
}
void PlaneNode::pick(ACG::GLState& _state, ACG::SceneGraph::PickTarget _target,
float sphereRadius) {
updateVBO();
unsigned int vertexOffset = 0;
if ( _target == ACG::SceneGraph::PICK_ANYTHING ) {
if (_target == ACG::SceneGraph::PICK_ANYTHING) {
// Anything is plane + 4 corners
_state.pick_set_maximum(1+4);
_state.pick_set_maximum(1 + 4);
vertexOffset = 1;
} else if ( _target == ACG::SceneGraph::PICK_FACE ) {
} else if (_target == ACG::SceneGraph::PICK_FACE) {
// Only the Face
_state.pick_set_maximum(1);
} else if ( _target == ACG::SceneGraph::PICK_VERTEX ) {
} else if (_target == ACG::SceneGraph::PICK_VERTEX) {
// 4 Vertices
_state.pick_set_maximum(4);
}
......@@ -243,31 +251,29 @@ void PlaneNode::pick(ACG::GLState& _state,
// load picking shader from cache
GLSL::Program* pickShader = 0;
if (!fixedFunctionGL)
{
if (!fixedFunctionGL) {
static ACG::ShaderGenDesc desc;
desc.fragmentTemplateFile = "Picking/single_color_fs.glsl";
desc.vertexTemplateFile = "Picking/vertex.glsl";
pickShader = ACG::ShaderCache::getInstance()->getProgram(&desc, nullptr);
if (!pickShader)
return;
if (!pickShader) return;
pickShader->use();
}
if (_target == ACG::SceneGraph::PICK_ANYTHING || _target == ACG::SceneGraph::PICK_FACE) {
ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
if (_target == ACG::SceneGraph::PICK_ANYTHING ||
_target == ACG::SceneGraph::PICK_FACE) {
ACG::Vec3d pos =
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
_state.push_modelview_matrix();
_state.translate(pos[0], pos[1], pos[2]);
// We only draw one plane. So we start at element 0 and have a maximum of one elements
// We only draw one plane. So we start at element 0 and have a maximum of
// one elements
_state.pick_set_name(0);
if (pickShader)
{
if (pickShader) {
pickShader->setUniform("color", _state.pick_get_name_color_norm(0));
ACG::GLMatrixf mWVP = _state.projection() * _state.modelview();
......@@ -276,17 +282,12 @@ void PlaneNode::pick(ACG::GLState& _state,
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
vertexDecl_.activateShaderPipeline(pickShader);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
vertexDecl_.deactivateShaderPipeline(pickShader);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
else
{
} else {
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
_state.enableClientState(GL_VERTEX_ARRAY);
......@@ -302,17 +303,17 @@ void PlaneNode::pick(ACG::GLState& _state,
}
_state.pop_modelview_matrix();
}
if (_target == ACG::SceneGraph::PICK_ANYTHING || _target == ACG::SceneGraph::PICK_VERTEX) {
float sphereRadius = 0.01f;
if (_target == ACG::SceneGraph::PICK_ANYTHING ||
_target == ACG::SceneGraph::PICK_VERTEX) {
// float sphereRadius = 0.01f;
if (pickShader)
{
// Compute zero corner of plane ( Shifted by half such that center of plane is 0,0
ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
if (pickShader) {
// Compute zero corner of plane ( Shifted by half such that center of
// plane is 0,0
ACG::Vec3d pos =
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
//==========================================
// Draw 0 Corner:
......@@ -323,94 +324,100 @@ void PlaneNode::pick(ACG::GLState& _state,
ACG::GLMatrixf mWVP = _state.projection() * _state.modelview();
mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
pickShader->setUniform("mWVP", mWVP);
pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
pickShader->setUniform("color",
_state.pick_get_name_color_norm(vertexOffset));
sphere_->draw_primitive(pickShader);
//==========================================
// Draw x Corner:
//==========================================
vertexOffset++;
_state.translate(plane_.xDirection[0] , plane_.xDirection[1], plane_.xDirection[2]);
_state.translate(plane_.xDirection[0], plane_.xDirection[1],
plane_.xDirection[2]);
mWVP = _state.projection() * _state.modelview();
mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
pickShader->setUniform("mWVP", mWVP);
pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
pickShader->setUniform("color",
_state.pick_get_name_color_norm(vertexOffset));
sphere_->draw_primitive(pickShader);
//==========================================
// Draw xy Corner:
//==========================================
vertexOffset++;
_state.translate(plane_.yDirection[0] , plane_.yDirection[1], plane_.yDirection[2]);
_state.translate(plane_.yDirection[0], plane_.yDirection[1],
plane_.yDirection[2]);
mWVP = _state.projection() * _state.modelview();
mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
pickShader->setUniform("mWVP", mWVP);
pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
pickShader->setUniform("color",
_state.pick_get_name_color_norm(vertexOffset));
sphere_->draw_primitive(pickShader);
//==========================================
// Draw y Corner:
//==========================================
vertexOffset++;
_state.translate(-plane_.xDirection[0] , -plane_.xDirection[1], -plane_.xDirection[2]);
_state.translate(-plane_.xDirection[0], -plane_.xDirection[1],
-plane_.xDirection[2]);
mWVP = _state.projection() * _state.modelview();
mWVP.scale(sphereRadius, sphereRadius, sphereRadius);
pickShader->setUniform("mWVP", mWVP);
pickShader->setUniform("color", _state.pick_get_name_color_norm(vertexOffset));
pickShader->setUniform("color",
_state.pick_get_name_color_norm(vertexOffset));
sphere_->draw_primitive(pickShader);
_state.pop_modelview_matrix();
} else {
// Compute zero corner of plane ( Shifted by half such that center of plane is 0,0
ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
// Compute zero corner of plane ( Shifted by half such that center of
// plane is 0,0
ACG::Vec3d pos =
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
//==========================================
// Draw 0 Corner:
//==========================================
_state.push_modelview_matrix();
_state.translate(pos[0], pos[1], pos[2]);
_state.pick_set_name (vertexOffset);
sphere_->draw(_state,sphereRadius);
_state.pick_set_name(vertexOffset);
sphere_->draw(_state, sphereRadius);
//==========================================
// Draw x Corner:
//==========================================
vertexOffset++;
_state.translate(plane_.xDirection[0] , plane_.xDirection[1], plane_.xDirection[2]);
_state.translate(plane_.xDirection[0], plane_.xDirection[1],
plane_.xDirection[2]);
_state.pick_set_name(vertexOffset);
sphere_->draw(_state,sphereRadius);
sphere_->draw(_state, sphereRadius);
//==========================================
// Draw xy Corner:
//==========================================
vertexOffset++;
_state.translate(plane_.yDirection[0] , plane_.yDirection[1], plane_.yDirection[2]);
_state.translate(plane_.yDirection[0], plane_.yDirection[1],
plane_.yDirection[2]);
_state.pick_set_name(vertexOffset);
sphere_->draw(_state,sphereRadius);
sphere_->draw(_state, sphereRadius);
//==========================================
// Draw y Corner:
//==========================================
vertexOffset++;
_state.translate(-plane_.xDirection[0] , -plane_.xDirection[1], -plane_.xDirection[2]);
_state.translate(-plane_.xDirection[0], -plane_.xDirection[1],
-plane_.xDirection[2]);
_state.pick_set_name(vertexOffset);
sphere_->draw(_state,sphereRadius);
sphere_->draw(_state, sphereRadius);
_state.pop_modelview_matrix();
}
}
}
//----------------------------------------------------------------
ACG::Vec3d PlaneNode::position() { return plane_.position; }
......@@ -538,7 +545,6 @@ void PlaneNode::getRenderObjects(
ACG::IRenderer* _renderer, ACG::GLState& _state,
const ACG::SceneGraph::DrawModes::DrawMode& _drawMode,
const ACG::SceneGraph::Material* _mat) {
// init base render object
ACG::RenderObject ro;
......@@ -620,15 +626,16 @@ void PlaneNode::getRenderObjects(
// Just draw the quads here ( front )
//---------------------------------------------------
ro.debugName = "PlaneNode.plane_front ";
applyRenderObjectSettings(ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON, &ro);
applyRenderObjectSettings(ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON,
&ro);
if (ro.textures().size() != 0) {
localMaterial.ambientColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
localMaterial.diffuseColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
localMaterial.specularColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
localMaterial.ambientColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
localMaterial.diffuseColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
localMaterial.specularColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
} else {
localMaterial.ambientColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.diffuseColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.specularColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.ambientColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.diffuseColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.specularColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
}
ro.setMaterial(&localMaterial);
/// quads are not accepted here in opengl core. this has to be updated
......@@ -639,15 +646,16 @@ void PlaneNode::getRenderObjects(
// Just draw the quads here ( back )
//---------------------------------------------------
ro.debugName = "PlaneNode.plane_back";
applyRenderObjectSettings(ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON, &ro);
applyRenderObjectSettings(ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON,
&ro);
if (ro.textures().size() != 0) {
localMaterial.ambientColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
localMaterial.diffuseColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
localMaterial.specularColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
localMaterial.ambientColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
localMaterial.diffuseColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
localMaterial.specularColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
} else {
localMaterial.ambientColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.diffuseColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.specularColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.ambientColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.diffuseColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
localMaterial.specularColor(ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
}
ro.setMaterial(&localMaterial);
......
......@@ -58,104 +58,110 @@
//== INCLUDES =================================================================
#include <ACG/GL/GLPrimitives.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/Geometry/Types/PlaneType.hh>
#include <ACG/Math/Matrix4x4T.hh>
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Math/Matrix4x4T.hh>
#include <OpenFlipper/common/ObjectTypeDLLDefines.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/GLPrimitives.hh>
//== NAMESPACES ===============================================================
//== CLASS DEFINITION =========================================================
class OBJECTTYPEDLLEXPORT PlaneNode : public ACG::SceneGraph::BaseNode
{
public:
using Plane = ACG::Geometry::Plane;
/** \brief Construct a plane rendering node
*
* @param _parent The parent node in the scenegraph
* @param _name The name of the new node (visible in the scenegraph dialogs)
* @param _plane A pointer to an existing plane
*/
PlaneNode(Plane& _plane, BaseNode *_parent = 0, std::string _name = "<PlaneNode>");
class OBJECTTYPEDLLEXPORT PlaneNode : public ACG::SceneGraph::BaseNode {
public:
using Plane = ACG::Geometry::Plane;
/** \brief Construct a plane rendering node
*
* @param _parent The parent node in the scenegraph
* @param _name The name of the new node (visible in the scenegraph dialogs)
* @param _plane A pointer to an existing plane
*/
PlaneNode(Plane& _plane, BaseNode* _parent = 0,
std::string _name = "<PlaneNode>");
/// destructor
~PlaneNode();
/// destructor
~PlaneNode();
/// static name of this class
ACG_CLASSNAME(PlaneNode);
/// static name of this class
ACG_CLASSNAME(PlaneNode);
/// return available draw modes
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override;
/// return available draw modes
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override;
/// update bounding box
void boundingBox(ACG::Vec3d & _bbMin, ACG::Vec3d & _bbMax) override;
/// update bounding box
void boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax) override;
/// draw Plane
void draw(ACG::GLState & _state, const ACG::SceneGraph::DrawModes::DrawMode & _drawMode) override;
/// draw Plane
void draw(ACG::GLState& _state,
const ACG::SceneGraph::DrawModes::DrawMode& _drawMode) override;
/// draw Plane for object picking
void pick(ACG::GLState & _state, ACG::SceneGraph::PickTarget _target) override;
/// draw Plane for object picking
void pick(ACG::GLState& _state, ACG::SceneGraph::PickTarget _target) override;
/// get center position of the plane
ACG::Vec3d position();
void pick(ACG::GLState& _state, ACG::SceneGraph::PickTarget _target,
float sphereRadius = .01f);
/// get current normal
ACG::Vec3d normal();
/// get center position of the plane
ACG::Vec3d position();
/// local x direction (multiplied with width)
ACG::Vec3d xDirection();
/// get current normal
ACG::Vec3d normal();
/// local y direction (multiplied with height)
ACG::Vec3d yDirection();
/// local x direction (multiplied with width)
ACG::Vec3d xDirection();
/// Get the currently rendered plane
Plane& getPlane();
/// local y direction (multiplied with height)
ACG::Vec3d yDirection();
/// Set a new plane for rendering
void setPlane(Plane plane);
/// Get the currently rendered plane
Plane& getPlane();
/** \brief Add the objects to the given renderer
*
* @param _renderer The renderer which will be used. Add your geometry into this class
* @param _state The current GL State when this object is called
* @param _drawMode The active draw mode
* @param _mat Current material
*/
void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) override;
/// Set a new plane for rendering
void setPlane(Plane plane);
/// updates the plane before the next render call
void update();
/** \brief Add the objects to the given renderer
*
* @param _renderer The renderer which will be used. Add your geometry into
* this class
* @param _state The current GL State when this object is called
* @param _drawMode The active draw mode
* @param _mat Current material
*/
void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state,
const ACG::SceneGraph::DrawModes::DrawMode& _drawMode,
const ACG::SceneGraph::Material* _mat) override;
private:
void drawPlane(ACG::GLState & _state);
void drawManipulator(ACG::GLState & _state);
/// updates the plane before the next render call
void update();
void drawManipulatorPick(ACG::GLState & _state);
private:
void drawPlane(ACG::GLState& _state);
void drawManipulator(ACG::GLState& _state);
/// create and update VBO
void updateVBO();
void drawManipulatorPick(ACG::GLState& _state);
/// create and update VBO
void updateVBO();
void addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer, ACG::GLState& _state, ACG::RenderObject* _ro);
void addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer,
ACG::GLState& _state, ACG::RenderObject* _ro);
Plane& plane_;
Plane& plane_;
/// VBO used to render the plane
unsigned int vbo_;
bool vboNeedsUpdate_;
/// VBO used to render the plane
unsigned int vbo_;
ACG::VertexDeclaration vertexDecl_;
bool vboNeedsUpdate_;
ACG::GLSphere* sphere_;
ACG::VertexDeclaration vertexDecl_;
ACG::GLSphere* sphere_;
};
//=============================================================================
#endif // ACG_PLANENODE_HH defined
#endif // ACG_PLANENODE_HH defined
//=============================================================================
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment