windows 下bullet库的安装使用

转自http://www.cnblogs.com/liangliangh/p/3575590.html

1 Bullet安装指导

  1. 下载bullet-2.82-r2704.zip,解压(r后面的数字可能不同);
  2. 运行“../build/vs2010.bat”,生成VS2010工程;
  3. 用VS2010打开“../vs2010/0BulletSolution.sln”;
  4. LinearMathBulletCollisionBulletDynamicsBulletSoftBody,分别在DebugRelease配置下编译生成LIB;
  5. 将“../lib”下的8个.lib文件,以及“../src”下所有.h文件,都拷贝出来即构成安装包;其中,.lib文件放到lib文件夹先,.h文件放到inc文件夹下。
注:生成lib也可参考http://bulletphysics.org/mediawiki-1.5.8/index.php/Creating_a_project_from_scratch,这里有详细的图文讲解

Bullet工程配置(使用Bullet库)

要使用Bullet,需要:

  1. 添加包含目录,将上一节拷贝的.h文件所在目录添加到工程的包含目录(在所有配置下);
  2. 添加库目录,将上一节拷贝的.lib文件所在目录添加到工程库目录(在所有配置下);
  3. 引用库,添加对.lib文件的引用(根据使用层次添加所需.lib文件,Debug和Release分别设置);
  4. 包含头文件,在代码中包含“btBulletDynamicsCommon.h”。
  5. 接下来,就可以自己编辑代码了。

注:

添加包含目录的两种方法:

  1. “项目属性 >> 配置属性 >> VC++目录 >> 包含目录”
  2. “项目属性 >> 配置属性 >> C/C++ >> 常规 >> 附加包含目录”。

添加库目录的两种方法:

  1. “项目属性 >> 配置属性 >> VC++目录 >> 库目录”
  2. “项目属性 >> 配置属性 >> 链接器 >> 常规 >> 附加库目录”。

引用库的两种方法:

  1. 代码#pragma comment (lib, "xxx.lib")(用#ifdef _DLL和#ifdef _DEBUG);
  2. “项目属性 >> 配置属性 >> 链接器 >> 输入 >> 附加依赖项”。
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 Windows 系统下的 C 语言飞机大战代码,使用了 WinAPI 。代码中实现了一个简单的游戏界面和飞机控制,具体细节可以根据需要进行修改和完善。 ```c #include <windows.h> #include <stdlib.h> #include <time.h> #define MAX_ENEMIES 10 #define ENEMY_SPEED 3 #define ENEMY_WIDTH 50 #define ENEMY_HEIGHT 50 #define BULLET_SPEED 8 #define BULLET_WIDTH 5 #define BULLET_HEIGHT 10 #define PLAYER_SPEED 5 #define PLAYER_WIDTH 50 #define PLAYER_HEIGHT 50 static int score = 0; static int game_over = 0; typedef struct { int x; int y; int alive; } enemy_t; typedef struct { int x; int y; int alive; } bullet_t; typedef struct { int x; int y; } player_t; static enemy_t enemies[MAX_ENEMIES]; static bullet_t bullets[MAX_ENEMIES]; static player_t player; void init_game() { int i; for (i = 0; i < MAX_ENEMIES; i++) { enemies[i].x = rand() % (600 - ENEMY_WIDTH); enemies[i].y = rand() % 1000 - 1000; enemies[i].alive = 1; } for (i = 0; i < MAX_ENEMIES; i++) { bullets[i].x = -1; bullets[i].y = -1; bullets[i].alive = 0; } player.x = 275; player.y = 700; } void draw_enemy(HDC hdc, int x, int y) { HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0)); HGDIOBJ old_brush = SelectObject(hdc, brush); Rectangle(hdc, x, y, x + ENEMY_WIDTH, y + ENEMY_HEIGHT); SelectObject(hdc, old_brush); DeleteObject(brush); } void draw_bullet(HDC hdc, int x, int y) { HBRUSH brush = CreateSolidBrush(RGB(0, 0, 255)); HGDIOBJ old_brush = SelectObject(hdc, brush); Rectangle(hdc, x, y, x + BULLET_WIDTH, y + BULLET_HEIGHT); SelectObject(hdc, old_brush); DeleteObject(brush); } void draw_player(HDC hdc, int x, int y) { HBRUSH brush = CreateSolidBrush(RGB(0, 255, 0)); HGDIOBJ old_brush = SelectObject(hdc, brush); Rectangle(hdc, x, y, x + PLAYER_WIDTH, y + PLAYER_HEIGHT); SelectObject(hdc, old_brush); DeleteObject(brush); } void update_game(HWND hwnd) { int i, j; if (game_over) { MessageBox(hwnd, "Game over", "Game over", MB_OK); init_game(); score = 0; game_over = 0; } for (i = 0; i < MAX_ENEMIES; i++) { if (enemies[i].alive) { enemies[i].y += ENEMY_SPEED; if (enemies[i].y > 800) { enemies[i].x = rand() % (600 - ENEMY_WIDTH); enemies[i].y = rand() % 1000 - 1000; enemies[i].alive = 1; } for (j = 0; j < MAX_ENEMIES; j++) { if (bullets[j].alive && bullets[j].x > enemies[i].x && bullets[j].x < enemies[i].x + ENEMY_WIDTH && bullets[j].y > enemies[i].y && bullets[j].y < enemies[i].y + ENEMY_HEIGHT) { enemies[i].alive = 0; bullets[j].alive = 0; score++; break; } } if (player.x > enemies[i].x && player.x < enemies[i].x + ENEMY_WIDTH && player.y > enemies[i].y && player.y < enemies[i].y + ENEMY_HEIGHT) { game_over = 1; } } } for (i = 0; i < MAX_ENEMIES; i++) { if (bullets[i].alive) { bullets[i].y -= BULLET_SPEED; if (bullets[i].y < 0) { bullets[i].alive = 0; } } } } void draw_game(HWND hwnd, HDC hdc) { int i; char score_str[100]; sprintf(score_str, "Score: %d", score); TextOut(hdc, 10, 10, score_str, strlen(score_str)); for (i = 0; i < MAX_ENEMIES; i++) { if (enemies[i].alive) { draw_enemy(hdc, enemies[i].x, enemies[i].y); } } for (i = 0; i < MAX_ENEMIES; i++) { if (bullets[i].alive) { draw_bullet(hdc, bullets[i].x, bullets[i].y); } } draw_player(hdc, player.x, player.y); } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (msg) { case WM_CREATE: srand(time(NULL)); init_game(); SetTimer(hwnd, 1, 30, NULL); break; case WM_TIMER: update_game(hwnd); InvalidateRect(hwnd, NULL, FALSE); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); draw_game(hwnd, hdc); EndPaint(hwnd, &ps); break; case WM_KEYDOWN: switch (wParam) { case VK_LEFT: if (player.x > 0) { player.x -= PLAYER_SPEED; } break; case VK_RIGHT: if (player.x < 550) { player.x += PLAYER_SPEED; } break; case VK_SPACE: for (int i = 0; i < MAX_ENEMIES; i++) { if (!bullets[i].alive) { bullets[i].x = player.x + PLAYER_WIDTH / 2 - BULLET_WIDTH / 2; bullets[i].y = player.y - BULLET_HEIGHT; bullets[i].alive = 1; break; } } break; default: break; } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG msg; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = "MainWindowClass"; RegisterClassEx(&wc); hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "MainWindowClass", "飞机大战", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 600, 800, NULL, NULL, hInstance, NULL); if (hwnd == NULL) { return 1; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值