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

📄 pov.cpp

📁 行人模拟
💻 CPP
字号:
//// pedsim - A microscopic pedestrian simulation system. // Copyright (c) 2003 - 2004 by Christian Gloor//                              // You can redistribute and/or modify this program under the terms of// the GNU General Public License.  See copying.txt for details.// #include <stdio.h>#include <iostream> // cout ...#include <fstream> // files#include <string>   // strncpy#include "pov.h"#include "agent.h"#include "functions.h"using namespace std;extern AgentContainer a;// ----------------------------------------------------// Name: newfile// Description: opens a new file and adds pov intro// Introduced: chgloor Monday, January  5, 2004  1:43:21// ----------------------------------------------------void Tpov::newfile(long systemtime) {  file.open (filename, ios::out);  file << "// Frame " << systemtime << endl << endl;  file << "#include \"colors.inc\"" << endl;  //file << "#include \"tree.inc\"" << endl;  file << "#include \"scene.inc\"" << endl;  file << "#include \"objects.inc\"" << endl;    file << endl;  file << "blob {" << endl;  file << "threshold .1" << endl;}// --------------------------------------------------// Name: Tpov// Purpose: Constructor. Initializes open files etc// Introduced: chgloor Monday, December 29, 2003 12:26:47// --------------------------------------------------Tpov::Tpov(char *pfilename) {  strncpy(filename, pfilename, sizeof(filename));  newfile(0);}// --------------------------------------------------// Name: draw_position// Purpose: draws an agent// Introduced: chgloor Monday, June 30, 2003 14:27:24// --------------------------------------------------void Tpov::draw_position(int id, int type, double color, double x, double y, double direction, double sword) {  direction = 360.0f * direction / 3.1415;  type = 4; // debug  if (type==0) {     file << "object { sword  rotate <0,0," << sword << "> translate <0,0,0.3> rotate <0," << -direction+180 << ",0> translate <" << x << ",0.8," << y << ">}" << endl;    file << "cylinder { <" << x << ", 0, " << y << ">, <" << x << ", 1, " << y << ">, 0.3 texture { pigment { color rgb<" << color/2 << "," << color/2 << ",0> } } }" << endl;     file << "object { head rotate <0," << -direction+180 << ",0> translate <" << x << ", 1.3, " << y << "> }" << endl;    file << "sphere { <" << x << "*4, 1.55*10, " << y << "*4>, 1 scale <0.25,0.1,0.25> texture { pigment { color rgb<" << color << "," << color << ",0> } } }" << endl;   }  if (type==1) {    file << "object { sword  rotate <0,0," << sword << "> translate <0,0,0.3> rotate <0," << -direction << ",0> translate <" << x << ",0.8," << y << ">}" << endl;    file << "cylinder { <" << x << ", 0, " << y << ">, <" << x << ", 1, " << y << ">, 0.3 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0> } } }" << endl;     file << "object { head rotate <0," << -direction << ",0> translate <" << x << ", 1.3, " << y << "> }" << endl;    file << "sphere { <" << x << "*4, 1.55*10, " << y << "*4>, 1 scale <0.25,0.1,0.25> texture { pigment { color rgb<" << color << "," << 0 << ",0> } } }" << endl;   }  if (type==2) {    file << "sphere { <" << x << ", 0.15, " << y << ">, 0.3 texture { pigment { color rgb<" << color/2 << "," << color/2 << ",0>  } } }" << endl;     file << "object { sword  rotate <0,90,0> rotate <0,0,90> translate <0,0,0.5> rotate <0," << -direction+180 << ",0> translate <" << x << ",0," << y << ">}" << endl;  }  if (type==3) {    file << "sphere { <" << x << ", 0.15, " << y << ">, 0.3 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;     file << "object { sword  rotate <0,90,0> rotate <0,0,90> translate <0,0,0.5> rotate <0," << -direction << ",0> translate <" << x << ",0," << y << ">}" << endl;  }  if (type==4) {        file << "   sphere { <" << x << ", 0.15," << y << ">, .2, 1 texture { pigment { color rgb<" << color/2 << "," << 1 << ",0>  } } }" << endl;         file << "   sphere { <" << x+.6 << ", 0.15," << y << ">, 0.2, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;         file << "   sphere { <" << x << ", 0.15," << y+.6 << ">, 0.2, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;        file << "   sphere { <" << x-.6 << ", 0.15," << y-.6 << ">, 0.2, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;         file << "   sphere { <" << x << ", 0.15," << y -.6<< ">, 0.2, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;     file << "   sphere { <" << x+.9 << ", 0.1," << y << ">, 0.1, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;         file << "   sphere { <" << x << ", 0.1," << y+.9 << ">, 0.1, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;        file << "   sphere { <" << x-.9 << ", 0.1," << y << ">, 0.1, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;         file << "   sphere { <" << x << ", 0.1," << y-.9<< ">, 0.1, 1 texture { pigment { color rgb<" << color/2 << "," << 0 << ",0>  } } }" << endl;   }  if ((id % 30) == 0) { // torch    if (type<2) file << "object { torch rotate <0,0,0> translate <0,0,-0.5> rotate <0," << -direction << ",0> translate <" << x << ", 0.7, " << y << ">}" << endl;  }  if ((id % 30) == 31) { // banner    if (type<2) file << "object { banner rotate <0,0,0> translate <0,0,-0.5> rotate <0," << -direction << ",0> translate <" << x << ", 0.7, " << y << ">}" << endl;  }}// --------------------------------------------------// Name: draw_tree// Purpose: draws a tree// Introduced: chgloor Wednesday, January  7, 2004 13:46:04// --------------------------------------------------void Tpov::draw_tree(int id, double size, double rotation, double x, double y) {  //  file << "object { Entire_Tree rotate y*" << rotation << " scale " << size << " translate <" << x << ",0," << y <<">}" << endl;};// ----------------------------------------------------// Name: render_frame// Description: // Introduced: chgloor Monday, January  5, 2004  1:08:41// Return value: // ----------------------------------------------------void Tpov::render_frame(long timestep, bool render) {    char command[200];  char temp[30];  file << "}" << endl;    if (render == true) {    //    strcpy(command, "povray output.pov +W640 +H480 +D -V +Opov/frame");    strcpy(command, "povray output.pov +W800 +H600 +D -V +Opov/frame");    sprintf(temp, "%.5ld",timestep);    strcat(command,temp);    strcat(command, ".png &> pov.out");    system(command);        strcpy(command, "convert pov/frame");    sprintf(temp, "%.5ld",timestep);    strcat(command,temp);    strcat(command, ".png pov/frame");    strcat(command,temp);    strcat(command, ".jpg");    system(command);  }    strcpy(command, "mv output.pov pov/frame");  sprintf(temp, "%.5ld",timestep);  strcat(command,temp);  strcat(command, ".pov");  system(command);    file.close();  newfile(timestep);}

⌨️ 快捷键说明

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