⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lorenz.cpp.in

📁 学习 open inventor 的例子
💻 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> *\**************************************************************************/#include <Inventor/@Gui@/So@Gui@.h>#include <Inventor/@Gui@/viewers/So@Gui@ExaminerViewer.h>#include <Inventor/nodes/SoSeparator.h>#include <Inventor/nodes/SoTexture2.h>#include <Inventor/nodes/SoTextureCoordinateEnvironment.h>#include <Inventor/nodes/SoShapeHints.h>#include <Inventor/nodes/SoTranslation.h>#include <Inventor/nodes/SoTriangleStripSet.h>#include <Inventor/nodes/SoCoordinate3.h>#include <Inventor/nodes/SoMaterial.h>#include <Inventor/nodes/SoFaceSet.h>#include <Inventor/nodes/SoTextureCoordinate2.h>#include <stdio.h>#include <stdlib.h> // exit()#include <math.h>#include "star.h"#define N 1000static char info[] ="-------------------------------- Lorenz Attractor ------------------------------\n\The so called \"lorenz attractor\" was first studied by Ed N. Lorenz, \n\a meterologist, around 1963. It was derived from a simplified model \n\of convention in the earths atmosphere. It also arises naturally in \n\models of lasers and dynamos. The system is most commonly expressed \n\as 3 coupled non-linear differential equations. \n\\n\dx / dt = a (y - x) \n\dy / dt = x (b - z) - y \n\\n\dz / dt = xy - c z \n\\n\where a = 10, b = 28, c = 8 / 3.\n\\n\\"a\" is sometimes known as the Prandtl number and \"b\" the Rayleigh number. \n\\n\The series does not form limit cyles nor does it ever reach a steady state.\n\Instead it is an example of deterministic chaos. As with other chaotic systems\n\the Lorenz system is sensitive to the initial conditions, two initial states no\n\matter how close will diverge, usually sooner rather than later.\n\n";static float vertices[18][3] ={  { -0.5, 0.5, 0 }, { 0.5, 0.5, 0 }, { 0.5, -0.5, 0 },  { -0.5, -0.5, 0 },  { -0.5, 0, 0.5 }, { 0.5, 0, 0.5 }, { 0.5, 0, -0.5 }, { -0.5, 0, -0.5 },  { 0, -0.5, 0.5}, { 0, 0.5, 0.5 }, { 0, 0.5, -0.5 }, { 0, -0.5, -0.5 }};SoSeparator * create_star(SbVec3f pos){  SoSeparator * sep = new SoSeparator;  sep->ref();  // FIXME: use delta-values for the translation on each "star" to  // avoid the necessity of using all the SoSeparator nodes. 20011009 mortene.  SoTranslation * trans = new SoTranslation;  trans->translation.setValue(pos);  sep->addChild(trans);  SoFaceSet * faces = new SoFaceSet;  int32_t numverts[] = { 4, 4, 4 };  faces->numVertices.setValues(0, 3, numverts);  sep->addChild(faces);  sep->unrefNoDelete();	  return sep;}int main (int argc, char ** argv) {  int i = 0;  double x0, y0, z0, x1, y1, z1;  double h = 0.01;  double a = 10.0;  double b = 28.0;  double c = 8.0 / 3.0;  printf(info);  if (argc == 5) {    h = atof(argv[1]);    a = atof(argv[2]);    b = atof(argv[3]);    c = atof(argv[4]);  }  else {    printf("Usage: %s <h> <a> <b> <c>\n", argv[0]);    printf("Default values are: h = 0.01, a = 10.0, b = 28.0, c = 8.0 / 3.0 \n\n");  }  @WIDGET@ window = So@Gui@::init(argv[0]);  if (window == NULL) exit(1);  SoSeparator * root = new SoSeparator;  root->ref();  SoShapeHints * hints = new SoShapeHints;  hints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;  hints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;  root->addChild(hints);  SoSeparator * stars = new SoSeparator;  SoMaterial * mat = new SoMaterial;  mat->specularColor.setValue( 1.0f, 1.0f, 1.0f );  mat->emissiveColor.setValue( 1.0f, 1.0f, 1.0f );  mat->shininess = 0.0f;  mat->transparency = 0.7f;  stars->addChild(mat);  SoTexture2 * texture = new SoTexture2;  texture->image.setValue(SbVec2s(64, 64), 4, (unsigned char *)star_raw);  texture->model = SoTexture2::DECAL;  texture->blendColor.setValue(1.0, 0.0, 0.0);  stars->addChild(texture);  SoTextureCoordinate2 * texcoord = new SoTextureCoordinate2;  const float MINTEX = 0.1f;  const float MAXTEX = 0.9f;  float tcs[][2] = {    { MINTEX, MINTEX }, { MINTEX, MAXTEX}, { MAXTEX, MAXTEX}, {MAXTEX, MINTEX},    { MINTEX, MINTEX }, { MINTEX, MAXTEX}, { MAXTEX, MAXTEX}, {MAXTEX, MINTEX},    { MINTEX, MINTEX }, { MINTEX, MAXTEX}, { MAXTEX, MAXTEX}, {MAXTEX, MINTEX} };  texcoord->point.setValues(0, 12, tcs);  stars->addChild(texcoord);  SoCoordinate3 * coords = new SoCoordinate3;  coords->point.setValues(0, 18, vertices);  stars->addChild(coords);  printf("Computing...\n");  x0 = 0.1;  y0 = 0;  z0 = 0;  for (i = 0; i < N; i++) {    x1 = x0 + h * a * (y0 - x0);    y1 = y0 + h * (x0 * (b - z0) - y0);    z1 = z0 + h * (x0 * y0 - c * z0);    x0 = x1;    y0 = y1;    z0 = z1;    if (i > 100) { // skip the first 100 to avoid a too tight cluster      stars->addChild(create_star(SbVec3f(x0, y0, z0)));    }  }  printf("\nOk, done!\n\n");  root->addChild(stars);  So@Gui@ExaminerViewer * viewer = new So@Gui@ExaminerViewer(window);  viewer->setSceneGraph(root);  viewer->setTitle("Lorenz Attractor");  viewer->setTransparencyType( SoGLRenderAction::ADD );  viewer->viewAll();  viewer->show();  So@Gui@::show(window);  So@Gui@::mainLoop();  delete viewer;  root->unref();  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -