Skip to content
Snippets Groups Projects

adding uvs

Merged Jan Möbius requested to merge update_type_plane into master
1 file
+ 217
216
Compare changes
  • Side-by-side
  • Inline
+ 217
216
@@ -53,174 +53,185 @@
@@ -53,174 +53,185 @@
//== IMPLEMENTATION ==========================================================
//== IMPLEMENTATION ==========================================================
PlaneNode::PlaneNode(Plane& _plane, BaseNode* _parent, std::string _name)
PlaneNode::PlaneNode(Plane& _plane, BaseNode *_parent, std::string _name)
: BaseNode(_parent, _name),
:BaseNode(_parent, _name),
plane_(_plane),
plane_(_plane),
vbo_(0),
vbo_(0),
vboNeedsUpdate_(true), // not initialized, so we need an update
vboNeedsUpdate_(true),//not initialized, so we need an update
sphere_(0)
sphere_(0)
{
{
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_NORMAL);
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_NORMAL);
 
vertexDecl_.addElement(GL_FLOAT, 2, ACG::VERTEX_USAGE_TEXCOORD);
sphere_ = new ACG::GLSphere(10, 10);
sphere_ = new ACG::GLSphere(10, 10);
setPlane(_plane);
setPlane(_plane);
}
}
PlaneNode::~PlaneNode()
PlaneNode::~PlaneNode() {
{
if (vbo_) glDeleteBuffers(1, &vbo_);
if ( vbo_)
glDeleteBuffers(1,&vbo_);
}
}
void PlaneNode::boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax)
void PlaneNode::boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax) {
{
ACG::Vec3d pos =
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
ACG::Vec3d pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
// add a little offset in normal direction
//add a little offset in normal direction
ACG::Vec3d pos0 = ACG::Vec3d(pos + plane_.normal * 0.1);
ACG::Vec3d pos0 = ACG::Vec3d( pos + plane_.normal * 0.1 );
ACG::Vec3d pos1 = ACG::Vec3d(pos - plane_.normal * 0.1);
ACG::Vec3d pos1 = ACG::Vec3d( pos - plane_.normal * 0.1 );
ACG::Vec3d xDird = ACG::Vec3d(plane_.xDirection);
ACG::Vec3d xDird = ACG::Vec3d( plane_.xDirection );
ACG::Vec3d yDird = ACG::Vec3d(plane_.yDirection);
ACG::Vec3d yDird = ACG::Vec3d( plane_.yDirection );
_bbMin.minimize(pos0);
_bbMin.minimize( pos0 );
_bbMin.minimize(pos0 + xDird);
_bbMin.minimize( pos0 + xDird);
_bbMin.minimize(pos0 + yDird);
_bbMin.minimize( pos0 + yDird);
_bbMin.minimize(pos0 + xDird + yDird);
_bbMin.minimize( pos0 + xDird + yDird);
_bbMax.maximize(pos1);
_bbMax.maximize( pos1 );
_bbMax.maximize(pos1 + xDird);
_bbMax.maximize( pos1 + xDird);
_bbMax.maximize(pos1 + yDird);
_bbMax.maximize( pos1 + yDird);
_bbMax.maximize(pos1 + xDird + yDird);
_bbMax.maximize( pos1 + xDird + yDird);
_bbMin.minimize(pos1);
_bbMin.minimize( pos1 );
_bbMin.minimize(pos1 + xDird);
_bbMin.minimize( pos1 + xDird);
_bbMin.minimize(pos1 + yDird);
_bbMin.minimize( pos1 + yDird);
_bbMin.minimize(pos1 + xDird + yDird);
_bbMin.minimize( pos1 + xDird + yDird);
_bbMax.maximize(pos0);
_bbMax.maximize( pos0 );
_bbMax.maximize(pos0 + xDird);
_bbMax.maximize( pos0 + xDird);
_bbMax.maximize(pos0 + yDird);
_bbMax.maximize( pos0 + yDird);
_bbMax.maximize(pos0 + xDird + yDird);
_bbMax.maximize( pos0 + xDird + yDird);
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
ACG::SceneGraph::DrawModes::DrawMode
ACG::SceneGraph::DrawModes::DrawMode PlaneNode::availableDrawModes() const {
PlaneNode::availableDrawModes() const
return (ACG::SceneGraph::DrawModes::POINTS |
{
ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED);
return ( ACG::SceneGraph::DrawModes::POINTS |
ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED );
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void PlaneNode::drawPlane( ACG::GLState& _state) {
void PlaneNode::drawPlane(ACG::GLState& _state) {
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
// Array of coordinates for the plane
// Array of coordinates for the plane
float vboData_[9 * 3 ] = { 0.0,0.0,0.0,
float vboData_[9 * 3] = {0.0,
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
0.0,
(float)xy[0],(float)xy[1],(float)xy[2],
0.0,
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)plane_.xDirection[0],
0.0,0.0,0.0,
(float)plane_.xDirection[1],
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)plane_.xDirection[2],
(float)xy[0],(float)xy[1],(float)xy[2],
(float)xy[0],
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
(float)xy[1],
0.0,0.0,0.0 };
(float)xy[2],
(float)plane_.yDirection[0],
// Enable the arrays
(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.enableClientState(GL_VERTEX_ARRAY);
_state.vertexPointer(3,GL_FLOAT,0,&vboData_[0]);
_state.vertexPointer(3, GL_FLOAT, 0, &vboData_[0]);
//first draw the lines
// first draw the lines
_state.set_color(ACG::Vec4f(1.0, 1.0, 1.0 , 1.0) );
_state.set_color(ACG::Vec4f(1.0, 1.0, 1.0, 1.0));
glLineWidth(2.0);
glLineWidth(2.0);
glDrawArrays(GL_LINE_STRIP,0,5);
glDrawArrays(GL_LINE_STRIP, 0, 5);
glLineWidth(1.0);
glLineWidth(1.0);
// Remember blending state
// Remember blending state
bool blending = _state.blending();
bool blending = _state.blending();
bool culling = _state.isStateEnabled(GL_CULL_FACE);
bool culling = _state.isStateEnabled(GL_CULL_FACE);
//then the red front side
ACG::GLState::enable (GL_BLEND);
ACG::GLState::blendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ACG::GLState::enable (GL_CULL_FACE);
// then the red front side
 
ACG::GLState::enable(GL_BLEND);
 
ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_state.set_color(ACG::Vec4f( 0.6f, 0.15f, 0.2f, 0.5f));
ACG::GLState::enable(GL_CULL_FACE);
glDrawArrays(GL_QUADS,0,4);
 
_state.set_color(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
 
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//finally the green back side
// finally the green back side
_state.set_color(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f ));
_state.set_color(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
glDrawArrays(GL_QUADS,5,4);
glDrawArrays(GL_TRIANGLE_FAN, 5, 4);
if ( !blending )
if (!blending) ACG::GLState::disable(GL_BLEND);
ACG::GLState::disable(GL_BLEND);
if ( !culling )
if (!culling) ACG::GLState::disable(GL_CULL_FACE);
ACG::GLState::disable(GL_CULL_FACE);
// deactivate vertex arrays after drawing
// deactivate vertex arrays after drawing
_state.disableClientState(GL_VERTEX_ARRAY);
_state.disableClientState(GL_VERTEX_ARRAY);
}
}
//----------------------------------------------------------------
//----------------------------------------------------------------
void PlaneNode::drawPlanePick( ACG::GLState& _state) {
void PlaneNode::drawPlanePick(ACG::GLState& _state) {
_state.pick_set_maximum(1);
_state.pick_set_maximum(1);
_state.pick_set_name(0);
_state.pick_set_name(0);
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
// Array of coordinates for the plane
// Array of coordinates for the plane
float vboData_[4* 3 ] = { 0.0,0.0,0.0,
float vboData_[4 * 3] = {0.0,
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
0.0,
(float)xy[0],(float)xy[1],(float)xy[2],
0.0,
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2] };
(float)plane_.xDirection[0],
(float)plane_.xDirection[1],
// Enable the arrays
(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]};
 
 
// Enable the arrays
_state.enableClientState(GL_VERTEX_ARRAY);
_state.enableClientState(GL_VERTEX_ARRAY);
_state.vertexPointer(3,GL_FLOAT,0,&vboData_[0]);
_state.vertexPointer(3, GL_FLOAT, 0, &vboData_[0]);
glDrawArrays(GL_QUADS,0,4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
// deactivate vertex arrays after drawing
// deactivate vertex arrays after drawing
_state.disableClientState(GL_VERTEX_ARRAY);
_state.disableClientState(GL_VERTEX_ARRAY);
}
}
//----------------------------------------------------------------
//----------------------------------------------------------------
void PlaneNode::draw(ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& /*_drawMode*/)
void PlaneNode::draw(
{
ACG::GLState& _state,
const ACG::SceneGraph::DrawModes::DrawMode& /*_drawMode*/) {
_state.push_modelview_matrix();
_state.push_modelview_matrix();
glPushAttrib(GL_COLOR_BUFFER_BIT);
glPushAttrib(GL_COLOR_BUFFER_BIT);
glPushAttrib(GL_LIGHTING_BIT);
glPushAttrib(GL_LIGHTING_BIT);
glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
ACG::GLState::enable(GL_COLOR_MATERIAL);
ACG::GLState::enable(GL_COLOR_MATERIAL);
// plane_.position represents the center of the plane.
// plane_.position represents the center of the plane.
// Compute the corner position
// Compute the corner position
ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
ACG::Vec3d pos =
 
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
// translate to corner position
// translate to corner position
_state.translate(pos[0], pos[1], pos[2]);
_state.translate(pos[0], pos[1], pos[2]);
@@ -233,87 +244,69 @@ void PlaneNode::draw(ACG::GLState& _state , const ACG::SceneGraph::DrawModes::
@@ -233,87 +244,69 @@ void PlaneNode::draw(ACG::GLState& _state , const ACG::SceneGraph::DrawModes::
_state.pop_modelview_matrix();
_state.pop_modelview_matrix();
}
}
//----------------------------------------------------------------
//----------------------------------------------------------------
void
void PlaneNode::pick(ACG::GLState& _state,
PlaneNode::pick(ACG::GLState& _state, ACG::SceneGraph::PickTarget _target)
ACG::SceneGraph::PickTarget _target) {
{
if (_target == ACG::SceneGraph::PICK_ANYTHING) {
if (_target == ACG::SceneGraph::PICK_ANYTHING) {
 
_state.push_modelview_matrix();
 
 
ACG::Vec3d pos =
 
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
 
 
_state.translate(pos[0], pos[1], pos[2]);
_state.push_modelview_matrix();
drawPlanePick(_state);
ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
_state.translate(pos[0], pos[1], pos[2]);
_state.pop_modelview_matrix();
drawPlanePick(_state);
_state.pop_modelview_matrix();
}
}
}
}
//----------------------------------------------------------------
//----------------------------------------------------------------
ACG::Vec3d PlaneNode::position()
ACG::Vec3d PlaneNode::position() { return plane_.position; }
{
return plane_.position;
}
//----------------------------------------------------------------
//----------------------------------------------------------------
ACG::Vec3d PlaneNode::normal()
ACG::Vec3d PlaneNode::normal() { return plane_.normal; }
{
return plane_.normal;
}
//----------------------------------------------------------------
//----------------------------------------------------------------
ACG::Vec3d PlaneNode::xDirection()
ACG::Vec3d PlaneNode::xDirection() { return plane_.xDirection; }
{
return plane_.xDirection;
}
//----------------------------------------------------------------
//----------------------------------------------------------------
ACG::Vec3d PlaneNode::yDirection()
ACG::Vec3d PlaneNode::yDirection() { return plane_.yDirection; }
{
return plane_.yDirection;
}
//----------------------------------------------------------------
//----------------------------------------------------------------
PlaneNode::Plane& PlaneNode::getPlane()
PlaneNode::Plane& PlaneNode::getPlane() { return plane_; }
{
return plane_;
}
//----------------------------------------------------------------
//----------------------------------------------------------------
void PlaneNode::setPlane(Plane plane)
void PlaneNode::setPlane(Plane plane) {
{
plane_ = plane;
plane_ = plane;
update();
update();
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void
void PlaneNode::addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer,
PlaneNode::
ACG::GLState& _state, ACG::RenderObject* _ro) {
addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer, ACG::GLState& _state, ACG::RenderObject* _ro) {
// 1. Project point to screen
// 1. Project point to screen
ACG::Vec3d projected = _state.project( _pos );
ACG::Vec3d projected = _state.project(_pos);
// 2. Shift it by the requested point size
// 2. Shift it by the requested point size
// glPointSize defines the diameter but we want the radius, so we divide it by two
// glPointSize defines the diameter but we want the radius, so we divide it
 
// by two
ACG::Vec3d shifted = projected;
ACG::Vec3d shifted = projected;
shifted[0] = shifted[0] + (double)_state.point_size() / 2.0 ;
shifted[0] = shifted[0] + (double)_state.point_size() / 2.0;
// 3. un-project into 3D
// 3. un-project into 3D
ACG::Vec3d unProjectedShifted = _state.unproject( shifted );
ACG::Vec3d unProjectedShifted = _state.unproject(shifted);
// 4. The difference vector defines the radius in 3D for the sphere
// 4. The difference vector defines the radius in 3D for the sphere
ACG::Vec3d difference = unProjectedShifted - _pos ;
ACG::Vec3d difference = unProjectedShifted - _pos;
const double sphereSize = difference.norm();
const double sphereSize = difference.norm();
@@ -321,79 +314,93 @@ addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer, ACG::GLState& _state, A
@@ -321,79 +314,93 @@ addSphereAt(ACG::Vec3d _pos, ACG::IRenderer* _renderer, ACG::GLState& _state, A
}
}
void PlaneNode::update() {
void PlaneNode::update() {
//update the plane in the next renderstep
// update the plane in the next renderstep
//if the old renderer is used, nothing to do here
// if the old renderer is used, nothing to do here
//if the new, shader based renderer is used, we have to update the vbo
// if the new, shader based renderer is used, we have to update the vbo
// this is done at the next render call
// this is done at the next render call
//this method prevents, that the vbo is created, if we don't use a shader based renderer
// this method prevents, that the vbo is created, if we don't use a shader
vboNeedsUpdate_ = true;
// based renderer
 
vboNeedsUpdate_ = true;
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void PlaneNode::updateVBO()
void PlaneNode::updateVBO() {
{
if (!vboNeedsUpdate_) return;
if (!vboNeedsUpdate_)
return;
if ( !vbo_ ) {
if (!vbo_) {
glGenBuffers(1, &vbo_);
glGenBuffers(1, &vbo_);
}
}
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
const ACG::Vec3d normal = (plane_.xDirection % plane_.yDirection).normalized();
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
// Array of coordinates for the plane ( duplicated due to front and back
// 8 vertices with (3 float for position + 3 float for normal)
// rendering ) Interleaved with normals 8 vertices with (3 float for position
const size_t vboSize = 8 * (3+3);
// + 3 float for normal + 2 for uv)
float vboData[vboSize] = { 0.0,0.0,0.0,
const size_t vboSize = 8 * (3 + 3 + 2);
(float)normal[0],(float)normal[1],(float)normal[2],
float vboData[vboSize] = {
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
// vertex A
(float)normal[0],(float)normal[1],(float)normal[2],
0.0, 0.0, 0.0, (float)normal[0], (float)normal[1], (float)normal[2], 0.f,
(float)xy[0],(float)xy[1],(float)xy[2],
0.f,
(float)normal[0],(float)normal[1],(float)normal[2],
// vertex B
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)plane_.xDirection[0], (float)plane_.xDirection[1],
(float)normal[0],(float)normal[1],(float)normal[2],
(float)plane_.xDirection[2], (float)normal[0], (float)normal[1],
(float)plane_.yDirection[0],(float)plane_.yDirection[1],(float)plane_.yDirection[2],
(float)normal[2], 1.f, 0.f,
(float)-normal[0],(float)-normal[1],(float)-normal[2],
// vertex C
(float)xy[0],(float)xy[1],(float)xy[2],
(float)xy[0], (float)xy[1], (float)xy[2], (float)normal[0],
(float)-normal[0],(float)-normal[1],(float)-normal[2],
(float)normal[1], (float)normal[2], 1.f, 1.f,
(float)plane_.xDirection[0],(float)plane_.xDirection[1],(float)plane_.xDirection[2],
// vertex D
(float)-normal[0],(float)-normal[1],(float)-normal[2],
(float)plane_.yDirection[0], (float)plane_.yDirection[1],
0.0,0.0,0.0,
(float)plane_.yDirection[2], (float)normal[0], (float)normal[1],
(float)-normal[0],(float)-normal[1],(float)-normal[2]};
(float)normal[2], 0.f, 1.f,
// backside vertex D
 
(float)plane_.yDirection[0], (float)plane_.yDirection[1],
 
(float)plane_.yDirection[2], (float)-normal[0], (float)-normal[1],
 
(float)-normal[2], 0.f, 1.f,
 
// backside vertex C
 
(float)xy[0], (float)xy[1], (float)xy[2], (float)-normal[0],
 
(float)-normal[1], (float)-normal[2], 1.f, 1.f,
 
// backside vertex B
 
(float)plane_.xDirection[0], (float)plane_.xDirection[1],
 
(float)plane_.xDirection[2], (float)-normal[0], (float)-normal[1],
 
(float)-normal[2], 1.f, 0.f,
 
// backside vertex A
 
0.0, 0.0, 0.0, (float)-normal[0], (float)-normal[1], (float)-normal[2],
 
0.f, 0.f};
// Bind buffer
// Bind buffer
glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo_);
glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo_);
// Upload to buffer
// Upload to buffer
glBufferData(GL_ARRAY_BUFFER_ARB, vboSize * sizeof(float), &vboData[0], GL_STATIC_DRAW_ARB);
glBufferData(GL_ARRAY_BUFFER_ARB, vboSize * sizeof(float), &vboData[0],
 
GL_STATIC_DRAW_ARB);
// Unbind
// Unbind
ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
ACG::GLState::bindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
// VBO is updated for the new renderer
// VBO is updated for the new renderer
vboNeedsUpdate_ = false;
vboNeedsUpdate_ = false;
}
}
void
void PlaneNode::getRenderObjects(
PlaneNode::
ACG::IRenderer* _renderer, ACG::GLState& _state,
getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) {
const ACG::SceneGraph::DrawModes::DrawMode& _drawMode,
const ACG::SceneGraph::Material* _mat) {
// init base render object
// init base render object
ACG::RenderObject ro;
ACG::RenderObject ro;
_state.enable(GL_COLOR_MATERIAL);
// _state.enable(GL_COLOR_MATERIAL);
_state.disable(GL_LIGHTING);
// _state.disable(GL_LIGHTING);
ro.initFromState(&_state);
ro.initFromState(&_state);
// plane_.position represents the center of the plane.
// plane_.position represents the center of the plane.
// Compute the corner position
// Compute the corner position
const ACG::Vec3d pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
const ACG::Vec3d pos =
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
 
const ACG::Vec3d xy = plane_.xDirection + plane_.yDirection;
// translate to corner position and store that in renderer
// translate to corner position and store that in renderer
_state.push_modelview_matrix();
_state.push_modelview_matrix();
@@ -408,20 +415,17 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
@@ -408,20 +415,17 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Set the buffers for rendering
// Set the buffers for rendering
ro.vertexBuffer = vbo_;
ro.vertexBuffer = vbo_;
ro.vertexDecl = &vertexDecl_;
ro.vertexDecl = &vertexDecl_;
for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i) {
for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
{
ACG::SceneGraph::Material localMaterial = *_mat;
ACG::SceneGraph::Material localMaterial = *_mat;
const ACG::SceneGraph::DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
const ACG::SceneGraph::DrawModes::DrawModeProperties* props =
_drawMode.getLayer(i);
ro.setupShaderGenFromDrawmode(props);
ro.setupShaderGenFromDrawmode(props);
switch (props->primitive()) {
switch (props->primitive()) {
case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
ro.blending = false;
ro.blending = false;
@@ -430,7 +434,7 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
@@ -430,7 +434,7 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// No lighting!
// No lighting!
// Therefore we need some emissive color
// Therefore we need some emissive color
//---------------------------------------------------
//---------------------------------------------------
localMaterial.baseColor( localMaterial.ambientColor() );
localMaterial.baseColor(localMaterial.ambientColor());
ro.setMaterial(&localMaterial);
ro.setMaterial(&localMaterial);
//---------------------------------------------------
//---------------------------------------------------
@@ -438,26 +442,25 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
@@ -438,26 +442,25 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
//---------------------------------------------------
//---------------------------------------------------
ro.debugName = "Plane Sphere x";
ro.debugName = "Plane Sphere x";
addSphereAt(plane_.xDirection,_renderer,_state,&ro);
addSphereAt(plane_.xDirection, _renderer, _state, &ro);
ro.debugName = "Plane Sphere y";
ro.debugName = "Plane Sphere y";
addSphereAt(plane_.yDirection,_renderer,_state,&ro);
addSphereAt(plane_.yDirection, _renderer, _state, &ro);
ro.debugName = "Plane Sphere xy";
ro.debugName = "Plane Sphere xy";
addSphereAt(xy,_renderer,_state,&ro);
addSphereAt(xy, _renderer, _state, &ro);
ro.debugName = "Plane Sphere 0";
ro.debugName = "Plane Sphere 0";
addSphereAt(ACG::Vec3d(0.0,0.0,0.0),_renderer,_state,&ro);
addSphereAt(ACG::Vec3d(0.0, 0.0, 0.0), _renderer, _state, &ro);
break;
break;
default:
default:
ro.priority = 10;
ro.priority = 10;
// Blending enabled, since we wan't some transparency
// Blending enabled, since we wan't some transparency
ro.blending = true;
ro.blending = true;
ro.blendSrc = GL_SRC_ALPHA;
ro.blendSrc = GL_SRC_ALPHA;
ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
// Enable culling in order to avoid z-fighting artifacts
// Enable culling in order to avoid z-fighting artifacts
@@ -467,31 +470,29 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
@@ -467,31 +470,29 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Just draw the quads here ( front )
// Just draw the quads here ( front )
//---------------------------------------------------
//---------------------------------------------------
ro.debugName = "PlaneNode.plane_front ";
ro.debugName = "PlaneNode.plane_front ";
localMaterial.ambientColor(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.diffuseColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
localMaterial.specularColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f ));
localMaterial.specularColor(ACG::Vec4f(0.6f, 0.15f, 0.2f, 0.5f));
ro.setMaterial(&localMaterial);
ro.setMaterial(&localMaterial);
ro.glDrawArrays(GL_QUADS, 0, 4);
/// quads are not accepted here in opengl core. this has to be updated
 
ro.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
_renderer->addRenderObject(&ro);
_renderer->addRenderObject(&ro);
//---------------------------------------------------
//---------------------------------------------------
// Just draw the quads here ( back )
// Just draw the quads here ( back )
//---------------------------------------------------
//---------------------------------------------------
ro.debugName = "PlaneNode.plane_back";
ro.debugName = "PlaneNode.plane_back";
localMaterial.ambientColor( 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.diffuseColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
localMaterial.specularColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f ));
localMaterial.specularColor(ACG::Vec4f(0.1f, 0.8f, 0.2f, 0.5f));
ro.setMaterial(&localMaterial);
ro.setMaterial(&localMaterial);
ro.glDrawArrays(GL_QUADS, 4, 4);
/// quads are not accepted here in opengl core. this has to be updated
 
ro.glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
_renderer->addRenderObject(&ro);
_renderer->addRenderObject(&ro);
break;
break;
}
}
}
}
}
}
//=============================================================================
//=============================================================================
Loading