Exemple #1
0
        //************************************************************************************************
        //
        //************************************************************************************************

        static public float NormalizeRad(float angle, NORM norm, GPS.TYPE type = GPS.TYPE.LONGITUDE)
        {
            int revs = ( int )(angle / PI_MUL2);

            angle -= (( float )revs * PI_MUL2);

            if (angle < 0.0f)
            {
                angle += PI_MUL2;
            }


            if ((norm == NORM.NEG) && (angle > PI))
            {
                angle -= PI_MUL2;
            }

            if (type == GPS.TYPE.LATITUDE)
            {
                if (angle > PI_34)
                {
                    angle = -PI_MUL2 + angle;
                }

                else if (angle > PI)
                {
                    angle = -PI + angle;
                }

                else if (angle > PI_DIV2)
                {
                    angle = PI - angle;
                }

                else if (angle < -PI_DIV2)
                {
                    angle = -PI - angle;
                }
            }

            return(angle);
        }
Exemple #2
0
        //************************************************************************************************
        //
        //************************************************************************************************

        static public float NormalizeDeg(float angle, NORM norm, GPS.TYPE type = GPS.TYPE.LONGITUDE)
        {
            int revs = ( int )(angle / 360.0f);

            angle -= (( float )revs * 360.0f);

            if (angle < 0.0f)
            {
                angle += 360.0f;
            }


            if ((norm == NORM.NEG) && (angle > 180.0f))
            {
                angle -= 360.0f;
            }

            if (type == GPS.TYPE.LATITUDE)
            {
                if (angle > 270.0f)
                {
                    angle = -360.0f + angle;
                }

                else if (angle > 180.0f)
                {
                    angle = -180.0f + angle;
                }

                else if (angle > 90.0f)
                {
                    angle = 180.0f - angle;
                }

                else if (angle < -90.0f)
                {
                    angle = -180.0f - angle;
                }
            }

            return(angle);
        }
Exemple #3
0
        /// <summary>
        /// takes in list of items contained in a NORM node and builds JSRF binary of NORM children
        /// </summary>
        /// <param name="nNORM"></param>
        /// <returns></returns>
        private byte[] build_NORM_children(NORM nNORM)
        {
            List <byte[]> item_data_list   = new List <byte[]>();
            int           item_data_offset = 32;

            // for each child item inside nNORM
            for (int c = 0; c < nNORM.items.Count; c++)
            {
                item cItem = nNORM.items[c];

                #region build item header

                // start offset // headers size + data length of previous items
                item_data_list.Add(BitConverter.GetBytes((Int32)item_data_offset)); //(c+1) * 16
                                                                                    // end offset
                item_data_list.Add(BitConverter.GetBytes((Int32)item_data_offset + cItem.data.Length));
                // size??
                item_data_list.Add(BitConverter.GetBytes((Int32)cItem.data.Length));
                // flag
                if (cItem.data.Length > 0)
                {
                    item_data_list.Add(BitConverter.GetBytes((Int32)0));
                }
                else // if empty set this to 1
                {
                    item_data_list.Add(BitConverter.GetBytes((Int32)1));
                }

                #endregion

                // add dataa
                item_data_list.Add(cItem.data);

                // increase position (header size + data size)
                item_data_offset += 16 + cItem.data.Length;
            }

            // merge list items into array and return
            return(item_data_list.SelectMany(a => a).ToArray());
        }
Exemple #4
0
        /// <summary>
        /// rebuilds JSRF container file structure and its data (based on MULT items list) and writes to binary file
        /// </summary>
        /// <param name="filepath_output"></param>
        public void rebuild_file(string filepath_output)
        {
            List <byte[]> file_buffer = new List <byte[]>();

            #region build for MULT file

            if (this.type == container_types.MULT)
            {
                #region build for MULT header

                // build MULT header (16 bytes)
                file_buffer.Add(Encoding.ASCII.GetBytes("MULT"));
                // number of children (NORMs)
                file_buffer.Add(BitConverter.GetBytes((Int32)this.MULT_root.items.Count));
                // padding
                file_buffer.Add(new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 });

                #endregion


                int mult_child_offset = 32;

                // for each NORM inside MULT
                for (int n = 0; n < this.MULT_root.items.Count; n++)
                {
                    NORM nNORM = this.MULT_root.items[n];

                    // merge item data
                    byte[] item_data = build_NORM_children(nNORM);

                    #region build MULT child header

                    // start offset
                    file_buffer.Add(BitConverter.GetBytes((Int32)mult_child_offset));
                    // end offset (item_data length + item header length)
                    file_buffer.Add(BitConverter.GetBytes((Int32)mult_child_offset + item_data.Length + 16));
                    // size
                    file_buffer.Add(BitConverter.GetBytes((Int32)item_data.Length + 16));
                    // flag
                    file_buffer.Add(BitConverter.GetBytes((Int32)0));

                    #endregion


                    #region build NORM header

                    // build MULT header (16 bytes)
                    file_buffer.Add(Encoding.ASCII.GetBytes("NORM"));
                    // number of children (NORMs)
                    file_buffer.Add(BitConverter.GetBytes((Int32)nNORM.items.Count));
                    // padding
                    file_buffer.Add(new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 });

                    #endregion

                    // write item data
                    file_buffer.Add(item_data);

                    // increase position (header size + data size)
                    mult_child_offset += item_data.Length + 32;
                }
            }

            #endregion



            #region build for NORM root file

            if (this.type == container_types.NORM)
            {
                NORM nNORM = this.NORM_root;

                // merge item data
                byte[] item_data = build_NORM_children(nNORM);

                #region build NORM header

                // build MULT header (16 bytes)
                file_buffer.Add(Encoding.ASCII.GetBytes("NORM"));
                // number of children (NORMs)
                file_buffer.Add(BitConverter.GetBytes((Int32)nNORM.items.Count));
                // padding
                file_buffer.Add(new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 });

                #endregion

                // write item data
                file_buffer.Add(item_data);
            }

            #endregion



            #region build for Indexed root file

            if (this.type == container_types.indexed)
            {
                //NORM nNORM = this.NORM_root;
                INDEXED nIndexed = this.INDX_root;

                // merge item data
                byte[] item_data = build_Indexed_children(nIndexed);

                #region build NORM header

                // build MULT header (16 bytes)
                // file_buffer.Add(Encoding.ASCII.GetBytes("NORM"));
                // number of children (NORMs)
                file_buffer.Add(BitConverter.GetBytes((Int32)nIndexed.items.Count));
                // padding
                file_buffer.Add(new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 });

                #endregion

                // write item data
                file_buffer.Add(item_data);
            }

            #endregion


            File.WriteAllBytes(filepath_output, file_buffer.SelectMany(a => a).ToArray());
        }
Exemple #5
0
        public File_Containers(string filepath = "")
        {
            if (filepath == "")
            {
                return;
            }
            if (!File.Exists(filepath))
            {
                return;
            }

            this.filepath = filepath;

            this.file_data = Parsing.FileToByteArray(filepath, 0);

            if (this.file_data.Length == 0)
            {
                MessageBox.Show("File is empty");
                return;
            }

            byte[] type = new byte[4];
            Array.Copy(this.file_data, 0, type, 0, 4);

            string header_type = System.Text.Encoding.UTF8.GetString(type);

            this.type = container_types.unknown;



            if (header_type == "MULT")
            {
                this.type = container_types.MULT;

                byte[] childs_buffer = new byte[file_data.Length];            //file_data.Length - 16]
                Array.Copy(file_data, 0, childs_buffer, 0, file_data.Length); //Array.Copy(file_data, 16, childs_buffer, 0, file_data.Length);

                List <byte[]> NORMs_buffers = get_children(childs_buffer);

                List <NORM> NORM_list = new List <NORM>();

                // for each NORM contained in the MULT
                // get the children data
                foreach (var NORM_buff in NORMs_buffers)
                {
                    List <byte[]> items_data = get_children(NORM_buff);

                    NORM n = new NORM();
                    // for each item contained in the NORM
                    // get the children data
                    foreach (var item_data in items_data)
                    {
                        // add item to NORM n
                        n.items.Add(new item(get_item_data_type(item_data), item_data));
                    }
                    NORM_list.Add(n);
                }

                this.MULT_root       = new MULT();
                this.MULT_root.items = NORM_list;
            }


            if (header_type == "NORM")
            {
                this.type = container_types.NORM;

                byte[] childs_buffer = new byte[file_data.Length];            //file_data.Length - 16]
                Array.Copy(file_data, 0, childs_buffer, 0, file_data.Length); //Array.Copy(file_data, 16, childs_buffer, 0, file_data.Length);

                List <byte[]> items_data = get_children(childs_buffer);

                List <NORM> NORM_list = new List <NORM>();

                NORM n = new NORM();
                // for each item contained in the NORM
                // get the children data
                foreach (var item_data in items_data)
                {
                    // add item to NORM n
                    n.items.Add(new item(get_item_data_type(item_data), item_data));
                }

                this.NORM_root = new NORM();
                this.NORM_root = n;
            }

            // indexed (no header name)
            if ((file_data[0] == 1 & file_data[1] == 0 & file_data[2] == 0 & file_data[3] == 0) || (file_data[0] == 0 & file_data[1] == 0 & file_data[2] == 0 & file_data[3] == 0))
            {
                this.type = container_types.indexed;

                File_Headers.Indexed_container indexed_items = new File_Headers.Indexed_container();
                indexed_items.get_Indexed(file_data, 0, file_data.Length);

                INDX_root       = new INDEXED();
                INDX_root.items = new List <item>();

                for (int i = 0; i < indexed_items.childs.Count; i++)
                {
                    item indx_item;
                    if (indexed_items.childs[i].block_end < 0)
                    {
                        MessageBox.Show("Error: invalid file structure."); break;
                    }
                    byte[] childs_buffer = new byte[indexed_items.childs[i].block_end - indexed_items.childs[i].block_start];
                    Array.Copy(file_data, indexed_items.childs[i].block_start, childs_buffer, 0, indexed_items.childs[i].block_end - indexed_items.childs[i].block_start);

                    item_data_type t = get_item_data_type(childs_buffer);

                    if (t == item_data_type.Texture)
                    {
                        // byte[] tex_buff = new byte[indexed_items.childs[i].block_end - indexed_items.childs[i].block_start];
                        Array.Copy(file_data, indexed_items.childs[i].block_start + 8, childs_buffer, 0, indexed_items.childs[i].block_end - indexed_items.childs[i].block_start);

                        indx_item = new item(t, childs_buffer);
                    }
                    else
                    {
                        indx_item = new item(t, childs_buffer);
                    }



                    INDX_root.items.Add(indx_item);
                }
            }
        }
Exemple #6
0
        //************************************************************************************************
        //
        //************************************************************************************************

        static public float Normalize(float angle, UNIT unit, NORM norm, GPS.TYPE type = GPS.TYPE.LONGITUDE)
        {
            return(NormalizeFunc[( int )unit](angle, norm, type));
        }