📄 styx.cpp.in
字号:
/**************************************************************************\ * * This file is part of a set of example programs for the Coin library. * Copyright (C) 2000-2003 by Systems in Motion. All rights reserved. * * <URL:http://www.coin3d.org> * * This sourcecode can be redistributed and/or modified under the * terms of the GNU General Public License version 2 as published by * the Free Software Foundation. See the file COPYING at the root * directory of the distribution for more details. * * As a special exception, all sourcecode of the demo examples can be * used for any purpose for licensees of the Coin Professional * Edition License, without the restrictions of the GNU GPL. See our * web pages for information about how to acquire a Professional Edition * License. * * Systems in Motion, <URL:http://www.sim.no>, <mailto:support@sim.no> *\**************************************************************************//* ********************************************************************** * * styx * * Demo application for showcasing Coin. * * Written by Lars J. Aas <larsa@coin3d.org>. * ********************************************************************** */#if HAVE_CONFIG_H#include <config.h>#endif // HAVE_CONFIG_H#include <Inventor/@Gui@/So@Gui@.h>#include <Inventor/@Gui@/viewers/So@Gui@ExaminerViewer.h>#include <Inventor/SbLinear.h>#include <Inventor/actions/SoGLRenderAction.h>#include <Inventor/actions/SoSearchAction.h>#include <Inventor/nodes/SoCoordinate3.h>#include <Inventor/nodes/SoCallback.h>#include <stdlib.h> // srand(), rand(), exit()#include <stdio.h>#include <string.h>/* ********************************************************************** */const char * scenegraph[] = { "#Inventor V2.1 ascii", "", "Separator {", " DEF hook Callback {}", " ShapeHints {", " vertexOrdering COUNTERCLOCKWISE", " shapeType SOLID", " }", " DirectionalLight {", " color 0.4 0 0.8", " intensity 0.5", " direction 0.1 0 1", " }",// " DEF camera PerspectiveCamera {}", " Rotor {", " rotation 0 1 0 0.01", " speed 0.02", " }", " Translation {", " translation -150 -100 -100", " }", " Separator {", " Coordinate3 {", " point [", " 0 0 0,", " 300 0 0,", " 300 200 0,", " 0 200 0,", " 0 0 200,", " 300 0 200,", " 300 200 200,", " 0 200 200", " ]", " }", " Material {", " diffuseColor 0.4 0 0", " transparency 0.6", " }",// " IndexedFaceSet {", // frontfaces// " coordIndex [",// " 3 2 1 0 -1",// " 4 5 6 7 -1",// " 0 1 5 4 -1",// " 2 3 7 6 -1",// " ]",// " }", " Material {", " diffuseColor 1 1 1", " transparency 0", " }", " IndexedLineSet {", " coordIndex [", " 0, 1, -1,", " 1, 2, -1,", " 2, 3, -1,", " 3, 0, -1,", " 0, 4, -1,", " 1, 5, -1,", " 2, 6, -1,", " 3, 7, -1,", " 4, 5, -1,", " 5, 6, -1,", " 6, 7, -1,", " 7, 4, -1", " ]", " }", " Separator {", // the animated styx#define LINES 33 " Material {", " diffuseColor 1 0 0", " transparency 0", " }", " DEF redlines Coordinate3 {}", " LineSet {", " numVertices [", " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2,", // 3 lines " -1", " ]", " }", " Material {", " diffuseColor 0 1 0", " transparency 0", " }", " DEF greenlines Coordinate3 {}", " LineSet {", " numVertices [", " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2,", // 3 lines " -1", " ]", " }", " Material {", " diffuseColor 0 0 1", " transparency 0", " }", " DEF bluelines Coordinate3 {}", " LineSet {", " numVertices [", " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,", // 10 lines " 2, 2, 2,", // 3 lines " -1", " ]", " }", " }",// " Separator {", // the animated star scrollers// " PolygonOffset {",// " units 1",// " styles POINTS",// " }", " Material {", " diffuseColor 0 0.5 1", " emissiveColor 0 0.9 0.9", " }", " DEF points Coordinate3 {}", " PointSet {",#define POINTS 400 " numPoints 400", " }",// " }", " }", "}", NULL};/* ********************************************************************** */char *strconcat(const char * array[], unsigned int &total){ int i; for (i = total = 0; array[i]; i++ ) total += strlen(array[i]) + 1; char * buf = new char [total + 1]; for (i = total = 0; array[i]; i++ ) { strcpy(buf+total, array[i]); total += strlen(array[i]); buf[total] = '\n'; total++; } return buf;}/* ********************************************************************** */SoNode *getNodeByName(SoNode * root, const char * name){ static SoSearchAction * action; if ( !action ) action = new SoSearchAction; action->setName(SbName(name)); action->setInterest(SoSearchAction::FIRST); action->apply(root); if ( !action->getPath() ) return NULL; return action->getPath()->getTail();}/* ********************************************************************** */voidinitLines(SoCoordinate3 * coords){ float floats[LINES*2][3]; // = new float [ LINES * 2 ][3]; for ( int i = 0; i < LINES; i++ ) { floats[i*2][0] = (300.0f / float(LINES)) * float(i); floats[i*2][1] = 0.0f; floats[i*2][2] = 0.0f; floats[i*2+1][0] = (300.0f / float(LINES)) * float(i); floats[i*2+1][1] = 0.0f; floats[i*2+1][2] = 200.0f; } // FIXME: this crashes under SGI Inventor. Investigate. 20010919 mortene. coords->point.setValues(0, LINES * 2, floats);}voidtickLines1(SoCoordinate3 * coords){ static SbBool initialized = FALSE; static SbVec3f p1dir; static SbVec3f p2dir; int i; if ( ! initialized ) { initialized = TRUE; p1dir.setValue(0, 1, 0); p2dir.setValue(0, 1, 0); } SbVec3f * points = coords->point.startEditing(); for ( i = 0; i < (LINES * 2); i++ ) { if ( (i / 2) == 0 ) { if ( (i&1) == 0 ) points[i] += p1dir * 5; else points[i] += p2dir * 5; } else { SbVec3f gravity = points[i-2] - points[i]; if ( (i&1) == 0 ) points[i] += (gravity * 0.2f); else points[i] += (gravity * 0.2f); } } if ( points[0][0] < 0.0f || points[0][0] > 300.0f ) p1dir[0] = 0.0f - p1dir[0]; if ( points[0][1] < 0.0f || points[0][1] > 200.0f ) p1dir[1] = 0.0f - p1dir[1]; if ( points[0][2] < 0.0f || points[0][2] > 200.0f ) p1dir[2] = 0.0f - p1dir[2];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -