Ejemplo n.º 1
0
        public CModel()
        {
            mod_novis = new byte[CQ2BSP.MAX_MAP_LEAFS / 8];

            for (int i = 0; i < (CQ2BSP.MAX_MAP_LEAFS / 8); i++)
            {
                mod_novis[i] = 0xff;
            }

            mod_numknown = 1; // slot 0 is always reserved for the worldmodel
            mod_known = new SModel[MAX_MOD_KNOWN];
            mod_inline = new SModel[MAX_MOD_KNOWN];

            for (int i = 0; i < MAX_MOD_KNOWN; i++)
            {
                mod_known[i] = new SModel();
                mod_inline[i] = new SModel();
            }

            NullModel = new SModel();
            CQ2BSP.SWorldData = new SModel();
        }
Ejemplo n.º 2
0
 public Form1()
 {
     InitializeComponent();
     store = new SModel();
 }
Ejemplo n.º 3
0
        public SModel Mod_ForName(string Name, bool Crash)
        {
            int i;
            byte[] header;
            MemoryStream ms;
            SModel _SModel;

            _SModel = new SModel();

            if (string.IsNullOrWhiteSpace(Name) == true | string.IsNullOrEmpty(Name) == true)
            {
                System.Diagnostics.Debug.WriteLine("Mod_ForName: NULL name");
                return _SModel;
            }

            //
            // inline models are grabbed only from worldmodel
            //
            if (Name.StartsWith("*") == true)
            {
                i = Convert.ToInt32(Name.Substring(1));
                if (i < 1 /*|| CQ2BSP.SWorldData == null ||*/ | i >= CQ2BSP.SWorldData.numsubmodels)
                    System.Diagnostics.Debug.WriteLine("bad inline model number");

                return mod_inline[i];
            }

            //
            // search the currently loaded models
            //
            for (i = 1; i < mod_numknown; i++)
            {
                if (string.IsNullOrWhiteSpace(mod_known[i].name) == true | string.IsNullOrEmpty(mod_known[i].name) == true)
                    continue;

                if (mod_known[i].name == Name)
                    return mod_known[i];
            }

            //
            // find a free model slot spot
            //
            for (i = 1; i < mod_numknown; i++)
            {
                if (string.IsNullOrWhiteSpace(mod_known[i].name) == true | string.IsNullOrEmpty(mod_known[i].name) == true)
                    break; // free spot
            }

            if (i == mod_numknown)
            {
                if (mod_numknown == MAX_MOD_KNOWN)
                {
                    System.Diagnostics.Debug.WriteLine("mod_numknown == MAX_MOD_KNOWN");
                    return _SModel;
                }

                mod_numknown++;
            }

            _SModel.name = Name;

            //
            // load the file
            //
            ms = null;
            if (CProgram.gQ2Game.gCMain.r_usepak == true)
            {
                CProgram.gQ2Game.gCMain.gCFiles.FS_ReadFile(Name, out ms);
            }
            else
            {
                string FilePath = CProgram.gQ2Game.Content.RootDirectory + "\\" + CConfig.GetConfigSTRING("Base Game") + "\\" + Name;
                FileStream _fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] buf = new byte[_fs.Length];

                _fs.Read(buf, 0, (int)_fs.Length);
                ms = new MemoryStream(buf);

                if (_fs != null)
                    _fs.Close();
            }

            if (ms == null | ms.Length == 0)
            {
                _SModel.name = null;

                if (Crash == true)
                    System.Diagnostics.Debug.WriteLine("Mod_NumForName: " + _SModel.name + " not found");

                return _SModel;
            }

            //
            // fill it in
            //

            header = new byte[4];
            ms.Read(header, 0, 4);
            ms.Seek(0, System.IO.SeekOrigin.Begin);

            // call the apropriate loader
            switch ((int)((header[3] << 24) + (header[2] << 16) + (header[1] << 8) + header[0]))
            {
                case CQ2MD2.IDALIASHEADER:
                    CProgram.gQ2Game.gCMain.gCQ2MD2.Mod_LoadAliasModel(ref _SModel, ms);
                    break;

                //case IDSPRITEHEADER:
                //    loadmodel->extradata = Hunk_Begin (0x10000);
                //    Mod_LoadSpriteModel (mod, buf);
                //    break;

                case CQ2BSP.IDBSPHEADER:
                    CProgram.gQ2Game.gCMain.gCQ2BSP.Mod_LoadBrushModel(ref _SModel, ms);
                    break;

                default:
                    System.Diagnostics.Debug.WriteLine("Mod_NumForName: unknown fileid for " + _SModel.name);
                    break;
            }

            if (ms != null)
                ms.Close();

            mod_known[i] = _SModel;

            return _SModel;
        }
Ejemplo n.º 4
0
        public static void CalcSurfaceExtents(ref SModel _SModel, ref SMSurface mface)
        {
            float[] mins;
            float[] maxs;
            int[] bmins;
            int[] bmaxs;
            float val;
            SMVertex v;
            SMTexInfo tex;

            mface.texturemins = new short[2];
            mface.extents = new short[2];

            mins = new float[2];
            maxs = new float[2];

            bmins = new int[2];
            bmaxs = new int[2];

            mins[0] = mins[1] = 999999;
            maxs[0] = maxs[1] = -999999;

            tex = _SModel.texinfo[mface.texinfo];

            for (int i = 0; i < mface.numedges; i++)
            {
                int e = _SModel.surfedges[mface.firstedge + i];

                if (e >= 0)
                    v = _SModel.vertexes[_SModel.edges[e].v[0]];
                else
                    v = _SModel.vertexes[_SModel.edges[-e].v[1]];

                for (int j = 0; j < 2; j++)
                {
                    Vector3 vec;
                    vec.X = tex.vecs[j].X;
                    vec.Y = tex.vecs[j].Y;
                    vec.Z = tex.vecs[j].Z;

                    val = Vector3.Dot(v.Position, vec) + tex.vecs[j].W;

                    if (val < mins[j])
                        mins[j] = val;
                    if (val > maxs[j])
                        maxs[j] = val;
                }
            }

            for (int i = 0; i < 2; i++)
            {
                bmins[i] = (int)Math.Floor(mins[i] / 16);
                bmaxs[i] = (int)Math.Ceiling(maxs[i] / 16);

                mface.texturemins[i] = (short)(bmins[i] * 16);
                mface.extents[i] = (short)((bmaxs[i] - bmins[i]) * 16);
            }
        }