資源簡介
vc6.0,opengl對stl文件的讀取及顯示。鼠標及鍵盤控制。

代碼片段和文件信息
//?Opengl.cpp:?implementation?of?the?Opengl?class.
//
//////////////////////////////////////////////////////////////////////
#include?“Opengl.h“
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;
bool lp;
bool fp;
bool keys[256];
bool active=TRUE;
bool fullscreen=FALSE; //FALSE非全屏;
float *Hnub?=?NULL;
float *Cout?=?NULL;
int Nnub?=?0;
GLfloat?rtri?=?7;
GLfloat xrot;
GLfloat yrot;
GLfloat zd?=?-3.0;
GLfloat?LightAmbient[]?=?{?0.5f?0.5f?0.5f?1.0f?};
GLfloat?LightDiffuse[]={?1.0f?1.0f?1.0f?1.0f?};
GLfloat?LightPosition[]?=?{?0.0f?0.0f?0.0f?1.0f?};
Opengl::Opengl()
{
}
Opengl::~Opengl()
{
}
LRESULT CALLBACK?WndProc(HWND?UINT?WPARAM?LPARAM);
void?Opengl::GetStlVertex()?
{
ifstream?File;
File.open(“tooth3.stl“);//F:The?New?File//
if(!(File.is_open()))
{
MessageBox(NULL“The?File?Open?False““ERROR“MB_OK|MB_ICONEXCLAMATION);
File.close();
// return?1;
}
int?numb1?=?0;
int?numb2?=?0;
int?Cont?=?0; //計算STL行數
char?SStr[1024];
string?Str;
while(File.good()?&&?!File.eof())?
{
memset(SStr01024);
//File.seekg(0ios::end);//移動指針
//int?Fsize?=?File.tellg();//大小
File.getline(SStr1024);
Str?=?SStr;
Cont++;
int?Ssize?=?Str.size();
}
Nnub?=?Cont/7;???????????????//三角形面的個數,7個為一個三角形面
//cout< Hnub?=?new?float[9*Nnub];
Cout?=?new?float[9*Nnub];
FILE*?file;
file=fopen(“tooth3.stl““r“);//F://The?New?File//
rewind(file);
????while?(getc(file)?!=?‘\n‘);
if(file?==?NULL)
{
// char?chInput[512]=“dasfsdfdfg“?;
// sprintf(chInput“int:%d\n“500);
// OutputDebugString(?chInput?);
//cout<“The?File?Open?Flase“?< MessageBox(NULL“The?File?Open?False““ERROR“MB_OK|MB_ICONEXCLAMATION);
fclose(file);
// return?1;
}
//?按行解析
for?(int?i=0;i ????{
????????char?x[200]?=?““;
????????char?y[200]?=?““;
????????char?z[200]?=?““;
????????if(3!=fscanf(file“%*s?%*s?%80s?%80s?%80s\n“xyz))
????????{
????????????break;
????????}
????????Cout[numb1]?=?Cout[numb1+3]?=?Cout[numb1+6]=atof(x);
????????numb1++;
????????Cout[numb1]?=?Cout[numb1+3]?=?Cout[numb1+6]=atof(y);
????????numb1++;
????????Cout[numb1]?=?Cout[numb1+3]?=?Cout[numb1+6]=atof(z);
????????numb1?+=?7;
????????fscanf(file“%*s?%*s“);
????????if?(3?!=?fscanf(file“%*s?%80s?%80s?%80s\n“xyz))
????????{
????????????break;
????????}
????????Hnub[numb2]?=?atof(x);
????????numb2++;
????????Hnub[numb2]?=?atof(y);
????????numb2++;
Hnub[numb2]?=?atof(z);
????????numb2++;
????????if?(3?!=?fscanf(file“%*s?%80s?%80s?%80s\n“xyz))
????????{
????????????break;
????????}
????????Hnub[numb2]?=?atof(x);
????????numb2++;
????????Hnub[numb2]?=?atof(y);
????????numb2++;
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????217036??2014-11-05?09:40??OpenGl_1\Debug\Opengl.obj
?????文件?????536666??2014-11-05?09:40??OpenGl_1\Debug\OpenGl_1.exe
?????文件?????788792??2014-11-05?09:40??OpenGl_1\Debug\OpenGl_1.ilk
?????文件????5659672??2014-11-04?11:38??OpenGl_1\Debug\OpenGl_1.pch
?????文件????1123328??2014-11-05?09:40??OpenGl_1\Debug\OpenGl_1.pdb
?????文件?????963910??2014-11-02?14:36??OpenGl_1\Debug\tooth3.stl
?????文件?????205824??2014-11-05?09:40??OpenGl_1\Debug\vc60.idb
?????文件?????159744??2014-11-05?09:40??OpenGl_1\Debug\vc60.pdb
?????文件??????13783??2014-11-05?09:39??OpenGl_1\Opengl.cpp
?????文件????????747??2014-11-04?11:38??OpenGl_1\Opengl.h
?????文件???????4073??2014-11-03?15:26??OpenGl_1\OpenGl_1.dsp
?????文件????????524??2014-11-03?13:59??OpenGl_1\OpenGl_1.dsw
?????文件??????50176??2014-11-05?09:41??OpenGl_1\OpenGl_1.ncb
?????文件??????48640??2014-11-05?09:41??OpenGl_1\OpenGl_1.opt
?????文件???????1226??2014-11-05?09:40??OpenGl_1\OpenGl_1.plg
?????文件?????963910??2014-11-02?14:36??OpenGl_1\tooth3.stl
?????文件?????169984??1998-08-18?16:25??OpenGl_1\開發庫\glut.dll
?????文件??????21440??1998-08-18?16:24??OpenGl_1\開發庫\glut.h
?????文件??????79654??1998-08-18?16:25??OpenGl_1\開發庫\glut.lib
?????文件?????169984??1998-08-18?16:25??OpenGl_1\開發庫\glut32.dll
?????文件??????79898??1998-08-18?16:25??OpenGl_1\開發庫\glut32.lib
?????目錄??????????0??2017-12-10?01:02??OpenGl_1\Debug
?????目錄??????????0??2017-12-10?01:02??OpenGl_1\開發庫
?????目錄??????????0??2017-12-10?01:02??OpenGl_1
-----------?---------??----------?-----??----
?????????????11259011????????????????????24
- 上一篇:C語言搭建的簡單web服務器
- 下一篇:最全 C/C++ API文檔
評論
共有 條評論