SoDrawingGrid.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "PreCompiled.h"
00024 #ifdef FC_OS_MACOSX
00025 #include <OpenGL/gl.h>
00026 #else
00027 #include <GL/gl.h>
00028 #endif
00029 #include <Inventor/actions/SoGLRenderAction.h>
00030 #include <Inventor/elements/SoCacheElement.h>
00031 #include <Inventor/elements/SoLazyElement.h>
00032 #include <Inventor/elements/SoModelMatrixElement.h>
00033 #include <Inventor/elements/SoProjectionMatrixElement.h>
00034 #include <Inventor/elements/SoViewingMatrixElement.h>
00035 #include <Inventor/elements/SoViewVolumeElement.h>
00036 #include <Inventor/elements/SoViewportRegionElement.h>
00037
00038 #include "SoDrawingGrid.h"
00039
00040 using namespace Gui::Inventor;
00041
00042
00043
00044
00045
00046
00047
00048 SO_NODE_SOURCE(SoDrawingGrid);
00049
00050 void
00051 SoDrawingGrid::initClass()
00052 {
00053 SO_NODE_INIT_CLASS(SoDrawingGrid, SoShape, "Shape");
00054 }
00055
00056 SoDrawingGrid::SoDrawingGrid()
00057 {
00058 SO_NODE_CONSTRUCTOR(SoDrawingGrid);
00059 }
00060
00061 void
00062 SoDrawingGrid::renderGrid(SoGLRenderAction *action)
00063 {
00064 if (!shouldGLRender(action))
00065 return;
00066
00067 SoState* state = action->getState();
00068 state->push();
00069 SoLazyElement::setLightModel(state, SoLazyElement::BASE_COLOR);
00070
00071 const SbMatrix & mat = SoModelMatrixElement::get(state);
00072
00073
00074
00075 const SbViewportRegion & vp = SoViewportRegionElement::get(state);
00076
00077 float fRatio = vp.getViewportAspectRatio();
00078
00079
00080
00081 SbVec3f worldcenter(0,0,0);
00082 mat.multVecMatrix(worldcenter, worldcenter);
00083
00084
00085
00086 SoModelMatrixElement::set(state,this,SbMatrix::identity());
00087 SoViewingMatrixElement::set(state,this,SbMatrix::identity());
00088 SoProjectionMatrixElement::set(state,this,SbMatrix::identity());
00089
00090 glColor3f(1.0f,0.0f,0.0f);
00091 glBegin(GL_LINES);
00092 float p[3];
00093 p[2] = 0.0f;
00094
00095 int numX = 20;
00096 for (int i=-numX; i<numX; i++) {
00097 p[0] = (float)i/numX;
00098 p[1] = -1.0f;
00099 glVertex3fv(p);
00100 p[1] = 1.0f;
00101 glVertex3fv(p);
00102 }
00103 int numY = numX / fRatio;
00104 for (int i=-numY; i<numY; i++) {
00105 p[0] = -1.0f;
00106 p[1] = (float)i/numY;
00107 glVertex3fv(p);
00108 p[0] = 1.0;
00109 glVertex3fv(p);
00110 }
00111 glEnd();
00112
00113 state->pop();
00114 }
00115
00116 void
00117 SoDrawingGrid::GLRender(SoGLRenderAction *action)
00118 {
00119
00120
00121 switch (action->getCurPathCode()) {
00122 case SoAction::NO_PATH:
00123 case SoAction::BELOW_PATH:
00124 this->GLRenderBelowPath(action);
00125 break;
00126 case SoAction::OFF_PATH:
00127
00128 break;
00129 case SoAction::IN_PATH:
00130 this->GLRenderInPath(action);
00131 break;
00132 }
00133 }
00134
00135 void
00136 SoDrawingGrid::GLRenderBelowPath(SoGLRenderAction * action)
00137 {
00138
00139
00140 if (action->isRenderingDelayedPaths()) {
00141 SbBool zbenabled = glIsEnabled(GL_DEPTH_TEST);
00142 if (zbenabled) glDisable(GL_DEPTH_TEST);
00143 renderGrid(action);
00144 if (zbenabled) glEnable(GL_DEPTH_TEST);
00145 }
00146 else {
00147 SoCacheElement::invalidate(action->getState());
00148 action->addDelayedPath(action->getCurPath()->copy());
00149 }
00150 }
00151
00152 void
00153 SoDrawingGrid::GLRenderInPath(SoGLRenderAction * action)
00154 {
00155
00156
00157 if (action->isRenderingDelayedPaths()) {
00158 SbBool zbenabled = glIsEnabled(GL_DEPTH_TEST);
00159 if (zbenabled) glDisable(GL_DEPTH_TEST);
00160 renderGrid(action);
00161 if (zbenabled) glEnable(GL_DEPTH_TEST);
00162 }
00163 else {
00164 SoCacheElement::invalidate(action->getState());
00165 action->addDelayedPath(action->getCurPath()->copy());
00166 }
00167 }
00168
00169 void
00170 SoDrawingGrid::GLRenderOffPath(SoGLRenderAction *)
00171 {
00172 }
00173
00174 void
00175 SoDrawingGrid::generatePrimitives(SoAction* action)
00176 {
00177 }
00178
00179 void
00180 SoDrawingGrid::computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er)
00181 {
00182
00183 }