Exemplo n.º 1
0
		public BaseEntity( MyObjectBuilder_EntityBase baseEntity )
			: base( baseEntity )
		{
			if ( baseEntity != null )
			{
				m_entityId = baseEntity.EntityId;
				if ( baseEntity.PositionAndOrientation != null )
				{
					m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault( );
				}
				else
				{
					m_positionOrientation = new MyPositionAndOrientation( );
					m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition( new Vector3D( -500000, -500000, -500000 ), new Vector3D( 500000, 500000, 500000 ) );
					m_positionOrientation.Forward = new Vector3( 0, 0, 1 );
					m_positionOrientation.Up = new Vector3( 0, 1, 0 );
				}
			}
			else
			{
				m_entityId = 0;
				m_positionOrientation = new MyPositionAndOrientation( );
				m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition( new Vector3( -500000, -500000, -500000 ), new Vector3( 500000, 500000, 500000 ) );
				m_positionOrientation.Forward = new Vector3( 0, 0, 1 );
				m_positionOrientation.Up = new Vector3( 0, 1, 0 );
			}

			m_linearVelocity = new Vector3( 0, 0, 0 );
			m_angularVelocity = new Vector3( 0, 0, 0 );
			m_maxLinearVelocity = (float)104.7;
		}
Exemplo n.º 2
0
 public void Load(MyPositionAndOrientation characterPosition)
 {
     CharacterPosition = characterPosition;
 }
Exemplo n.º 3
0
        public void Rotation()
        {
            var positionAndOrientation = new MyPositionAndOrientation(
                    new SerializableVector3D(10.0d, -10.0d, -2.5d),
                    new SerializableVector3(0.0f, 0.0f, -1.0f),
                    new SerializableVector3(0.0f, 1.0f, 0.0f));

            // -90 around Z
            var quaternion = Quaternion.CreateFromYawPitchRoll(0, 0, -VRageMath.MathHelper.PiOver2);
            var o = positionAndOrientation.ToQuaternion() * quaternion;
            var on = Quaternion.Normalize(o);
            var p = new MyPositionAndOrientation(on.ToMatrix());

            var quaternion2 = QuaternionD.CreateFromYawPitchRoll(0, 0, -Math.PI / 2);
            var o2 = positionAndOrientation.ToQuaternionD() * quaternion2;
            var on2 = QuaternionD.Normalize(o2);
            var p2 = new MyPositionAndOrientation(on2.ToMatrixD());

            var quaternion3 = new System.Windows.Media.Media3D.Quaternion(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), -90d);
            var x3 = positionAndOrientation.ToQuaternionD();
            var o3 = new System.Windows.Media.Media3D.Quaternion(x3.X, x3.Y, x3.Z, x3.W)*quaternion3;
            var on3 = o3;
            on3.Normalize();


            double num = on3.X * on3.X;
            double num3 = on3.Z * on3.Z;
            double num4 = on3.X * on3.Y;
            double num5 = on3.Z * on3.W;
            double num8 = on3.Y * on3.Z;
            double num9 = on3.X * on3.W;
            var M21 = (2.0d * (num4 - num5));
            var M22 = (1.0d - 2.0d * (num3 + num));
            var M23 = (2.0d * (num8 + num9));

            var up3 = new Vector3D(M21, M22, M23);

            


            var fwd = new SerializableVector3(0.0f, 0.0f, -1.0f);
            var up = new SerializableVector3(1.0f, 0.0f, 0.0f);

            Assert.AreEqual(fwd.X, p.Forward.X, "Forward.X Should Equal");
            Assert.AreEqual(fwd.Y, p.Forward.Y, "Forward.Y Should Equal");
            Assert.AreEqual(fwd.Z, p.Forward.Z, "Forward.Z Should Equal");
            Assert.AreEqual(up.X, p.Up.X, "Up.X Should Equal");
            Assert.AreEqual(up.Y, p.Up.Y, "Up.Y Should Equal");
            Assert.AreEqual(up.Z, p.Up.Z, "Up.Z Should Equal");
        }
Exemplo n.º 4
0
        public void CubeRotate()
        {
            var positionOrientation = new MyPositionAndOrientation(new Vector3D(10, 10, 10), Vector3.Backward, Vector3.Up);
            var gridSizeEnum = MyCubeSize.Large;

            var cube = (MyObjectBuilder_CubeBlock)MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock");
            //var cube = (MyObjectBuilder_CubeBlock)MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_Thrust), "LargeBlockLargeThrust");
            cube.Min = new SerializableVector3I(10, 10, 10);
            cube.BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up);
            cube.BuildPercent = 1;

            var quaternion = positionOrientation.ToQuaternionD();
            var definition = SpaceEngineersApi.GetCubeDefinition(cube.TypeId, gridSizeEnum, cube.SubtypeName);


            var orientSize = definition.Size.Transform(cube.BlockOrientation).Abs();
            var min = cube.Min.ToVector3D() * gridSizeEnum.ToLength();
            var max = (cube.Min + orientSize).ToVector3D() * gridSizeEnum.ToLength();
            var p1 = min.Transform(quaternion) + positionOrientation.Position;
            var p2 = max.Transform(quaternion) + positionOrientation.Position;
            var nb = new BoundingBoxD(p1, p2);
        }
Exemplo n.º 5
0
        public void Load(MyPositionAndOrientation characterPosition)
        {
            if (!_isInitialValueSet)
            {
                // only set the position first time opened and cache.
                CenterPositionX = characterPosition.Position.X;
                CenterPositionY = characterPosition.Position.Y;
                CenterPositionZ = characterPosition.Position.Z;
                AsteroidFillType = AsteroidFillType.ByteFiller;
                _isInitialValueSet = true;
            }

            MaterialsCollection.Clear();
            foreach (var material in SpaceEngineersCore.Resources.VoxelMaterialDefinitions)
            {
                MaterialsCollection.Add(new MaterialSelectionModel { Value = material.Id.SubtypeName, DisplayName = material.Id.SubtypeName, IsRare = material.IsRare, MinedRatio = material.MinedOreRatio });
            }

            BaseMaterial = MaterialsCollection.FirstOrDefault(m => m.IsRare == false) ?? MaterialsCollection.FirstOrDefault();

            // Voxel Map Storage, includes stock and mod asteroids.
            var vms = SpaceEngineersCore.Resources.VoxelMapStorageDefinitions;
            var contentPath = ToolboxUpdater.GetApplicationContentPath();
            var list = new List<GenerateVoxelDetailModel>();

            foreach (var voxelMap in vms)
            {
                var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile));

                if (!File.Exists(fileName))
                    continue;

                var voxel = new GenerateVoxelDetailModel
                {
                    Name = Path.GetFileNameWithoutExtension(voxelMap.StorageFile),
                    SourceFilename = fileName,
                    FileSize = new FileInfo(fileName).Length,
                    Size = MyVoxelMap.LoadVoxelSize(fileName)
                };
                list.Add(voxel);
            }

            // Custom voxel files directory.
            List<string> files = new List<string>();
            if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath))
	        {
 	            files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension));
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension));
 	        }

            list.AddRange(files.Select(file => new GenerateVoxelDetailModel
            {
 	            Name = Path.GetFileNameWithoutExtension(file),
 	            SourceFilename = file,
 	            FileSize = new FileInfo(file).Length,
 	            Size = MyVoxelMap.LoadVoxelSize(file)
 	        }));

            VoxelFileList = new ObservableCollection<GenerateVoxelDetailModel>(list.OrderBy(s => s.Name));

            // Set up a default start.
            if (VoxelStore.Count == 0)
            {
                VoxelCollection.Add(NewDefaultVoxel(1));
            }
            else
            {
                foreach (var item in VoxelStore)
                {
                    var v1 = (AsteroidByteFillProperties)item.Clone();
                    v1.VoxelFile = VoxelFileList.FirstOrDefault(v => v.Name == v1.VoxelFile.Name);
                    v1.MainMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.MainMaterial.DisplayName);
                    v1.SecondMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SecondMaterial.DisplayName);
                    v1.ThirdMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.ThirdMaterial.DisplayName);
                    v1.FourthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.FourthMaterial.DisplayName);
                    v1.FifthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.FifthMaterial.DisplayName);
                    v1.SixthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SixthMaterial.DisplayName);
                    v1.SeventhMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SeventhMaterial.DisplayName);
                    VoxelCollection.Add(v1);
                }
                RenumberCollection();
            }

            for (var i = 0; i < 100; i++)
            {
                PercentList.Add(i);
            }
        }
Exemplo n.º 6
0
        public void Load(MyPositionAndOrientation characterPosition)
        {
            CharacterPosition = characterPosition;

            var vms = SpaceEngineersCore.Resources.VoxelMapStorageDefinitions;
            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            foreach (var voxelMap in vms)
            {
                var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile));

                if (!File.Exists(fileName))
                    continue;

                var voxel = new GenerateVoxelDetailModel
                {
                    Name = Path.GetFileNameWithoutExtension(voxelMap.StorageFile),
                    SourceFilename = fileName,
                    FileSize = new FileInfo(fileName).Length,
                    Size = MyVoxelMap.LoadVoxelSize(fileName)
                };
                VoxelFileList.Add(voxel);
            }

            // Custom voxel files directory.
            List<string> files = new List<string>();
            if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath))
            {
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension));
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension));
            }

            VoxelFileList.AddRange(files.Select(file => new GenerateVoxelDetailModel
            {
                Name = Path.GetFileNameWithoutExtension(file),
                SourceFilename = file,
                FileSize = new FileInfo(file).Length,
                Size = MyVoxelMap.LoadVoxelSize(file)
            }));


            VoxelFileList = VoxelFileList.OrderBy(s => s.Name).ToList();
        }
        public void AddItemExecuted()
        {
            var model = new GenerateFloatingObjectModel();
            var position = new MyPositionAndOrientation(Vector3D.Zero, Vector3.Forward, Vector3.Up);
            var settings = SpaceEngineersCore.WorldResource.Checkpoint.Settings;

            model.Load(position, settings.MaxFloatingObjects);
            var loadVm = new GenerateFloatingObjectViewModel(this, model);
            var result = _dialogService.ShowDialog<WindowGenerateFloatingObject>(this, loadVm);
            if (result == true)
            {
                var newEntities = loadVm.BuildEntities();
                if (loadVm.IsValidItemToImport)
                {
                    for (var i = 0; i < newEntities.Length; i++)
                    {
                        var item = ((MyObjectBuilder_FloatingObject)newEntities[i]).Item;
                        _dataModel.Additem(item);
                    }

                    //  TODO: need to bubble change up to MainViewModel.IsModified = true;
                }
            }
        }
            public override void Init(MyObjectBuilder_WorldGeneratorOperation builder)
            {
                base.Init(builder);
                var ob = builder as MyObjectBuilder_WorldGeneratorOperation_AddShipPrefab;

                PrefabFile         = ob.PrefabFile;
                UseFirstGridOrigin = ob.UseFirstGridOrigin;
                Transform          = ob.Transform;
                RandomRadius       = ob.RandomRadius;
            }
 public MyObjectBuilder_VoxelMap(Vector3 position, string storageName)
     : base()
 {
     PositionAndOrientation = new MyPositionAndOrientation(position, Vector3.Forward, Vector3.Up);
     StorageName = storageName;
 }
 public MyObjectBuilder_VoxelMap()
     : base()
 {
     PositionAndOrientation = new MyPositionAndOrientation(Vector3.Zero, Vector3.Forward, Vector3.Up);
 }
Exemplo n.º 11
0
		public BaseEntity( MyObjectBuilder_EntityBase baseEntity, Object backingObject )
			: base( baseEntity, backingObject )
		{
			if ( baseEntity != null )
			{
				m_entityId = baseEntity.EntityId;
				if ( baseEntity.PositionAndOrientation != null )
				{
					m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault( );
				}
				else
				{
					m_positionOrientation = new MyPositionAndOrientation( );
					m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition( new Vector3( -500000, -500000, -500000 ), new Vector3( 500000, 500000, 500000 ) );
					m_positionOrientation.Forward = new Vector3( 0, 0, 1 );
					m_positionOrientation.Up = new Vector3( 0, 1, 0 );
				}
			}
			else
			{
				m_entityId = 0;
				m_positionOrientation = new MyPositionAndOrientation( );
				m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition( new Vector3( -500000, -500000, -500000 ), new Vector3( 500000, 500000, 500000 ) );
				m_positionOrientation.Forward = new Vector3( 0, 0, 1 );
				m_positionOrientation.Up = new Vector3( 0, 1, 0 );
			}

			m_networkManager = new BaseEntityNetworkManager( this, GetEntityNetworkManager( BackingObject ) );

			m_linearVelocity = new Vector3( 0, 0, 0 );
			m_angularVelocity = new Vector3( 0, 0, 0 );
			m_maxLinearVelocity = (float)104.7;

			if ( EntityId != 0 )
			{
				GameEntityManager.AddEntity( EntityId, this );
			}

			MySandboxGame.Static.Invoke( InternalRegisterEntityMovedEvent );
		}
        public void Load(MyPositionAndOrientation characterPosition, float maxFloatingObjects)
        {
            MaxFloatingObjects = maxFloatingObjects;
            CharacterPosition = characterPosition;
            StockItemList.Clear();
            var list = new List<ComponentItemModel>();
            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            foreach (var componentDefinition in SpaceEngineersCore.Resources.ComponentDefinitions)
            {
                var bp = SpaceEngineersApi.GetBlueprint(componentDefinition.Id.TypeId, componentDefinition.Id.SubtypeName);
                list.Add(new ComponentItemModel
                {
                    Name = componentDefinition.DisplayNameText,
                    TypeId = componentDefinition.Id.TypeId,
                    SubtypeId = componentDefinition.Id.SubtypeName,
                    Mass = componentDefinition.Mass,
                    TextureFile = componentDefinition.Icons == null ? null : SpaceEngineersCore.GetDataPathOrDefault(componentDefinition.Icons.First(), Path.Combine(contentPath, componentDefinition.Icons.First())),
                    Volume = componentDefinition.Volume * SpaceEngineersConsts.VolumeMultiplyer,
                    Accessible = componentDefinition.Public,
                    Time = bp != null ? TimeSpan.FromSeconds(TimeSpan.TicksPerSecond * bp.BaseProductionTimeInSeconds) : (TimeSpan?)null,
                });
            }

            foreach (var physicalItemDefinition in SpaceEngineersCore.Resources.PhysicalItemDefinitions)
            {
                if (physicalItemDefinition.Id.SubtypeName == "CubePlacerItem" || physicalItemDefinition.Id.SubtypeName == "WallPlacerItem")
                    continue;

                var bp = SpaceEngineersApi.GetBlueprint(physicalItemDefinition.Id.TypeId, physicalItemDefinition.Id.SubtypeName);
                list.Add(new ComponentItemModel
                {
                    Name = physicalItemDefinition.DisplayNameText,
                    TypeId = physicalItemDefinition.Id.TypeId,
                    SubtypeId = physicalItemDefinition.Id.SubtypeName,
                    Mass = physicalItemDefinition.Mass,
                    Volume = physicalItemDefinition.Volume * SpaceEngineersConsts.VolumeMultiplyer,
                    TextureFile = physicalItemDefinition.Icons == null ? null : SpaceEngineersCore.GetDataPathOrDefault(physicalItemDefinition.Icons.First(), Path.Combine(contentPath, physicalItemDefinition.Icons.First())),
                    Accessible = physicalItemDefinition.Public,
                    Time = bp != null ? TimeSpan.FromSeconds(bp.BaseProductionTimeInSeconds) : (TimeSpan?)null,
                });
            }

            foreach (var physicalItemDefinition in SpaceEngineersCore.Resources.AmmoMagazineDefinitions)
            {
                var bp = SpaceEngineersApi.GetBlueprint(physicalItemDefinition.Id.TypeId, physicalItemDefinition.Id.SubtypeName);
                list.Add(new ComponentItemModel
                {
                    Name = physicalItemDefinition.DisplayNameText,
                    TypeId = physicalItemDefinition.Id.TypeId,
                    SubtypeId = physicalItemDefinition.Id.SubtypeName,
                    Mass = physicalItemDefinition.Mass,
                    Volume = physicalItemDefinition.Volume * SpaceEngineersConsts.VolumeMultiplyer,
                    TextureFile = physicalItemDefinition.Icons == null ? null : SpaceEngineersCore.GetDataPathOrDefault(physicalItemDefinition.Icons.First(), Path.Combine(contentPath, physicalItemDefinition.Icons.First())),
                    Accessible = !string.IsNullOrEmpty(physicalItemDefinition.Model),
                    Time = bp != null ? TimeSpan.FromSeconds(bp.BaseProductionTimeInSeconds) : (TimeSpan?)null,
                });
            }

            foreach (var item in list.OrderBy(i => i.FriendlyName))
            {
                StockItemList.Add(item);
            }

            //list.Clear();

            //foreach (var cubeDefinition in SpaceEngineersAPI.CubeBlockDefinitions)
            //{
            //    list.Add(new ComponentItemModel
            //    {
            //        Name = cubeDefinition.DisplayName,
            //        TypeId = cubeDefinition.Id.TypeId,
            //        SubtypeId = cubeDefinition.Id.SubtypeName,
            //        CubeSize = cubeDefinition.CubeSize,
            //        TextureFile = cubeDefinition.Icon == null ? null : Path.Combine(contentPath, cubeDefinition.Icon),
            //        Accessible = !string.IsNullOrEmpty(cubeDefinition.Model),
            //    });
            //}

            //foreach (var item in list.OrderBy(i => i.FriendlyName))
            //{
            //    StockItemList.Add(item);
            //}
        }