Documentation


myGLRendererShapeVisitor.cpp

Go to the documentation of this file.
00001 #include "myGLRendererShapeVisitor.h"
00002 #include "myGLRendererStateVariables.h"
00003 #include "myGLBbox.h"
00004 
00005 #include <X3DTK/private/GL_Material.h>
00006 #include <X3DTK/private/GL_X3DShapeNode.h>
00007 
00008 #include <iostream>
00009 
00010 using namespace std;
00011 
00012 namespace X3DTK {
00013 namespace GL {
00014 
00015 MyRendererShapeVisitor::MyRendererShapeVisitor()
00016 : ShapeVisitor()
00017 {
00018 // Enter functions.
00019   define(Recorder<Material>::getEnterFunction(&MyRendererShapeVisitor::enterMaterial));
00020   define(Recorder<X3DShapeNode>::getEnterFunction(&MyRendererShapeVisitor::enterX3DShapeNode));
00021 //   // Enter functions.
00022 //   defineEnterFunction(&MyRendererShapeVisitor::enterMaterial);
00023 //   defineEnterFunction(&MyRendererShapeVisitor::enterX3DShapeNode);
00024 }
00025 
00026 void MyRendererShapeVisitor::enterMaterial(Material *M) 
00027 {
00028   glMaterialfv(GL_FRONT, GL_DIFFUSE, &M->getDiffuseColor().front());
00029   glMaterialfv(GL_FRONT, GL_AMBIENT, &M->getAmbientColor().front());
00030   glMaterialfv(GL_FRONT, GL_EMISSION, &M->getEmissiveColor().front());
00031   SFFloat s = M->getShininess();
00032   glMaterialfv(GL_FRONT, GL_SHININESS, &s); 
00033   glMaterialfv(GL_FRONT, GL_SPECULAR, &M->getSpecularColor().front());
00034 }
00035 
00036 void MyRendererShapeVisitor::enterX3DShapeNode(X3DShapeNode *N) 
00037 {
00038 
00039 MyRendererStateVariables *stateVariables = Singleton<MyRendererStateVariables>::getInstance();
00040   if (stateVariables->getSelectionMode())
00041   {
00042     stateVariables->storeShape(N);
00043     glLoadName(stateVariables->getCurrentId());
00044    }
00045 //   MyRendererStateVariables *stateVariables = GraphTraversal::getInstanceOf<MyRendererStateVariables>();
00046 //   if (stateVariables->getSelectionMode())
00047 //   {
00048 //     stateVariables->storeShape(N);
00049 //     glLoadName(stateVariables->getCurrentId());
00050 // //    cout << "loading name " << stateVariables->getCurrentId() << endl;
00051 //   } 
00052   
00053   X3D::X3DNode * X3D_N = N->getX3DReference ();
00054   if (X3D::X3DBoundedObject * X3DBN = dynamic_cast<X3D::X3DBoundedObject *>(X3D_N))
00055   {
00056     if (stateVariables->boundedObject==X3DBN)
00057     {
00058       GL::MyGLBbox bbox;
00059       bbox.setSize(X3DBN->getBBoxSize());
00060       bbox.setCenter(X3DBN->getBBoxCenter());
00061       bbox.draw();
00062     }
00063   } 
00064 }
00065 
00066 }
00067 }
00068 
00069 /*
00070 RendererShapeVisitor::RendererShapeVisitor()
00071 : ShapeVisitor()
00072 {
00073   // Enter functions.
00074   define(Recorder<Material>::getEnterFunction(&RendererShapeVisitor::enterMaterial));
00075   define(Recorder<X3DShapeNode>::getEnterFunction(&RendererShapeVisitor::enterX3DShapeNode));
00076 }
00077 
00078 void RendererShapeVisitor::enterMaterial(Material *M) 
00079 {
00080   RendererStateVariables *stateVariables = Singleton<RendererStateVariables>::getInstance();
00081   
00082   glMaterialfv(GL_FRONT, GL_DIFFUSE, &M->getDiffuseColor().front());
00083   glMaterialfv(GL_FRONT, GL_AMBIENT, &M->getAmbientColor().front());
00084   glMaterialfv(GL_FRONT, GL_EMISSION, &M->getEmissiveColor().front());
00085   SFFloat s = M->getShininess();
00086   glMaterialfv(GL_FRONT, GL_SHININESS, &s); 
00087   glMaterialfv(GL_FRONT, GL_SPECULAR, &M->getSpecularColor().front());
00088 }
00089 
00090 void RendererShapeVisitor::enterX3DShapeNode(X3DShapeNode *N) 
00091 {
00092   RendererStateVariables *stateVariables = Singleton<RendererStateVariables>::getInstance();
00093   if (stateVariables->getSelectionMode())
00094   {
00095     stateVariables->storeShape(N);
00096     glLoadName(stateVariables->getCurrentId());
00097 //    cout << "loading name " << stateVariables->getCurrentId() << endl;
00098   }  
00099 }
00100 */

Generated on Thu Dec 23 13:52:26 2004 by doxygen 1.3.6