資源簡介
Visual C++ / opengl 實現的陰影算法;

代碼片段和文件信息
//?a?bouncing?ball
//?Ping-Che?Chen
#define?GLUT_DISABLE_ATEXIT_HACK
#include?
#include?
#include?
#include?
#ifndef?M_PI
#define?M_PI?3.1415926535897932384626433832795
#endif
#ifndef?WIN32
#include?
typedef?clock_t?my_clock_t;
#else
#define?WIN32_LEAN_AND_MEAN
#include?
typedef?LONGLONG?my_clock_t;
#endif
const?char*?title?=?“ball“;
//?number?bitmaps
const?GLubyte?number[12][8]?=?{
{?0x00?0x7C?0xE6?0xF6?0xDE?0xCE?0xC6?0x7C?} //?0
{?0x00?0xFC?0x30?0x30?0x30?0x30?0x70?0x30?}?//?1
{?0x00?0xFC?0xCC?0x60?0x38?0x0C?0xCC?0x78?}?//?2
{?0x00?0x78?0xCC?0x0C?0x38?0x0C?0xCC?0x78?}?//?3
{?0x00?0x1E?0x0C?0xFE?0xCC?0x6C?0x3C?0x1C?}?//?4
{?0x00?0x78?0xCC?0x0C?0x0C?0xF8?0xC0?0xFC?}?//?5
{?0x00?0x78?0xCC?0xCC?0xF8?0xC0?0x60?0x38?}?//?6
{?0x00?0x30?0x30?0x30?0x18?0x0C?0xCC?0xFC?}?//?7
{?0x00?0x78?0xCC?0xCC?0x78?0xCC?0xCC?0x78?}?//?8
{?0x00?0x70?0x18?0x0C?0x7C?0xCC?0xCC?0x78?}?//?9
{?0x00?0x30?0x30?0x00?0x00?0x00?0x00?0x00?}?//?.
{?0x00?0x00?0x00?0x00?0x00?0x00?0x00?0x00?} //?others
};
//?display?lists
GLuint?box;
GLuint?sphere;
GLuint?fonts;
GLuint?wall;
//?viewer?position
const?GLdouble?eye[3]?=?{?0.5?1.5f?5?};
const?GLdouble?center[3]?=?{?0?1.5f?0?};
//?light
GLfloat?light_pos[4]?=?{?2?3?4?0?};
//?color
const?GLfloat?color_box[3]?=?{?0.7f?0.4f?0.1f?};
const?GLfloat?color_sphere[3]?=?{?0.3f?0.1f?0.9f?};
const?GLfloat?color_shadow[3]?=?{?0.3f?0.3f?0.3f?};
const?GLfloat?color_wall[3]?=?{?0.6f?0.3f?0.4f?};
//?ground?parameter?(Ax?+?By?+?Cz?+?D?=?0)
const?GLfloat?ground_parameter[4]?=?{?0?1?0?0?};
const?GLfloat?wall_parameter1[4]?=?{?0?0?1?4?};
const?GLfloat?wall_parameter2[4]?=?{?1?0?0?4?};
//?clip?planes
const?GLdouble?plane0[4]?=?{?0?0?1?4?};
const?GLdouble?plane1[4]?=?{?1?0?0?4?};
const?GLdouble?plane2[4]?=?{?0?1?0?0?};
//?shadow?matrix
GLfloat?shadow_matrix[4][4];
GLfloat?shadow_matrix1[4][4];
GLfloat?shadow_matrix2[4][4];
//?ball?position
GLfloat?ball_t?=?0;
my_clock_t?last_time?timer_frequency?last_sec_time;
int?frame_no?=?0;
bool?odd_frame?=?false?z_trick?=?false;
float?fps?=?0;
my_clock_t?get_system_time()
{
#ifdef?WIN32
LARGE_INTEGER?r;
QueryPerformanceCounter(&r);
return?r.QuadPart;
#else
struct?timeval?t;
gettimeofday(&t?NULL);
return?t.tv_sec?*?1000?+?t.tv_usec?/?1000;
#endif
}
void?set_up_system_time()
{
#ifdef?WIN32
LARGE_INTEGER?r;
QueryPerformanceFrequency(&r);
if(r.QuadPart?==?0)?{
throw?“Timer?is?not?available“;
}
timer_frequency?=?r.QuadPart;
#else
timer_frequency?=?1000;
#endif
last_sec_time?=?last_time?=?get_system_time();
}
void?generate_box(GLuint?p?GLfloat?width?GLfloat?height?GLfloat?depth)
{
GLfloat?x?y?z;
x?=?width?/?2;
y?=?-height;
z?=?depth?/?2;
glNewList(p?GL_COMPILE);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????11034??2013-10-14?18:41??shadow\ball_shadow.cpp
?????文件???????4180??1999-08-18?03:17??shadow\ball_shadow.dsp
?????文件????????545??1999-06-28?02:32??shadow\ball_shadow.dsw
?????文件??????40960??2000-06-08?03:01??shadow\ball_shadow.exe
?????文件??????50176??2013-12-18?17:05??shadow\ball_shadow.ncb
?????文件??????78848??2013-12-18?17:05??shadow\ball_shadow.opt
?????文件???????1206??2013-12-18?17:03??shadow\ball_shadow.plg
?????文件?????169984??1998-08-18?16:25??shadow\glut32.dll
?????目錄??????????0??2013-12-18?17:03??shadow\Debug
?????目錄??????????0??2013-12-18?17:05??shadow
-----------?---------??----------?-----??----
???????????????356933????????????????????10
- 上一篇:網關模板 C/C++程序編寫
- 下一篇:基于QT的網絡聊天室和服務器
評論
共有 條評論