| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <FCConfig.h>
|
| |
|
| | #include <Inventor/actions/SoGLRenderAction.h>
|
| | #include <Inventor/elements/SoCacheElement.h>
|
| | #include <Inventor/elements/SoLazyElement.h>
|
| | #include <Inventor/elements/SoModelMatrixElement.h>
|
| | #include <Inventor/elements/SoProjectionMatrixElement.h>
|
| | #include <Inventor/elements/SoViewingMatrixElement.h>
|
| | #include <Inventor/elements/SoViewportRegionElement.h>
|
| |
|
| | #if defined(FC_OS_WIN32)
|
| | # include <windows.h>
|
| | #endif
|
| |
|
| | #ifdef FC_OS_MACOSX
|
| | # include <OpenGL/gl.h>
|
| | #else
|
| | # include <GL/gl.h>
|
| | #endif
|
| |
|
| | #include "SoDrawingGrid.h"
|
| |
|
| |
|
| | using namespace Gui::Inventor;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| |
|
| | SO_NODE_SOURCE(SoDrawingGrid)
|
| |
|
| | void SoDrawingGrid::initClass()
|
| | {
|
| | SO_NODE_INIT_CLASS(SoDrawingGrid, SoShape, "Shape");
|
| | }
|
| |
|
| | SoDrawingGrid::SoDrawingGrid()
|
| | {
|
| | SO_NODE_CONSTRUCTOR(SoDrawingGrid);
|
| | }
|
| |
|
| | void SoDrawingGrid::renderGrid(SoGLRenderAction* action)
|
| | {
|
| | if (!shouldGLRender(action)) {
|
| | return;
|
| | }
|
| |
|
| | SoState* state = action->getState();
|
| | state->push();
|
| | SoLazyElement::setLightModel(state, SoLazyElement::BASE_COLOR);
|
| |
|
| | const SbMatrix& mat = SoModelMatrixElement::get(state);
|
| |
|
| |
|
| |
|
| | const SbViewportRegion& vp = SoViewportRegionElement::get(state);
|
| |
|
| | float fRatio = vp.getViewportAspectRatio();
|
| |
|
| |
|
| |
|
| | SbVec3f worldcenter(0, 0, 0);
|
| | mat.multVecMatrix(worldcenter, worldcenter);
|
| |
|
| |
|
| |
|
| | SoModelMatrixElement::set(state, this, SbMatrix::identity());
|
| | SoViewingMatrixElement::set(state, this, SbMatrix::identity());
|
| | SoProjectionMatrixElement::set(state, this, SbMatrix::identity());
|
| |
|
| | glColor3f(1.0f, 0.0f, 0.0f);
|
| | glBegin(GL_LINES);
|
| | float p[3];
|
| | p[2] = 0.0f;
|
| |
|
| | int numX = 20;
|
| | for (int i = -numX; i < numX; i++) {
|
| | p[0] = (float)i / numX;
|
| | p[1] = -1.0f;
|
| | glVertex3fv(p);
|
| | p[1] = 1.0f;
|
| | glVertex3fv(p);
|
| | }
|
| | int numY = numX / fRatio;
|
| | for (int i = -numY; i < numY; i++) {
|
| | p[0] = -1.0f;
|
| | p[1] = (float)i / numY;
|
| | glVertex3fv(p);
|
| | p[0] = 1.0;
|
| | glVertex3fv(p);
|
| | }
|
| | glEnd();
|
| |
|
| | state->pop();
|
| | }
|
| |
|
| | void SoDrawingGrid::GLRender(SoGLRenderAction* action)
|
| | {
|
| |
|
| |
|
| | switch (action->getCurPathCode()) {
|
| | case SoAction::NO_PATH:
|
| | case SoAction::BELOW_PATH:
|
| | this->GLRenderBelowPath(action);
|
| | break;
|
| | case SoAction::OFF_PATH:
|
| |
|
| | break;
|
| | case SoAction::IN_PATH:
|
| | this->GLRenderInPath(action);
|
| | break;
|
| | }
|
| | }
|
| |
|
| | void SoDrawingGrid::GLRenderBelowPath(SoGLRenderAction* action)
|
| | {
|
| |
|
| |
|
| | if (action->isRenderingDelayedPaths()) {
|
| | SbBool zbenabled = glIsEnabled(GL_DEPTH_TEST);
|
| | if (zbenabled) {
|
| | glDisable(GL_DEPTH_TEST);
|
| | }
|
| | renderGrid(action);
|
| | if (zbenabled) {
|
| | glEnable(GL_DEPTH_TEST);
|
| | }
|
| | }
|
| | else {
|
| | SoCacheElement::invalidate(action->getState());
|
| | action->addDelayedPath(action->getCurPath()->copy());
|
| | }
|
| | }
|
| |
|
| | void SoDrawingGrid::GLRenderInPath(SoGLRenderAction* action)
|
| | {
|
| |
|
| |
|
| | if (action->isRenderingDelayedPaths()) {
|
| | SbBool zbenabled = glIsEnabled(GL_DEPTH_TEST);
|
| | if (zbenabled) {
|
| | glDisable(GL_DEPTH_TEST);
|
| | }
|
| | renderGrid(action);
|
| | if (zbenabled) {
|
| | glEnable(GL_DEPTH_TEST);
|
| | }
|
| | }
|
| | else {
|
| | SoCacheElement::invalidate(action->getState());
|
| | action->addDelayedPath(action->getCurPath()->copy());
|
| | }
|
| | }
|
| |
|
| | void SoDrawingGrid::GLRenderOffPath(SoGLRenderAction*)
|
| | {}
|
| |
|
| | void SoDrawingGrid::generatePrimitives(SoAction* action)
|
| | {
|
| | (void)action;
|
| | }
|
| |
|
| | void SoDrawingGrid::computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center)
|
| | {
|
| | (void)action;
|
| | (void)box;
|
| | (void)center;
|
| |
|
| | }
|
| |
|