Commit 95267c35 authored by Jan Möbius's avatar Jan Möbius
Browse files

Finished new interface for Plane Object. Fixed some parts in the standard renderer.

refs #1286

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15847 383ad7c9-94d9-4d36-a494-682f7c89f535
parent be3d09ad
......@@ -52,9 +52,13 @@
PlaneNode::PlaneNode(Plane& _plane, BaseNode *_parent, std::string _name)
:BaseNode(_parent, _name),
plane_(_plane),
vbo_(0)
vbo_(0),
sphere_(0)
{
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_NORMAL);
sphere_ = new ACG::GLSphere(10, 10);
}
PlaneNode::~PlaneNode()
......@@ -92,8 +96,7 @@ ACG::SceneGraph::DrawModes::DrawMode
PlaneNode::availableDrawModes() const
{
return ( ACG::SceneGraph::DrawModes::POINTS |
ACG::SceneGraph::DrawModes::POINTS_SHADED |
ACG::SceneGraph::DrawModes::POINTS_COLORED );
ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED );
}
//----------------------------------------------------------------------------
......@@ -104,43 +107,49 @@ PlaneNode::availableDrawModes() const
void PlaneNode::drawPlane( ACG::GLState& _state) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
// Array of coordinates for the plane
float vboData_[4* 3 ] = { 0.0,0.0,0.0,
float vboData_[9 * 3 ] = { 0.0,0.0,0.0,
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
(float)xy[0],(float)xy[1],(float)xy[2],
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2] };
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
0.0,0.0,0.0,
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)xy[0],(float)xy[1],(float)xy[2],
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
0.0,0.0,0.0 };
// Enable the arrays
_state.enableClientState(GL_VERTEX_ARRAY);
_state.vertexPointer(3,GL_FLOAT,0,&vboData_[0]);
//first draw the lines
glColor3f( 1.0, 1.0, 1.0 );
_state.set_color(ACG::Vec4f(1.0, 1.0, 1.0 , 1.0) );
glLineWidth(2.0);
glDrawArrays(GL_QUADS,0,4);
glDrawArrays(GL_LINE_STRIP,0,5);
glLineWidth(1.0);
// Remember blending state
bool blending = _state.blending();
//then the red front side
ACG::GLState::enable (GL_BLEND);
ACG::GLState::blendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPolygonMode(GL_FRONT, GL_FILL);
glColor4f( 0.6, 0.15, 0.2, 0.5 );
_state.set_color(ACG::Vec4f( 0.6, 0.15, 0.2, 0.5));
glDrawArrays(GL_QUADS,0,4);
//finally the green back side
glPolygonMode(GL_BACK, GL_FILL);
glColor4f( 0.1, 0.8, 0.2, 0.5 );
_state.set_color(ACG::Vec4f(0.1, 0.8, 0.2, 0.5 ));
glDrawArrays(GL_QUADS,0,4);
glDrawArrays(GL_QUADS,4,4);
if ( !blending )
ACG::GLState::disable(GL_BLEND);
// deactivate vertex arrays after drawing
_state.disableClientState(GL_VERTEX_ARRAY);
......@@ -264,83 +273,163 @@ void PlaneNode::setPlane(Plane plane)
//----------------------------------------------------------------------------
void
PlaneNode::
addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer, ACG::GLState& _state, ACG::RenderObject* _ro) {
// 1. Project point to screen
ACG::Vec3d projected = _state.project( _pos );
// 2. Shift it by the requested point size
// glPointSize defines the diameter but we want the radius, so we divide it by two
ACG::Vec3d shifted = projected;
shifted[0] = shifted[0] + (double)_state.point_size() / 2.0 ;
// 3. un-project into 3D
ACG::Vec3d unProjectedShifted = _state.unproject( shifted );
// 4. The difference vector defines the radius in 3D for the sphere
ACG::Vec3d difference = unProjectedShifted - _pos ;
const double sphereSize = difference.norm();
sphere_->addToRenderer(_renderer, _ro, sphereSize, ACG::Vec3f(_pos));
}
//----------------------------------------------------------------------------
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;
// memset(&ro, 0, sizeof(ACG::RenderObject));
//
//_state.enable(GL_COLOR_MATERIAL);
//_state.disable(GL_LIGHTING);
// ro.initFromState(&_state);
//
//
//// glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
//// ACG::GLState::enable(GL_COLOR_MATERIAL);
//
// // plane_.position represents the center of the plane.
// // Compute the corner position
// const ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
//
// // translate to corner position and store that in renderer
// _state.push_modelview_matrix();
// _state.translate(pos[0], pos[1], pos[2]);
// ro.modelview = _state.modelview();
// _state.pop_modelview_matrix();
//
//
// // Set the local material
// ACG::SceneGraph::Material localMaterial = *_mat;
// localMaterial.baseColor(ACG::Vec4f(1.0,0.0,0.0,1.0));
// localMaterial.ambientColor(ACG::Vec4f(1.0,0.0,0.0,1.0));
// localMaterial.diffuseColor(ACG::Vec4f(1.0,0.0,0.0,1.0));
// localMaterial.specularColor(ACG::Vec4f(1.0,0.0,0.0,1.0));
//// localMaterial.disableBackfaceCulling();
//// localMaterial.enableColorMaterial();
//
// ro.setMaterial(_mat);
//
//
// // draw the plane
//
// const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
//
// // Array of coordinates for the plane ( duplicated due to front and back rendering )
// float vboData_[8 * 3 ] = { 0.0,0.0,0.0,
// (float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
// (float)xy[0],(float)xy[1],(float)xy[2],
// (float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
// (float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
// (float)xy[0],(float)xy[1],(float)xy[2],
// (float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
// 0.0,0.0,0.0 };
//
// // Create buffer for vertex coordinates if necessary
// if ( ! vbo_ ) {
// glGenBuffersARB(1, &vbo_);
// }
//
// // Bind buffer
// glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
//
// // Upload to buffer ( 4 vertices with 3 coordinates of 4 byte sized floats)
// glBufferDataARB(GL_ARRAY_BUFFER_ARB, 8 * 3 * 4, &vboData_[0], GL_STATIC_DRAW_ARB);
//
//
// ro.vertexBuffer = vbo_;
// ro.vertexDecl = &vertexDecl_;
//
//// ro.culling = false;
//// ro.blending = false;
//// ro.depthTest =false;
//
// ro.glDrawArrays(GL_QUADS, 0, 8);
//
// ro.debugName = "PlaneNode.plane";
//
// _renderer->addRenderObject(&ro);
// init base render object
ACG::RenderObject ro;
memset(&ro, 0, sizeof(ACG::RenderObject));
_state.enable(GL_COLOR_MATERIAL);
_state.disable(GL_LIGHTING);
ro.initFromState(&_state);
// plane_.position represents the center of the plane.
// Compute the corner position
const ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
// translate to corner position and store that in renderer
_state.push_modelview_matrix();
_state.translate(pos[0], pos[1], pos[2]);
ro.modelview = _state.modelview();
_state.pop_modelview_matrix();
// Render with depth test enabled
ro.depthTest = true;
// Compute the plane normal and outer corner
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
const ACG::Vec3d normal = (plane_.xDirection % plane_.yDirection).normalized();
// Array of coordinates for the plane ( duplicated due to front and back rendering )
// Interleaved with normals
float vboData_[8 * 3 * 2 ] = { 0.0,0.0,0.0,
(float)normal[0],(float)normal[1],(float)normal[2],
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
(float)normal[0],(float)normal[1],(float)normal[2],
(float)xy[0],(float)xy[1],(float)xy[2],
(float)normal[0],(float)normal[1],(float)normal[2],
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)normal[0],(float)normal[1],(float)normal[2],
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)-normal[0],(float)-normal[1],(float)-normal[2],
(float)xy[0],(float)xy[1],(float)xy[2],
(float)-normal[0],(float)-normal[1],(float)-normal[2],
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
(float)-normal[0],(float)-normal[1],(float)-normal[2],
0.0,0.0,0.0,
(float)-normal[0],(float)-normal[1],(float)-normal[2]};
// Create buffer for vertex coordinates if necessary
if ( ! vbo_ ) {
glGenBuffersARB(1, &vbo_);
}
// Bind buffer
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_);
// Upload to buffer ( 4 vertices with 3 coordinates for point and normal of 4 byte sized floats)
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 8 * 3 * 2 * 4, &vboData_[0], GL_STATIC_DRAW_ARB);
// Set the buffers for rendering
ro.vertexBuffer = vbo_;
ro.vertexDecl = &vertexDecl_;
for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
{
ACG::SceneGraph::Material localMaterial = *_mat;
const ACG::SceneGraph::DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
ro.setupShaderGenFromDrawmode(props);
switch (props->primitive()) {
case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
ro.blending = false;
//---------------------------------------------------
// No lighting!
// Therefore we need some emissive color
//---------------------------------------------------
localMaterial.baseColor( localMaterial.ambientColor() );
ro.setMaterial(&localMaterial);
//---------------------------------------------------
// Simulate glPointSize(12) with a sphere
//---------------------------------------------------
addSphereAt(plane_.xDirection,_renderer,_state,&ro);
addSphereAt(plane_.yDirection,_renderer,_state,&ro);
addSphereAt(xy,_renderer,_state,&ro);
addSphereAt(ACG::Vec3d(0.0,0.0,0.0),_renderer,_state,&ro);
break;
default:
ro.priority = 10;
// Blending enabled, since we wan't some transparency
ro.blending = true;
ro.blendSrc = GL_SRC_ALPHA;
ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
//---------------------------------------------------
// Just draw the quads here ( front )
//---------------------------------------------------
ro.debugName = "PlaneNode.plane_front";
localMaterial.ambientColor(ACG::Vec4f(0.6, 0.15, 0.2, 0.5 ));
localMaterial.diffuseColor(ACG::Vec4f(0.6, 0.15, 0.2, 0.5 ));
localMaterial.specularColor(ACG::Vec4f(0.6, 0.15, 0.2, 0.5 ));
ro.setMaterial(&localMaterial);
ro.glDrawArrays(GL_QUADS, 0, 4);
_renderer->addRenderObject(&ro);
//---------------------------------------------------
// Just draw the quads here ( back )
//---------------------------------------------------
ro.debugName = "PlaneNode.plane_back";
localMaterial.ambientColor( ACG::Vec4f(0.1, 0.8, 0.2, 0.5 ));
localMaterial.diffuseColor( ACG::Vec4f(0.1, 0.8, 0.2, 0.5 ));
localMaterial.specularColor(ACG::Vec4f(0.1, 0.8, 0.2, 0.5 ));
ro.setMaterial(&localMaterial);
ro.glDrawArrays(GL_QUADS, 4, 4);
_renderer->addRenderObject(&ro);
break;
}
}
}
......
......@@ -58,6 +58,7 @@
#include <OpenFlipper/common/GlobalDefines.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/GLPrimitives.hh>
//== NAMESPACES ===============================================================
......@@ -125,12 +126,17 @@ private:
void drawPlanePick(ACG::GLState & _state);
void drawManipulatorPick(ACG::GLState & _state);
void addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer, ACG::GLState& _state, ACG::RenderObject* _ro);
Plane& plane_;
unsigned int vbo_;
ACG::VertexDeclaration vertexDecl_;
ACG::GLSphere* sphere_;
};
//=============================================================================
......
......@@ -128,12 +128,14 @@ BaseObject* PlaneObject::copy() {
return dynamic_cast< BaseObject* >(object);
}
/** This function initalizes the plane object. It creates the scenegraph nodes.
/** This function initializes the plane object. It creates the scenegraph nodes.
*/
void PlaneObject::init(const Plane* _plane) {
if ( materialNode() == NULL)
if ( materialNode() == NULL) {
std::cerr << "Error when creating Plane Object! materialNode is NULL!" << std::endl;
return;
}
planeNode_ = new PlaneNode( plane_, materialNode() , "NEW PlaneNode" );
......@@ -143,6 +145,8 @@ void PlaneObject::init(const Plane* _plane) {
plane_.setPlane( ACG::Vec3d(0.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0) );
plane_.setSize( 5.0, 5.0 );
}
materialNode()->set_point_size(3.0);
}
// ===============================================================================
......
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