| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
_______________________________________________________________________ |
| 39 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 40 |
| |
| 41 |
| $Revision: 1.1.1.1 $ |
| 42 |
| |
| 43 |
| Classes : TsField::buildBlock |
| 44 |
| |
| 45 |
| Author : Dave Immel |
| 46 |
| |
| 47 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 48 |
_______________________________________________________________________ |
| 49 |
*/ |
| 50 |
|
| 51 |
//--------------------------- Include ---------------------------------- |
| 52 |
#include <X11/Intrinsic.h> |
| 53 |
#include <Xm/Xm.h> |
| 54 |
|
| 55 |
#include <Inventor/nodes/SoSeparator.h> |
| 56 |
#include <Inventor/nodes/SoCoordinate3.h> |
| 57 |
#include <Inventor/nodes/SoIndexedFaceSet.h> |
| 58 |
#include <Inventor/nodes/SoNormal.h> |
| 59 |
#include "TsField.h" |
| 60 |
|
| 61 |
|
| 62 |
//////////////////////////////////////////////////////////////////////// |
| 63 |
// |
| 64 |
// Description: |
| 65 |
// Initialize the Inventor data representing the block. The block |
| 66 |
// is the basic unit from which all of the pieces are built. It |
| 67 |
// is instanced for all pieces and the field. The block is centered at |
| 68 |
// (1, 1, -1) and as length of 2. |
| 69 |
// |
| 70 |
// Use: private |
| 71 |
|
| 72 |
void |
| 73 |
TsField::buildBlock() |
| 74 |
|
| 75 |
// |
| 76 |
//////////////////////////////////////////////////////////////////////// |
| 77 |
{ |
| 78 |
SoCoordinate3 *coords; |
| 79 |
SoIndexedFaceSet *faces; |
| 80 |
SoNormal *normals; |
| 81 |
SbVec3f *verts, tcoord; |
| 82 |
int32_t *indices, *ind; |
| 83 |
int i; |
| 84 |
|
| 85 |
block = new SoSeparator(); |
| 86 |
block->renderCaching = SoSeparator::ON; |
| 87 |
block->ref(); |
| 88 |
|
| 89 |
verts = new SbVec3f[24]; |
| 90 |
// Front |
| 91 |
verts[0].setValue ( 0.1, 0.1, 0.0); |
| 92 |
verts[1].setValue ( 1.9, 0.1, 0.0); |
| 93 |
verts[2].setValue ( 1.9, 1.9, 0.0); |
| 94 |
verts[3].setValue ( 0.1, 1.9, 0.0); |
| 95 |
// Right |
| 96 |
verts[4].setValue ( 2.0, 0.1, -0.1); |
| 97 |
verts[5].setValue ( 2.0, 0.1, -1.9); |
| 98 |
verts[6].setValue ( 2.0, 1.9, -1.9); |
| 99 |
verts[7].setValue ( 2.0, 1.9, -0.1); |
| 100 |
// Back |
| 101 |
verts[8].setValue ( 1.9, 0.1, -2.0); |
| 102 |
verts[9].setValue ( 0.1, 0.1, -2.0); |
| 103 |
verts[10].setValue ( 0.1, 1.9, -2.0); |
| 104 |
verts[11].setValue ( 1.9, 1.9, -2.0); |
| 105 |
// Left |
| 106 |
verts[12].setValue ( 0.0, 0.1, -1.9); |
| 107 |
verts[13].setValue ( 0.0, 0.1, -0.1); |
| 108 |
verts[14].setValue ( 0.0, 1.9, -0.1); |
| 109 |
verts[15].setValue ( 0.0, 1.9, -1.9); |
| 110 |
// Bottom |
| 111 |
verts[16].setValue ( 0.1, 0.0, -1.9); |
| 112 |
verts[17].setValue ( 1.9, 0.0, -1.9); |
| 113 |
verts[18].setValue ( 1.9, 0.0, -0.1); |
| 114 |
verts[19].setValue ( 0.1, 0.0, -0.1); |
| 115 |
// Top |
| 116 |
verts[20].setValue ( 0.1, 2.0, -0.1); |
| 117 |
verts[21].setValue ( 1.9, 2.0, -0.1); |
| 118 |
verts[22].setValue ( 1.9, 2.0, -1.9); |
| 119 |
verts[23].setValue ( 0.1, 2.0, -1.9); |
| 120 |
coords = new SoCoordinate3(); |
| 121 |
coords->point.setValues (0, 24, verts); |
| 122 |
tcoord.setValue (0.0, 0.0, 1.0); |
| 123 |
verts[0] = tcoord; |
| 124 |
verts[1] = tcoord; |
| 125 |
verts[2] = tcoord; |
| 126 |
verts[3] = tcoord; |
| 127 |
tcoord.setValue (1.0, 0.0, 0.0); |
| 128 |
verts[4] = tcoord; |
| 129 |
verts[5] = tcoord; |
| 130 |
verts[6] = tcoord; |
| 131 |
verts[7] = tcoord; |
| 132 |
tcoord.setValue (0.0, 0.0, -1.0); |
| 133 |
verts[8] = tcoord; |
| 134 |
verts[9] = tcoord; |
| 135 |
verts[10] = tcoord; |
| 136 |
verts[11] = tcoord; |
| 137 |
tcoord.setValue (-1.0, 0.0, 0.0); |
| 138 |
verts[12] = tcoord; |
| 139 |
verts[13] = tcoord; |
| 140 |
verts[14] = tcoord; |
| 141 |
verts[15] = tcoord; |
| 142 |
tcoord.setValue (0.0, -1.0, 0.0); |
| 143 |
verts[16] = tcoord; |
| 144 |
verts[17] = tcoord; |
| 145 |
verts[18] = tcoord; |
| 146 |
verts[19] = tcoord; |
| 147 |
tcoord.setValue (0.0, 1.0, 0.0); |
| 148 |
verts[20] = tcoord; |
| 149 |
verts[21] = tcoord; |
| 150 |
verts[22] = tcoord; |
| 151 |
verts[23] = tcoord; |
| 152 |
normals = new SoNormal(); |
| 153 |
normals->vector.setValues (0, 24, verts); |
| 154 |
delete[] verts; |
| 155 |
|
| 156 |
indices = new int32_t[30+60+32]; |
| 157 |
ind = indices; |
| 158 |
for (i=0; i<6; i++) |
| 159 |
{ |
| 160 |
*ind++ = i*4; |
| 161 |
*ind++ = i*4+1; |
| 162 |
*ind++ = i*4+2; |
| 163 |
*ind++ = i*4+3; |
| 164 |
*ind++ = -1; |
| 165 |
} |
| 166 |
*ind++ = 13; *ind++ = 12; *ind++ = 16; *ind++ = 19; *ind++ = -1; |
| 167 |
*ind++ = 18; *ind++ = 17; *ind++ = 5; *ind++ = 4; *ind++ = -1; |
| 168 |
*ind++ = 7; *ind++ = 6; *ind++ = 22; *ind++ = 21; *ind++ = -1; |
| 169 |
*ind++ = 15; *ind++ = 14; *ind++ = 20; *ind++ = 23; *ind++ = -1; |
| 170 |
*ind++ = 19; *ind++ = 18; *ind++ = 1; *ind++ = 0; *ind++ = -1; |
| 171 |
*ind++ = 4; *ind++ = 7; *ind++ = 2; *ind++ = 1; *ind++ = -1; |
| 172 |
*ind++ = 3; *ind++ = 2; *ind++ = 21; *ind++ = 20; *ind++ = -1; |
| 173 |
*ind++ = 0; *ind++ = 3; *ind++ = 14; *ind++ = 13; *ind++ = -1; |
| 174 |
*ind++ = 17; *ind++ = 16; *ind++ = 9; *ind++ = 8; *ind++ = -1; |
| 175 |
*ind++ = 6; *ind++ = 5; *ind++ = 8; *ind++ = 11; *ind++ = -1; |
| 176 |
*ind++ = 11; *ind++ = 10; *ind++ = 23; *ind++ = 22; *ind++ = -1; |
| 177 |
*ind++ = 10; *ind++ = 9; *ind++ = 12; *ind++ = 15; *ind++ = -1; |
| 178 |
|
| 179 |
*ind++ = 0; *ind++ = 13; *ind++ = 19; *ind++ = -1; |
| 180 |
*ind++ = 1; *ind++ = 18; *ind++ = 4; *ind++ = -1; |
| 181 |
*ind++ = 2; *ind++ = 7; *ind++ = 21; *ind++ = -1; |
| 182 |
*ind++ = 3; *ind++ = 20; *ind++ = 14; *ind++ = -1; |
| 183 |
*ind++ = 9; *ind++ = 16; *ind++ = 12; *ind++ = -1; |
| 184 |
*ind++ = 8; *ind++ = 5; *ind++ = 17; *ind++ = -1; |
| 185 |
*ind++ = 11; *ind++ = 22; *ind++ = 6; *ind++ = -1; |
| 186 |
*ind++ = 10; *ind++ = 15; *ind++ = 23; *ind++ = -1; |
| 187 |
|
| 188 |
faces = new SoIndexedFaceSet(); |
| 189 |
faces->coordIndex.setValues (0, 30+60+32, indices); |
| 190 |
delete[] indices; |
| 191 |
|
| 192 |
block->addChild (coords); |
| 193 |
block->addChild (normals); |
| 194 |
block->addChild (faces); |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|