#include "Main.h"
#include "Camera.h"
#include "Quake3Bsp.h"
#include "Frustum.h"
// This is our maximum height that the user can climb over
const float kMaxStepHeight = 10.0f;
// We use the camera in our TryToStep() function so we extern the global camera
extern CCamera g_Camera;
/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
// This is our global frustum class, which is used to cull BSP leafs
extern CFrustum g_Frustum;
// This will store how many faces are drawn and are seen by the camera
extern int g_VisibleFaces;
// This tells us if we want to render the lightmaps
extern bool g_bLightmaps;
// This holds the gamma value that was stored in the config file
extern float g_Gamma;
// This tells us if we want to render the textures
extern bool g_bTextures;
//////////////////////////// CQUAKE3BSP \\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This is our object's constructor to initial all it's data members
/////
//////////////////////////// CQUAKE3BSP \\\\\\\\\\\\\\\\\\\\\\\\\\\*
CQuake3BSP::CQuake3BSP()
{
// Here we simply initialize our member variables to 0
m_numOfVerts = 0;
m_numOfFaces = 0;
m_numOfIndices = 0;
m_numOfTextures = 0;
m_numOfLightmaps = 0;
m_numOfNodes = 0;
m_numOfLeafs = 0;
m_numOfLeafFaces = 0;
m_numOfPlanes = 0;
m_numOfBrushes = 0;
m_numOfBrushSides = 0;
m_numOfLeafBrushes = 0;
m_traceRatio = 0;
m_traceType = 0;
m_traceRadius = 0;
bool m_bCollided = false;
/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
// Initialize our variables to start off
bool m_bGrounded = false;
bool m_bTryStep = false;
/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
// We need to initialize our Min and Max and Extent variables
m_vTraceMins = CVector3(0, 0, 0);
m_vTraceMaxs = CVector3(0, 0, 0);
m_vExtents = CVector3(0, 0, 0);
// This will store the normal of the plane we collided with
m_vCollisionNormal = CVector3(0, 0, 0);
// Initialize all the dynamic BSP data pointers to NULL
m_pVerts = NULL;
m_pFaces = NULL;
m_pIndices = NULL;
m_pNodes = NULL;
m_pLeafs = NULL;
m_pPlanes = NULL;
m_pLeafFaces = NULL;
memset(&m_clusters, 0, sizeof(tBSPVisData));
// Here we initialize our dynamic arrays of data for the brush information of the BSP
m_pBrushes = NULL;
m_pBrushSides = NULL;
m_pTextures = NULL;
m_pLeafBrushes = NULL;
}
//////////////////////////// CHANGE GAMMA \\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This manually changes the gamma of an image
/////
//////////////////////////// CHANGE GAMMA \\\\\\\\\\\\\\\\\\\\\\\\\\\*
void CQuake3BSP::ChangeGamma(byte *pImage, int size, float factor)
{
// Go through every pixel in the lightmap
for(int i = 0; i < size / 3; i++, pImage += 3)
{
float scale = 1.0f, temp = 0.0f;
float r = 0, g = 0, b = 0;
// extract the current RGB values
r = (float)pImage[0];
g = (float)pImage[1];
b = (float)pImage[2];
// Multiply the factor by the RGB values, while keeping it to a 255 ratio
r = r * factor / 255.0f;
g = g * factor / 255.0f;
b = b * factor / 255.0f;
// Check if the the values went past the highest value
if(r > 1.0f && (temp = (1.0f/r)) < scale) scale=temp;
if(g > 1.0f && (temp = (1.0f/g)) < scale) scale=temp;
if(b > 1.0f && (temp = (1.0f/b)) < scale) scale=temp;
// Get the scale for this pixel and multiply it by our pixel values
scale*=255.0f;
r*=scale; g*=scale; b*=scale;
// Assign the new gamma'nized RGB values to our image
pImage[0] = (byte)r;
pImage[1] = (byte)g;
pImage[2] = (byte)b;
}
}
////////////////////////////// CREATE LIGHTMAP TEXTURE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This creates a texture map from the light map image bits
/////
////////////////////////////// CREATE LIGHTMAP TEXTURE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
void CQuake3BSP::CreateLightmapTexture(UINT &texture, byte *pImageBits, int width, int height)
{
// Generate a texture with the associative texture ID stored in the array
glGenTextures(1, &texture);
// This sets the alignment requirements for the start of each pixel row in memory.
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
// Bind the texture to the texture arrays index and init the texture
glBindTexture(GL_TEXTURE_2D, texture);
// Change the lightmap gamma values by our desired gamma
ChangeGamma(pImageBits, width*height*3, g_Gamma);
// Build Mipmaps (builds different versions of the picture for distances - looks better)
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, pImageBits);
//Assign the mip map levels
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
//////////////////////////// FIND TEXTURE EXTENSION \\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This attaches the image extension to the texture name, if found
/////
//////////////////////////// FIND TEXTURE EXTENSION \\\\\\\\\\\\\\\\\\\\\\\\\\\*
void CQuake3BSP::FindTextureExtension(char *strFileName)
{
char strJPGPath[MAX_PATH] = {0};
char strTGAPath[MAX_PATH] = {0};
FILE *fp = NULL;
// Get the current path we are in
GetCurrentDirectory(MAX_PATH, strJPGPath);
// Add on a '\' and the file name to the end of the current path.
// We create 2 seperate strings to test each image extension.
strcat(strJPGPath, "\\");
strcat(strJPGPath, strFileName);
strcpy(strTGAPath, strJPGPath);
// Add the extensions on to the file name and path
strcat(strJPGPath, ".jpg");
strcat(strTGAPath, ".tga");
// Check if there is a jpeg file with the texture name
if((fp = fopen(strJPGPath, "rb")) != NULL)
{
// If so, then let's add ".jpg" onto the file name and return
strcat(strFileName, ".jpg");
return;
}
// Check if there is a targa file with the texture name
if((fp = fopen(strTGAPath, "rb")) != NULL)
{
// If so, then let's add a ".tga" onto the file name and return
strcat(strFileName, ".tga");
return;
}
}
//////////////////////////// LOAD BSP \\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This loads in all of the .bsp data for the level
/////
//////////////////////////// LOAD BSP \\\\\\\\\\\\\\\\\\\\\\\\\\\*
bool CQuake3BSP::LoadBSP(const char *strFileName)
{
FILE *fp = NULL;
int i = 0;
// Check if the .bsp file could be opened
if((fp = fopen(strFileName, "rb")) == NULL)
{
// Display an error message and quit if the file can't be found.
MessageBox(g_hWnd, "Could not find BSP file!", "Error", MB_OK);
return false;
}
// Initialize the header and lump structures
tBSPHeader header = {0};
tBSPLump lumps[kMaxLumps] = {0};
// Read in the header and lump data
fread(&header, 1, sizeof(tBSPHeader), fp);
fread(&lumps, kMaxLumps, sizeof(tBSPLump), fp);
// Now we know all the information about our file. We can
// then allocate the needed memory for our member variables.
// Allocate the vertex memory
m_numOfVerts = lumps[kVertices].length / sizeof(tBSPVertex);
m_pVerts = new tBSPVertex [m_numOfVerts];
// Allocate the face memory
m_numOfFaces = lumps[kFaces].length / sizeof(tBSPFace);
m_pFaces = new tBSPFace [m_numOfFaces];
// Allocate the index memory
m_numOfIndices = lumps[kIndices].length / sizeof(int);
m_pIndices = new int [m_numOfIndices];
// Allocate memory to read in the texture information.
m_numOfTextures = lumps[kTextures].length / sizeof(tBSPTexture);
m_pTextures = new tBSPTexture [m_numOfTextures];
// Allocate memory to read in the lightmap data.
m_numOfLightmaps = lumps[kLightmaps].length / sizeof(tBSPLightmap);
tBSPLightmap *pLightmaps = new tBSPLightmap
没有合适的资源?快使用搜索试试~ 我知道了~
基于bsp的漫游程序框架
共76个文件
jpg:27个
cpp:6个
obj:6个
5星 · 超过95%的资源 需积分: 6 32 下载量 90 浏览量
2008-12-11
16:41:01
上传
评论
收藏 5.22MB RAR 举报
温馨提示
bsp 漫游程序 用bsp树组织场景,并应用于碰撞检测
资源详情
资源评论
资源推荐
收起资源包目录
bspdemo.rar (76个子文件)
QuakeBsp
QuakeBsp
main.cpp 4KB
main.h 3KB
Init.cpp 6KB
Image.h 528B
textures
egyptians
heiro_01.jpg 21KB
stei_tele2.jpg 5KB
oldbrk_01broken13.jpg 29KB
oldstone2_bas05.jpg 22KB
gold_groove.jpg 30KB
ankhlite_ylw.jpg 4KB
leaf.tga 36KB
oldstone2.jpg 17KB
oldbrk_03_bloody.jpg 20KB
oldstone2_bas01.jpg 24KB
oldbrk_01.jpg 19KB
oldbrk_03.jpg 19KB
plant_egy.tga 31KB
oldstone2_trim01.jpg 5KB
oldstone2_bas04.jpg 20KB
ankhlite_wht.jpg 4KB
bounce_effects.jpg 8KB
oldstone2_trim02.jpg 11KB
ankhlite_ylw.blend.jpg 3KB
gold_trim02.jpg 4KB
oldstone2_step.jpg 4KB
oldstone2_bas03.jpg 19KB
oldstone_ramses.jpg 19KB
sand_egy.jpg 16KB
oldstone2_bas06.jpg 21KB
gold_trim01.jpg 4KB
oldstone2_bas07.jpg 19KB
gold_trim03.jpg 994B
oldstone2grooved.jpg 18KB
maps
Tutorial.bsp 2.58MB
Quake3Bsp.cpp 43KB
QuakeBsp.exe 436KB
Debug
Image.obj 57KB
vc70.idb 563KB
QuakeBsp.exe.embed.manifest.res 212B
QuakeBsp.pdb 2.85MB
QuakeBsp.ilk 1.42MB
vc80.pdb 244KB
QuakeBsp.exe.embed.manifest 146B
QuakeBsp.exe 644KB
vc70.pdb 196KB
BuildLog.htm 7KB
Camera.obj 76KB
Init.obj 64KB
QuakeBsp.exe.intermediate.manifest 145B
mt.dep 67B
main.obj 498KB
vc80.idb 619KB
Quake3Bsp.obj 102KB
Frustum.obj 196KB
QuakeBsp.vcproj 5KB
Frustum.cpp 9KB
Camera.h 2KB
Quake3Bsp.h 13KB
Config.ini 38B
Camera.cpp 6KB
jpeglib.h 64KB
Frustum.h 813B
jpeg.lib 287KB
QuakeBsp.vcproj.CANDRY.L.candry.user 1KB
Image.cpp 5KB
QuakeBsp.vcproj.7.10.old 4KB
_UpgradeReport_Files
UpgradeReport.xslt 12KB
UpgradeReport_Plus.gif 71B
UpgradeReport.css 3KB
UpgradeReport_Minus.gif 69B
QuakeBsp.suo 34KB
UpgradeLog.XML 4KB
QuakeBsp.ncb 10.5MB
QuakeBsp.sln.old 914B
QuakeBsp.suo.old 8KB
QuakeBsp.sln 884B
共 76 条
- 1
l_candry_163_com
- 粉丝: 5
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1