資源簡介
這是計算機圖形學的一個大作業,繪制了一個3D模型,可以實現模型視圖縮放,旋轉,平移。有控制窗口實現模型不見得旋轉,平移以及光源的改變等等。

代碼片段和文件信息
//
//?bitmap.cpp
//
//?handle?MS?bitmap?I/O.?For?portability?we?don‘t?use?the?data?structure?defined?in?Windows.h
//?However?there?is?some?strange?thing?the?side?of?our?structure?is?different?from?what?it?
//?should?though?we?define?it?in?the?same?way?as?MS?did.?So?there?is?a?hack?we?use?the?hardcoded
//?constanr?14?instead?of?the?sizeof?to?calculate?the?size?of?the?structure.
//?You?are?not?supposed?to?worry?about?this?part.?However?I?will?appreciate?if?you?find?out?the
//?reason?and?let?me?know.?Thanks.
//
#include?“bitmap.h“
?
BMP_BITMAPFILEHEADER?bmfh;?
BMP_BITMAPINFOHEADER?bmih;?
unsigned?char?*readBMP(char?*fname?int&?width?int&?height)
{?
????????FILE*?file;?
????????BMP_DWORD?pos;?
?
????????if?(?(file=fopen(?fname?“rb“?))?==?NULL?)??
????????????????return?NULL;?
?????????
//??????I?am?doing?fread(?&bmfh?sizeof(BMP_BITMAPFILEHEADER)?1?file?)?in?a?safe?way.?:}
????????fread(?&(bmfh.bfType)?2?1?file);?
????????fread(?&(bmfh.bfSize)?4?1?file);?
????????fread(?&(bmfh.bfReserved1)?2?1?file);?
????????fread(?&(bmfh.bfReserved2)?2?1?file);?
????????fread(?&(bmfh.bfOffBits)?4?1?file);?
????????pos?=?bmfh.bfOffBits;?
?
????????fread(?&bmih?sizeof(BMP_BITMAPINFOHEADER)?1?file?);?
?
????????//?error?checking
????????if?(?bmfh.bfType!=?0x4d42?)?{???//?“BM“?actually
????????????????return?NULL;
????????}
????????if?(?bmih.biBitCount?!=?24?)??
????????????????return?NULL;?
/*
????????if?(?bmih.biCompression?!=?BMP_BI_RGB?)?{
????????????????return?NULL;
????????}
*/
????????fseek(?file?pos?SEEK_SET?);?
?
????????width?=?bmih.biWidth;?
????????height?=?bmih.biHeight;?
?
????????int?padWidth?=?width?*?3;?
????????int?pad?=?0;?
????????if?(?padWidth?%?4?!=?0?)?
????????{?
????????????????pad?=?4?-?(padWidth?%?4);?
????????????????padWidth?+=?pad;?
????????}?
????????int?bytes?=?height*padWidth;?
?
????????unsigned?char?*data?=?new?unsigned?char?[bytes];?
????????int?foo?=?fread(?data?bytes?1?file?);?
????????
????????if?(!foo)?{
????????????????delete?[]?data;
????????????????return?NULL;
????????}
????????fclose(?file?);
????????
????????//?shuffle?bitmap?data?such?that?it?is?(RGB)?tuples?in?row-major?order
????????int?i?j;
????????j?=?0;
????????unsigned?char?temp;
????????unsigned?char*?in;
????????unsigned?char*?out;
????????in?=?data;
????????out?=?data;
????????for?(?j?=?0;?j?????????{
????????????????for?(?i?=?0;?i?????????????????{
????????????????????????out[1]?=?in[1];
????????????????????????temp?=?in[2];
????????????????????????out[2]?=?in[0];
????????????????????????out[0]?=?temp;
????????????????????????in?+=?3;
????????????????????????out?+=?3;
????????????????}
????????????????in?+=?pad;
????????}
??????????????????????????
????????return?data;?
}?
?
void?writeBMP(char?*iname?int?width?int?height?unsigned?char?*data)?
{?
????????int?bytes?pad;
????????bytes
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-12-31?17:25??Modeler_VC2005\
?????目錄???????????0??2015-12-31?17:25??Modeler_VC2005\Debug\
?????文件????????7142??2015-12-12?17:03??Modeler_VC2005\Debug\BuildLog.htm
?????文件???????27575??2015-12-06?14:28??Modeler_VC2005\Debug\bitmap.obj
?????文件???????71155??2015-12-06?14:28??Modeler_VC2005\Debug\camera.obj
?????文件??????499712??2015-12-12?17:03??Modeler_VC2005\Debug\modeler.exe
?????文件?????????655??2015-12-06?14:28??Modeler_VC2005\Debug\modeler.exe.em
?????文件?????????720??2015-12-06?14:28??Modeler_VC2005\Debug\modeler.exe.em
?????文件?????????620??2015-12-12?17:03??Modeler_VC2005\Debug\modeler.exe.intermediate.manifest
?????文件?????1455652??2015-12-12?17:03??Modeler_VC2005\Debug\modeler.ilk
?????文件?????1330176??2015-12-12?17:03??Modeler_VC2005\Debug\modeler.pdb
?????文件???????71395??2015-12-06?14:28??Modeler_VC2005\Debug\modelerapp.obj
?????文件???????52216??2015-12-06?14:28??Modeler_VC2005\Debug\modelerdraw.obj
?????文件??????127175??2015-12-06?14:28??Modeler_VC2005\Debug\modelerui.obj
?????文件???????58260??2015-12-06?14:28??Modeler_VC2005\Debug\modelerview.obj
?????文件??????????65??2015-12-12?17:03??Modeler_VC2005\Debug\mt.dep
?????文件???????48034??2015-12-12?17:03??Modeler_VC2005\Debug\sample.obj
?????文件?????1018880??2015-12-12?17:03??Modeler_VC2005\Debug\vc80.idb
?????文件??????323584??2015-12-12?17:03??Modeler_VC2005\Debug\vc80.pdb
?????文件?????????600??2015-12-06?14:28??Modeler_VC2005\ModelerSkeleton-11.2-sp01_ReleaseNotes.txt
?????目錄???????????0??2015-12-31?17:25??Modeler_VC2005\Release\
?????文件???????10848??2015-12-06?14:28??Modeler_VC2005\Release\BuildLog.htm
?????文件????????4937??2015-12-06?14:28??Modeler_VC2005\bitmap.cpp
?????文件????????1207??2015-12-06?14:28??Modeler_VC2005\bitmap.h
?????文件????????4313??2015-12-06?14:28??Modeler_VC2005\camera.cpp
?????文件????????2503??2015-12-06?14:28??Modeler_VC2005\camera.h
?????文件??????169984??1998-08-18?16:25??Modeler_VC2005\glut32.dll
?????目錄???????????0??2015-12-31?17:25??Modeler_VC2005\local\
?????目錄???????????0??2015-12-31?17:25??Modeler_VC2005\local\include\
?????目錄???????????0??2015-12-31?17:25??Modeler_VC2005\local\include\FL\
?????文件???????14327??2015-12-06?14:28??Modeler_VC2005\local\include\FL\Enumerations.H
............此處省略149個文件信息
評論
共有 條評論