13 Jan 2008
This commit is contained in:
parent
59bec04c9f
commit
bb5ef5b1d3
|
@ -14,6 +14,7 @@ fopen
|
|||
1. SC_ParseToken вылетает при парсинге сейв-файла
|
||||
2. viewer ничего не пишет в лог (сцуко)
|
||||
3. По прежнему глюк с загрузкой спрайтов
|
||||
4. скриншотам гамму вывернуть
|
||||
|
||||
// из неоконченного
|
||||
0. Приделать бы всем утилитам разные иконки
|
||||
|
@ -23,8 +24,12 @@ fopen
|
|||
|
||||
Полная отладка network messaging, физики встроенной, физики на ньютоне
|
||||
{
|
||||
1. Вернуть квантизацию пространства в 0.125 юнита
|
||||
2.
|
||||
1. Вернуть квантизацию пространства в 0.125 юнита OK
|
||||
2. поля в вирт машине для сохранения матрицы OK
|
||||
3. сохранить velocity и avelocity OK
|
||||
4. дописать лоадер кастомных мешей OK
|
||||
5. Придумать как развернуть меш на 90 грд
|
||||
6. Пофиксить утечку памяти в cmodel OK
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,12 +11,10 @@
|
|||
|
||||
#define VALVE_FORMAT 220
|
||||
#define MAX_BRUSH_SIDES 128
|
||||
#define CLIP_EPSILON 0.1
|
||||
#define BOGUS_RANGE 8192
|
||||
#define TEXINFO_NODE -1 // side is allready on a node
|
||||
#define MAX_PORTALS 32768
|
||||
#define PORTALFILE "PRT1"
|
||||
#define ON_EPSILON 0.1
|
||||
#define MAX_POINTS_ON_WINDING 64
|
||||
#define PLANENUM_LEAF -1
|
||||
#define MAXEDGES 20
|
||||
|
|
|
@ -620,9 +620,6 @@ FACE MERGING
|
|||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#define CONTINUOUS_EPSILON 0.001
|
||||
|
||||
/*
|
||||
=============
|
||||
TryMergeWinding
|
||||
|
@ -687,9 +684,9 @@ winding_t *TryMergeWinding (winding_t *f1, winding_t *f2, vec3_t planenormal)
|
|||
back = f2->p[(j+2)%f2->numpoints];
|
||||
VectorSubtract (back, p1, delta);
|
||||
dot = DotProduct (delta, normal);
|
||||
if (dot > CONTINUOUS_EPSILON)
|
||||
if (dot > EQUAL_EPSILON)
|
||||
return NULL; // not a convex polygon
|
||||
keep1 = (bool)(dot < -CONTINUOUS_EPSILON);
|
||||
keep1 = (bool)(dot < -EQUAL_EPSILON);
|
||||
|
||||
back = f1->p[(i+2)%f1->numpoints];
|
||||
VectorSubtract (back, p2, delta);
|
||||
|
@ -699,9 +696,9 @@ winding_t *TryMergeWinding (winding_t *f1, winding_t *f2, vec3_t planenormal)
|
|||
back = f2->p[(j+f2->numpoints-1)%f2->numpoints];
|
||||
VectorSubtract (back, p2, delta);
|
||||
dot = DotProduct (delta, normal);
|
||||
if (dot > CONTINUOUS_EPSILON)
|
||||
if (dot > EQUAL_EPSILON)
|
||||
return NULL; // not a convex polygon
|
||||
keep2 = (bool)(dot < -CONTINUOUS_EPSILON);
|
||||
keep2 = (bool)(dot < -EQUAL_EPSILON);
|
||||
|
||||
//
|
||||
// build the new polygon
|
||||
|
|
|
@ -112,9 +112,9 @@ viswinding_t *ChopWinding (viswinding_t *in, pstack_t *stack, visplane_t *split)
|
|||
dot = DotProduct (in->points[i], split->normal);
|
||||
dot -= split->dist;
|
||||
dists[i] = dot;
|
||||
if (dot > EQUAL_EPSILON)
|
||||
if (dot > ON_EPSILON)
|
||||
sides[i] = SIDE_FRONT;
|
||||
else if (dot < -EQUAL_EPSILON)
|
||||
else if (dot < -ON_EPSILON)
|
||||
sides[i] = SIDE_BACK;
|
||||
else
|
||||
{
|
||||
|
@ -245,7 +245,7 @@ viswinding_t *ClipToSeperators (viswinding_t *source, viswinding_t *pass, viswin
|
|||
+ plane.normal[1] * plane.normal[1]
|
||||
+ plane.normal[2] * plane.normal[2];
|
||||
|
||||
if (length < EQUAL_EPSILON)
|
||||
if (length < ON_EPSILON)
|
||||
continue;
|
||||
|
||||
length = 1/sqrt(length);
|
||||
|
@ -267,13 +267,13 @@ viswinding_t *ClipToSeperators (viswinding_t *source, viswinding_t *pass, viswin
|
|||
if (k == i || k == l)
|
||||
continue;
|
||||
d = DotProduct (source->points[k], plane.normal) - plane.dist;
|
||||
if (d < -EQUAL_EPSILON)
|
||||
if (d < -ON_EPSILON)
|
||||
{ // source is on the negative side, so we want all
|
||||
// pass and target on the positive side
|
||||
fliptest = false;
|
||||
break;
|
||||
}
|
||||
else if (d > EQUAL_EPSILON)
|
||||
else if (d > ON_EPSILON)
|
||||
{ // source is on the positive side, so we want all
|
||||
// pass and target on the negative side
|
||||
fliptest = true;
|
||||
|
@ -304,9 +304,9 @@ viswinding_t *ClipToSeperators (viswinding_t *source, viswinding_t *pass, viswin
|
|||
if (k==j)
|
||||
continue;
|
||||
d = DotProduct (pass->points[k], plane.normal) - plane.dist;
|
||||
if (d < -EQUAL_EPSILON)
|
||||
if (d < -ON_EPSILON)
|
||||
break;
|
||||
else if (d > EQUAL_EPSILON)
|
||||
else if (d > ON_EPSILON)
|
||||
counts[0]++;
|
||||
else
|
||||
counts[2]++;
|
||||
|
@ -319,11 +319,11 @@ viswinding_t *ClipToSeperators (viswinding_t *source, viswinding_t *pass, viswin
|
|||
#else
|
||||
k = (j+1)%pass->numpoints;
|
||||
d = DotProduct (pass->points[k], plane.normal) - plane.dist;
|
||||
if (d < -EQUAL_EPSILON)
|
||||
if (d < -ON_EPSILON)
|
||||
continue;
|
||||
k = (j+pass->numpoints-1)%pass->numpoints;
|
||||
d = DotProduct (pass->points[k], plane.normal) - plane.dist;
|
||||
if (d < -EQUAL_EPSILON)
|
||||
if (d < -ON_EPSILON)
|
||||
continue;
|
||||
#endif
|
||||
//
|
||||
|
@ -648,7 +648,7 @@ void BasePortalVis (int portalnum)
|
|||
{
|
||||
d = DotProduct (w->points[k], p->plane.normal)
|
||||
- p->plane.dist;
|
||||
if (d > EQUAL_EPSILON)
|
||||
if (d > ON_EPSILON)
|
||||
break;
|
||||
}
|
||||
if (k == w->numpoints)
|
||||
|
@ -659,7 +659,7 @@ void BasePortalVis (int portalnum)
|
|||
{
|
||||
d = DotProduct (w->points[k], tp->plane.normal)
|
||||
- tp->plane.dist;
|
||||
if (d < -EQUAL_EPSILON)
|
||||
if (d < -ON_EPSILON)
|
||||
break;
|
||||
}
|
||||
if (k == w->numpoints)
|
||||
|
|
|
@ -296,9 +296,6 @@ void MakeHeadnodePortals (tree_t *tree)
|
|||
BaseWindingForNode
|
||||
================
|
||||
*/
|
||||
#define BASE_WINDING_EPSILON 0.001
|
||||
#define SPLIT_WINDING_EPSILON 0.001
|
||||
|
||||
winding_t *BaseWindingForNode (node_t *node)
|
||||
{
|
||||
winding_t *w;
|
||||
|
@ -307,8 +304,7 @@ winding_t *BaseWindingForNode (node_t *node)
|
|||
vec3_t normal;
|
||||
vec_t dist;
|
||||
|
||||
w = BaseWindingForPlane (mapplanes[node->planenum].normal
|
||||
, mapplanes[node->planenum].dist);
|
||||
w = BaseWindingForPlane (mapplanes[node->planenum].normal, mapplanes[node->planenum].dist);
|
||||
|
||||
// clip by all the parents
|
||||
for (n=node->parent ; n && w ; )
|
||||
|
@ -317,13 +313,13 @@ winding_t *BaseWindingForNode (node_t *node)
|
|||
|
||||
if (n->children[0] == node)
|
||||
{ // take front
|
||||
ChopWindingInPlace (&w, plane->normal, plane->dist, BASE_WINDING_EPSILON);
|
||||
ChopWindingInPlace (&w, plane->normal, plane->dist, EQUAL_EPSILON);
|
||||
}
|
||||
else
|
||||
{ // take back
|
||||
VectorSubtract (vec3_origin, plane->normal, normal);
|
||||
dist = -plane->dist;
|
||||
ChopWindingInPlace (&w, normal, dist, BASE_WINDING_EPSILON);
|
||||
ChopWindingInPlace (&w, normal, dist, EQUAL_EPSILON);
|
||||
}
|
||||
node = n;
|
||||
n = n->parent;
|
||||
|
@ -434,7 +430,7 @@ void SplitNodePortals (node_t *node)
|
|||
// cut the portal into two portals, one on each side of the cut plane
|
||||
//
|
||||
ClipWindingEpsilon (p->winding, plane->normal, plane->dist,
|
||||
SPLIT_WINDING_EPSILON, &frontwinding, &backwinding);
|
||||
EQUAL_EPSILON, &frontwinding, &backwinding);
|
||||
|
||||
if (frontwinding && WindingIsTiny(frontwinding))
|
||||
{
|
||||
|
|
|
@ -107,7 +107,7 @@ int TestLine_r (int node, vec3_t start, vec3_t stop)
|
|||
if (front >= -ON_EPSILON && back >= -ON_EPSILON)
|
||||
return TestLine_r (tnode->children[0], start, stop);
|
||||
|
||||
if (front < EQUAL_EPSILON && back < ON_EPSILON)
|
||||
if (front < ON_EPSILON && back < ON_EPSILON)
|
||||
return TestLine_r (tnode->children[1], start, stop);
|
||||
|
||||
side = front < 0;
|
||||
|
@ -241,7 +241,7 @@ bool _TestLine (vec3_t start, vec3_t stop)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (front < EQUAL_EPSILON && back < ON_EPSILON)
|
||||
if (front < ON_EPSILON && back < ON_EPSILON)
|
||||
// if (front <= 0 && back <= 0)
|
||||
{
|
||||
node = tnode->children[1];
|
||||
|
|
|
@ -38,7 +38,7 @@ float LerpAngle (float a2, float a1, float frac)
|
|||
|
||||
float LerpView(float org1, float org2, float ofs1, float ofs2, float frac)
|
||||
{
|
||||
return org1 + ofs1 + frac * (org2 + ofs2 - (org1 + ofs1));
|
||||
return org1 * CL_COORD_FRAC + ofs1 + frac * (org2 * CL_COORD_FRAC + ofs2 - (org1 * CL_COORD_FRAC + ofs1));
|
||||
}
|
||||
|
||||
|
||||
|
@ -318,9 +318,9 @@ void CL_ParsePlayerstate (frame_t *oldframe, frame_t *newframe)
|
|||
|
||||
if (flags & PS_VIEWANGLES)
|
||||
{
|
||||
state->viewangles[0] = MSG_ReadAngle16 (&net_message);
|
||||
state->viewangles[1] = MSG_ReadAngle16 (&net_message);
|
||||
state->viewangles[2] = MSG_ReadAngle16 (&net_message);
|
||||
state->viewangles[0] = MSG_ReadAngle32 (&net_message);
|
||||
state->viewangles[1] = MSG_ReadAngle32 (&net_message);
|
||||
state->viewangles[2] = MSG_ReadAngle32 (&net_message);
|
||||
}
|
||||
|
||||
if (flags & PS_KICKANGLES)
|
||||
|
@ -494,7 +494,7 @@ void CL_ParseFrame (void)
|
|||
{
|
||||
cls.state = ca_active;
|
||||
cl.force_refdef = true;
|
||||
VectorCopy( cl.frame.playerstate.pmove.origin, cl.predicted_origin );
|
||||
VectorScale( cl.frame.playerstate.pmove.origin, CL_COORD_FRAC, cl.predicted_origin );
|
||||
VectorCopy( cl.frame.playerstate.viewangles, cl.predicted_angles );
|
||||
}
|
||||
// fire entity events
|
||||
|
@ -821,7 +821,7 @@ void CL_CalcViewValues (void)
|
|||
// smooth out stair climbing
|
||||
delta = cls.realtime - cl.predicted_step_time;
|
||||
if (delta < host_frametime->value)
|
||||
cl.refdef.vieworg[2] -= cl.predicted_step * (host_frametime->value - delta) * host_frametime->value;
|
||||
cl.refdef.vieworg[2] -= cl.predicted_step * (host_frametime->value - delta) * 0.01f;
|
||||
}
|
||||
else
|
||||
{ // just use interpolated values
|
||||
|
|
|
@ -56,7 +56,7 @@ void CL_CheckPredictionError (void)
|
|||
VectorCopy (cl.frame.playerstate.pmove.origin, cl.predicted_origins[frame]);
|
||||
|
||||
// save for error itnerpolation
|
||||
for (i = 0; i < 3; i++) cl.prediction_error[i] = delta[i];
|
||||
for (i = 0; i < 3; i++) cl.prediction_error[i] = delta[i] * CL_COORD_FRAC;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,6 +263,6 @@ void CL_PredictMovement (void)
|
|||
}
|
||||
|
||||
// copy results out for rendering
|
||||
VectorCopy (pm.s.origin, cl.predicted_origin);
|
||||
VectorCopy (pm.viewangles, cl.predicted_angles);
|
||||
VectorScale(pm.s.origin, CL_COORD_FRAC, cl.predicted_origin);
|
||||
VectorCopy(pm.viewangles, cl.predicted_angles);
|
||||
}
|
||||
|
|
|
@ -396,21 +396,16 @@ void CL_PrepRefresh( void )
|
|||
CalcFov
|
||||
====================
|
||||
*/
|
||||
float CalcFov (float fov_x, float width, float height)
|
||||
float CalcFov( float fov_x, float width, float height )
|
||||
{
|
||||
float a;
|
||||
float x;
|
||||
float fov_y, x, rad = 360.0f * M_PI;
|
||||
|
||||
if (fov_x < 1 || fov_x > 179)
|
||||
{
|
||||
Host_Error("CalcFov: Bad fov: %f\n", fov_x);
|
||||
}
|
||||
fov_x = bound( 1, fov_x, 179 );
|
||||
x = width / tan( fov_x / rad );
|
||||
fov_y = atan2( height, x );
|
||||
fov_y = (fov_y * rad);
|
||||
|
||||
x = width/tan(fov_x/360*M_PI);
|
||||
a = atan (height/x);
|
||||
a = a*360/M_PI;
|
||||
|
||||
return a;
|
||||
return fov_y;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
|
|
@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "engine.h"
|
||||
#include "screen.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
#define MAX_EDIT_LINE 256
|
||||
#define COMMAND_HISTORY 32
|
||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "basefiles.h"
|
||||
#include "server.h"
|
||||
#include "collision.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -579,8 +580,6 @@ cmodel_t *CM_LoadMap (char *name, bool clientload, unsigned *checksum)
|
|||
numplanes = 0;
|
||||
numnodes = 0;
|
||||
numleafs = 0;
|
||||
numcmodels = 0;
|
||||
numsmodels = 0;
|
||||
numvisibility = 0;
|
||||
numentitychars = 0;
|
||||
stringdatasize = 0;
|
||||
|
@ -589,6 +588,7 @@ cmodel_t *CM_LoadMap (char *name, bool clientload, unsigned *checksum)
|
|||
map_stringdata[0] = 0;
|
||||
map_name[0] = 0;
|
||||
pe->FreeWorld();
|
||||
CM_FreeModels();
|
||||
|
||||
if (!name || !name[0])
|
||||
{
|
||||
|
@ -1745,38 +1745,6 @@ STUDIO SHARED CMODELS
|
|||
|
||||
===============================================================================
|
||||
*/
|
||||
#define HULL_PRECISION 4
|
||||
|
||||
word hull_table[] = { 0, 4, 8, 16, 18, 24, 28, 30, 32, 40, 48, 54, 56, 60, 64, 72, 80, 112, 120, 128, 140, 176 };
|
||||
#define NUM_HULL_ROUNDS (sizeof(hull_table) / sizeof(word))
|
||||
|
||||
void CM_RoundUpHullSize(vec3_t size, bool down)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
bool negative = false;
|
||||
float result, value;
|
||||
|
||||
value = down ? floor(size[i]) : ceil(size[i]);//round it
|
||||
if(value < 0) negative = true;
|
||||
value = fabs(value);//make positive
|
||||
|
||||
// lookup hull table
|
||||
for(j = 0; j < NUM_HULL_ROUNDS; j++)
|
||||
{
|
||||
result = value - hull_table[j];
|
||||
if(result <= HULL_PRECISION)
|
||||
{
|
||||
result = negative ? -hull_table[j] : hull_table[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
size[i] = result;//copy new value
|
||||
}
|
||||
}
|
||||
|
||||
cmodel_t *CM_StudioModel( char *name, edict_t *ent, byte *buffer, uint filesize )
|
||||
{
|
||||
cmodel_t *out;
|
||||
|
@ -1795,10 +1763,7 @@ cmodel_t *CM_StudioModel( char *name, edict_t *ent, byte *buffer, uint filesize
|
|||
com.strncpy(out->name, name, sizeof(out->name));
|
||||
if(!out->mempool) out->mempool = Mem_AllocPool( out->name );// create pool
|
||||
out->extradata = Mem_Alloc( out->mempool, filesize );
|
||||
Mem_Move( out->mempool, &out->extradata, buffer, filesize );
|
||||
|
||||
// create convex mesh physbuffer
|
||||
SV_CreateMeshBuffer( ent, out );
|
||||
Mem_Copy( out->extradata, buffer, filesize );
|
||||
|
||||
numsmodels++;
|
||||
return out;
|
||||
|
@ -1826,8 +1791,6 @@ cmodel_t *CM_SpriteModel( char *name, edict_t *ent, byte *buffer, uint filesize
|
|||
out->mins[2] = -phdr->height / 2;
|
||||
out->maxs[2] = phdr->height / 2;
|
||||
|
||||
Msg("register sprite %s, frames %d\n", name, out->numframes );
|
||||
|
||||
numsmodels++;
|
||||
return out;
|
||||
}
|
||||
|
@ -1837,14 +1800,14 @@ cmodel_t *CM_LoadModel( edict_t *ent )
|
|||
char name[MAX_QPATH];
|
||||
byte *buffer;
|
||||
cmodel_t *mod = NULL;
|
||||
int i, max_models = numcmodels + numsmodels;
|
||||
int i, max_models = numcmodels + numsmodels + 1;
|
||||
int size, modelindex = ent->progs.sv->modelindex;
|
||||
|
||||
// check for preloading
|
||||
strncpy(name, sv.configstrings[CS_MODELS + modelindex], MAX_QPATH );
|
||||
if(name[0] == '*') return CM_InlineModel( name ); // skip bmodels
|
||||
|
||||
for(i = numsmodels; i < max_models; i++ )
|
||||
for(i = numcmodels; i < max_models; i++ )
|
||||
{
|
||||
mod = &map_cmodels[i];
|
||||
if(!com.strcmp(name, mod->name))
|
||||
|
@ -1876,5 +1839,23 @@ cmodel_t *CM_LoadModel( edict_t *ent )
|
|||
mod = CM_SpriteModel( name, ent, buffer, size );
|
||||
break;
|
||||
}
|
||||
Mem_Free( buffer );
|
||||
return mod;
|
||||
}
|
||||
|
||||
void CM_FreeModels( void )
|
||||
{
|
||||
cmodel_t *mod = NULL;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < MAX_MAP_MODELS; i++ )
|
||||
{
|
||||
mod = &map_cmodels[i];
|
||||
if( mod->mempool )
|
||||
{
|
||||
Msg("free pool %s\n", mod->name );//debug
|
||||
Mem_FreePool( &mod->mempool );
|
||||
}
|
||||
}
|
||||
numcmodels = numsmodels = 0;
|
||||
}
|
|
@ -30,6 +30,7 @@
|
|||
cmodel_t *CM_LoadMap (char *name, bool clientload, unsigned *checksum);
|
||||
cmodel_t *CM_InlineModel (char *name); // *1, *2, etc
|
||||
cmodel_t *CM_LoadModel( edict_t *ent );
|
||||
void CM_FreeModels( void );
|
||||
int CM_NumClusters (void);
|
||||
int CM_NumInlineModels (void);
|
||||
char *CM_EntityString (void);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <time.h>
|
||||
#include <io.h>
|
||||
#include "basetypes.h"
|
||||
#include "mathlib.h"
|
||||
#include "net_msg.h"
|
||||
#include "screen.h"
|
||||
#include "keycodes.h"
|
||||
|
@ -147,7 +146,7 @@ void CL_Frame (float time);
|
|||
void SV_Init( void );
|
||||
void SV_Shutdown( bool reconnect );
|
||||
void SV_Frame( float time );
|
||||
void SV_Transform( sv_edict_t *ed, vec3_t origin, vec3_t angles );
|
||||
void SV_Transform( sv_edict_t *ed, matrix4x3 transform );
|
||||
|
||||
/*
|
||||
==============================================================
|
||||
|
|
|
@ -117,6 +117,7 @@ void Host_InitPhysic( void )
|
|||
// phys callback
|
||||
pi.api_size = sizeof(physic_imp_t);
|
||||
pi.Transform = SV_Transform;
|
||||
pi.GetModelVerts = SV_GetModelVerts;
|
||||
|
||||
Sys_LoadLibrary( &physic_dll );
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
/*
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
//=======================================================================
|
||||
|
||||
#include "engine.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
@ -121,9 +122,9 @@ void _MSG_WriteAngle32(sizebuf_t *sb, float f, const char *filename, int filelin
|
|||
|
||||
void _MSG_WritePos16(sizebuf_t *sb, vec3_t pos, const char *filename, int fileline)
|
||||
{
|
||||
_MSG_WriteCoord32(sb, pos[0] * SV_COORD_FRAC, filename, fileline );
|
||||
_MSG_WriteCoord32(sb, pos[1] * SV_COORD_FRAC, filename, fileline );
|
||||
_MSG_WriteCoord32(sb, pos[2] * SV_COORD_FRAC, filename, fileline );
|
||||
_MSG_WriteCoord16(sb, pos[0], filename, fileline );
|
||||
_MSG_WriteCoord16(sb, pos[1], filename, fileline );
|
||||
_MSG_WriteCoord16(sb, pos[2], filename, fileline );
|
||||
}
|
||||
|
||||
void _MSG_WritePos32(sizebuf_t *sb, vec3_t pos, const char *filename, int fileline)
|
||||
|
@ -450,9 +451,9 @@ void MSG_ReadPos32(sizebuf_t *msg_read, vec3_t pos)
|
|||
|
||||
void MSG_ReadPos16(sizebuf_t *msg_read, vec3_t pos)
|
||||
{
|
||||
pos[0] = MSG_ReadShort(msg_read) * CL_COORD_FRAC;
|
||||
pos[1] = MSG_ReadShort(msg_read) * CL_COORD_FRAC;
|
||||
pos[2] = MSG_ReadShort(msg_read) * CL_COORD_FRAC;
|
||||
pos[0] = MSG_ReadCoord16(msg_read);
|
||||
pos[1] = MSG_ReadCoord16(msg_read);
|
||||
pos[2] = MSG_ReadCoord16(msg_read);
|
||||
}
|
||||
|
||||
float MSG_ReadAngle16(sizebuf_t *msg_read)
|
||||
|
|
|
@ -313,8 +313,8 @@ typedef enum
|
|||
#define MAX_ENTITIES 128
|
||||
#define MAX_DLIGHTS 32
|
||||
#define MAX_CLIENTS 256 // absolute limit
|
||||
#define MAX_EDICTS 2048 // must change protocol to increase more
|
||||
#define MAX_MODELS 256 // these are sent over the net as short
|
||||
#define MAX_EDICTS 4096 // must change protocol to increase more
|
||||
#define MAX_MODELS 4096 // these are sent over the net as short
|
||||
#define MAX_PARTICLES 4096
|
||||
#define MAX_LIGHTSTYLES 256
|
||||
#define MAX_SOUNDS 256 // so they cannot be blindly increased
|
||||
|
@ -459,7 +459,7 @@ NET
|
|||
==============================================================
|
||||
*/
|
||||
#define PORT_ANY -1
|
||||
#define MAX_MSGLEN 1600 // max length of a message
|
||||
#define MAX_MSGLEN 2048 // max length of a message
|
||||
#define PACKET_HEADER 10 // two ints and a short
|
||||
|
||||
typedef enum { NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX } netadrtype_t;
|
||||
|
|
|
@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "engine.h"
|
||||
#include "collision.h"
|
||||
|
||||
#include "mathlib.h"
|
||||
|
||||
#define STEPSIZE 18
|
||||
|
||||
|
@ -962,7 +962,7 @@ bool PM_GoodPosition (void)
|
|||
|
||||
if (pm->s.pm_type == PM_SPECTATOR) return true;
|
||||
|
||||
for (i = 0; i < 3; i++) origin[i] = end[i] = pm->s.origin[i];
|
||||
for (i = 0; i < 3; i++) origin[i] = end[i] = pm->s.origin[i] * CL_COORD_FRAC;
|
||||
trace = pm->trace (origin, pm->mins, pm->maxs, end);
|
||||
|
||||
return !trace.allsolid;
|
||||
|
@ -978,10 +978,37 @@ precision of the network channel and in a valid position.
|
|||
*/
|
||||
void PM_SnapPosition (void)
|
||||
{
|
||||
VectorCopy( pml.origin, pm->s.origin );
|
||||
VectorCopy( pml.velocity, pm->s.velocity );
|
||||
int sign[3];
|
||||
int i, j, bits;
|
||||
short base[3];
|
||||
// try all single bits first
|
||||
static int jitterbits[8] = {0,4,1,2,3,5,6,7};
|
||||
|
||||
if (PM_GoodPosition()) return;
|
||||
// snap velocity to eigths
|
||||
for (i = 0; i < 3; i++) pm->s.velocity[i] = (int)(pml.velocity[i]*8);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (pml.origin[i] >= 0) sign[i] = 1;
|
||||
else sign[i] = -1;
|
||||
pm->s.origin[i] = (int)(pml.origin[i]*8);
|
||||
if (pm->s.origin[i]*0.125 == pml.origin[i]) sign[i] = 0;
|
||||
}
|
||||
VectorCopy (pm->s.origin, base);
|
||||
|
||||
// try all combinations
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
bits = jitterbits[j];
|
||||
VectorCopy (base, pm->s.origin);
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
if (bits & (1<<i) ) pm->s.origin[i] += sign[i];
|
||||
}
|
||||
if (PM_GoodPosition()) return;
|
||||
}
|
||||
|
||||
// go back to the last position
|
||||
VectorCopy (pml.previous_origin, pm->s.origin);
|
||||
}
|
||||
|
||||
|
@ -1010,8 +1037,8 @@ void PM_InitialSnapPosition(void)
|
|||
pm->s.origin[0] = base[0] + offset[ x ];
|
||||
if (PM_GoodPosition ())
|
||||
{
|
||||
VectorCopy (pm->s.origin, pml.origin);
|
||||
VectorCopy (pm->s.origin, pml.previous_origin);
|
||||
VectorScale(pm->s.origin, CL_COORD_FRAC, pml.origin);
|
||||
VectorCopy(pm->s.origin, pml.previous_origin);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1077,8 +1104,8 @@ void Pmove (pmove_t *pmove)
|
|||
memset (&pml, 0, sizeof(pml));
|
||||
|
||||
// convert origin and velocity to float values
|
||||
VectorCopy(pm->s.origin, pml.origin );
|
||||
VectorCopy(pm->s.velocity, pml.velocity);
|
||||
VectorScale(pm->s.origin, CL_COORD_FRAC, pml.origin );
|
||||
VectorScale(pm->s.velocity, CL_COORD_FRAC, pml.velocity);
|
||||
VectorCopy (pm->s.origin, pml.previous_origin); // save old org in case we get stuck
|
||||
pml.frametime = pm->cmd.msec * 0.001;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ The code uses void pointers instead.
|
|||
#include "sv_edict.h" // server progs
|
||||
#include "cl_edict.h" // client progs
|
||||
#include "ui_edict.h" // uimenu progs
|
||||
#include "mathlib.h"
|
||||
|
||||
typedef struct prvm_stack_s
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "progsvm.h"
|
||||
#include "net_msg.h"
|
||||
#include "collision.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
//=============================================================================
|
||||
|
||||
|
@ -319,6 +320,9 @@ void SV_ShutdownGameProgs (void);
|
|||
void SV_InitEdict (edict_t *e);
|
||||
void SV_ConfigString (int index, const char *val);
|
||||
void SV_SetModel (edict_t *ent, const char *name);
|
||||
void SV_CreatePhysBody( edict_t *ent );
|
||||
void SV_SetPhysForce( edict_t *ent );
|
||||
void SV_SetMassCentre( edict_t *ent);
|
||||
|
||||
//
|
||||
// sv_studio.c
|
||||
|
@ -333,7 +337,7 @@ bool SV_CreateMeshBuffer( edict_t *in, cmodel_t *out );
|
|||
//
|
||||
void SV_SpawnEntities (char *mapname, char *entities);
|
||||
void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
|
||||
void SV_Transform( sv_edict_t *ed, vec3_t origin, vec3_t angles );
|
||||
void SV_Transform( sv_edict_t *ed, matrix4x3 transform );
|
||||
void SV_FreeEdict (edict_t *ed);
|
||||
void SV_InitEdict (edict_t *e);
|
||||
edict_t *SV_Spawn (void);
|
||||
|
|
|
@ -123,12 +123,13 @@ typedef struct sv_entvars_s
|
|||
vec3_t old_angles;
|
||||
vec3_t velocity;
|
||||
vec3_t avelocity;
|
||||
vec3_t m_pmatrix[4];
|
||||
vec3_t m_pcentre[3];
|
||||
vec3_t torque;
|
||||
vec3_t force;
|
||||
vec3_t post_origin;
|
||||
vec3_t post_angles;
|
||||
vec3_t post_velocity;
|
||||
vec3_t post_avelocity;
|
||||
vec3_t origin_offset;
|
||||
vec3_t angles_offset;
|
||||
float ltime;
|
||||
float bouncetype;
|
||||
float movetype;
|
||||
|
@ -288,6 +289,6 @@ static fields_t sv_reqfields[] =
|
|||
{217, 1, "oldmodel"}
|
||||
};
|
||||
|
||||
#define PROG_CRC_SERVER 64081
|
||||
#define PROG_CRC_SERVER 6477
|
||||
|
||||
#endif//SV_EDICT_H
|
|
@ -217,9 +217,9 @@ void SV_WritePlayerstateToClient (client_frame_t *from, client_frame_t *to, size
|
|||
|
||||
if (pflags & PS_VIEWANGLES)
|
||||
{
|
||||
MSG_WriteAngle16 (msg, ps->viewangles[0]);
|
||||
MSG_WriteAngle16 (msg, ps->viewangles[1]);
|
||||
MSG_WriteAngle16 (msg, ps->viewangles[2]);
|
||||
MSG_WriteAngle32 (msg, ps->viewangles[0]);
|
||||
MSG_WriteAngle32 (msg, ps->viewangles[1]);
|
||||
MSG_WriteAngle32 (msg, ps->viewangles[2]);
|
||||
}
|
||||
|
||||
if (pflags & PS_KICKANGLES)
|
||||
|
@ -341,7 +341,7 @@ Build a client frame structure
|
|||
=============================================================================
|
||||
*/
|
||||
|
||||
byte fatpvs[65536/8]; // 32767 is MAX_MAP_LEAFS
|
||||
byte fatpvs[MAX_MAP_LEAFS/8]; // 32767 is MAX_MAP_LEAFS
|
||||
|
||||
/*
|
||||
============
|
||||
|
@ -361,8 +361,8 @@ void SV_FatPVS (vec3_t org)
|
|||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
mins[i] = org[i] - 8;
|
||||
maxs[i] = org[i] + 8;
|
||||
mins[i] = org[i] - SV_COORD_FRAC;
|
||||
maxs[i] = org[i] + SV_COORD_FRAC;
|
||||
}
|
||||
|
||||
count = CM_BoxLeafnums (mins, maxs, leafs, 64, NULL);
|
||||
|
@ -421,7 +421,8 @@ void SV_BuildClientFrame (client_state_t *client)
|
|||
frame->senttime = svs.realtime; // save it for ping calc later
|
||||
|
||||
// find the client's PVS
|
||||
VectorAdd(clent->priv.sv->client->ps.pmove.origin, clent->priv.sv->client->ps.viewoffset, org );
|
||||
VectorScale( clent->priv.sv->client->ps.pmove.origin, CL_COORD_FRAC, org );
|
||||
VectorAdd( org, clent->priv.sv->client->ps.viewoffset, org );
|
||||
|
||||
leafnum = CM_PointLeafnum (org);
|
||||
clientarea = CM_LeafArea (leafnum);
|
||||
|
|
|
@ -18,16 +18,16 @@ be accurate for client side prediction
|
|||
*/
|
||||
void SV_ClampCoord( vec3_t coord )
|
||||
{
|
||||
coord[0] -= floor(coord[0]);
|
||||
coord[1] -= floor(coord[1]);
|
||||
coord[2] -= floor(coord[2]);
|
||||
coord[0] -= SV_COORD_FRAC * floor(coord[0] * CL_COORD_FRAC);
|
||||
coord[1] -= SV_COORD_FRAC * floor(coord[1] * CL_COORD_FRAC);
|
||||
coord[2] -= SV_COORD_FRAC * floor(coord[2] * CL_COORD_FRAC);
|
||||
}
|
||||
|
||||
void SV_ClampAngle( vec3_t angle )
|
||||
{
|
||||
angle[0] -= floor(angle[0]);
|
||||
angle[1] -= floor(angle[1]);
|
||||
angle[2] -= floor(angle[2]);
|
||||
angle[0] -= SV_ANGLE_FRAC * floor(angle[0] * CL_ANGLE_FRAC);
|
||||
angle[1] -= SV_ANGLE_FRAC * floor(angle[1] * CL_ANGLE_FRAC);
|
||||
angle[2] -= SV_ANGLE_FRAC * floor(angle[2] * CL_ANGLE_FRAC);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1219,7 +1219,7 @@ void SV_WalkMove (edict_t *ent)
|
|||
if (clip & 2)
|
||||
{
|
||||
// if move was not trying to move into the step, return
|
||||
if (fabs(start_velocity[0]) < 0.125 && fabs(start_velocity[1]) < 0.125)
|
||||
if (fabs(start_velocity[0]) < 0.125 && fabs(start_velocity[1]) < CL_COORD_FRAC)
|
||||
return;
|
||||
|
||||
if (ent->progs.sv->movetype != MOVETYPE_FLY)
|
||||
|
@ -1253,7 +1253,7 @@ void SV_WalkMove (edict_t *ent)
|
|||
|
||||
// check for stuckness, possibly due to the limited precision of floats
|
||||
// in the clipping hulls
|
||||
if (clip && fabs(originalmove_origin[1] - ent->progs.sv->origin[1]) < 0.125 && fabs(originalmove_origin[0] - ent->progs.sv->origin[0]) < 0.125)
|
||||
if (clip && fabs(originalmove_origin[1] - ent->progs.sv->origin[1]) < CL_COORD_FRAC && fabs(originalmove_origin[0] - ent->progs.sv->origin[0]) < CL_COORD_FRAC)
|
||||
{
|
||||
//Msg("wall\n");
|
||||
// stepping up didn't make any progress, revert to original move
|
||||
|
@ -1273,7 +1273,7 @@ void SV_WalkMove (edict_t *ent)
|
|||
if (clip & 2) SV_WallFriction (ent, stepnormal);
|
||||
}
|
||||
// skip out if stepdown is enabled, moving downward, not in water, and the move started onground and ended offground
|
||||
else if (ent->progs.sv->waterlevel < 2 && start_velocity[2] < 0.125 && oldonground && !((int)ent->progs.sv->aiflags & AI_ONGROUND))
|
||||
else if (ent->progs.sv->waterlevel < 2 && start_velocity[2] < CL_COORD_FRAC && oldonground && !((int)ent->progs.sv->aiflags & AI_ONGROUND))
|
||||
return;
|
||||
|
||||
// move down
|
||||
|
|
|
@ -278,12 +278,10 @@ void Sav_LoadLocals( lump_t *l )
|
|||
// link it into the bsp tree
|
||||
if (!ent->priv.sv->free)
|
||||
{
|
||||
//SV_SetModel( ent, PRVM_GetString( ent->progs.sv->model ));
|
||||
SV_LinkEdict( ent );
|
||||
if(ent->progs.sv->movetype == MOVETYPE_PHYSIC)
|
||||
{
|
||||
pe->CreateBody( ent->priv.sv, SV_GetModelPtr(ent), ent->progs.sv->origin, ent->progs.sv->angles, ent->progs.sv->solid );
|
||||
}
|
||||
SV_CreatePhysBody( ent );
|
||||
SV_SetPhysForce( ent ); // restore forces
|
||||
SV_SetMassCentre( ent ); // and mass force
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ void SV_PutClientInServer (edict_t *ent)
|
|||
memset (&ent->priv.sv->client->ps, 0, sizeof(client->ps));
|
||||
|
||||
// info_player_start
|
||||
VectorCopy(ent->progs.sv->origin, client->ps.pmove.origin);
|
||||
VectorScale(ent->progs.sv->origin, SV_COORD_FRAC, client->ps.pmove.origin);
|
||||
|
||||
client->ps.fov = 90;
|
||||
client->ps.fov = bound(1, client->ps.fov, 160);
|
||||
|
@ -344,8 +344,8 @@ void ClientEndServerFrame (edict_t *ent)
|
|||
// If it wasn't updated here, the view position would lag a frame
|
||||
// behind the body position when pushed -- "sinking into plats"
|
||||
//
|
||||
VectorCopy(ent->progs.sv->origin, current_client->ps.pmove.origin );
|
||||
VectorCopy(ent->progs.sv->velocity, current_client->ps.pmove.velocity );
|
||||
VectorScale(ent->progs.sv->origin, SV_COORD_FRAC, current_client->ps.pmove.origin );
|
||||
VectorScale(ent->progs.sv->velocity, SV_COORD_FRAC, current_client->ps.pmove.velocity );
|
||||
AngleVectors (ent->priv.sv->client->v_angle, forward, right, up);
|
||||
|
||||
//
|
||||
|
@ -583,8 +583,8 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
|
|||
|
||||
pm.s = client->ps.pmove;
|
||||
|
||||
VectorCopy(ent->progs.sv->origin, pm.s.origin );
|
||||
VectorCopy(ent->progs.sv->velocity, pm.s.velocity );
|
||||
VectorScale(ent->progs.sv->origin, SV_COORD_FRAC, pm.s.origin );
|
||||
VectorScale(ent->progs.sv->velocity, SV_COORD_FRAC, pm.s.velocity );
|
||||
|
||||
if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s)))
|
||||
pm.snapinitial = true;
|
||||
|
@ -601,8 +601,8 @@ void ClientThink (edict_t *ent, usercmd_t *ucmd)
|
|||
client->ps.pmove = pm.s;
|
||||
client->old_pmove = pm.s;
|
||||
|
||||
VectorCopy(pm.s.origin, ent->progs.sv->origin);
|
||||
VectorCopy(pm.s.velocity, ent->progs.sv->velocity);
|
||||
VectorScale(pm.s.origin, CL_COORD_FRAC, ent->progs.sv->origin);
|
||||
VectorScale(pm.s.velocity, CL_COORD_FRAC, ent->progs.sv->velocity);
|
||||
VectorCopy (pm.mins, ent->progs.sv->mins);
|
||||
VectorCopy (pm.maxs, ent->progs.sv->maxs);
|
||||
VectorCopy (pm.viewangles, client->v_angle);
|
||||
|
@ -833,12 +833,32 @@ void SV_ClientCommand (edict_t *ent)
|
|||
}
|
||||
}
|
||||
|
||||
void SV_Transform( sv_edict_t *ed, vec3_t origin, vec3_t angles )
|
||||
void SV_Transform( sv_edict_t *ed, matrix4x3 transform )
|
||||
{
|
||||
edict_t *edict;
|
||||
if(!ed) return;
|
||||
vec3_t origin, angles;
|
||||
matrix4x4 objmatrix;
|
||||
|
||||
if(!ed) return;
|
||||
edict = PRVM_EDICT_NUM( ed->serialnumber );
|
||||
|
||||
// save matrix (fourth value will be reset on save\load)
|
||||
VectorCopy( transform[0], edict->progs.sv->m_pmatrix[0] );
|
||||
VectorCopy( transform[1], edict->progs.sv->m_pmatrix[1] );
|
||||
VectorCopy( transform[2], edict->progs.sv->m_pmatrix[2] );
|
||||
VectorCopy( transform[3], edict->progs.sv->m_pmatrix[3] );
|
||||
|
||||
MatrixLoadIdentity( objmatrix );
|
||||
VectorCopy( transform[0], objmatrix[0] );
|
||||
VectorCopy( transform[1], objmatrix[1] );
|
||||
VectorCopy( transform[2], objmatrix[2] );
|
||||
VectorCopy( transform[3], objmatrix[3] );
|
||||
MatrixAngles( objmatrix, origin, angles );
|
||||
|
||||
VectorCopy( origin, edict->progs.sv->origin );
|
||||
VectorCopy( angles, edict->progs.sv->angles );
|
||||
|
||||
// refresh force and torque
|
||||
pe->GetForce( ed->physbody, edict->progs.sv->velocity, edict->progs.sv->avelocity, edict->progs.sv->force, edict->progs.sv->torque );
|
||||
pe->GetMassCentre( ed->physbody, edict->progs.sv->m_pcentre );
|
||||
}
|
|
@ -94,6 +94,8 @@ void SV_StudioSetUpTransform ( void )
|
|||
{
|
||||
vec3_t mins, maxs, modelpos;
|
||||
|
||||
// clear count
|
||||
iNumVertices = 0;
|
||||
SV_StudioExtractBbox( m_pStudioHeader, 0, mins, maxs );
|
||||
CM_RoundUpHullSize(mins, true );
|
||||
CM_RoundUpHullSize(maxs, true );
|
||||
|
@ -184,18 +186,15 @@ void SV_StudioAddMesh( int mesh )
|
|||
{
|
||||
for(i = abs(i); i > 0; i--, ptricmds += 4)
|
||||
{
|
||||
if(!ptricmds) Sys_Error("ptricmds == NULL");
|
||||
m_pModelVerts[iNumVertices][0] = INCH2METER(g_xVertsTransform[ptricmds[0]][0]);
|
||||
m_pModelVerts[iNumVertices][1] = INCH2METER(g_xVertsTransform[ptricmds[0]][1]);
|
||||
m_pModelVerts[iNumVertices][2] = INCH2METER(g_xVertsTransform[ptricmds[0]][2]);
|
||||
iNumVertices++;
|
||||
}
|
||||
if(!ptricmds) Sys_Error("ptricmds == NULL");
|
||||
}
|
||||
if(!ptricmds) Sys_Error("ptricmds == NULL");
|
||||
}
|
||||
|
||||
void SV_StudioDrawMeshes ( void )
|
||||
void SV_StudioLookMeshes ( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -216,9 +215,9 @@ void SV_StudioGetVertices( void )
|
|||
|
||||
for (i = 0; i < m_pSubModel->numverts; i++)
|
||||
{
|
||||
VectorTransform(pstudioverts[i], g_xBonesTransform[pvertbone[i]], g_xVertsTransform[i]);
|
||||
VectorTransform( pstudioverts[i], g_xBonesTransform[pvertbone[i]], g_xVertsTransform[i]);
|
||||
}
|
||||
SV_StudioDrawMeshes();
|
||||
SV_StudioLookMeshes();
|
||||
}
|
||||
|
||||
float *SV_GetModelVerts( sv_edict_t *ent, int *numvertices )
|
||||
|
@ -230,7 +229,7 @@ float *SV_GetModelVerts( sv_edict_t *ent, int *numvertices )
|
|||
i = (int)m_pCurrentEntity->progs.sv->body;
|
||||
cmod = CM_LoadModel( m_pCurrentEntity );
|
||||
|
||||
if(cmod)
|
||||
if(SV_CreateMeshBuffer( m_pCurrentEntity, cmod ))
|
||||
{
|
||||
Msg("get physmesh for %s(%s) with index %d(%d)\n", cmod->name, PRVM_GetString(m_pCurrentEntity->progs.sv->model), (int)m_pCurrentEntity->progs.sv->modelindex, ent->serialnumber );
|
||||
*numvertices = cmod->physmesh[i].numverts;
|
||||
|
@ -241,52 +240,38 @@ float *SV_GetModelVerts( sv_edict_t *ent, int *numvertices )
|
|||
|
||||
bool SV_CreateMeshBuffer( edict_t *in, cmodel_t *out )
|
||||
{
|
||||
//int i, j;
|
||||
int i, j;
|
||||
|
||||
// validate args
|
||||
if(!in || !out || !out->extradata)
|
||||
if(!in || !out || !out->extradata || in->progs.sv->movetype != MOVETYPE_PHYSIC)
|
||||
return false;
|
||||
|
||||
// setup global pointers
|
||||
m_pCurrentEntity = in;
|
||||
m_pStudioHeader = (studiohdr_t *)out->extradata;
|
||||
m_pModelVerts = &g_xModelVerts[0];
|
||||
|
||||
SV_GetBodyCount();
|
||||
|
||||
// first we need to recalculate bounding box
|
||||
SV_StudioExtractBbox( m_pStudioHeader, 0, out->mins, out->maxs );
|
||||
CM_RoundUpHullSize(out->mins, false ); // normalize mins ( ceil )
|
||||
CM_RoundUpHullSize(out->maxs, false ); // normalize maxs ( ceil )
|
||||
|
||||
Msg("create physmesh for %s\n", out->name );
|
||||
/*for( i = 0; i < m_BodyCount; i++)
|
||||
for( i = 0; i < m_BodyCount; i++)
|
||||
{
|
||||
// clear count
|
||||
iNumVertices = 0;
|
||||
// already loaded
|
||||
if( out->physmesh[i].verts )
|
||||
continue;
|
||||
|
||||
__try // FIXME
|
||||
SV_StudioSetUpTransform();
|
||||
SV_StudioSetupBones();
|
||||
|
||||
for (j = 0; j < m_pStudioHeader->numbodyparts; j++)
|
||||
{
|
||||
SV_StudioSetUpTransform();
|
||||
SV_StudioSetupBones();
|
||||
|
||||
for (j = 0; j < m_pStudioHeader->numbodyparts; j++)
|
||||
{
|
||||
SV_StudioSetupModel( j, i );
|
||||
SV_StudioGetVertices();
|
||||
}
|
||||
SV_StudioSetupModel( j, i );
|
||||
SV_StudioGetVertices();
|
||||
}
|
||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
Sys_Error("m_pSubModel == NULL" );
|
||||
}
|
||||
if(iNumVertices)
|
||||
if( iNumVertices )
|
||||
{
|
||||
out->physmesh[i].verts = Mem_Alloc( out->mempool, iNumVertices * sizeof(vec3_t));
|
||||
Mem_Copy(out->physmesh[i].verts,m_pModelVerts, iNumVertices * sizeof(vec3_t));
|
||||
Mem_Copy(out->physmesh[i].verts, m_pModelVerts, iNumVertices * sizeof(vec3_t));
|
||||
out->physmesh[i].numverts = iNumVertices;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -98,6 +98,24 @@ void SV_SetMinMaxSize (edict_t *e, float *min, float *max, bool rotate)
|
|||
SV_LinkEdict (e);
|
||||
}
|
||||
|
||||
void SV_CreatePhysBody( edict_t *ent )
|
||||
{
|
||||
if( !ent || ent->progs.sv->movetype != MOVETYPE_PHYSIC ) return;
|
||||
ent->priv.sv->physbody = pe->CreateBody( ent->priv.sv, SV_GetModelPtr(ent), ent->progs.sv->m_pmatrix, ent->progs.sv->solid );
|
||||
}
|
||||
|
||||
void SV_SetPhysForce( edict_t *ent )
|
||||
{
|
||||
if( !ent || ent->progs.sv->movetype != MOVETYPE_PHYSIC ) return;
|
||||
pe->SetForce( ent->priv.sv->physbody, ent->progs.sv->velocity, ent->progs.sv->avelocity, ent->progs.sv->force, ent->progs.sv->torque );
|
||||
}
|
||||
|
||||
void SV_SetMassCentre( edict_t *ent )
|
||||
{
|
||||
if( !ent || ent->progs.sv->movetype != MOVETYPE_PHYSIC ) return;
|
||||
pe->SetMassCentre( ent->priv.sv->physbody, ent->progs.sv->m_pcentre );
|
||||
}
|
||||
|
||||
void SV_SetModel (edict_t *ent, const char *name)
|
||||
{
|
||||
int i;
|
||||
|
@ -111,10 +129,11 @@ void SV_SetModel (edict_t *ent, const char *name)
|
|||
mod = CM_LoadModel( ent );
|
||||
if( mod ) SV_SetMinMaxSize( ent, mod->mins, mod->maxs, false );
|
||||
|
||||
if(ent->progs.sv->movetype == MOVETYPE_PHYSIC)
|
||||
{
|
||||
ent->priv.sv->physbody = pe->CreateBody( ent->priv.sv, SV_GetModelPtr(ent), ent->progs.sv->origin, ent->progs.sv->angles, ent->progs.sv->solid );
|
||||
}
|
||||
// setup matrix
|
||||
AngleVectors( ent->progs.sv->angles, ent->progs.sv->m_pmatrix[0], ent->progs.sv->m_pmatrix[1], ent->progs.sv->m_pmatrix[2] );
|
||||
VectorCopy( ent->progs.sv->origin, ent->progs.sv->m_pmatrix[3] );
|
||||
ConvertPositionToPhysic( ent->progs.sv->m_pmatrix[3] );
|
||||
SV_CreatePhysBody( ent );
|
||||
}
|
||||
|
||||
float SV_AngleMod( float ideal, float current, float speed )
|
||||
|
|
|
@ -176,17 +176,17 @@ void SV_LinkEdict (edict_t *ent)
|
|||
if (ent->progs.sv->solid == SOLID_BBOX && !((int)ent->progs.sv->flags & FL_DEADMONSTER))
|
||||
{
|
||||
// assume that x/y are equal and symetric
|
||||
i = ent->progs.sv->maxs[0]/8;
|
||||
i = ent->progs.sv->maxs[0]/SV_COORD_FRAC;
|
||||
if (i<1) i = 1;
|
||||
if (i>31) i = 31;
|
||||
|
||||
// z is not symetric
|
||||
j = (-ent->progs.sv->mins[2])/8;
|
||||
j = (-ent->progs.sv->mins[2])/SV_COORD_FRAC;
|
||||
if (j < 1) j = 1;
|
||||
if (j > 31) j = 31;
|
||||
|
||||
// and z maxs can be negative...
|
||||
k = (ent->progs.sv->maxs[2]+32)/8;
|
||||
k = (ent->progs.sv->maxs[2]+32)/SV_COORD_FRAC;
|
||||
if (k<1) k = 1;
|
||||
if (k>63) k = 63;
|
||||
ent->priv.sv->solid = (k<<10) | (j<<5) | i;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2007 ©
|
||||
// cm_collision.c - collision hulls
|
||||
// cm_bsptree.c - collision tree
|
||||
//=======================================================================
|
||||
|
||||
#include "physic.h"
|
||||
|
@ -10,9 +10,9 @@ typedef struct cfacedesc_s
|
|||
int flags; // surface description
|
||||
} cfacedesc_t;
|
||||
|
||||
typedef struct collision_tree_s
|
||||
struct collision_tree_s
|
||||
{
|
||||
byte *pmod_base; // buffer
|
||||
byte *pmod_base; // start of buffer
|
||||
dvertex_t *vertices;
|
||||
int *surfedges;
|
||||
dface_t *surfaces;
|
||||
|
@ -22,18 +22,15 @@ typedef struct collision_tree_s
|
|||
|
||||
int num_models;
|
||||
int num_faces; // for bounds checking
|
||||
|
||||
vfile_t *world_tree; // pre-calcualated collision tree (not including submodels, worldmodel only)
|
||||
vfile_t *world_tree; // pre-calcualated collision tree (worldmodel only)
|
||||
|
||||
NewtonCollision *collision;
|
||||
NewtonBody *body;
|
||||
bool loaded; // map is loaded?
|
||||
bool tree_build; // phys tree is builded ?
|
||||
bool tree_build; // phys tree is created ?
|
||||
bool use_thread; // bsplib use thread
|
||||
|
||||
} collision_tree_t;
|
||||
|
||||
collision_tree_t map;
|
||||
} map;
|
||||
|
||||
/*
|
||||
=================
|
||||
|
@ -95,7 +92,6 @@ void BSP_LoadSurfedges( lump_t *l )
|
|||
count = l->filelen / sizeof(*in);
|
||||
if (count < 1 || count >= MAX_MAP_SURFEDGES) Host_Error("BSP_LoadSurfedges: funny lump size\n");
|
||||
map.surfedges = out = Mem_Alloc( physpool, count * sizeof(*out));
|
||||
|
||||
for ( i = 0; i < count; i++) out[i] = LittleLong(in[i]);
|
||||
}
|
||||
|
||||
|
@ -166,11 +162,7 @@ void BSP_LoadSurfDesc( lump_t *l )
|
|||
if (l->filelen % sizeof(*in)) Host_Error("BSP_LoadSurfDesc: funny lump size\n" );
|
||||
count = l->filelen / sizeof(*in);
|
||||
map.surfdesc = out = Mem_Alloc( physpool, count * sizeof(*out));
|
||||
|
||||
for ( i = 0; i < count; i++, in++, out++)
|
||||
{
|
||||
out->flags = LittleLong (in->flags);
|
||||
}
|
||||
for ( i = 0; i < count; i++, in++, out++) out->flags = LittleLong (in->flags);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -181,12 +173,12 @@ BSP_LoadModels
|
|||
void BSP_LoadCollision( lump_t *l )
|
||||
{
|
||||
byte *in;
|
||||
int i, count;
|
||||
int count;
|
||||
|
||||
in = (void *)(map.pmod_base + l->fileofs);
|
||||
if (l->filelen % sizeof(*in)) Host_Error("BSP_LoadCollision: funny lump size\n");
|
||||
count = l->filelen / sizeof(*in);
|
||||
map.world_tree = com.vfcreate( in, count );
|
||||
map.world_tree = VFS_Create( in, count );
|
||||
}
|
||||
|
||||
void CM_GetPoint( int index, vec3_t out )
|
||||
|
@ -214,7 +206,7 @@ void BSP_AddCollisionFace( int facenum )
|
|||
|
||||
if(facenum < 0 || facenum >= map.num_faces)
|
||||
{
|
||||
MsgDev(D_ERROR, "invalid face number %d, must be in range [0 == %d]\n", map.num_faces - 1);
|
||||
MsgDev(D_ERROR, "invalid face number %d, must be in range [0 == %d]\n", facenum, map.num_faces - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -232,10 +224,10 @@ void BSP_AddCollisionFace( int facenum )
|
|||
{
|
||||
vec3_t face[3]; // triangle
|
||||
|
||||
CM_GetPoint( k, face[0] );
|
||||
CM_GetPoint( k, face[0] );
|
||||
CM_GetPoint( k+j+1, face[1] );
|
||||
CM_GetPoint( k+j+2, face[2] );
|
||||
NewtonTreeCollisionAddFace( map.collision, 3, (float *)face[0], sizeof(vec3_t), 1);
|
||||
NewtonTreeCollisionAddFace( map.collision, 3, (float *)face[0], sizeof(vec3_t), 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -243,15 +235,15 @@ void BSP_AddCollisionFace( int facenum )
|
|||
vec3_t *face = Mem_Alloc( physpool, m_face->numedges * sizeof(vec3_t));
|
||||
for(j = 0; j < m_face->numedges; j++ ) CM_GetPoint( k+j, face[j] );
|
||||
NewtonTreeCollisionAddFace( map.collision, m_face->numedges, (float *)face[0], sizeof(vec3_t), 1);
|
||||
Mem_Free( face );
|
||||
if( face ) Mem_Free( face ); // polygons with 0 edges ?
|
||||
}
|
||||
}
|
||||
|
||||
void BSP_EndBuildTree( void )
|
||||
{
|
||||
if(map.use_thread) Msg("Optimize collision tree..." );
|
||||
if( map.use_thread ) Msg("Optimize collision tree..." );
|
||||
NewtonTreeCollisionEndBuild( map.collision, true );
|
||||
if(map.use_thread) Msg(" done\n");
|
||||
if( map.use_thread ) Msg(" done\n");
|
||||
}
|
||||
|
||||
static void BSP_LoadTree( vfile_t* handle, void* buffer, size_t size )
|
||||
|
@ -322,6 +314,8 @@ void CM_SaveCollisionTree( file_t *f, cmsave_t callback )
|
|||
void CM_LoadCollisionTree( void )
|
||||
{
|
||||
map.collision = NewtonCreateTreeCollisionFromSerialization( gWorld, NULL, BSP_LoadTree, map.world_tree );
|
||||
VFS_Close( map.world_tree );
|
||||
map.world_tree = NULL;
|
||||
}
|
||||
|
||||
void CM_LoadWorld( const void *buffer )
|
||||
|
@ -334,12 +328,12 @@ void CM_LoadWorld( const void *buffer )
|
|||
|
||||
map.use_thread = false;
|
||||
if(map.world_tree) CM_LoadCollisionTree();
|
||||
else CM_MakeCollisionTree();
|
||||
else CM_MakeCollisionTree(); // can be used for old maps
|
||||
|
||||
map.body = NewtonCreateBody( gWorld, map.collision );
|
||||
NewtonBodyGetMatrix( map.body, &m_matrix[0][0] ); // set the global position of this body
|
||||
NewtonCollisionCalculateAABB( map.collision, &m_matrix[0][0], &boxP0[0], &boxP1[0] );
|
||||
NewtonReleaseCollision (gWorld, map.collision );
|
||||
NewtonReleaseCollision( gWorld, map.collision );
|
||||
|
||||
VectorSubtract( boxP0, extra, boxP0 );
|
||||
VectorAdd( boxP1, extra, boxP1 );
|
||||
|
@ -356,8 +350,6 @@ void CM_FreeWorld( void )
|
|||
if(!map.body) return;
|
||||
// and physical body release too
|
||||
NewtonDestroyBody( gWorld, map.body );
|
||||
VFS_Close( map.world_tree );
|
||||
map.body = NULL;
|
||||
map.collision = NULL;
|
||||
map.world_tree = NULL;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2007 ©
|
||||
// cm_callback.c - game callbacks
|
||||
//=======================================================================
|
||||
|
||||
#include "physic.h"
|
||||
|
||||
|
||||
void Callback_ApplyForce( const NewtonBody* body )
|
||||
{
|
||||
float mass;
|
||||
vec3_t size, force, torque;
|
||||
|
||||
NewtonBodyGetMassMatrix (body, &mass, &size[0], &size[1], &size[2]);
|
||||
|
||||
VectorSet( torque, 0.0f, 0.0f, 0.0f );
|
||||
VectorSet( force, 0.0f, -9.8f * mass, 0.0f );
|
||||
|
||||
NewtonBodyAddForce (body, force);
|
||||
NewtonBodyAddTorque (body, torque);
|
||||
}
|
||||
|
||||
void Callback_ApplyTransform( const NewtonBody* body, const float* matrix )
|
||||
{
|
||||
sv_edict_t *edict = (sv_edict_t *)NewtonBodyGetUserData( body );
|
||||
matrix4x4 objcoords;
|
||||
matrix4x3 translate;// obj matrix
|
||||
|
||||
// convert matrix4x4 into 4x3
|
||||
Mem_Copy( objcoords, (float *)matrix, sizeof(matrix4x4));
|
||||
VectorCopy( objcoords[0], translate[0] );
|
||||
VectorCopy( objcoords[1], translate[1] );
|
||||
VectorCopy( objcoords[2], translate[2] );
|
||||
VectorCopy( objcoords[3], translate[3] );
|
||||
|
||||
pi.Transform( edict, translate );
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2007 ©
|
||||
// cm_debug.c - draw collision hulls outlines
|
||||
//=======================================================================
|
||||
|
||||
#include "physic.h"
|
||||
|
||||
void DebugShowGeometryCollision( const NewtonBody* body, int vertexCount, const float* faceVertec, int id )
|
||||
{
|
||||
// callback to render.dll
|
||||
if( ph.debug_line ) ph.debug_line( 0, vertexCount, faceVertec );
|
||||
}
|
||||
|
||||
void DebugShowBodyCollision( const NewtonBody* body )
|
||||
{
|
||||
NewtonBodyForEachPolygonDo(body, DebugShowGeometryCollision );
|
||||
}
|
||||
|
||||
void DebugShowCollision( cmdraw_t callback )
|
||||
{
|
||||
// called from render.dll
|
||||
ph.debug_line = callback; // member draw function
|
||||
NewtonWorldForEachBodyDo( gWorld, DebugShowBodyCollision );
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2007 ©
|
||||
// cm_rigidbody.c - rigid body stuff
|
||||
//=======================================================================
|
||||
|
||||
#include "physic.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
physbody_t *Phys_CreateBody( sv_edict_t *ed, void *buffer, matrix4x3 transform, int solid )
|
||||
{
|
||||
NewtonCollision *col;
|
||||
NewtonBody *body;
|
||||
matrix4x4 trans, offset;
|
||||
float *vertices;
|
||||
int numvertices;
|
||||
vec3_t size, center, mins, maxs;
|
||||
studiohdr_t *phdr = (studiohdr_t *)buffer;
|
||||
mstudioseqdesc_t *pseqdesc;
|
||||
|
||||
// identity matrixes
|
||||
MatrixLoadIdentity( trans );
|
||||
MatrixLoadIdentity( offset );
|
||||
|
||||
if( phdr )
|
||||
{
|
||||
// custom convex hull
|
||||
pseqdesc = (mstudioseqdesc_t *)((byte *)phdr + phdr->seqindex);
|
||||
VectorCopy( pseqdesc[0].bbmin, mins );
|
||||
VectorCopy( pseqdesc[0].bbmax, maxs );
|
||||
|
||||
if( solid == SOLID_BOX )
|
||||
{
|
||||
CM_RoundUpHullSize( mins, false );
|
||||
CM_RoundUpHullSize( maxs, false );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// default size
|
||||
VectorSet( mins, -32, -32, -32 );
|
||||
VectorSet( maxs, 32, 32, 32 );
|
||||
MsgWarn("can't compute bounding box, use default size\n");
|
||||
}
|
||||
|
||||
// setup offset matrix
|
||||
VectorSubtract( maxs, mins, size );
|
||||
VectorAdd( mins, maxs, center );
|
||||
ConvertDimensionToPhysic( size );
|
||||
ConvertDimensionToPhysic( center );
|
||||
VectorScale( center, 0.5, offset[3] );
|
||||
|
||||
// setup translation matrix
|
||||
VectorCopy( transform[0], trans[0] );
|
||||
VectorCopy( transform[1], trans[1] );
|
||||
VectorCopy( transform[2], trans[2] );
|
||||
VectorCopy( transform[3], trans[3] );
|
||||
|
||||
switch(solid)
|
||||
{
|
||||
case SOLID_BOX:
|
||||
col = NewtonCreateBox( gWorld, size[0], size[1], size[2], &offset[0][0] );
|
||||
break;
|
||||
case SOLID_SPHERE:
|
||||
col = NewtonCreateSphere( gWorld, size[0]/2, size[1]/2, size[2]/2, &offset[0][0] );
|
||||
break;
|
||||
case SOLID_CYLINDER:
|
||||
col = NewtonCreateCylinder( gWorld, size[0], size[1], &offset[0][0] );
|
||||
break;
|
||||
case SOLID_MESH:
|
||||
vertices = pi.GetModelVerts( ed, &numvertices );
|
||||
if(!vertices || !numvertices ) return NULL;
|
||||
col = NewtonCreateConvexHull( gWorld, numvertices, vertices, sizeof(vec3_t), &offset[0][0] );
|
||||
break;
|
||||
default:
|
||||
Host_Error("Phys_CreateBody: unsupported solid type\n");
|
||||
return NULL;
|
||||
}
|
||||
body = NewtonCreateBody( gWorld, col );
|
||||
NewtonBodySetUserData( body, ed );
|
||||
NewtonBodySetMassMatrix( body, 10.0f, size[0], size[1], size[2] ); // 10 kg
|
||||
|
||||
// setup generic callback to engine.dll
|
||||
NewtonBodySetTransformCallback(body, Callback_ApplyTransform );
|
||||
NewtonBodySetForceAndTorqueCallback( body, Callback_ApplyForce );
|
||||
NewtonBodySetMatrix(body, &trans[0][0]);// origin
|
||||
NewtonReleaseCollision( gWorld, col );
|
||||
|
||||
return (physbody_t *)body;
|
||||
}
|
||||
|
||||
void Phys_RemoveBody( physbody_t *body )
|
||||
{
|
||||
if( body ) NewtonDestroyBody( gWorld, (NewtonBody*)body );
|
||||
}
|
||||
|
||||
bool Phys_GetForce( physbody_t *body, vec3_t velocity, vec3_t avelocity, vec3_t force, vec3_t torque )
|
||||
{
|
||||
if(!body) return false;
|
||||
|
||||
NewtonBodyGetOmega( body, avelocity );
|
||||
NewtonBodyGetVelocity( body, velocity );
|
||||
NewtonBodyGetForce( body, force );
|
||||
NewtonBodyGetTorque( body, torque );
|
||||
|
||||
ConvertPositionToGame( avelocity );
|
||||
ConvertPositionToGame( velocity );
|
||||
return true;
|
||||
}
|
||||
|
||||
void Phys_SetForce( physbody_t *body, vec3_t velocity, vec3_t avelocity, vec3_t force, vec3_t torque )
|
||||
{
|
||||
if(!body) return;
|
||||
ConvertPositionToPhysic( avelocity );
|
||||
ConvertPositionToPhysic( velocity );
|
||||
NewtonBodySetOmega( body, avelocity );
|
||||
NewtonBodySetVelocity( body, velocity );
|
||||
NewtonBodySetForce( body, force );
|
||||
NewtonBodySetTorque( body, torque );
|
||||
}
|
||||
|
||||
bool Phys_GetMassCentre( physbody_t *body, matrix3x3 mass )
|
||||
{
|
||||
if(!body) return false;
|
||||
NewtonBodyGetCentreOfMass( body, (float *)mass );
|
||||
return true;
|
||||
}
|
||||
|
||||
void Phys_SetMassCentre( physbody_t *body, matrix3x3 mass )
|
||||
{
|
||||
if(!body) return;
|
||||
NewtonBodySetCentreOfMass( body, (float *)mass );
|
||||
}
|
|
@ -57,6 +57,10 @@ physic_exp_t DLLEXPORT *CreateAPI ( stdlib_api_t *input, physic_imp_t *engfuncs
|
|||
Phys.FreeWorld = CM_FreeWorld;
|
||||
Phys.Frame = Phys_Frame;
|
||||
Phys.CreateBody = Phys_CreateBody;
|
||||
Phys.GetForce = Phys_GetForce;
|
||||
Phys.SetForce = Phys_SetForce;
|
||||
Phys.GetMassCentre = Phys_GetMassCentre;
|
||||
Phys.SetMassCentre = Phys_SetMassCentre;
|
||||
Phys.RemoveBody = Phys_RemoveBody;
|
||||
|
||||
return &Phys;
|
||||
|
|
|
@ -56,8 +56,8 @@ LINK32=link.exe
|
|||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 user32.lib msvcrt.lib newton.lib opengl32.lib /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"libc.lib" /libpath:"../public/libs/"
|
||||
# Begin Custom Build
|
||||
TargetDir=\XASH3D\src_main\!source\temp\physic\!release
|
||||
InputPath=\XASH3D\src_main\!source\temp\physic\!release\physic.dll
|
||||
TargetDir=\XASH3D\src_main\temp\physic\!release
|
||||
InputPath=\XASH3D\src_main\temp\physic\!release\physic.dll
|
||||
SOURCE="$(InputPath)"
|
||||
|
||||
"D:\Xash3D\bin\physic.dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
|
@ -93,8 +93,8 @@ LINK32=link.exe
|
|||
# ADD LINK32 user32.lib msvcrtd.lib newton.lib opengl32.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libc.lib" /pdbtype:sept /libpath:"../public/libs/"
|
||||
# SUBTRACT LINK32 /nodefaultlib
|
||||
# Begin Custom Build
|
||||
TargetDir=\XASH3D\src_main\!source\temp\physic\!debug
|
||||
InputPath=\XASH3D\src_main\!source\temp\physic\!debug\physic.dll
|
||||
TargetDir=\XASH3D\src_main\temp\physic\!debug
|
||||
InputPath=\XASH3D\src_main\temp\physic\!debug\physic.dll
|
||||
SOURCE="$(InputPath)"
|
||||
|
||||
"D:\Xash3D\bin\physic.dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
|
@ -113,7 +113,19 @@ SOURCE="$(InputPath)"
|
|||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cm_collision.c
|
||||
SOURCE=.\cm_bsptree.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cm_callback.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cm_debug.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cm_rigidbody.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
|
@ -135,6 +147,10 @@ SOURCE=.\cm_utils.h
|
|||
|
||||
SOURCE=.\physic.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\transform.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
|
|
|
@ -35,9 +35,23 @@ void Phys_LoadBSP( uint *buffer );
|
|||
void Phys_FreeBSP( void );
|
||||
void DebugShowCollision ( cmdraw_t callback );
|
||||
void Phys_Frame( float time );
|
||||
physbody_t *Phys_CreateBody( sv_edict_t *ed, void *buffer, vec3_t org, vec3_t ang, int solid );
|
||||
|
||||
//
|
||||
// cm_rigidbody.c
|
||||
//
|
||||
physbody_t *Phys_CreateBody( sv_edict_t *ed, void *buffer, matrix4x3 transform, int solid );
|
||||
bool Phys_GetForce( physbody_t *body, vec3_t velocity, vec3_t avelocity, vec3_t force, vec3_t torque );
|
||||
void Phys_SetForce( physbody_t *body, vec3_t velocity, vec3_t avelocity, vec3_t force, vec3_t torque );
|
||||
bool Phys_GetMassCentre( physbody_t *body, matrix3x3 mass );
|
||||
void Phys_SetMassCentre( physbody_t *body, matrix3x3 mass );
|
||||
void Phys_RemoveBody( physbody_t *body );
|
||||
|
||||
//
|
||||
// cm_callback.c
|
||||
//
|
||||
void Callback_ApplyForce( const NewtonBody* body );
|
||||
void Callback_ApplyTransform( const NewtonBody* body, const float* matrix );
|
||||
|
||||
#define Host_Error com.error
|
||||
|
||||
typedef struct physic_s
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
void MatrixAngles(matrix4x4 matrix, vec3_t origin, vec3_t angles )
|
||||
{
|
||||
vec3_t forward, right, up;
|
||||
float xyDist;
|
||||
|
||||
forward[0] = matrix[0][0];
|
||||
forward[1] = matrix[0][2];
|
||||
forward[2] = matrix[0][1];
|
||||
right[0] = matrix[1][0];
|
||||
right[1] = matrix[1][2];
|
||||
right[2] = matrix[1][1];
|
||||
up[2] = matrix[2][1];
|
||||
|
||||
xyDist = sqrt( forward[0] * forward[0] + forward[1] * forward[1] );
|
||||
|
||||
if ( xyDist > EQUAL_EPSILON ) // enough here to get angles?
|
||||
{
|
||||
angles[1] = RAD2DEG( atan2( forward[1], forward[0] ));
|
||||
angles[0] = RAD2DEG( atan2( -forward[2], xyDist ));
|
||||
angles[2] = RAD2DEG( atan2( -right[2], up[2] ));
|
||||
}
|
||||
else
|
||||
{
|
||||
angles[1] = RAD2DEG( atan2( right[0], -right[1] ) );
|
||||
angles[0] = RAD2DEG( atan2( -forward[2], xyDist ) );
|
||||
angles[2] = 0;
|
||||
}
|
||||
VectorCopy(matrix[3], origin );// extract origin
|
||||
ConvertPositionToGame( origin );
|
||||
}
|
||||
|
||||
void AnglesMatrix(vec3_t origin, vec3_t angles, matrix4x4 matrix )
|
||||
{
|
||||
float angle;
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
angle = DEG2RAD(angles[YAW]);
|
||||
sy = sin(angle);
|
||||
cy = cos(angle);
|
||||
angle = DEG2RAD(angles[PITCH]);
|
||||
sp = sin(angle);
|
||||
cp = cos(angle);
|
||||
|
||||
MatrixLoadIdentity( matrix );
|
||||
|
||||
// forward
|
||||
matrix[0][0] = cp*cy;
|
||||
matrix[0][2] = cp*sy;
|
||||
matrix[0][1] = -sp;
|
||||
|
||||
if (angles[ROLL] == 180)
|
||||
{
|
||||
angle = DEG2RAD(angles[ROLL]);
|
||||
sr = sin(angle);
|
||||
cr = cos(angle);
|
||||
|
||||
// right
|
||||
matrix[1][0] = -1*(sr*sp*cy+cr*-sy);
|
||||
matrix[1][2] = -1*(sr*sp*sy+cr*cy);
|
||||
matrix[1][1] = -1*(sr*cp);
|
||||
|
||||
// up
|
||||
matrix[2][0] = (cr*sp*cy+-sr*-sy);
|
||||
matrix[2][2] = (cr*sp*sy+-sr*cy);
|
||||
matrix[2][1] = cr*cp;
|
||||
}
|
||||
else
|
||||
{
|
||||
// right
|
||||
matrix[1][0] = sy;
|
||||
matrix[1][2] = -cy;
|
||||
matrix[1][1] = 0;
|
||||
|
||||
// up
|
||||
matrix[2][0] = (sp*cy);
|
||||
matrix[2][2] = (sp*sy);
|
||||
matrix[2][1] = cp;
|
||||
}
|
||||
VectorCopy(origin, matrix[3] ); // pack origin
|
||||
ConvertPositionToPhysic( matrix[3] );
|
||||
}
|
||||
void AnglesMatrix2(vec3_t origin, vec3_t angles, matrix4x4 matrix )
|
||||
{
|
||||
float angle;
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
angle = DEG2RAD(angles[YAW]);
|
||||
sy = sin(angle);
|
||||
cy = cos(angle);
|
||||
angle = DEG2RAD(angles[PITCH]);
|
||||
sp = sin(angle);
|
||||
cp = cos(angle);
|
||||
|
||||
MatrixLoadIdentity( matrix );
|
||||
|
||||
// forward
|
||||
matrix[0][0] = cp*cy;
|
||||
matrix[0][1] = cp*sy;
|
||||
matrix[0][2] = -sp;
|
||||
|
||||
if (angles[ROLL])
|
||||
{
|
||||
angle = DEG2RAD(angles[ROLL]);
|
||||
sr = sin(angle);
|
||||
cr = cos(angle);
|
||||
|
||||
// right
|
||||
matrix[1][0] = (sr*sp*cy+cr*-sy);
|
||||
matrix[1][1] = (sr*sp*sy+cr*cy);
|
||||
matrix[1][2] = (sr*cp);
|
||||
|
||||
// up
|
||||
matrix[2][0] = (cr*sp*cy+-sr*-sy);
|
||||
matrix[2][1] = (cr*sp*sy+-sr*cy);
|
||||
matrix[2][2] = cr*cp;
|
||||
}
|
||||
else
|
||||
{
|
||||
// right
|
||||
matrix[1][0] = -sy;
|
||||
matrix[1][1] = cy;
|
||||
matrix[1][2] = 0;
|
||||
|
||||
// up
|
||||
matrix[2][0] = (sp*cy);
|
||||
matrix[2][1] = (sp*sy);
|
||||
matrix[2][2] = cp;
|
||||
}
|
||||
VectorCopy(origin, matrix[3] ); // pack origin
|
||||
}
|
119
physic/utils.c
119
physic/utils.c
|
@ -4,10 +4,6 @@
|
|||
//=======================================================================
|
||||
|
||||
#include "physic.h"
|
||||
#include "transform.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <gl/gl.h>
|
||||
|
||||
long _ftol( double );
|
||||
long _ftol2( double dblSource )
|
||||
|
@ -28,119 +24,4 @@ void Pfree (void *ptr, int size )
|
|||
void Phys_Frame( float time )
|
||||
{
|
||||
NewtonUpdate(gWorld, time );
|
||||
}
|
||||
|
||||
void Phys_ApplyForce(const NewtonBody* body)
|
||||
{
|
||||
float mass;
|
||||
vec3_t size, force, torque;
|
||||
|
||||
NewtonBodyGetMassMatrix (body, &mass, &size[0], &size[1], &size[2]);
|
||||
|
||||
VectorSet( torque, 0.0f, 0.0f, 0.0f );
|
||||
VectorSet( force, 0.0f, -9.8f * mass, 0.0f );
|
||||
|
||||
NewtonBodyAddForce (body, force);
|
||||
NewtonBodyAddTorque (body, torque);
|
||||
}
|
||||
|
||||
void Phys_ApplyTransform( const NewtonBody* body, const float* matrix )
|
||||
{
|
||||
sv_edict_t *edict = (sv_edict_t *)NewtonBodyGetUserData( body );
|
||||
matrix4x4 translate;// obj matrix
|
||||
vec3_t origin, angles;
|
||||
|
||||
Mem_Copy(translate, (float *)matrix, sizeof(matrix4x4));
|
||||
MatrixAngles( translate, origin, angles );
|
||||
pi.Transform( edict, origin, angles );
|
||||
}
|
||||
|
||||
physbody_t *Phys_CreateBody( sv_edict_t *ed, void *buffer, vec3_t org, vec3_t ang, int solid )
|
||||
{
|
||||
NewtonCollision *col;
|
||||
NewtonBody *body;
|
||||
matrix4x4 trans, offset;
|
||||
vec3_t size, center;
|
||||
float *vertices;
|
||||
int numvertices;
|
||||
vec3_t rot, ang2, org2, mins, maxs;
|
||||
studiohdr_t *phdr = (studiohdr_t *)buffer;
|
||||
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)phdr + phdr->seqindex);
|
||||
|
||||
VectorCopy( pseqdesc[ 0 ].bbmin, mins );
|
||||
VectorCopy( pseqdesc[ 0 ].bbmax, maxs );
|
||||
|
||||
VectorSubtract( maxs, mins, size );
|
||||
VectorAdd( mins, maxs, center );
|
||||
|
||||
ConvertDimensionToPhysic( size );
|
||||
ConvertDimensionToPhysic( center );
|
||||
|
||||
VectorScale( center, 0.5, center );
|
||||
VectorNegate( center, center );
|
||||
|
||||
MatrixLoadIdentity( trans );
|
||||
MatrixLoadIdentity( offset );
|
||||
|
||||
AnglesMatrix( org, ang, trans );
|
||||
VectorCopy( center, offset[3] );
|
||||
|
||||
switch(solid)
|
||||
{
|
||||
case SOLID_BOX:
|
||||
col = NewtonCreateBox( gWorld, size[0], size[1], size[2], &offset[0][0] );
|
||||
break;
|
||||
case SOLID_SPHERE:
|
||||
col = NewtonCreateSphere( gWorld, size[0]/2, size[1]/2, size[2]/2, &offset[0][0] );
|
||||
break;
|
||||
case SOLID_CYLINDER:
|
||||
col = NewtonCreateCylinder( gWorld, size[0], size[1], &offset[0][0] );
|
||||
break;
|
||||
case SOLID_MESH:
|
||||
/* vertices = pi.GetModelVerts( ed, &numvertices );
|
||||
if(!vertices) return;
|
||||
col = NewtonCreateConvexHull(gWorld, numvertices, vertices, sizeof(vec3_t), &offset[0][0] );
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
Host_Error("Phys_CreateBody: unsupported solid type\n");
|
||||
return NULL;
|
||||
}
|
||||
body = NewtonCreateBody( gWorld, col );
|
||||
NewtonBodySetUserData( body, ed );
|
||||
NewtonBodySetMassMatrix( body, 10.0f, size[0], size[1], size[2] ); // 10 kg
|
||||
|
||||
// Setup generic callback to engine.dll
|
||||
NewtonBodySetTransformCallback(body, Phys_ApplyTransform );
|
||||
NewtonBodySetForceAndTorqueCallback(body, Phys_ApplyForce );
|
||||
NewtonBodySetMatrix(body, &trans[0][0]);// origin
|
||||
//NewtonReleaseCollision( gWorld, col );
|
||||
|
||||
return (physbody_t *)body;
|
||||
}
|
||||
|
||||
void Phys_RemoveBody( physbody_t *body )
|
||||
{
|
||||
if(body)
|
||||
{
|
||||
Msg("remove body\n");
|
||||
NewtonDestroyBody( gWorld, (NewtonBody*)body );
|
||||
}
|
||||
}
|
||||
|
||||
void DebugShowGeometryCollision(const NewtonBody* body, int vertexCount, const float* faceVertec, int id)
|
||||
{
|
||||
if(ph.debug_line) ph.debug_line( 0, vertexCount, faceVertec );
|
||||
}
|
||||
|
||||
void DebugShowBodyCollision (const NewtonBody* body)
|
||||
{
|
||||
NewtonBodyForEachPolygonDo(body, DebugShowGeometryCollision);
|
||||
}
|
||||
|
||||
// show all collision geometry
|
||||
void DebugShowCollision ( cmdraw_t callback )
|
||||
{
|
||||
ph.debug_line = callback; // member draw function
|
||||
NewtonWorldForEachBodyDo(gWorld, DebugShowBodyCollision);
|
||||
}
|
|
@ -80,16 +80,17 @@ void end_sys_globals; // flag for structure dumping
|
|||
// physics description
|
||||
.vector origin;
|
||||
.vector angles;
|
||||
.vector old_origin;
|
||||
.vector old_origin; // interpolated values
|
||||
.vector old_angles;
|
||||
.vector velocity;
|
||||
.vector avelocity;
|
||||
.vector m_pmatrix[4];
|
||||
.vector m_pcentre[3]; // current centre of mass
|
||||
.vector torque;
|
||||
.vector force;
|
||||
.vector post_origin;
|
||||
.vector post_angles;
|
||||
.vector post_velocity;
|
||||
.vector post_avelocity;
|
||||
.vector origin_offset;
|
||||
.vector angles_offset;
|
||||
.float ltime;
|
||||
|
||||
.float bouncetype;
|
||||
|
|
|
@ -146,11 +146,11 @@ void() misc_explobox =
|
|||
|
||||
void misc_physbox ( void )
|
||||
{
|
||||
precache_model ("models/box.mdl");
|
||||
precache_model ("models/box2.mdl");
|
||||
pev->owner = pev;
|
||||
pev->solid = SOLID_BOX;
|
||||
pev->movetype = MOVETYPE_PHYSIC;
|
||||
setmodel (pev, "models/box.mdl");
|
||||
setmodel (pev, "models/box2.mdl");
|
||||
}
|
||||
|
||||
void misc_barrel( void )
|
||||
|
@ -159,7 +159,7 @@ void misc_barrel( void )
|
|||
|
||||
precache_model( name );
|
||||
pev->owner = pev;
|
||||
pev->solid = SOLID_CYLINDER; //test
|
||||
pev->solid = SOLID_MESH; //test
|
||||
pev->movetype = MOVETYPE_PHYSIC;
|
||||
setmodel (pev, name );
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ void item_healthkit( void )
|
|||
{
|
||||
precache_model( "models/w_medkit.mdl" );
|
||||
pev->owner = pev;
|
||||
pev->solid = SOLID_CYLINDER;
|
||||
pev->solid = SOLID_MESH;
|
||||
pev->movetype = MOVETYPE_PHYSIC;
|
||||
setmodel (pev, "models/w_medkit.mdl" );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
|
||||
// progdefs.h
|
||||
// generated by Xash3D QuakeC compiler
|
||||
|
||||
#ifndef PROGDEFS_H
|
||||
#define PROGDEFS_H
|
||||
|
||||
typedef struct globalvars_s
|
||||
{
|
||||
int pad[28];
|
||||
int pev;
|
||||
int other;
|
||||
int world;
|
||||
float time;
|
||||
float frametime;
|
||||
string_t mapname;
|
||||
string_t startspot;
|
||||
vec3_t spotoffset;
|
||||
float deathmatch;
|
||||
float coop;
|
||||
float teamplay;
|
||||
float serverflags;
|
||||
float total_secrets;
|
||||
float total_monsters;
|
||||
float found_secrets;
|
||||
float killed_monsters;
|
||||
vec3_t v_forward;
|
||||
vec3_t v_right;
|
||||
vec3_t v_up;
|
||||
float trace_allsolid;
|
||||
float trace_startsolid;
|
||||
float trace_fraction;
|
||||
vec3_t trace_endpos;
|
||||
vec3_t trace_plane_normal;
|
||||
float trace_plane_dist;
|
||||
float trace_hitgroup;
|
||||
float trace_contents;
|
||||
int trace_ent;
|
||||
float trace_flags;
|
||||
func_t main;
|
||||
func_t StartFrame;
|
||||
func_t EndFrame;
|
||||
func_t PlayerPreThink;
|
||||
func_t PlayerPostThink;
|
||||
func_t ClientKill;
|
||||
func_t ClientConnect;
|
||||
func_t PutClientInServer;
|
||||
func_t ClientDisconnect;
|
||||
func_t ClientCommand;
|
||||
} globalvars_t;
|
||||
|
||||
typedef struct entvars_s
|
||||
{
|
||||
string_t classname;
|
||||
string_t globalname;
|
||||
float modelindex;
|
||||
vec3_t origin;
|
||||
vec3_t angles;
|
||||
vec3_t old_origin;
|
||||
vec3_t old_angles;
|
||||
vec3_t velocity;
|
||||
vec3_t avelocity;
|
||||
vec3_t m_pmatrix;
|
||||
vec3_t m_pmatrix[1];
|
||||
vec3_t m_pmatrix[2];
|
||||
vec3_t m_pmatrix[3];
|
||||
vec3_t m_pcentre;
|
||||
vec3_t m_pcentre[1];
|
||||
vec3_t m_pcentre[2];
|
||||
vec3_t torque;
|
||||
vec3_t force;
|
||||
vec3_t post_origin;
|
||||
vec3_t post_angles;
|
||||
vec3_t origin_offset;
|
||||
float ltime;
|
||||
float bouncetype;
|
||||
float movetype;
|
||||
float solid;
|
||||
vec3_t absmin;
|
||||
vec3_t absmax;
|
||||
vec3_t mins;
|
||||
vec3_t maxs;
|
||||
vec3_t size;
|
||||
int chain;
|
||||
string_t model;
|
||||
float frame;
|
||||
float sequence;
|
||||
float renderfx;
|
||||
float effects;
|
||||
float skin;
|
||||
float body;
|
||||
string_t weaponmodel;
|
||||
float weaponframe;
|
||||
func_t use;
|
||||
func_t touch;
|
||||
func_t think;
|
||||
func_t blocked;
|
||||
func_t activate;
|
||||
func_t walk;
|
||||
func_t jump;
|
||||
func_t duck;
|
||||
float flags;
|
||||
float aiflags;
|
||||
float spawnflags;
|
||||
int groundentity;
|
||||
float nextthink;
|
||||
float takedamage;
|
||||
float health;
|
||||
float frags;
|
||||
float weapon;
|
||||
float items;
|
||||
string_t target;
|
||||
string_t parent;
|
||||
string_t targetname;
|
||||
int aiment;
|
||||
int goalentity;
|
||||
vec3_t punchangle;
|
||||
float deadflag;
|
||||
vec3_t view_ofs;
|
||||
float button0;
|
||||
float button1;
|
||||
float button2;
|
||||
float impulse;
|
||||
float fixangle;
|
||||
vec3_t v_angle;
|
||||
float idealpitch;
|
||||
string_t netname;
|
||||
int enemy;
|
||||
float alpha;
|
||||
float team;
|
||||
float max_health;
|
||||
float teleport_time;
|
||||
float armortype;
|
||||
float armorvalue;
|
||||
float waterlevel;
|
||||
float watertype;
|
||||
float ideal_yaw;
|
||||
float yaw_speed;
|
||||
float dmg_take;
|
||||
float dmg_save;
|
||||
int dmg_inflictor;
|
||||
int owner;
|
||||
vec3_t movedir;
|
||||
string_t message;
|
||||
float sounds;
|
||||
string_t noise;
|
||||
string_t noise1;
|
||||
string_t noise2;
|
||||
string_t noise3;
|
||||
float jumpup;
|
||||
float jumpdn;
|
||||
int movetarget;
|
||||
float mass;
|
||||
float density;
|
||||
float gravity;
|
||||
float dmg;
|
||||
float dmgtime;
|
||||
float speed;
|
||||
} entvars_t;
|
||||
|
||||
|
||||
#define REQFIELDS (sizeof(reqfields) / sizeof(fields_t))
|
||||
|
||||
static fields_t reqfields[] =
|
||||
{
|
||||
{159, 6, "th_stand"},
|
||||
{160, 6, "th_walk"},
|
||||
{161, 6, "th_run"},
|
||||
{162, 6, "th_pain"},
|
||||
{163, 6, "th_die"},
|
||||
{164, 6, "th_missile"},
|
||||
{165, 6, "th_melee"},
|
||||
{166, 1, "wad"},
|
||||
{167, 1, "map"},
|
||||
{168, 1, "landmark"},
|
||||
{169, 2, "worldtype"},
|
||||
{170, 2, "delay"},
|
||||
{171, 2, "wait"},
|
||||
{172, 2, "lip"},
|
||||
{173, 2, "light_lev"},
|
||||
{174, 2, "style"},
|
||||
{175, 2, "skill"},
|
||||
{176, 1, "killtarget"},
|
||||
{177, 3, "pos1"},
|
||||
{180, 3, "pos2"},
|
||||
{183, 3, "mangle"},
|
||||
{186, 2, "pain_finished"},
|
||||
{187, 2, "air_finished"},
|
||||
{188, 3, "camview"},
|
||||
{191, 2, "aflag"},
|
||||
{192, 4, "trigger_field"},
|
||||
{193, 2, "anim_time"},
|
||||
{194, 2, "anim_end"},
|
||||
{195, 2, "anim_priority"},
|
||||
{196, 2, "anim_run"},
|
||||
{197, 2, "showhelp"},
|
||||
{198, 2, "showinventory"},
|
||||
{199, 2, "touched"},
|
||||
{200, 1, "name"},
|
||||
{201, 4, "triggerer"},
|
||||
{202, 1, "targ"},
|
||||
{203, 1, "targ[1]"},
|
||||
{204, 1, "targ[2]"},
|
||||
{205, 1, "targ[3]"},
|
||||
{206, 1, "targ[4]"},
|
||||
{207, 1, "targ[5]"},
|
||||
{208, 1, "targ[6]"},
|
||||
{209, 1, "targ[7]"},
|
||||
{210, 1, "oldtarg"},
|
||||
{211, 1, "oldtarg[1]"},
|
||||
{212, 1, "oldtarg[2]"},
|
||||
{213, 1, "oldtarg[3]"},
|
||||
{214, 1, "oldtarg[4]"},
|
||||
{215, 1, "oldtarg[5]"},
|
||||
{216, 1, "oldtarg[6]"},
|
||||
{217, 1, "oldtarg[7]"},
|
||||
{218, 2, "twait"},
|
||||
{219, 2, "twait[1]"},
|
||||
{220, 2, "twait[2]"},
|
||||
{221, 2, "twait[3]"},
|
||||
{222, 2, "twait[4]"},
|
||||
{223, 2, "twait[5]"},
|
||||
{224, 2, "twait[6]"},
|
||||
{225, 2, "twait[7]"},
|
||||
{226, 2, "olddelay"},
|
||||
{227, 1, "message1"},
|
||||
{228, 1, "message2"},
|
||||
{229, 2, "count"},
|
||||
{230, 2, "state"},
|
||||
{231, 2, "used"},
|
||||
{232, 3, "dest"},
|
||||
{235, 1, "target_dest"},
|
||||
{236, 1, "oldmodel"}
|
||||
};
|
||||
|
||||
#define PROG_CRC_SERVER 6477
|
||||
|
||||
#endif//PROGDEFS_H
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
qcclib -progdefs
|
|
@ -111,7 +111,9 @@ typedef vec_t vec2_t[2];
|
|||
typedef vec_t vec3_t[3];
|
||||
typedef vec_t vec4_t[4];
|
||||
typedef long fs_offset_t;
|
||||
typedef vec_t matrix3x3[3][3];
|
||||
typedef vec_t matrix3x4[3][4];
|
||||
typedef vec_t matrix4x3[4][3];
|
||||
typedef vec_t matrix4x4[4][4];
|
||||
typedef char string[MAX_STRING];
|
||||
typedef struct { size_t api_size; } generic_api_t;
|
||||
|
|
|
@ -236,9 +236,12 @@ typedef struct physic_exp_s
|
|||
void (*Frame)( float time ); // physics frame
|
||||
|
||||
// simple objects
|
||||
physbody_t *(*CreateBody)( sv_edict_t *ed, void *buffer, vec3_t org, vec3_t ang, int solid );
|
||||
physbody_t *(*CreateBody)( sv_edict_t *ed, void *buffer, matrix4x3 transform, int solid );
|
||||
bool (*GetForce)(physbody_t *body, vec3_t vel, vec3_t avel, vec3_t force, vec3_t torque );
|
||||
void (*SetForce)(physbody_t *body, vec3_t vel, vec3_t avel, vec3_t force, vec3_t torque );
|
||||
bool (*GetMassCentre)( physbody_t *body, matrix3x3 mass );
|
||||
void (*SetMassCentre)( physbody_t *body, matrix3x3 mass );
|
||||
void (*RemoveBody)( physbody_t *body );
|
||||
|
||||
} physic_exp_t;
|
||||
|
||||
typedef struct physic_imp_s
|
||||
|
@ -246,7 +249,8 @@ typedef struct physic_imp_s
|
|||
// interface validator
|
||||
size_t api_size; // must matched with sizeof(physic_imp_t)
|
||||
|
||||
void (*Transform)( sv_edict_t *ed, vec3_t origin, vec3_t angles );
|
||||
void (*Transform)( sv_edict_t *ed, matrix4x3 transform );
|
||||
float *(*GetModelVerts)( sv_edict_t *ent, int *numvertices );
|
||||
} physic_imp_t;
|
||||
|
||||
// this is the only function actually exported at the linker level
|
||||
|
|
226
public/mathlib.h
226
public/mathlib.h
|
@ -25,6 +25,7 @@
|
|||
#define METERS_PER_INCH 0.0254f
|
||||
#define EQUAL_EPSILON 0.001f
|
||||
#define STOP_EPSILON 0.1f
|
||||
#define ON_EPSILON 0.1f
|
||||
|
||||
#define ANGLE2CHAR(x) ((int)((x)*256/360) & 255)
|
||||
#define CHAR2ANGLE(x) ((x)*(360.0/256))
|
||||
|
@ -87,6 +88,67 @@ _inline int nearest_pow(int size)
|
|||
}
|
||||
}
|
||||
|
||||
_inline void ConvertDimensionToPhysic( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = INCH2METER(tmp[0]);
|
||||
v[1] = INCH2METER(tmp[1]);
|
||||
v[2] = INCH2METER(tmp[2]);
|
||||
}
|
||||
|
||||
_inline void ConvertDimensionToGame( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = METER2INCH(tmp[0]);
|
||||
v[1] = METER2INCH(tmp[1]);
|
||||
v[2] = METER2INCH(tmp[2]);
|
||||
}
|
||||
|
||||
_inline void ConvertPositionToPhysic( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = INCH2METER(tmp[0]);
|
||||
v[1] = INCH2METER(tmp[2]);
|
||||
v[2] = INCH2METER(tmp[1]);
|
||||
}
|
||||
|
||||
_inline void ConvertPositionToGame( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
|
||||
v[2] = METER2INCH(tmp[1]);
|
||||
v[1] = METER2INCH(tmp[2]);
|
||||
v[0] = METER2INCH(tmp[0]);
|
||||
}
|
||||
|
||||
_inline void ConvertDirectionToPhysic( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = tmp[0];
|
||||
v[1] = tmp[2];
|
||||
v[2] = tmp[1];
|
||||
}
|
||||
|
||||
_inline void ConvertDirectionToGame( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = tmp[0];
|
||||
v[1] = tmp[2];
|
||||
v[2] = tmp[1];
|
||||
}
|
||||
|
||||
_inline void VectorBound(const float min, vec3_t v, const float max)
|
||||
{
|
||||
v[0] = bound(min, v[0], max);
|
||||
|
@ -469,6 +531,88 @@ _inline void AngleIMatrixFLU(const vec3_t angles, matrix3x4 matrix )
|
|||
matrix[2][3] = 0.0;
|
||||
}
|
||||
|
||||
_inline void MatrixAngles(matrix4x4 matrix, vec3_t origin, vec3_t angles )
|
||||
{
|
||||
vec3_t forward, right, up;
|
||||
float xyDist;
|
||||
|
||||
forward[0] = matrix[0][0];
|
||||
forward[1] = matrix[0][2];
|
||||
forward[2] = matrix[0][1];
|
||||
right[0] = matrix[1][0];
|
||||
right[1] = matrix[1][2];
|
||||
right[2] = matrix[1][1];
|
||||
up[2] = matrix[2][1];
|
||||
|
||||
xyDist = sqrt( forward[0] * forward[0] + forward[1] * forward[1] );
|
||||
|
||||
if ( xyDist > EQUAL_EPSILON ) // enough here to get angles?
|
||||
{
|
||||
angles[1] = RAD2DEG( atan2( forward[1], forward[0] ));
|
||||
angles[0] = RAD2DEG( atan2( -forward[2], xyDist ));
|
||||
angles[2] = RAD2DEG( atan2( -right[2], up[2] ));
|
||||
}
|
||||
else
|
||||
{
|
||||
angles[1] = RAD2DEG( atan2( right[0], -right[1] ) );
|
||||
angles[0] = RAD2DEG( atan2( -forward[2], xyDist ) );
|
||||
angles[2] = 0;
|
||||
}
|
||||
VectorCopy(matrix[3], origin );// extract origin
|
||||
ConvertPositionToGame( origin );
|
||||
}
|
||||
|
||||
_inline void AnglesMatrix(vec3_t origin, vec3_t angles, matrix4x4 matrix )
|
||||
{
|
||||
float angle;
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
angle = DEG2RAD(angles[YAW]);
|
||||
sy = sin(angle);
|
||||
cy = cos(angle);
|
||||
angle = DEG2RAD(angles[PITCH]);
|
||||
sp = sin(angle);
|
||||
cp = cos(angle);
|
||||
|
||||
MatrixLoadIdentity( matrix );
|
||||
|
||||
// forward
|
||||
matrix[0][0] = cp*cy;
|
||||
matrix[0][2] = cp*sy;
|
||||
matrix[0][1] = -sp;
|
||||
|
||||
if (angles[ROLL] == 180)
|
||||
{
|
||||
angle = DEG2RAD(angles[ROLL]);
|
||||
sr = sin(angle);
|
||||
cr = cos(angle);
|
||||
|
||||
// right
|
||||
matrix[1][0] = -1*(sr*sp*cy+cr*-sy);
|
||||
matrix[1][2] = -1*(sr*sp*sy+cr*cy);
|
||||
matrix[1][1] = -1*(sr*cp);
|
||||
|
||||
// up
|
||||
matrix[2][0] = (cr*sp*cy+-sr*-sy);
|
||||
matrix[2][2] = (cr*sp*sy+-sr*cy);
|
||||
matrix[2][1] = cr*cp;
|
||||
}
|
||||
else
|
||||
{
|
||||
// right
|
||||
matrix[1][0] = sy;
|
||||
matrix[1][2] = -cy;
|
||||
matrix[1][1] = 0;
|
||||
|
||||
// up
|
||||
matrix[2][0] = (sp*cy);
|
||||
matrix[2][2] = (sp*sy);
|
||||
matrix[2][1] = cp;
|
||||
}
|
||||
VectorCopy(origin, matrix[3] ); // pack origin
|
||||
ConvertPositionToPhysic( matrix[3] );
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
MatrixCopy
|
||||
|
@ -785,65 +929,35 @@ _inline int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, cplane_t *p)
|
|||
#define PlaneDist(point,plane) ((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal))
|
||||
#define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist)
|
||||
|
||||
_inline void ConvertDimensionToPhysic( vec3_t v )
|
||||
#define NUM_HULL_ROUNDS (sizeof(hull_table) / sizeof(word))
|
||||
#define HULL_PRECISION 4
|
||||
static word hull_table[] = { 0, 4, 8, 16, 18, 24, 28, 30, 32, 40, 48, 54, 56, 60, 64, 72, 80, 112, 120, 128, 140, 176 };
|
||||
|
||||
_inline void CM_RoundUpHullSize( vec3_t size, bool down )
|
||||
{
|
||||
vec3_t tmp;
|
||||
int i, j;
|
||||
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
bool negative = false;
|
||||
float result, value;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = INCH2METER(tmp[0]);
|
||||
v[1] = INCH2METER(tmp[1]);
|
||||
v[2] = INCH2METER(tmp[2]);
|
||||
}
|
||||
value = down ? floor(size[i]) : ceil(size[i]); // round it
|
||||
if(value < 0) negative = true;
|
||||
value = fabs( value ); // make positive
|
||||
|
||||
_inline void ConvertDimensionToGame( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = METER2INCH(tmp[0]);
|
||||
v[1] = METER2INCH(tmp[1]);
|
||||
v[2] = METER2INCH(tmp[2]);
|
||||
}
|
||||
|
||||
_inline void ConvertPositionToPhysic( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = INCH2METER(tmp[0]);
|
||||
v[1] = INCH2METER(tmp[2]);
|
||||
v[2] = INCH2METER(tmp[1]);
|
||||
}
|
||||
|
||||
_inline void ConvertPositionToGame( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
|
||||
v[2] = METER2INCH(tmp[1]);
|
||||
v[1] = METER2INCH(tmp[2]);
|
||||
v[0] = METER2INCH(tmp[0]);
|
||||
}
|
||||
|
||||
_inline void ConvertDirectionToPhysic( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = tmp[0];
|
||||
v[1] = tmp[2];
|
||||
v[2] = tmp[1];
|
||||
}
|
||||
|
||||
_inline void ConvertDirectionToGame( vec3_t v )
|
||||
{
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy(v, tmp);
|
||||
v[0] = tmp[0];
|
||||
v[1] = tmp[2];
|
||||
v[2] = tmp[1];
|
||||
// lookup hull table
|
||||
for(j = 0; j < NUM_HULL_ROUNDS; j++)
|
||||
{
|
||||
result = value - hull_table[j];
|
||||
if(result <= HULL_PRECISION)
|
||||
{
|
||||
result = negative ? -hull_table[j] : hull_table[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
size[i] = result; // copy new value
|
||||
}
|
||||
}
|
||||
|
||||
static vec3_t vec3_origin = { 0, 0, 0 };
|
||||
|
|
|
@ -177,7 +177,7 @@ bool R_CullBox (vec3_t mins, vec3_t maxs)
|
|||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if ( BoxOnPlaneSide(mins, maxs, &frustum[i]) == SIDE_ON)
|
||||
if ( BoxOnPlaneSide(mins, maxs, &frustum[i]) == SIDE_ON )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -481,7 +481,7 @@ void R_SetFrustum (void)
|
|||
RotatePointAroundVector( frustum[3].normal, vright, vforward, -( 90 - r_newrefdef.fov_y / 2 ) );
|
||||
#endif
|
||||
|
||||
for (i=0 ; i<4 ; i++)
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
frustum[i].type = 3;
|
||||
frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
|
||||
|
|
|
@ -943,10 +943,8 @@ void R_RecursiveWorldNode (mnode_t *node)
|
|||
if (node->contents == CONTENTS_SOLID)
|
||||
return; // solid
|
||||
|
||||
if (node->visframe != r_visframecount)
|
||||
return;
|
||||
if (R_CullBox (node->minmaxs, node->minmaxs+3))
|
||||
return;
|
||||
if(node->visframe != r_visframecount) return;
|
||||
if(R_CullBox (node->minmaxs, node->minmaxs+3)) return;
|
||||
|
||||
// if a leaf node, draw stuff
|
||||
if (node->contents != -1)
|
||||
|
|
|
@ -228,11 +228,11 @@ void EmitWaterPolys (msurface_t *fa)
|
|||
os = v[3];
|
||||
ot = v[4];
|
||||
|
||||
s = os + r_turbsin[(int)((ot * (1.0/8.0) + rdt) * TURBSCALE) & 255];
|
||||
s = os + r_turbsin[(int)((ot * CL_COORD_FRAC + rdt) * TURBSCALE) & 255];
|
||||
s += scroll;
|
||||
s *= (1.0/64);
|
||||
|
||||
t = ot + r_turbsin[(int)((os * (1.0/8.0) + rdt) * TURBSCALE) & 255];
|
||||
t = ot + r_turbsin[(int)((os * CL_COORD_FRAC + rdt) * TURBSCALE) & 255];
|
||||
t *= (1.0/64);
|
||||
|
||||
qglTexCoord2f (s, t);
|
||||
|
@ -373,7 +373,6 @@ return;
|
|||
}
|
||||
}
|
||||
|
||||
#define ON_EPSILON 0.1 // point on plane side epsilon
|
||||
#define MAX_CLIP_VERTS 64
|
||||
void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
||||
{
|
||||
|
@ -399,12 +398,12 @@ void ClipSkyPolygon (int nump, vec3_t vecs, int stage)
|
|||
for (i=0, v = vecs ; i<nump ; i++, v+=3)
|
||||
{
|
||||
d = DotProduct (v, norm);
|
||||
if (d > EQUAL_EPSILON)
|
||||
if (d > ON_EPSILON)
|
||||
{
|
||||
front = true;
|
||||
sides[i] = SIDE_FRONT;
|
||||
}
|
||||
else if (d < -EQUAL_EPSILON)
|
||||
else if (d < -ON_EPSILON)
|
||||
{
|
||||
back = true;
|
||||
sides[i] = SIDE_BACK;
|
||||
|
|
Reference in New Issue