这节需要把顶点布局写在文件里面,为了方便,因为一大串非常抽象的坐标放在CPP和程序混在一起非常的不方便。
下面全为c++知识,读取文件里面的特定格式的数据:
Vertex Count: 36 Data: -1.0 1.0 -1.0 0.0 0.0 0.0 0.0 -1.0 1.0 1.0 -1.0 1.0 0.0 0.0 0.0 -1.0 -1.0 -1.0 -1.0 0.0 1.0 0.0 0.0 -1.0 -1.0 -1.0 -1.0 0.0 1.0 0.0 0.0 -1.0 1.0 1.0 -1.0 1.0 0.0 0.0 0.0 -1.0 1.0 -1.0 -1.0 1.0 1.0 0.0 0.0 -1.0 1.0 1.0 -1.0 0.0 0.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 0.0 1.0 -1.0 -1.0 0.0 1.0 1.0 0.0 0.0 1.0 -1.0 -1.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 1.0 0.0 0.0 1.0 -1.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 1.0 -1.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 -1.0 1.0 0.0 1.0 0.0 0.0 1.0 1.0 -1.0 1.0 0.0 1.0 0.0 0.0 1.0 -1.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0 -1.0 -1.0 1.0 1.0 1.0 0.0 0.0 1.0 -1.0 1.0 1.0 0.0 0.0 -1.0 0.0 0.0 -1.0 1.0 -1.0 1.0 0.0 -1.0 0.0 0.0 -1.0 -1.0 1.0 0.0 1.0 -1.0 0.0 0.0 -1.0 -1.0 1.0 0.0 1.0 -1.0 0.0 0.0 -1.0 1.0 -1.0 1.0 0.0 -1.0 0.0 0.0 -1.0 -1.0 -1.0 1.0 1.0 -1.0 0.0 0.0 -1.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 -1.0 1.0 -1.0 0.0 1.0 0.0 1.0 0.0 -1.0 1.0 -1.0 0.0 1.0 0.0 1.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0 -1.0 1.0 1.0 0.0 1.0 0.0 -1.0 -1.0 -1.0 0.0 0.0 0.0 -1.0 0.0 1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0 -1.0 -1.0 1.0 0.0 1.0 0.0 -1.0 0.0 -1.0 -1.0 1.0 0.0 1.0 0.0 -1.0 0.0 1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0 1.0 -1.0 1.0 1.0 1.0 0.0 -1.0 0.0
#include <iostream> #include <fstream> using namespace std; int main() { ifstream in; in.open("cube.txt"); if(!in) { cout<<"打开失败"<<endl; }else { cout<<"打开成功"<<endl; } char ch; int count; float f[8]; while(ch=in.get(),ch!=':');//跳过"Vertex Count:" in>>count; cout<<count<<endl; while(ch=in.get(),ch!=':');//跳过"Data:" while(!in.eof()) { for(int i=0;i<8;i++) in>>f[i]; for(int i=0;i<8;i++) cout<<f[i]<<" "; cout<<endl; } in.close(); in.clear(); getchar(); }
本文转载请注明:Younfor的博客笔记,http://blog.csdn.net/cq361106306/article/details/40300205
原文地址:http://blog.csdn.net/cq361106306/article/details/40300205