static void Generate_SphereOctant(void) { int i,j; VECTORCH *o = OctantVertex; /* i=0, j=0 */ MakeVertex(o,0,0,SPHERE_RADIUS); for (i=1; i<SPHERE_ORDER; i++) { int cosPhi, sinPhi; { int phi = 1024*i/SPHERE_ORDER; cosPhi = GetCos(phi); sinPhi = GetSin(phi); } /* 0<i<n, j=0 */ /* => cosTheta = 1, sinTheta = 0 */ MakeVertex(o,sinPhi,0,cosPhi); for (j=1; j<i; j++) { int cosTheta, sinTheta; { int theta = 1024*j/i; cosTheta = GetCos(theta); sinTheta = GetSin(theta); } /* 0<i<n, 0<j<i */ MakeVertex(o,MUL_FIXED(cosTheta,sinPhi),MUL_FIXED(sinTheta,sinPhi),cosPhi); } /* 0<i<n, j=i */ MakeVertex(o,0,sinPhi,cosPhi); } /* i=n, j=0 */ MakeVertex(o,SPHERE_RADIUS,0,0); for (j=1; j<SPHERE_ORDER; j++) { int cosTheta, sinTheta; { int theta = 1024*j/SPHERE_ORDER; cosTheta = GetCos(theta); sinTheta = GetSin(theta); } /* i=n, 0<j<i */ MakeVertex(o,cosTheta,sinTheta,0); } /* i=n, j=i */ MakeVertex(o,0,SPHERE_RADIUS,0); }
void CreateEulerVector(EULER *e, VECTORCH *v) { int t, sx, sy, sz, cx, cy, cz; sx = GetSin(e->EulerX); sy = GetSin(e->EulerY); sz = GetSin(e->EulerZ); cx = GetCos(e->EulerX); cy = GetCos(e->EulerY); cz = GetCos(e->EulerZ); /* x = -sy*cz + sx*cy*sz */ v->vx = MUL_FIXED(-sy, cz); t = MUL_FIXED(sx, cy); t = MUL_FIXED(t, sz); v->vx += t; /* y = sy*sz + sx*cy*cz */ v->vy = MUL_FIXED(sy, sz); t = MUL_FIXED(sx, cy); t = MUL_FIXED(t, cz); v->vy += t; /* z = cx*cy */ v->vz = MUL_FIXED(cx,cy); }
void ConstructOneOverSinTable(void) { int a,sin; for (a=0; a<4096; a++) { sin=GetSin(a); if (sin!=0) { oneoversin[a]=DIV_FIXED(ONE_FIXED,sin); } else { sin=100; oneoversin[a]=DIV_FIXED(ONE_FIXED,sin); } } }
void TeleportPreservedSBsToNewEnvModule(MODULE *new_pos, MODULE* old_pos, int orient_change) { int i; VECTORCH mod_offset; mod_offset.vx = new_pos->m_world.vx - old_pos->m_world.vx; mod_offset.vy = new_pos->m_world.vy - old_pos->m_world.vy; mod_offset.vz = new_pos->m_world.vz - old_pos->m_world.vz; for(i = 0; i < Num_SB_Preserved; i++) { VECTORCH obj_world; VECTORCH pos_rel; STRATEGYBLOCK *sbptr; DYNAMICSBLOCK *dynptr; sbptr = &SB_Preserved[i]; dynptr = sbptr->DynPtr; GLOBALASSERT(dynptr); obj_world = sbptr->DynPtr->Position; { // okay we need to find our relative position to the moduke int cos; int sin; int angle; MATRIXCH mat; pos_rel.vx = dynptr->Position.vx - old_pos->m_world.vx; pos_rel.vy = dynptr->Position.vy - old_pos->m_world.vy; pos_rel.vz = dynptr->Position.vz - old_pos->m_world.vz; if(orient_change == 1 || orient_change == -3) angle = 1024; else if(orient_change == 2 || orient_change == -2) angle = 2048; else if(orient_change == 3 || orient_change == -1) angle = 3072; else angle = 0; cos = GetCos(angle); sin = GetSin(angle); mat.mat11 = cos; mat.mat12 = 0; mat.mat13 = -sin; mat.mat21 = 0; mat.mat22 = 65536; mat.mat23 = 0; mat.mat31 = sin; mat.mat32 = 0; mat.mat33 = cos; // rotate the relative object about the center of the // module and rotate the abject about its own y-axis RotateVector(&pos_rel, &mat); MatrixMultiply(&dynptr->OrientMat,&mat,&dynptr->OrientMat); MatrixToEuler(&dynptr->OrientMat, &dynptr->OrientEuler); } #if 0 dynptr->Position.vx = mod_offset.vx; dynptr->Position.vy = mod_offset.vy; dynptr->Position.vz = mod_offset.vz; dynptr->PrevPosition.vx = mod_offset.vx; dynptr->PrevPosition.vy = mod_offset.vy; dynptr->PrevPosition.vz = mod_offset.vz; #endif dynptr->Position.vx = pos_rel.vx + new_pos->m_world.vx; dynptr->Position.vy = pos_rel.vy + new_pos->m_world.vy; dynptr->Position.vz = pos_rel.vz + new_pos->m_world.vz; dynptr->PrevPosition.vx = -pos_rel.vx + old_pos->m_world.vx; dynptr->PrevPosition.vy = -pos_rel.vy + old_pos->m_world.vy; dynptr->PrevPosition.vz = -pos_rel.vz + old_pos->m_world.vz; } }
void AddDecalToHModel(VECTORCH *normalPtr, VECTORCH *positionPtr, SECTION_DATA *sectionDataPtr) { enum DECAL_ID decalID; OBJECT_DECAL *decalPtr; MATRIXCH orientation; VECTORCH v; int decalSize; int theta,sin,cos; if (!LocalDetailLevels.DrawHierarchicalDecals) return; theta = FastRandom()&4095; sin = GetSin(theta); cos = GetCos(theta); LOCALASSERT(sectionDataPtr->NumberOfDecals <= MAX_NO_OF_DECALS_PER_HIERARCHICAL_SECTION); { MATRIXCH mat = sectionDataPtr->SecMat; VECTORCH n = *normalPtr; TransposeMatrixCH(&mat); RotateVector(&n,&mat); MakeMatrixFromDirection(&n,&orientation); v = *positionPtr; v.vx -= sectionDataPtr->World_Offset.vx; v.vy -= sectionDataPtr->World_Offset.vy; v.vz -= sectionDataPtr->World_Offset.vz; RotateVector(&v,&mat); } { SECTION *sectionPtr = sectionDataPtr->sempai; if(sectionPtr->flags§ion_sprays_blood) { decalID = DECAL_HUMAN_BLOOD; } else if(sectionPtr->flags§ion_sprays_predoblood) { decalID = DECAL_PREDATOR_BLOOD; } else if(sectionPtr->flags§ion_sprays_acid) { decalID = DECAL_ALIEN_BLOOD; } else { decalID = DECAL_BULLETHOLE; } } decalPtr = §ionDataPtr->Decals[sectionDataPtr->NextDecalToUse]; if (sectionDataPtr->NextDecalToUse >= MAX_NO_OF_DECALS_PER_HIERARCHICAL_SECTION-1) { sectionDataPtr->NextDecalToUse = 0; } else { sectionDataPtr->NextDecalToUse++; } if (sectionDataPtr->NumberOfDecals < MAX_NO_OF_DECALS_PER_HIERARCHICAL_SECTION) { sectionDataPtr->NumberOfDecals++; } decalPtr->DecalID = decalID; decalSize = 40;//DecalDescription[decalID].MaxSize; decalPtr->Centre = v; decalPtr->Vertices[0].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[0].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[0].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[0]),&orientation); decalPtr->Vertices[0].vx += v.vx; decalPtr->Vertices[0].vy += v.vy; decalPtr->Vertices[0].vz += v.vz; decalPtr->Vertices[1].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[1].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[1].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[1]),&orientation); decalPtr->Vertices[1].vx += v.vx; decalPtr->Vertices[1].vy += v.vy; decalPtr->Vertices[1].vz += v.vz; decalPtr->Vertices[2].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[2].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[2].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[2]),&orientation); decalPtr->Vertices[2].vx += v.vx; decalPtr->Vertices[2].vy += v.vy; decalPtr->Vertices[2].vz += v.vz; decalPtr->Vertices[3].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[3].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[3].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[3]),&orientation); decalPtr->Vertices[3].vx += v.vx; decalPtr->Vertices[3].vy += v.vy; decalPtr->Vertices[3].vz += v.vz; }
void AddDecal(enum DECAL_ID decalID, VECTORCH *normalPtr, VECTORCH *positionPtr, int moduleIndex) { DECAL *decalPtr; MATRIXCH orientation; int decalSize; int theta = FastRandom()&4095; int sin = GetSin(theta); int cos = GetCos(theta); MakeMatrixFromDirection(normalPtr,&orientation); if (decalID == DECAL_BULLETHOLE) { MakeImpactSmoke(&orientation,positionPtr); } decalPtr = AllocateDecal(); decalPtr->DecalID = decalID; decalPtr->Centre = *positionPtr; if(DecalDescription[decalID].GrowthRate) { decalSize = ONE_FIXED; decalPtr->Direction[0].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Direction[0].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Direction[0].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[0]),&orientation); Normalise(&(decalPtr->Direction[0])); decalPtr->Direction[1].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Direction[1].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Direction[1].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[1]),&orientation); Normalise(&(decalPtr->Direction[1])); decalPtr->Direction[2].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Direction[2].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Direction[2].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[2]),&orientation); Normalise(&(decalPtr->Direction[2])); decalPtr->Direction[3].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Direction[3].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Direction[3].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Direction[3]),&orientation); Normalise(&(decalPtr->Direction[3])); decalPtr->CurrentSize = DecalDescription[decalID].MinSize; decalPtr->TargetSize = DecalDescription[decalID].MaxSize; if (DecalDescription[decalID].CanCombine) decalPtr->TargetSize/=4; } else { decalSize = DecalDescription[decalID].MinSize; decalPtr->Vertices[0].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[0].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[0].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[0]),&orientation); decalPtr->Vertices[0].vx += positionPtr->vx; decalPtr->Vertices[0].vy += positionPtr->vy; decalPtr->Vertices[0].vz += positionPtr->vz; decalPtr->Vertices[1].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(-decalSize,sin); decalPtr->Vertices[1].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(-decalSize,cos); decalPtr->Vertices[1].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[1]),&orientation); decalPtr->Vertices[1].vx += positionPtr->vx; decalPtr->Vertices[1].vy += positionPtr->vy; decalPtr->Vertices[1].vz += positionPtr->vz; decalPtr->Vertices[2].vx = MUL_FIXED(decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[2].vy = MUL_FIXED(decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[2].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[2]),&orientation); decalPtr->Vertices[2].vx += positionPtr->vx; decalPtr->Vertices[2].vy += positionPtr->vy; decalPtr->Vertices[2].vz += positionPtr->vz; decalPtr->Vertices[3].vx = MUL_FIXED(-decalSize,cos) - MUL_FIXED(decalSize,sin); decalPtr->Vertices[3].vy = MUL_FIXED(-decalSize,sin) + MUL_FIXED(decalSize,cos); decalPtr->Vertices[3].vz = DECAL_Z_OFFSET; RotateVector(&(decalPtr->Vertices[3]),&orientation); decalPtr->Vertices[3].vx += positionPtr->vx; decalPtr->Vertices[3].vy += positionPtr->vy; decalPtr->Vertices[3].vz += positionPtr->vz; } decalPtr->ModuleIndex = moduleIndex; switch (decalID) { case DECAL_HUMAN_BLOOD: case DECAL_PREDATOR_BLOOD: case DECAL_ANDROID_BLOOD: { decalPtr->UOffset = (FastRandom()&1)*(32<<16); if (normalPtr->vy<-32768) { decalPtr->UOffset+=64<<16; } else { decalPtr->TargetSize = DecalDescription[decalID].MaxSize; decalPtr->CurrentSize = decalPtr->TargetSize-1; } break; } default: { decalPtr->UOffset = 0; break; } } }
void CreateEulerMatrix(EULER *e, MATRIXCH *m1) { int t, sx, sy, sz, cx, cy, cz; sx = GetSin(e->EulerX); sy = GetSin(e->EulerY); sz = GetSin(e->EulerZ); cx = GetCos(e->EulerX); cy = GetCos(e->EulerY); cz = GetCos(e->EulerZ); #if 0 textprint("Euler Matrix Sines & Cosines\n"); textprint("%d, %d, %d\n", sx, sy, sz); textprint("%d, %d, %d\n", cx, cy, cz); #endif /* m11 = cy*cz + sx*sy*sz */ m1->mat11 = MUL_FIXED(cy, cz); /* cy*cz */ t = MUL_FIXED(sx, sy); /* sx*sy */ t = MUL_FIXED(t, sz); /* *sz */ m1->mat11 += t; /* m12 = -cy*sz + sx*sy*cz */ m1->mat12=MUL_FIXED(-cy,sz); t=MUL_FIXED(sx,sy); t=MUL_FIXED(t,cz); m1->mat12+=t; /* m13 = cx*sy */ m1->mat13=MUL_FIXED(cx,sy); /* m21 = cx*sz */ m1->mat21=MUL_FIXED(cx,sz); /* m22 = cx*cz */ m1->mat22=MUL_FIXED(cx,cz); /* m23 = -sx */ m1->mat23=-sx; /* m31 = -sy*cz + sx*cy*sz */ m1->mat31=MUL_FIXED(-sy,cz); t=MUL_FIXED(sx,cy); t=MUL_FIXED(t,sz); m1->mat31+=t; /* m32 = sy*sz + sx*cy*cz */ m1->mat32=MUL_FIXED(sy,sz); t=MUL_FIXED(sx,cy); t=MUL_FIXED(t,cz); m1->mat32+=t; /* m33 = cx*cy */ m1->mat33=MUL_FIXED(cx,cy); }
/* ddrval = lpDDSBack->BltFast(xdest, ydest, font->data, rect, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY); LOGDXERR(ddrval); if(ddrval != DD_OK) { LOGDXERR(ddrval); GLOBALASSERT(0); finiObjects(); exit(ddrval); } */ fprintf(stderr, "BLTFontOffsetToHUD(%p, %d, %d, %d)\n", font, xdest, ydest, offset); return(font->srcRect[offset].right - font->srcRect[offset].left); } #endif // SBF void YClipMotionTrackerVertices(struct VertexTag *v1, struct VertexTag *v2); void XClipMotionTrackerVertices(struct VertexTag *v1, struct VertexTag *v2); #if 0 /* SBF - not used */ static void DrawMotionTrackerPoly(void) { struct VertexTag vertex[4]; int widthCos,widthSin; { int angle = 4095 - Player->ObEuler.EulerY; widthCos = MUL_FIXED ( MotionTrackerWidth, GetCos(angle) ); widthSin = MUL_FIXED ( MotionTrackerWidth, GetSin(angle) ); } /* I've put these -1s in here to help clipping 45 degree cases, where two vertices can end up around the clipping line of Y=0 */ vertex[0].X = (-widthCos - (-widthSin))/2; vertex[0].Y = (-widthSin + (-widthCos))/2 -1; vertex[0].U = 0; vertex[0].V = 0; vertex[1].X = (widthCos - (-widthSin))/2; vertex[1].Y = (widthSin + (-widthCos))/2 -1; vertex[1].U = MotionTrackerTextureSize; vertex[1].V = 0; vertex[2].X = (widthCos - widthSin)/2; vertex[2].Y = (widthSin + widthCos)/2 -1; vertex[2].U = MotionTrackerTextureSize; vertex[2].V = MotionTrackerTextureSize; vertex[3].X = ((-widthCos) - widthSin)/2; vertex[3].Y = ((-widthSin) + widthCos)/2 -1; vertex[3].U = 0; vertex[3].V = MotionTrackerTextureSize; /* clip to Y<=0 */ YClipMotionTrackerVertices(&vertex[0],&vertex[1]); YClipMotionTrackerVertices(&vertex[1],&vertex[2]); YClipMotionTrackerVertices(&vertex[2],&vertex[3]); YClipMotionTrackerVertices(&vertex[3],&vertex[0]); /* translate into screen coords */ vertex[0].X += MotionTrackerCentreX; vertex[1].X += MotionTrackerCentreX; vertex[2].X += MotionTrackerCentreX; vertex[3].X += MotionTrackerCentreX; vertex[0].Y += MotionTrackerCentreY; vertex[1].Y += MotionTrackerCentreY; vertex[2].Y += MotionTrackerCentreY; vertex[3].Y += MotionTrackerCentreY; #if 0 textprint("%d %d %d %d\n%d %d %d %d\n%d %d %d %d\n%d %d %d %d\n", vertex[0].X,vertex[0].Y,vertex[0].U,vertex[0].V, vertex[1].X,vertex[1].Y,vertex[1].U,vertex[1].V, vertex[2].X,vertex[2].Y,vertex[2].U,vertex[2].V, vertex[3].X,vertex[3].Y,vertex[3].U,vertex[3].V); #endif /* dodgy offset 'cos I'm not x clipping */ if (vertex[0].X==-1) vertex[0].X = 0; if (vertex[1].X==-1) vertex[1].X = 0; if (vertex[2].X==-1) vertex[2].X = 0; if (vertex[3].X==-1) vertex[3].X = 0; /* setup polygon in item format */ { int *itemDataPtr = TrackerPolyBuffer+4; *itemDataPtr++ = vertex[3].X; *itemDataPtr++ = vertex[3].Y; *itemDataPtr++ = vertex[3].U; *itemDataPtr++ = vertex[3].V; *itemDataPtr++ = vertex[2].X; *itemDataPtr++ = vertex[2].Y; *itemDataPtr++ = vertex[2].U; *itemDataPtr++ = vertex[2].V; *itemDataPtr++ = vertex[1].X; *itemDataPtr++ = vertex[1].Y; *itemDataPtr++ = vertex[1].U; *itemDataPtr++ = vertex[1].V; *itemDataPtr++ = vertex[0].X; *itemDataPtr++ = vertex[0].Y; *itemDataPtr++ = vertex[0].U; *itemDataPtr++ = vertex[0].V; *itemDataPtr = Term; /* draw polygon */ Draw_Item_2dTexturePolygon(TrackerPolyBuffer); } }