mirror of
https://github.com/UberGames/rpgxEF.git
synced 2024-11-10 15:21:34 +00:00
Replaced ray box intersection and added additinal function
- Replaced the ray box intersection function by a other - added BG_OriginFromBoundingBox which calculates an approximate origin from a given bounding box
This commit is contained in:
parent
f0cbc78f41
commit
056553e85c
8 changed files with 125 additions and 109 deletions
2
Makefile
2
Makefile
|
@ -2071,6 +2071,7 @@ Q3CGOBJ_ = \
|
|||
$(B)/$(BASEGAME)/cgame/bg_slidemove.o \
|
||||
$(B)/$(BASEGAME)/cgame/bg_lex.yy.o \
|
||||
$(B)/$(BASEGAME)/cgame/bg_list.o \
|
||||
$(B)/$(BASEGAME)/cgame/bg_collision.o \
|
||||
$(B)/$(BASEGAME)/cgame/cg_consolecmds.o \
|
||||
$(B)/$(BASEGAME)/cgame/cg_draw.o \
|
||||
$(B)/$(BASEGAME)/cgame/cg_drawtools.o \
|
||||
|
@ -2222,6 +2223,7 @@ Q3GOBJ_ = \
|
|||
$(B)/$(BASEGAME)/game/bg_oums.o \
|
||||
$(B)/$(BASEGAME)/game/bg_lex.yy.o \
|
||||
$(B)/$(BASEGAME)/game/bg_list.o \
|
||||
$(B)/$(BASEGAME)/game/bg_collision.o \
|
||||
$(B)/$(BASEGAME)/game/g_active.o \
|
||||
$(B)/$(BASEGAME)/game/g_arenas.o \
|
||||
$(B)/$(BASEGAME)/game/g_bot.o \
|
||||
|
|
66
code/game/bg_collision.c
Normal file
66
code/game/bg_collision.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "bg_collision.h"
|
||||
#include "q_shared.h"
|
||||
|
||||
#define QUADRANT_LEFT 0
|
||||
#define QUADRANT_RIGHT 1
|
||||
#define QUADRANT_MIDDLE 2
|
||||
qboolean BG_LineBoxIntersection(vec3_t mins, vec2_t maxs, vec3_t origin, vec3_t dir, vec_t* hit) {
|
||||
qboolean inside;
|
||||
char quadrant[3];
|
||||
int i;
|
||||
int plane;
|
||||
vec3_t maxT;
|
||||
vec3_t candidate;
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(origin[i] < mins[i]) {
|
||||
quadrant[i] = QUADRANT_LEFT;
|
||||
candidate[i] = mins[i];
|
||||
inside = qfalse;
|
||||
} else if(origin[i] > maxs[i]) {
|
||||
quadrant[i] = QUADRANT_RIGHT;
|
||||
candidate[i] = maxs[i];
|
||||
inside = qfalse;
|
||||
} else {
|
||||
quadrant[i] = QUADRANT_MIDDLE;
|
||||
}
|
||||
}
|
||||
|
||||
if(inside) {
|
||||
VectorCopy(origin, hit);
|
||||
return qtrue;
|
||||
}
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(quadrant[i] != QUADRANT_MIDDLE && dir[0] != 0) {
|
||||
maxT[i] = (candidate[i] - origin[i]) / dir[i];
|
||||
} else {
|
||||
maxT[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
plane = 0;
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(maxT[plane] < maxT[i]) {
|
||||
plane = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(maxT[plane] < 0) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
if(plane != i) {
|
||||
hit[i] = origin[i] + maxT[plane] * dir[i];
|
||||
|
||||
if(hit[i] < mins[i] || hit[i] > maxs[i]) {
|
||||
return qfalse;
|
||||
}
|
||||
} else {
|
||||
hit[i] = candidate[i];
|
||||
}
|
||||
}
|
||||
|
||||
return qtrue;
|
||||
}
|
8
code/game/bg_collision.h
Normal file
8
code/game/bg_collision.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef BG_COLLISION_H_
|
||||
#define BG_COLLISION_H_
|
||||
|
||||
#include "q_shared.h"
|
||||
|
||||
qboolean BG_LineBoxIntersection(vec3_t mins, vec2_t maxs, vec3_t origin, vec3_t dir, vec_t* hit);
|
||||
|
||||
#endif
|
|
@ -1849,57 +1849,6 @@ char *EndWord(char *pos)
|
|||
return pos;
|
||||
}
|
||||
|
||||
void BG_PrepareRay(bgRay_t* ray, vec3_t origin, vec3_t dir) {
|
||||
if(ray == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
VectorCopy(origin, ray->origin);
|
||||
VectorCopy(dir, ray->direction);
|
||||
VectorCopy(dir, ray->inverse_direction);
|
||||
VectorInverse(ray->inverse_direction);
|
||||
|
||||
ray->sign[0] = (ray->inverse_direction[0] < 0);
|
||||
ray->sign[1] = (ray->inverse_direction[1] < 0);
|
||||
ray->sign[2] = (ray->inverse_direction[2] < 0);
|
||||
}
|
||||
|
||||
int BG_RayIntersect(bgRay_t* ray, bgBBox_t* bbox) {
|
||||
double tmin = 0.0;
|
||||
double tmax = 0.0;
|
||||
double tymin = 0.0;
|
||||
double tymax = 0.0;
|
||||
double tzmin = 0.0;
|
||||
double tzmax = 0.0;
|
||||
|
||||
if(ray == NULL || bbox == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmin = (bbox->bounds[ray->sign[0]][0] - ray->origin[0]) * ray->inverse_direction[0];
|
||||
tmax = (bbox->bounds[1 - ray->sign[0]][0] - ray->origin[0]) * ray->inverse_direction[0];
|
||||
tymin = (bbox->bounds[ray->sign[1]][1] - ray->origin[1]) * ray->inverse_direction[1];
|
||||
tymax = (bbox->bounds[1 - ray->sign[1]][1] - ray->origin[1]) * ray->inverse_direction[1];
|
||||
|
||||
if((tmin > tymax) || (tymin > tmax)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(tymin > tmin) {
|
||||
tmin = tymin;
|
||||
}
|
||||
|
||||
if(tymax < tmax) {
|
||||
tmax = tymax;
|
||||
}
|
||||
|
||||
tzmin = (bbox->bounds[ray->sign[2]][2] - ray->origin[2]) * ray->inverse_direction[2];
|
||||
tzmax = (bbox->bounds[1 - ray->sign[2]][2] - ray->origin[2]) * ray->inverse_direction[2];
|
||||
|
||||
if((tmin > tzmax) || (tzmin > tmax)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
void BG_OriginFromBoundingBox(vec3_t mins, vec3_t maxs, vec_t* origin) {
|
||||
}
|
||||
|
||||
|
|
|
@ -6,32 +6,14 @@
|
|||
void BG_LanguageFilename(char *baseName,char *baseExtension,char *finalName);
|
||||
char* BG_RegisterRace( const char *name );
|
||||
|
||||
typedef struct bgRay_s bgRay_t;
|
||||
struct bgRay_s {
|
||||
vec3_t origin;
|
||||
vec3_t direction;
|
||||
vec3_t inverse_direction;
|
||||
int sign[3];
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Prepares a ray with a given origin and direction.
|
||||
* @param ray The ray.
|
||||
* @param origin The origin.
|
||||
* @param dir The direction.
|
||||
* @brief Calculates an approximate origin from a bounding box.
|
||||
* Calculates an approximate origin from a bounding box. The bounding box is
|
||||
* specified by it's minimal and maximal point.
|
||||
* @param mins [in] Minimal point of the bounding box.
|
||||
* @param maxs [in] Maxmimal point of the bounding box.
|
||||
* @param origin [out] Three dimensional vector the origin should be stored into.
|
||||
*/
|
||||
void BG_PrepareRay(bgRay_t* ray, vec3_t origin, vec3_t dir);
|
||||
|
||||
typedef struct bgBBox_s bgBBox_t;
|
||||
struct bgBBox_s {
|
||||
vec3_t bounds[2];
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Checks is a given ray intersects with a given bounding box.
|
||||
* @param ray The ray.
|
||||
* @param bbox The bounding box.
|
||||
*/
|
||||
int BG_RayIntersect(bgRay_t* ray, bgBBox_t* bbox);
|
||||
void BG_OriginFromBoundingBox(vec3_t mins, vec3_t maxs, vec_t* origin);
|
||||
|
||||
#endif /* _BG_MISC_H */
|
|
@ -2,39 +2,40 @@
|
|||
#ifndef _G_SQL_H_
|
||||
#define _G_SQL_H_
|
||||
|
||||
#define MAX_SQL_RESULT 4096
|
||||
#define MAX_SQL_RESULT 4096
|
||||
#define SQL_ENABLE_FOREIGN_KEY_CONSTRAINTS "PRAGMA foreign_keys = ON;"
|
||||
#define SQL_BEGIN_TRANSACTION "BEGIN TRANSACTION"
|
||||
#define SQL_ROLLBACK_TRANSACTION "ROLLBACK TRANSACTION"
|
||||
#define SQL_COMMIT_TRANSACTION "COMMIT TRANSACTION"
|
||||
#define SQL_USER_CREATEUSERTABLE "CREATE TABLE IF NOT EXISTS rpgx_users ( \
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||
username TEXT NOT NULL , \
|
||||
password TEXT NOT NULL \
|
||||
)"
|
||||
#define SQL_USER_CREATERIGHTSTABLE "CREATE TABLE IF NOT EXISTS rpgx_userRights ( \
|
||||
id INT NOT NULL PRIMARY KEY, \
|
||||
admin BIT NOT NULL, \
|
||||
rights LONG NOT NULL, \
|
||||
FOREIGN KEY(id) REFERENCES rpgx_users(id) \
|
||||
)"
|
||||
#define SQL_USER_DELETE "DELETE FROM rpgx_users WHERE username = :UNAME"
|
||||
#define SQL_USER_DELTE_RIGHTS "DELETE FROM rpgx_userRights WHERE id = :ID"
|
||||
#define SQL_USER_ADD "INSERT INTO rpgx_users VALUES(NULL,:USERNAME,:PASSWORD)"
|
||||
#define SQL_USER_ADD_RIGHTS "INSERT INTO rpgx_userRights VALUES(:ID, 0, 0)"
|
||||
#define SQL_USER_MOD_RIGHTS "UPDATE rpgx_userRights SET rights = :RIGHTS WHERE id = :ID"
|
||||
#define SQL_USER_GET_RIGHTS "SELECT rights FROM rpgx_userRights WHERE id = :ID"
|
||||
#define SQL_USER_CHECK_ADMIN "SELECT admin FROM rpgx_userRights WHERE id = :ID"
|
||||
#define SQL_USER_GET_PASSWORD "SELECT password FROM rpgx_users WHERE id = :ID"
|
||||
#define SQL_USER_SET_PASSWORD "UPDATE rpgx_users SET password = :PASSWORD WHERE id = :ID"
|
||||
#define SQL_USER_GET_UID "SELECT id FROM rpgx_users WHERE username = :UNAME"
|
||||
#define SQL_USER_LOGIN "SELECT id FROM rpgx_users WHERE username = :UNAME AND password = :PASSWORD"
|
||||
#define SQL_STRING_CREATE_TABLE "CREATE TABLE IF NOT EXISTS rpgx_strings ( \
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||
text TEXT NOT NULL, \
|
||||
text_de TEXT NOT NULL, \
|
||||
text_nl TEXT NOT NULL \
|
||||
)"
|
||||
#define SQL_BEGIN_TRANSACTION "BEGIN TRANSACTION"
|
||||
#define SQL_ROLLBACK_TRANSACTION "ROLLBACK TRANSACTION"
|
||||
#define SQL_COMMIT_TRANSACTION "COMMIT TRANSACTION"
|
||||
#define SQL_USER_CREATEUSERTABLE "CREATE TABLE IF NOT EXISTS rpgx_users ( \
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||
username TEXT NOT NULL , \
|
||||
password TEXT NOT NULL \
|
||||
)"
|
||||
#define SQL_USER_CREATERIGHTSTABLE "CREATE TABLE IF NOT EXISTS rpgx_userRights ( \
|
||||
id INT NOT NULL PRIMARY KEY, \
|
||||
admin BIT NOT NULL, \
|
||||
rights LONG NOT NULL, \
|
||||
FOREIGN KEY(id) REFERENCES rpgx_users(id) \
|
||||
)"
|
||||
#define SQL_USER_DELETE "DELETE FROM rpgx_users WHERE username = :UNAME"
|
||||
#define SQL_USER_DELTE_RIGHTS "DELETE FROM rpgx_userRights WHERE id = :ID"
|
||||
#define SQL_USER_ADD "INSERT INTO rpgx_users VALUES(NULL,:USERNAME,:PASSWORD)"
|
||||
#define SQL_USER_ADD_RIGHTS "INSERT INTO rpgx_userRights VALUES(:ID, 0, 0)"
|
||||
#define SQL_USER_MOD_RIGHTS "UPDATE rpgx_userRights SET rights = :RIGHTS WHERE id = :ID"
|
||||
#define SQL_USER_GET_RIGHTS "SELECT rights FROM rpgx_userRights WHERE id = :ID"
|
||||
#define SQL_USER_CHECK_ADMIN "SELECT admin FROM rpgx_userRights WHERE id = :ID"
|
||||
#define SQL_USER_GET_PASSWORD "SELECT password FROM rpgx_users WHERE id = :ID"
|
||||
#define SQL_USER_SET_PASSWORD "UPDATE rpgx_users SET password = :PASSWORD WHERE id = :ID"
|
||||
#define SQL_USER_GET_UID "SELECT id FROM rpgx_users WHERE username = :UNAME"
|
||||
#define SQL_USER_LOGIN "SELECT id FROM rpgx_users WHERE username = :UNAME AND password = :PASSWORD"
|
||||
#define SQL_STRING_CREATE_TABLE "CREATE TABLE IF NOT EXISTS rpgx_strings ( \
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||
text TEXT NOT NULL, \
|
||||
text_de TEXT NOT NULL, \
|
||||
text_nl TEXT NOT NULL \
|
||||
)"
|
||||
|
||||
/* Okay. I think this list is way too long and some things should be put together. Here is the original list for reference.
|
||||
typedef enum {
|
||||
SQLF_GIVE = 1,
|
||||
|
|
|
@ -231,6 +231,7 @@
|
|||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">WIN32;NDEBUG;_WINDOWS</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="g_cinematic.c" />
|
||||
<ClCompile Include="bg_collision.c" />
|
||||
<ClCompile Include="g_logger.c" />
|
||||
<ClCompile Include="lapi.c" />
|
||||
<ClCompile Include="lauxlib.c" />
|
||||
|
@ -493,6 +494,7 @@
|
|||
<ClInclude Include="be_ai_move.h" />
|
||||
<ClInclude Include="be_ai_weap.h" />
|
||||
<ClInclude Include="be_ea.h" />
|
||||
<ClInclude Include="bg_collision.h" />
|
||||
<ClInclude Include="bg_lex.h" />
|
||||
<ClInclude Include="bg_lib.h" />
|
||||
<ClInclude Include="bg_local.h" />
|
||||
|
|
|
@ -288,6 +288,9 @@
|
|||
<ClCompile Include="bg_list.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bg_collision.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ai_chat.h">
|
||||
|
@ -518,6 +521,9 @@
|
|||
<ClInclude Include="g_trigger.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="bg_collision.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="game.def">
|
||||
|
|
Loading…
Reference in a new issue