/*
*
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Further, this software is distributed without any warranty that it is
* free of the rightful claim of any third person regarding infringement
* or the like. Any license provided herein, whether implied or
* otherwise, applies only to this software file. Patent licenses, if
* any, provided herein do not apply to combinations of this program with
* other software, or any other product whatsoever.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
* Mountain View, CA 94043, or:
*
* http://www.sgi.com
*
* For further information regarding this notice, see:
*
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/
*
*/
/*--------------------------------------------------------------
* This is an example from the Inventor Mentor,
* chapter 5, example 4.
*
* This example creates the St. Louis Arch using a QuadMesh.
*------------------------------------------------------------*/
#include <stdlib.h>
#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoQuadMesh.h>
#include <Inventor/nodes/SoSeparator.h>
//////////////////////////////////////////////////////////////
// CODE FOR The Inventor Mentor STARTS HERE
// Positions of all of the vertices:
static float vertexPositions[160][3] =
{ // 1st row
{-13.0, 0.0, 1.5}, {-10.3, 13.7, 1.2}, { -7.6, 21.7, 1.0},
{ -5.0, 26.1, 0.8}, { -2.3, 28.2, 0.6}, { -0.3, 28.8, 0.5},
{ 0.3, 28.8, 0.5}, { 2.3, 28.2, 0.6}, { 5.0, 26.1, 0.8},
{ 7.6, 21.7, 1.0}, { 10.3, 13.7, 1.2}, { 13.0, 0.0, 1.5},
// 2nd row
{-10.0, 0.0, 1.5}, { -7.9, 13.2, 1.2}, { -5.8, 20.8, 1.0},
{ -3.8, 25.0, 0.8}, { -1.7, 27.1, 0.6}, { -0.2, 27.6, 0.5},
{ 0.2, 27.6, 0.5}, { 1.7, 27.1, 0.6}, { 3.8, 25.0, 0.8},
{ 5.8, 20.8, 1.0}, { 7.9, 13.2, 1.2}, { 10.0, 0.0, 1.5},
// 3rd row
{-10.0, 0.0,-1.5}, { -7.9, 13.2,-1.2}, { -5.8, 20.8,-1.0},
{ -3.8, 25.0,-0.8}, { -1.7, 27.1,-0.6}, { -0.2, 27.6,-0.5},
{ 0.2, 27.6,-0.5}, { 1.7, 27.1,-0.6}, { 3.8, 25.0,-0.8},
{ 5.8, 20.8,-1.0}, { 7.9, 13.2,-1.2}, { 10.0, 0.0,-1.5},
// 4th row
{-13.0, 0.0,-1.5}, {-10.3, 13.7,-1.2}, { -7.6, 21.7,-1.0},
{ -5.0, 26.1,-0.8}, { -2.3, 28.2,-0.6}, { -0.3, 28.8,-0.5},
{ 0.3, 28.8,-0.5}, { 2.3, 28.2,-0.6}, { 5.0, 26.1,-0.8},
{ 7.6, 21.7,-1.0}, { 10.3, 13.7,-1.2}, { 13.0, 0.0,-1.5},
// 5th row
{-13.0, 0.0, 1.5}, {-10.3, 13.7, 1.2}, { -7.6, 21.7, 1.0},
{ -5.0, 26.1, 0.8}, { -2.3, 28.2, 0.6}, { -0.3, 28.8, 0.5},
{ 0.3, 28.8, 0.5}, { 2.3, 28.2, 0.6}, { 5.0, 26.1, 0.8},
{ 7.6, 21.7, 1.0}, { 10.3, 13.7, 1.2}, { 13.0, 0.0, 1.5}
};
// Routine to create a scene graph representing an arch.
SoSeparator *
makeArch()
{
SoSeparator *result = new SoSeparator;
result->ref();
#ifdef IV_STRICT
// This is the preferred code for Inventor 2.1
// Using the new SoVertexProperty node is more efficient
SoVertexProperty *myVertexProperty = new SoVertexProperty;
// Define the material
myVertexProperty->orderedRGBA.setValue(SbColor(.78, .57, .11).getPackedValue());
// Define coordinates for vertices
myVertexProperty->vertex.setValues(0, 60, vertexPositions);
// Define the QuadMesh.
SoQuadMesh *myQuadMesh = new SoQuadMesh;
myQuadMesh->verticesPerRow = 12;
myQuadMesh->verticesPerColumn = 5;
myQuadMesh->vertexProperty.setValue(myVertexProperty);
result->addChild(myQuadMesh);
#else
// Define the material
SoMaterial *myMaterial = new SoMaterial;
myMaterial->diffuseColor.setValue(.78, .57, .11);
result->addChild(myMaterial);
// Define coordinates for vertices
SoCoordinate3 *myCoords = new SoCoordinate3;
myCoords->point.setValues(0, 60, vertexPositions);
result->addChild(myCoords);
// Define the QuadMesh.
SoQuadMesh *myQuadMesh = new SoQuadMesh;
myQuadMesh->verticesPerRow = 12;
#endif
myQuadMesh->verticesPerColumn = 5;
result->addChild(myQuadMesh);
result->unrefNoDelete();
return result;
}
// CODE FOR The Inventor Mentor ENDS HERE
//////////////////////////////////////////////////////////////
int
main(int, char **argv)
{
// Initialize Inventor and Xt
Widget myWindow = SoXt::init(argv[0]);
if (myWindow == NULL) exit(1);
SoSeparator *root = makeArch();
root->ref();
SoXtExaminerViewer *myViewer =
new SoXtExaminerViewer(myWindow);
myViewer->setSceneGraph(root);
myViewer->setTitle("Quad Mesh: Arch");
myViewer->show();
myViewer->viewAll();
SoXt::show(myWindow);
SoXt::mainLoop();
}