00001
00002 #include "revolt.h"
00003 #include "mirror.h"
00004 #include "model.h"
00005 #include "registry.h"
00006 #include "level.h"
00007
00008
00009
00010 long MirrorPlaneNum;
00011 MIRROR_PLANE *MirrorPlanes;
00012 long MirrorType, MirrorAlpha;
00013 float MirrorHeight, MirrorMul, MirrorAdd, MirrorDist;
00014
00016
00018
00019 bool LoadMirrorPlanes(char *file)
00020 {
00021 long i;
00022 MIRROR_PLANE_HEADER mph;
00023 MIRROR_PLANE_LOAD mpl;
00024 FILE *fp;
00025
00026
00027
00028 fp = fopen(file, "rb");
00029 if (!fp)
00030 {
00031 MirrorPlaneNum = 0;
00032 MirrorPlanes = NULL;
00033 return FALSE;
00034 }
00035
00036
00037
00038 fread(&mph, sizeof(mph), 1, fp);
00039 MirrorPlaneNum = mph.MirrorPlaneNum;
00040 MirrorPlanes = (MIRROR_PLANE*)malloc(MirrorPlaneNum * sizeof(MIRROR_PLANE));
00041 if (!MirrorPlanes)
00042 {
00043 MirrorPlaneNum = 0;
00044 return FALSE;
00045 }
00046
00047
00048
00049 for (i = 0 ; i < MirrorPlaneNum ; i++)
00050 {
00051 fread(&mpl, sizeof(mpl), 1, fp);
00052
00053 MirrorPlanes[i].Xmin = mpl.MinX - MIRROR_PLANE_OVERLAP;
00054 MirrorPlanes[i].Xmax = mpl.MaxX + MIRROR_PLANE_OVERLAP;
00055
00056 MirrorPlanes[i].Zmin = mpl.MinZ - MIRROR_PLANE_OVERLAP;
00057 MirrorPlanes[i].Zmax = mpl.MaxZ + MIRROR_PLANE_OVERLAP;
00058
00059 MirrorPlanes[i].Height = mpl.v0.v[Y];
00060 }
00061
00062
00063
00064 fclose(fp);
00065
00066
00067
00068 return TRUE;
00069 }
00070
00072
00074
00075 void FreeMirrorPlanes(void)
00076 {
00077 free(MirrorPlanes);
00078 }
00079
00081
00083
00084 void SetMirrorParams(LEVELINFO *lev)
00085 {
00086 MirrorType = lev->MirrorType;
00087 MirrorAlpha = (long)(lev->MirrorMix * 255) << 24;
00088
00089 MirrorAdd = lev->MirrorIntensity * 256;
00090 MirrorDist = lev->MirrorDist;
00091 MirrorMul = (256 - MirrorAdd) / MirrorDist;
00092 }
00093
00095
00097
00098 long GetMirrorPlane(VEC *pos)
00099 {
00100 long i;
00101
00102
00103
00104 for (i = 0 ; i < MirrorPlaneNum ; i++)
00105 {
00106 if (pos->v[X] < MirrorPlanes[i].Xmin ||
00107 pos->v[X] > MirrorPlanes[i].Xmax ||
00108 pos->v[Z] < MirrorPlanes[i].Zmin ||
00109 pos->v[Z] > MirrorPlanes[i].Zmax)
00110 continue;
00111
00112
00113
00114 MirrorHeight = MirrorPlanes[i].Height;
00115 return TRUE;
00116 }
00117
00118
00119
00120 return FALSE;
00121 }