コード例 #1
0
ファイル: CubeGrid.cs プロジェクト: elidiak/SpaceEditor
        public TreeNode getTreeNode()
        {
            TreeNode node = base.getTreeNode();

            if (quick_loaded == false)
            {
                if (cockpit != null)
                {
                    node.Nodes.Add("[cockpit] " + cockpit.EntityId);
                }
                node.Nodes.Add("[blockCount] " + CubeBlocks.Count());
                CubeBlock attachmentPoint = this.getBlock("LargeBlockArmorSlopeWhite");
                if (attachmentPoint != null)
                {
                    TreeNode block = new TreeNode(attachmentPoint.SubTypeName);
                    block.Nodes.Add("Up " + attachmentPoint.PositionAndOrientation.up.ToString());
                    block.Nodes.Add("Forward " + attachmentPoint.PositionAndOrientation.forward.ToString());
                    block.Nodes.Add("Orientation " + attachmentPoint.Orientation.ToString());
                    node.Nodes.Add(block);
                }
            }
            else
            {
                node.Nodes.Add("[blockCount] " + this.quick_count);
            }
            node.Tag = this;
            return(node);
        }
コード例 #2
0
        /*
         * private void thumbnailToolStripMenuItem_Click(object sender, EventArgs e)
         * {
         *  TreeNode node = SectorTree.SelectedNode;
         *  CubeGrid cg = (CubeGrid)node.Tag;
         *  pictureBox1.Image = cg.getThumbnail();
         * }
         *
         * private void loggingCheck_CheckedChanged(object sender, EventArgs e)
         * {
         *  loggingEnabled = loggingCheck.Checked;
         * }
         */



        private void importModuleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode     node   = SectorTree.SelectedNode;
            CubeGrid     cg     = (CubeGrid)node.Tag;
            DialogResult result = fileopen.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.update_status("Importing Module");
                string    filename = fileopen.FileName;
                string    xml      = File.ReadAllText(filename);
                CubeGrid  module   = sector.loadCGFragment(xml, false);
                CubeBlock module_attachment_point = module.getBlock("LargeBlockArmorCornerInvWhite");
                if (module_attachment_point != null)
                {
                    //Console.WriteLine("Got module attachment");
                    TreeNode  main_node             = SectorTree.SelectedNode;
                    CubeGrid  main                  = (CubeGrid)main_node.Tag;
                    CubeBlock main_attachment_point = main.getBlock("LargeBlockArmorCornerInvWhite");
                    if (main_attachment_point != null)
                    {
                        Console.WriteLine("Before rotation!!");
                        VRageMath.Vector3 diff = Sector.diff_orientation(main_attachment_point, module_attachment_point);

                        //Console.WriteLine("Got module attachment");

                        //Console.WriteLine("Up :" + main_attachment_point.PositionAndOrientation.up.ToString() + " " + module_attachment_point.PositionAndOrientation.up.ToString());
                        //Console.WriteLine("Forward :" + main_attachment_point.PositionAndOrientation.forward.ToString() + " " + module_attachment_point.PositionAndOrientation.forward.ToString());
                        module.reOrient(module_attachment_point);
                        //Console.WriteLine("module attachment point after reorient: "+module_attachment_point.PositionAndOrientation.position.ToString());
                        main.reOrient(main_attachment_point);
                        //lets try some rotation
                        Console.WriteLine("Steps: " + vrageMath.AngleToSteps(diff.X) + " " + vrageMath.AngleToSteps(diff.Y) + " " + vrageMath.AngleToSteps(diff.Z));
                        module.rotate_grid("X", vrageMath.AngleToSteps(diff.X));
                        module.rotate_grid("Y", vrageMath.AngleToSteps(diff.Y));
                        module.rotate_grid("Z", vrageMath.AngleToSteps(diff.Z));
                        Console.WriteLine("After rotation!!");
                        diff = Sector.diff_orientation(module_attachment_point, main_attachment_point);


                        main.merge(module);
                        SectorTree.Nodes.Clear();
                        SectorTree.Nodes.Add(sector.getTreeNode());
                    }
                }
                else
                {
                    Console.WriteLine("Couldn't get module attachment");
                }
            }
            this.update_status("");
        }
コード例 #3
0
ファイル: Sector.cs プロジェクト: Tall-Paul/SpaceEditor
 public static Vector3 diff_orientation(CubeBlock block1, CubeBlock block2)
 {
     Quaternion orientation_1 = new Quaternion((float)block1.Orientation.X, (float)block1.Orientation.Y, (float)block1.Orientation.Z, (float)block1.Orientation.W);
     Quaternion orientation_2 = new Quaternion((float)block2.Orientation.X, (float)block2.Orientation.Y, (float)block2.Orientation.Z, (float)block2.Orientation.W);
     Console.WriteLine("############## diff_orientation ########################");
     Console.Write("block 1 orientation = " );
     Vector3 vec1 = vrageMath.quat_to_angles(orientation_1);
     Console.WriteLine(MathHelper.ToDegrees(vec1.X) + " " + MathHelper.ToDegrees(vec1.Y) + " " + MathHelper.ToDegrees(vec1.Z));
     Console.Write("block 2 orientation = ");
     vec1 = vrageMath.quat_to_angles(orientation_2);
     Console.WriteLine(MathHelper.ToDegrees(vec1.X) + " " + MathHelper.ToDegrees(vec1.Y) + " " + MathHelper.ToDegrees(vec1.Z));
     Console.Write("difference = ");
     Vector3 diff = vrageMath.diff_quats(orientation_1, orientation_2);
     Console.WriteLine(MathHelper.ToDegrees(diff.X) + " " + MathHelper.ToDegrees(diff.Y) + " " + MathHelper.ToDegrees(diff.Z));
     Console.WriteLine("############## /diff_orientation ########################");
     return diff;
 }
コード例 #4
0
ファイル: Sector.cs プロジェクト: elidiak/SpaceEditor
        public static Vector3 diff_orientation(CubeBlock block1, CubeBlock block2)
        {
            Quaternion orientation_1 = new Quaternion((float)block1.Orientation.X, (float)block1.Orientation.Y, (float)block1.Orientation.Z, (float)block1.Orientation.W);
            Quaternion orientation_2 = new Quaternion((float)block2.Orientation.X, (float)block2.Orientation.Y, (float)block2.Orientation.Z, (float)block2.Orientation.W);

            Console.WriteLine("############## diff_orientation ########################");
            Console.Write("block 1 orientation = ");
            Vector3 vec1 = vrageMath.quat_to_angles(orientation_1);

            Console.WriteLine(MathHelper.ToDegrees(vec1.X) + " " + MathHelper.ToDegrees(vec1.Y) + " " + MathHelper.ToDegrees(vec1.Z));
            Console.Write("block 2 orientation = ");
            vec1 = vrageMath.quat_to_angles(orientation_2);
            Console.WriteLine(MathHelper.ToDegrees(vec1.X) + " " + MathHelper.ToDegrees(vec1.Y) + " " + MathHelper.ToDegrees(vec1.Z));
            Console.Write("difference = ");
            Vector3 diff = vrageMath.diff_quats(orientation_1, orientation_2);

            Console.WriteLine(MathHelper.ToDegrees(diff.X) + " " + MathHelper.ToDegrees(diff.Y) + " " + MathHelper.ToDegrees(diff.Z));
            Console.WriteLine("############## /diff_orientation ########################");
            return(diff);
        }
コード例 #5
0
ファイル: CubeGrid.cs プロジェクト: elidiak/SpaceEditor
        public CubeBlock loadXMLFragment(string xml)
        {
            NameTable           nt    = new NameTable();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);

            nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            XmlParserContext  context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
            XmlReaderSettings xset    = new XmlReaderSettings();

            xset.ConformanceLevel = ConformanceLevel.Fragment;
            XmlReader   rd     = XmlReader.Create(new StringReader(xml), xset, context);
            XmlDocument NewDoc = new XmlDocument();

            NewDoc.Load(rd);
            CubeBlock cb = new CubeBlock(this.parent_sector);

            cb.loadFromXML(NewDoc.SelectSingleNode("MyObjectBuilder_CubeBlock"));
            cb.new_id();
            return(cb);
        }
コード例 #6
0
ファイル: CubeGrid.cs プロジェクト: elidiak/SpaceEditor
        public void mirror(string axis)
        {
            List <CubeBlock> NewCubeBlocks = new List <CubeBlock>();

            foreach (CubeBlock cb in CubeBlocks)
            {
                CubeBlock new_cb = this.loadXMLFragment(cb.getXML());
                double    newVal = 0;
                switch (axis)
                {
                case "X":
                    new_cb.PositionAndOrientation.position.X = -new_cb.PositionAndOrientation.position.X;
                    new_cb.Min.X = -new_cb.Min.X;
                    new_cb.Max.X = -new_cb.Max.X;
                    newVal       = new_cb.PositionAndOrientation.position.X;
                    break;

                case "Y":
                    new_cb.PositionAndOrientation.position.Y = -new_cb.PositionAndOrientation.position.Y;
                    new_cb.Min.Y = -new_cb.Min.Y;
                    new_cb.Max.Y = -new_cb.Max.Y;
                    newVal       = new_cb.PositionAndOrientation.position.Y;
                    break;

                case "Z":
                    new_cb.PositionAndOrientation.position.Z = -new_cb.PositionAndOrientation.position.Z;
                    new_cb.Min.Z = -new_cb.Min.Z;
                    new_cb.Max.Z = -new_cb.Max.Z;
                    newVal       = new_cb.PositionAndOrientation.position.Z;
                    break;
                }
                if (newVal != -0)
                {
                    NewCubeBlocks.Add(new_cb);
                }
            }
            this.CubeBlocks.AddRange(NewCubeBlocks);
        }
コード例 #7
0
ファイル: CubeGrid.cs プロジェクト: elidiak/SpaceEditor
 public void reOrient(CubeBlock new_anchor)
 {
     this.dirty = true;
     reOrient(new_anchor.PositionAndOrientation.clone(), new_anchor.Min.clone(), new_anchor.Max.clone());
 }
コード例 #8
0
ファイル: CubeGrid.cs プロジェクト: elidiak/SpaceEditor
        public void loadFromXML(XmlNode node, bool quick = false)
        {
            base.loadFromXML(node);
            this.GridSizeEnum = node.SelectSingleNode("GridSizeEnum").InnerText;
            this.quick_loaded = quick;
            XmlNodeList blocks = node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock");

            if (quick == false)
            {
                Console.WriteLine("Loading blocks...");
                foreach (XmlNode block in blocks)
                {
                    CubeBlock new_block = new CubeBlock(this.parent_sector);
                    new_block.loadFromXML(block);
                    if (new_block.SubTypeName == "LargeBlockCockpit" || new_block.SubTypeName == "SmallBlockCockpit")
                    {
                        this.cockpit = new_block;
                        if (new_block.hasPilot == true)
                        {
                            Console.WriteLine("Grid has pilot");
                            this.hasPilot          = true;
                            new_block.Pilot.parent = this.EntityId;
                            this.Pilot             = new_block.Pilot;
                        }
                    }
                    CubeBlocks.Add(new_block);
                }
            }
            else
            {
                this.raw = node.SelectSingleNode("CubeBlocks").OuterXml;
                Console.WriteLine("Quick loaded");
                this.quick_count = blocks.Count;
            }
            try
            {
                IsStatic = node.SelectSingleNode("IsStatic").InnerText;
                LinearVelocity.loadFromXML(node.SelectSingleNode("LinearVelocity"));
                AngularVelocity.loadFromXML(node.SelectSingleNode("AngularVelocity"));
            }
            catch (NullReferenceException) { }
            if (this.GridSizeEnum == "Large")
            {
                if (this.IsStatic == "true")
                {
                    this.displayType = "Station";
                }
                else
                {
                    this.displayType = "Large Ship";
                }
            }
            if (this.GridSizeEnum == "Small")
            {
                this.displayType = "Small Ship";
            }
            if (this.hasPilot == true)
            {
                this.displayType = "[*] " + this.displayType;
            }
            this.actualType = "Ship";
            Console.WriteLine("Loaded");
            //Console.WriteLine("Loaded "+displayType+" with "+CubeBlocks.Count +" blocks");
        }
コード例 #9
0
ファイル: CubeGrid.cs プロジェクト: Tall-Paul/SpaceEditor
 public void reOrient(CubeBlock new_anchor)
 {
     this.dirty = true;
     reOrient(new_anchor.PositionAndOrientation.clone(), new_anchor.Min.clone(), new_anchor.Max.clone());
 }
コード例 #10
0
ファイル: CubeGrid.cs プロジェクト: Tall-Paul/SpaceEditor
 public CubeBlock loadXMLFragment(string xml)
 {
     NameTable nt = new NameTable();
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
     nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
     XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
     XmlReaderSettings xset = new XmlReaderSettings();
     xset.ConformanceLevel = ConformanceLevel.Fragment;
     XmlReader rd = XmlReader.Create(new StringReader(xml), xset, context);
     XmlDocument NewDoc = new XmlDocument();
     NewDoc.Load(rd);
     CubeBlock cb = new CubeBlock(this.parent_sector);
     cb.loadFromXML(NewDoc.SelectSingleNode("MyObjectBuilder_CubeBlock"));
     cb.new_id();
     return cb;
 }
コード例 #11
0
ファイル: CubeGrid.cs プロジェクト: Tall-Paul/SpaceEditor
 public void loadFromXML(XmlNode node, bool quick = false)
 {
     base.loadFromXML(node);
     this.GridSizeEnum = node.SelectSingleNode("GridSizeEnum").InnerText;
     this.quick_loaded = quick;
     XmlNodeList blocks = node.SelectNodes("CubeBlocks/MyObjectBuilder_CubeBlock");
     if (quick == false)
     {
         Console.WriteLine("Loading blocks...");
         foreach (XmlNode block in blocks)
         {
             CubeBlock new_block = new CubeBlock(this.parent_sector);
             new_block.loadFromXML(block);
             if (new_block.SubTypeName == "LargeBlockCockpit" || new_block.SubTypeName == "SmallBlockCockpit")
             {
                 this.cockpit = new_block;
                 if (new_block.hasPilot == true)
                 {
                     Console.WriteLine("Grid has pilot");
                     this.hasPilot = true;
                     new_block.Pilot.parent = this.EntityId;
                     this.Pilot = new_block.Pilot;
                 }
             }
             CubeBlocks.Add(new_block);
         }
     }
     else
     {
         this.raw = node.SelectSingleNode("CubeBlocks").OuterXml;
         Console.WriteLine("Quick loaded");
         this.quick_count = blocks.Count;
     }
     try
     {
         IsStatic = node.SelectSingleNode("IsStatic").InnerText;
         LinearVelocity.loadFromXML(node.SelectSingleNode("LinearVelocity"));
         AngularVelocity.loadFromXML(node.SelectSingleNode("AngularVelocity"));
     }
     catch (NullReferenceException) { }
     if (this.GridSizeEnum == "Large")
         if (this.IsStatic == "true")
             this.displayType = "Station";
         else
             this.displayType = "Large Ship";
     if (this.GridSizeEnum == "Small")
         this.displayType = "Small Ship";
     if (this.hasPilot == true)
     {
         this.displayType = "[*] " + this.displayType;
     }
     this.actualType = "Ship";
     Console.WriteLine("Loaded");
     //Console.WriteLine("Loaded "+displayType+" with "+CubeBlocks.Count +" blocks");
 }