Generic cleanup, often variable initialisation

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3939 4a71c877-e1ca-e34f-864e-861f7616d084
master
Dennis Schridde 2008-03-07 15:09:03 +00:00
parent dd8b729dc2
commit a8dc02f672
8 changed files with 70 additions and 104 deletions

View File

@ -306,6 +306,8 @@ static BOOL _imd_load_points( const char **ppFileData, iIMDShape *s )
// Read in points and remove duplicates (!)
if ( ReadPoints( ppFileData, s ) == FALSE )
{
free(s->points);
s->points = NULL;
return FALSE;
}
@ -418,7 +420,7 @@ static BOOL _imd_load_points( const char **ppFileData, iIMDShape *s )
ymax = MAX(s->max.y, -s->min.y);
zmax = MAX(s->max.z, -s->min.z);
s->radius = MAX(xmax, (MAX(ymax, zmax)));
s->radius = MAX(xmax, MAX(ymax, zmax));
s->sradius = sqrtf(xmax*xmax + ymax*ymax + zmax*zmax);
// START: tight bounding sphere

View File

@ -45,7 +45,5 @@
#define iV_MatrixRotateY pie_MatRotY
#define iV_MatrixRotateZ pie_MatRotZ
#define iV_TRANSLATE pie_TRANSLATE
#define iV_SIN SIN
#define iV_COS COS
#endif // _ivispatch_h

View File

@ -42,8 +42,6 @@
/***************************************************************************/
#define DEG_360 65536
#define DEG_1 (DEG_360/360)
#define DEG_2 (DEG_360/180)
#define DEG_60 (DEG_360/6)
#define DEG(X) (DEG_1 * (X))
//! PSX-style float emulation: 12 digit semi-floats stored in an int
@ -55,7 +53,6 @@
#define MAX_Z (32000) // raised to 32000 from 6000 when stretched
#define MIN_STRETCHED_Z 256
#define LONG_WAY (1<<15)
#define LONG_TEST (1<<14)
#define INTERFACE_DEPTH (MAX_Z - 1)
#define BUTTON_DEPTH 2000 // will be stretched to 16000

View File

@ -45,9 +45,6 @@ static SDMATRIX *psMatrix = &aMatrixStack[0];
BOOL drawing_interface = TRUE;
#define SC_TABLESIZE 4096
//*************************************************************************
// We use FP12_MULTIPLIER => This matrix should be float instead
@ -119,8 +116,7 @@ void pie_MATTRANS(int x, int y, int z)
matrix[12] = x;
matrix[13] = y;
matrix[14] = z;
glLoadIdentity();
glMultMatrixf(matrix);
glLoadMatrixf(matrix);
}
void pie_TRANSLATE(int x, int y, int z)
@ -136,17 +132,15 @@ void pie_TRANSLATE(int x, int y, int z)
//*** matrix scale current transformation matrix
//*
//******
void pie_MatScale( UDWORD percent )
void pie_MatScale( unsigned int percent )
{
SDWORD scaleFactor;
SDWORD scaleFactor = percent * ONE_PERCENT;
if (percent == 100)
{
return;
}
scaleFactor = percent * ONE_PERCENT;
psMatrix->a = (psMatrix->a * scaleFactor) / 4096;
psMatrix->b = (psMatrix->b * scaleFactor) / 4096;
psMatrix->c = (psMatrix->c * scaleFactor) / 4096;
@ -170,12 +164,10 @@ void pie_MatScale( UDWORD percent )
void pie_MatRotY(int y)
{
int t;
int cra, sra;
if (y != 0) {
cra = COS(y);
sra = SIN(y);
if (y != 0)
{
int t;
int cra = COS(y), sra = SIN(y);
t = ((cra * psMatrix->a) - (sra * psMatrix->g))>>FP12_SHIFT;
psMatrix->g = ((sra * psMatrix->a) + (cra * psMatrix->g))>>FP12_SHIFT;
@ -188,9 +180,9 @@ void pie_MatRotY(int y)
t = ((cra * psMatrix->c) - (sra * psMatrix->i))>>FP12_SHIFT;
psMatrix->i = ((sra * psMatrix->c) + (cra * psMatrix->i))>>FP12_SHIFT;
psMatrix->c = t;
}
glRotatef(y*22.5f/4096.0f, 0.0f, 1.0f, 0.0f);
glRotatef(y*22.5f/4096.0f, 0.0f, 1.0f, 0.0f);
}
}
@ -201,12 +193,10 @@ void pie_MatRotY(int y)
void pie_MatRotZ(int z)
{
int t;
int cra, sra;
if (z != 0) {
cra = COS(z);
sra = SIN(z);
if (z != 0)
{
int t;
int cra = COS(z), sra = SIN(z);
t = ((cra * psMatrix->a) + (sra * psMatrix->d))>>FP12_SHIFT;
psMatrix->d = ((cra * psMatrix->d) - (sra * psMatrix->a))>>FP12_SHIFT;
@ -219,9 +209,9 @@ void pie_MatRotZ(int z)
t = ((cra * psMatrix->c) + (sra * psMatrix->f))>>FP12_SHIFT;
psMatrix->f = ((cra * psMatrix->f) - (sra * psMatrix->c))>>FP12_SHIFT;
psMatrix->c = t;
}
glRotatef(z*22.5f/4096.0f, 0.0f, 0.0f, 1.0f);
glRotatef(z*22.5f/4096.0f, 0.0f, 0.0f, 1.0f);
}
}
@ -232,12 +222,10 @@ void pie_MatRotZ(int z)
void pie_MatRotX(int x)
{
int cra, sra;
int t;
if (x != 0) {
cra = COS(x);
sra = SIN(x);
if (x != 0)
{
int t;
int cra = COS(x), sra = SIN(x);
t = ((cra * psMatrix->d) + (sra * psMatrix->g))>>FP12_SHIFT;
psMatrix->g = ((cra * psMatrix->g) - (sra * psMatrix->d))>>FP12_SHIFT;
@ -250,9 +238,9 @@ void pie_MatRotX(int x)
t = ((cra * psMatrix->f) + (sra * psMatrix->i))>>FP12_SHIFT;
psMatrix->i = ((cra * psMatrix->i) - (sra * psMatrix->f))>>FP12_SHIFT;
psMatrix->f = t;
}
glRotatef(x*22.5f/4096.0f, 1.0f, 0.0f, 0.0f);
glRotatef(x*22.5f/4096.0f, 1.0f, 0.0f, 0.0f);
}
}
@ -265,17 +253,15 @@ void pie_MatRotX(int x)
*/
Sint32 pie_RotateProject(const Vector3i *v3d, Vector2i *v2d)
{
Sint32 zfx, zfy;
Sint32 zz, _x, _y, _z;
Vector3i v = {
v3d->x * psMatrix->a + v3d->y * psMatrix->d + v3d->z * psMatrix->g + psMatrix->j,
v3d->x * psMatrix->b + v3d->y * psMatrix->e + v3d->z * psMatrix->h + psMatrix->k,
v3d->x * psMatrix->c + v3d->y * psMatrix->f + v3d->z * psMatrix->i + psMatrix->l
};
_x = v3d->x * psMatrix->a + v3d->y * psMatrix->d + v3d->z * psMatrix->g + psMatrix->j;
_y = v3d->x * psMatrix->b + v3d->y * psMatrix->e + v3d->z * psMatrix->h + psMatrix->k;
_z = v3d->x * psMatrix->c + v3d->y * psMatrix->f + v3d->z * psMatrix->i + psMatrix->l;
zz = _z >> STRETCHED_Z_SHIFT;
zfx = _z >> psRendSurface->xpshift;
zfy = _z >> psRendSurface->ypshift;
int zz = v.z >> STRETCHED_Z_SHIFT;
int zfx = v.z >> psRendSurface->xpshift;
int zfy = v.z >> psRendSurface->ypshift;
if (zfx <= 0 || zfy <= 0 || zz < MIN_STRETCHED_Z)
{
@ -284,8 +270,8 @@ Sint32 pie_RotateProject(const Vector3i *v3d, Vector2i *v2d)
}
else
{
v2d->x = psRendSurface->xcentre + (_x / zfx);
v2d->y = psRendSurface->ycentre - (_y / zfy);
v2d->x = psRendSurface->xcentre + (v.x / zfx);
v2d->y = psRendSurface->ycentre - (v.y / zfy);
}
return zz;
@ -295,13 +281,15 @@ void pie_PerspectiveBegin(void)
{
const float width = pie_GetVideoBufferWidth();
const float height = pie_GetVideoBufferHeight();
const float xangle = width/6;
const float yangle = height/6;
const float xangle = width/6.0f;
const float yangle = height/6.0f;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef((2*psRendSurface->xcentre-width)/width,
(height-2*psRendSurface->ycentre)/height , 0);
glTranslatef(
(2 * psRendSurface->xcentre-width) / width,
(height - 2 * psRendSurface->ycentre) / height,
0);
glFrustum(-xangle, xangle, -yangle, yangle, 330, 100000);
glScalef(1, 1, -1);
glMatrixMode(GL_MODELVIEW);
@ -357,30 +345,23 @@ void pie_SetGeometricOffset(int x, int y)
*/
void pie_VectorInverseRotate0(const Vector3i *v1, Vector3i *v2)
{
Sint32 x, y, z;
unsigned int x = v1->x, y = v1->y, z = v1->z;
x = v1->x; y = v1->y; z = v1->z;
v2->x = (x * psMatrix->a+y * psMatrix->b+z * psMatrix->c) >> FP12_SHIFT;
v2->y = (x * psMatrix->d+y * psMatrix->e+z * psMatrix->f) >> FP12_SHIFT;
v2->z = (x * psMatrix->g+y * psMatrix->h+z * psMatrix->i) >> FP12_SHIFT;
v2->x = (x * psMatrix->a + y * psMatrix->b + z * psMatrix->c) >> FP12_SHIFT;
v2->y = (x * psMatrix->d + y * psMatrix->e + z * psMatrix->f) >> FP12_SHIFT;
v2->z = (x * psMatrix->g + y * psMatrix->h + z * psMatrix->i) >> FP12_SHIFT;
}
/** Sets up transformation matrices/quaternions and trig tables
*/
void pie_MatInit(void)
{
unsigned i, scsize;
double conv, v;
// sin/cos table
scsize = SC_TABLESIZE + (SC_TABLESIZE / 4);
conv = (double)(M_PI / (0.5 * SC_TABLESIZE));
const double conv = M_PI / (0.5 * SC_TABLESIZE);
unsigned int i, scsize = SC_TABLESIZE + (SC_TABLESIZE / 4);
for (i = 0; i < scsize; i++)
{
v = sin(i * conv) * FP12_MULTIPLIER;
double v = sin(i * conv) * FP12_MULTIPLIER;
if (v >= 0.0)
aSinTable[i] = (Sint32)(v + 0.5);
@ -389,7 +370,6 @@ void pie_MatInit(void)
}
// init matrix/quat stack
pie_MatReset();
}

View File

@ -30,21 +30,13 @@
#include "lib/ivis_common/piedef.h"
/***************************************************************************/
/*
* Global Variables
*/
/***************************************************************************/
// FIXME DUPLICATE CODE! Already present in trig.c!
#define SC_TABLESIZE 4096
#define SIN(X) aSinTable[(Uint16)(X) >> 4]
#define COS(X) aSinTable[((Uint16)(X) >> 4) + (SC_TABLESIZE/4)]
extern SDWORD aSinTable[];
//*************************************************************************
// FIXME DUPLICATE CODE! Already present in trig.c!
#define SIN(X) aSinTable[(Uint16)(X) >> 4]
#define COS(X) aSinTable[((Uint16)(X) >> 4) + 1024]
//*************************************************************************
/*!
@ -104,7 +96,7 @@ extern void pie_MatBegin(void);
extern void pie_MatEnd(void);
extern void pie_MATTRANS(int x, int y, int z);
extern void pie_TRANSLATE(int x, int y, int z);
extern void pie_MatScale( UDWORD percent );
extern void pie_MatScale( unsigned int percent );
extern void pie_MatRotX(int x);
extern void pie_MatRotY(int y);
extern void pie_MatRotZ(int z);

View File

@ -2477,8 +2477,8 @@ static void effectDroidUpdates(void)
if( (SDWORD)psDroid->sMove.speed != 0 )
{
/* Present direction is important */
xBehind = ( ( 50 * iV_SIN( DEG( (int)psDroid->direction) ) ) >> FP12_SHIFT );
yBehind = ( ( 50 * iV_COS( DEG( (int)psDroid->direction) ) ) >> FP12_SHIFT );
xBehind = ( 50 * SIN( DEG( (int)psDroid->direction) ) ) >> FP12_SHIFT;
yBehind = ( 50 * COS( DEG( (int)psDroid->direction) ) ) >> FP12_SHIFT;
pos.x = psDroid->pos.x - xBehind;
pos.z = psDroid->pos.y - yBehind;
pos.y = map_Height(pos.x, pos.z);

View File

@ -753,12 +753,14 @@ static void RotateVector2D(Vector3i *Vector, Vector3i *TVector, Vector3i *Pos, i
Vector3i *Vec = Vector;
Vector3i *TVec = TVector;
if(Pos) {
if (Pos)
{
ox = Pos->x;
oy = Pos->y;
}
for(i=0; i<Count; i++) {
for (i = 0; i < Count; i++)
{
TVec->x = ( (Vec->x*Cos + Vec->y*Sin) >> FP12_SHIFT ) + ox;
TVec->y = ( (Vec->y*Cos - Vec->x*Sin) >> FP12_SHIFT ) + oy;
Vec++;

View File

@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file warcam.c
* @file warcam.c
* Handles tracking/following of in game objects.
*/
/* Alex McLean, Pumpkin Studios, EIDOS Interactive, 1998 */
@ -709,21 +709,16 @@ in the case of location and degrees of arc in the case of rotation.
static void updateCameraAcceleration(UBYTE update)
{
float separation;
SDWORD realPos;
SDWORD xConcern,yConcern,zConcern;
SDWORD xBehind,yBehind;
BOOL bFlying;
DROID *psDroid;
UDWORD multiAngle;
PROPULSION_STATS *psPropStats;
//SDWORD pitch;
SDWORD angle;
float separation;
SDWORD realPos;
SDWORD xConcern,yConcern,zConcern;
SDWORD xBehind,yBehind;
BOOL bFlying = FALSE;
DROID *psDroid;
UDWORD multiAngle;
PROPULSION_STATS *psPropStats;
SDWORD angle = 90 - abs(((player.r.x/182)%90));
angle = abs(((player.r.x/182)%90));
angle = 90-angle;
bFlying = FALSE;
if(trackingCamera.target->type == OBJ_DROID)
{
psDroid = (DROID*)trackingCamera.target;
@ -745,7 +740,7 @@ SDWORD angle;
if(trackingCamera.target->type == OBJ_DROID)
{
/* Present direction is important */
if(getNumDroidsSelected()>2)
if(getNumDroidsSelected() > 2)
{
if(trackingCamera.target->selected)
{
@ -772,7 +767,7 @@ SDWORD angle;
}
/* Get these new coordinates */
if(getNumDroidsSelected()>2 && trackingCamera.target->type == OBJ_DROID)
if(trackingCamera.target->type == OBJ_DROID && getNumDroidsSelected() > 2)
{
xConcern = trackingCamera.target->pos.x; // nb - still NEED to be set
yConcern = trackingCamera.target->pos.z;