home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / noodle / LineManipHilight.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.1 KB  |  193 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. //
  18. // Stuff to hilight parts of the line-set manipulator
  19. //
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <math.h>
  24. #include <assert.h>
  25.  
  26. #include <Inventor/SoDB.h>
  27. #include <Inventor/nodes/SoPickStyle.h>
  28. #include <Inventor/nodes/SoTransform.h>
  29. #include <Inventor/nodes/SoMaterial.h>
  30. #include <Inventor/nodes/SoSwitch.h>
  31. #include <Inventor/nodes/SoCoordinate3.h>
  32. #include <Inventor/nodes/SoLineSet.h>
  33. #include <Inventor/SoInput.h>
  34.  
  35. #include "LineManip.h"
  36.  
  37. void
  38. LineManip2::setHilightSize(float size)
  39. {
  40.     hilightSize = size;
  41. //
  42. // This should really be figured out during event handling to give the
  43. // hilights a uniform size in screen space (say, 5 or 10 pixels).
  44. //
  45.     hilightTransform->scaleFactor = SbVec3f(hilightSize, hilightSize,
  46.                         hilightSize);
  47. }
  48.  
  49. void
  50. LineManip2::initHilightStuff()
  51. {
  52.     SoSeparator *sep = new SoSeparator;
  53.     addChild(sep);
  54.  
  55.     SoPickStyle *ps = new SoPickStyle;
  56.     sep->addChild(ps);
  57.     ps->style = SoPickStyle::UNPICKABLE;
  58.  
  59.     hilightMaterial = new SoMaterial;
  60.     sep->addChild(hilightMaterial);
  61.  
  62.     hilightSwitch = new SoSwitch;
  63.     sep->addChild(hilightSwitch);
  64.     hilightSwitch->whichChild = SO_SWITCH_NONE;
  65.  
  66.     hilightTransform = new SoTransform;
  67. //
  68. // This should really be figured out during event handling to give the
  69. // hilights a uniform size in screen space (say, 5 or 10 pixels).
  70. //
  71.     hilightTransform->scaleFactor = SbVec3f(hilightSize, hilightSize,
  72.                         hilightSize);
  73.  
  74.     {    // VERTEX HILIGHT MUST BE CHILD 0
  75.     // The vertex hilight is a little cross-hair:
  76.     //
  77.     static float vhCoords[8][3] = {
  78.         {.25, 0, 0}, {1, 0, 0}, {0, .25, 0}, {0, 1, 0},
  79.         {-.25, 0, 0}, {-1, 0, 0}, {0, -.25, 0}, {0, -1, 0},
  80.     };
  81.     static long lsNV[4] = { 2, 2, 2, 2 };
  82.  
  83.     SoGroup *g = new SoGroup;
  84.     hilightSwitch->addChild(g);
  85.     g->addChild(hilightTransform);
  86.     SoCoordinate3 *c = new SoCoordinate3;
  87.     g->addChild(c);
  88.     c->point.setValues(0, 8, vhCoords);
  89.     SoLineSet *ls = new SoLineSet;
  90.     g->addChild(ls);
  91.     ls->numVertices.setValues(0, 4, lsNV);
  92.     }
  93.     {    // LINE HILIGHT MUST BE CHILD 1
  94.     // The line hilight is a line (or lines) to the new vertex and
  95.     // an octagon surrounding the new vertex.
  96.     //
  97.     SoGroup *g = new SoGroup;
  98.     hilightSwitch->addChild(g);
  99.  
  100.     // First, lines from previous to next vertex
  101.     hilightCoord = new SoCoordinate3;
  102.     g->addChild(hilightCoord);
  103.     SoLineSet *ls = new SoLineSet;
  104.     g->addChild(ls);
  105.  
  106.     // Second: octagon:
  107.     static float lhCoords[9][3] = {
  108.         {1, 0, 0}, {M_SQRT1_2, M_SQRT1_2, 0},
  109.         {0, 1, 0}, {-M_SQRT1_2, M_SQRT1_2, 0},
  110.         {-1, 0, 0}, {-M_SQRT1_2, -M_SQRT1_2, 0},
  111.         {0, -1, 0}, {M_SQRT1_2, -M_SQRT1_2, 0},
  112.         {1, 0, 0}
  113.     };
  114.     g->addChild(hilightTransform);
  115.     SoCoordinate3 *c = new SoCoordinate3;
  116.     g->addChild(c);
  117.     c->point.setValues(0, 9, lhCoords);
  118.     g->addChild(ls);
  119.     }
  120. }
  121.  
  122. void
  123. LineManip2::hilightVertex(const SbVec3f &position, const SbColor &color)
  124. {
  125.     // Set switch to vertex (if necessary)
  126.     if (hilightSwitch->whichChild.getValue() != 0)
  127.     {
  128.     hilightSwitch->whichChild.setValue(0);
  129.     }
  130.     // Set transformation to given position (if necessary)
  131.     if (hilightTransform->translation.getValue() != position)
  132.     {
  133.     hilightTransform->translation.setValue(position);
  134.     }
  135.     // And set color, if necessary.
  136.     if (hilightMaterial->diffuseColor[0] != color)
  137.     {
  138.     hilightMaterial->diffuseColor.setValue(color);
  139.     }
  140. }
  141.  
  142. void
  143. LineManip2::hilightLine(int whichLine, const SbVec3f &position,
  144.             const SbColor &color)
  145. {
  146.     if (coord == NULL)
  147.     return;
  148.  
  149.     // Draw the line hilight
  150.     if (hilightSwitch->whichChild.getValue() != 1)
  151.     {
  152.     hilightSwitch->whichChild.setValue(1);
  153.     }
  154.  
  155.     // Set transformation to given position
  156.     hilightTransform->translation.setValue(position);
  157.  
  158.     // And set color, if necessary.
  159.     if (hilightMaterial->diffuseColor[0] != color)
  160.     {
  161.     hilightMaterial->diffuseColor.setValue(color);
  162.     }
  163.  
  164.     int n = coord->point.getNum();
  165.     // And set coordinates of the extra line segments:
  166.     if (whichLine >= 0 && whichLine < n)
  167.     {
  168.     hilightCoord->point.set1Value(0, coord->point[whichLine]);
  169.     }
  170.     else
  171.     {
  172.     hilightCoord->point.set1Value(0, position);
  173.     }
  174.     if (whichLine+1 < coord->point.getNum() && whichLine+1 >= 0)
  175.     {
  176.     hilightCoord->point.set1Value(2, coord->point[whichLine+1]);
  177.     }
  178.     else
  179.     {
  180.     hilightCoord->point.set1Value(2, position);
  181.     }
  182.     hilightCoord->point.set1Value(1, position);
  183. }
  184.  
  185. void
  186. LineManip2::removeHilights()
  187. {
  188.     if (hilightSwitch->whichChild.getValue() != SO_SWITCH_NONE)
  189.     {
  190.     hilightSwitch->whichChild.setValue(SO_SWITCH_NONE);
  191.     }
  192. }
  193.