Exemplo n.º 1
0
 private static void GetSurfaceAndMaterial(IMyEntity entity, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
 {
     if (entity is MyVoxelMap)
     {
         materialType  = MyMaterialType.ROCK;
         surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
     }
     else if (entity is MyCharacter)
     {
         surfaceImpact = MySurfaceImpactEnum.CHARACTER;
         materialType  = MyMaterialType.CHARACTER;
     }
     else if (entity is MyFloatingObject)
     {
         MyFloatingObject obj = entity as MyFloatingObject;
         materialType  = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : MyMaterialType.METAL;
         surfaceImpact = MySurfaceImpactEnum.METAL;
     }
     else
     {
         surfaceImpact = MySurfaceImpactEnum.METAL;
         materialType  = MyMaterialType.METAL;
     }
 }
        private static void GetSurfaceAndMaterial(IMyEntity entity, ref Vector3D hitPosition, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
        {
            var voxelBase = entity as MyVoxelBase;
            if (voxelBase != null)
            {
                materialType = MyMaterialType.ROCK;
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;

                var voxelDefinition = voxelBase.GetMaterialAt(ref hitPosition);
                if(voxelDefinition != null)
                    materialType = MyStringHash.GetOrCompute(voxelDefinition.MaterialTypeName);
            }
            else if (entity is MyCharacter)
            {
                surfaceImpact = MySurfaceImpactEnum.CHARACTER;
                materialType = MyMaterialType.CHARACTER;
                if ((entity as MyCharacter).Definition.PhysicalMaterial != null) materialType = MyStringHash.GetOrCompute((entity as MyCharacter).Definition.PhysicalMaterial);
            }
            else if (entity is MyFloatingObject)
            {
                MyFloatingObject obj = entity as MyFloatingObject;
                materialType = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : (obj.ItemDefinition != null && obj.ItemDefinition.PhysicalMaterial != MyStringHash.NullOrEmpty ? obj.ItemDefinition.PhysicalMaterial : MyMaterialType.METAL);
                surfaceImpact = MySurfaceImpactEnum.METAL;
            }
            else if (entity is MyTrees)
            {
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
                materialType = MyMaterialType.WOOD;
            }
            else if (entity is IMyHandheldGunObject<MyGunBase>)
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType = MyMaterialType.METAL;
                var mat = (entity as IMyHandheldGunObject<MyGunBase>).GunBase;
                if (mat != null && mat.WeaponProperties != null && mat.WeaponProperties.WeaponDefinition != null)
                    materialType = mat.WeaponProperties.WeaponDefinition.PhysicalMaterial;
            }
            else
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType = MyMaterialType.METAL;
                if (entity is MyCubeGrid)
                {
                    Vector3I blockPos;
                    var grid = (entity as MyCubeGrid);
                    if (grid != null)
                    {
                        grid.FixTargetCube(out blockPos, Vector3D.Transform(hitPosition, grid.PositionComp.WorldMatrixNormalizedInv) / grid.GridSize);
                        var block = grid.GetCubeBlock(blockPos);
                        if (block != null)
                        {
                            if (block.BlockDefinition.PhysicalMaterial != null)
                            {
                                materialType = MyStringHash.GetOrCompute(block.BlockDefinition.PhysicalMaterial.Id.SubtypeName);
                            }
                        }
                    }
                }
            }
            if (materialType.GetHashCode() == 0) materialType = MyMaterialType.METAL;
        }
        static void CreateHitMaterialSmallParticles(ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MySurfaceImpactEnum surfaceImpact, MyEntity weapon, float scale)
        {
            if (weapon != null)
            {
                Vector3 reflectedDirection = Vector3.Reflect(direction, normal);

                MyParticleEffect effect = null;
                switch (surfaceImpact)
                {
                case MySurfaceImpactEnum.METAL:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_MetalSmall);
                    break;

                case MySurfaceImpactEnum.DESTRUCTIBLE:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_DestructibleSmall);
                    break;

                case MySurfaceImpactEnum.INDESTRUCTIBLE:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_IndestructibleSmall);
                    break;

                case MySurfaceImpactEnum.CHARACTER:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_CharacterSmall);
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false);
                    break;
                }
                if (effect != null)
                {
                    MatrixD dirMatrix = MatrixD.CreateFromDir(reflectedDirection);
                    effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up);
                    effect.UserScale   = scale;
                }
            }
        }
Exemplo n.º 4
0
        private static void GetSurfaceAndMaterial(IMyEntity entity, ref Vector3D hitPosition, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
        {
            var voxelBase = entity as MyVoxelBase;
            if (voxelBase != null)
            {
                materialType = MyMaterialType.ROCK;
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;

                var voxelDefinition = voxelBase.GetMaterialAt(ref hitPosition);
                if(voxelDefinition != null)
                    materialType = MyStringHash.GetOrCompute(voxelDefinition.MaterialTypeName);
            }
            else if (entity is MyCharacter)
            {
                surfaceImpact = MySurfaceImpactEnum.CHARACTER;
                materialType = MyMaterialType.CHARACTER;
            }
            else if (entity is MyFloatingObject)
            {
                MyFloatingObject obj = entity as MyFloatingObject;
                materialType = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : MyMaterialType.METAL;
                surfaceImpact = MySurfaceImpactEnum.METAL;
            }
            else
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType = MyMaterialType.METAL;
            }
        }
Exemplo n.º 5
0
        private static void GetSurfaceAndMaterial(IMyEntity entity, ref LineD line, ref Vector3D hitPosition, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
        {
            var voxelBase = entity as MyVoxelBase;

            if (voxelBase != null)
            {
                materialType  = MyMaterialType.ROCK;
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;

                var voxelDefinition = voxelBase.GetMaterialAt(ref hitPosition);
                if (voxelDefinition != null)
                {
                    materialType = MyStringHash.GetOrCompute(voxelDefinition.MaterialTypeName);
                }
            }
            else if (entity is MyCharacter)
            {
                surfaceImpact = MySurfaceImpactEnum.CHARACTER;
                materialType  = MyMaterialType.CHARACTER;
                if ((entity as MyCharacter).Definition.PhysicalMaterial != null)
                {
                    materialType = MyStringHash.GetOrCompute((entity as MyCharacter).Definition.PhysicalMaterial);
                }
            }
            else if (entity is MyFloatingObject)
            {
                MyFloatingObject obj = entity as MyFloatingObject;
                materialType  = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : (obj.ItemDefinition != null && obj.ItemDefinition.PhysicalMaterial != MyStringHash.NullOrEmpty ? obj.ItemDefinition.PhysicalMaterial : MyMaterialType.METAL);
                surfaceImpact = MySurfaceImpactEnum.METAL;
            }
            else if (entity is MyTrees)
            {
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
                materialType  = MyMaterialType.WOOD;
            }
            else if (entity is IMyHandheldGunObject <MyGunBase> )
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType  = MyMaterialType.METAL;
                var mat = (entity as IMyHandheldGunObject <MyGunBase>).GunBase;
                if (mat != null && mat.WeaponProperties != null && mat.WeaponProperties.WeaponDefinition != null)
                {
                    materialType = mat.WeaponProperties.WeaponDefinition.PhysicalMaterial;
                }
            }
            else
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType  = MyMaterialType.METAL;
                if (entity is MyCubeGrid)
                {
                    var grid = (entity as MyCubeGrid);
                    if (grid != null)
                    {
                        var block = grid.GetTargetedBlock(hitPosition);
                        if (block != null)
                        {
                            if (block.BlockDefinition.PhysicalMaterial != null && !block.BlockDefinition.PhysicalMaterial.Id.TypeId.IsNull)
                            {
                                materialType = MyStringHash.GetOrCompute(block.BlockDefinition.PhysicalMaterial.Id.SubtypeName);
                            }
                            else
                            {
                                if (block.FatBlock != null)
                                {
                                    MyIntersectionResultLineTriangleEx?res = null;
                                    block.FatBlock.GetIntersectionWithLine(ref line, out res);
                                    if (res.HasValue)
                                    {
                                        var technique = block.FatBlock.ModelCollision.GetDrawTechnique(res.Value.Triangle.TriangleIndex);
                                        if (technique == VRageRender.Import.MyMeshDrawTechnique.GLASS)
                                        {
                                            materialType = MyStringHash.GetOrCompute("Glass");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            System.Diagnostics.Debug.Assert(materialType.GetHashCode() != 0, "Unknown material");
        }
Exemplo n.º 6
0
        static void CreateAutocannonHitMaterialParticles(ref Vector3 hitPoint, ref Vector3 normal, ref Vector3 direction, MyEntity physObject, MySurfaceImpactEnum surfaceImpact, MyEntity weapon)
        {
            Vector3 reflectedDirection = Vector3.Reflect(direction, normal);

            MyParticleEffect effect = null;

            switch (surfaceImpact)
            {
            case MySurfaceImpactEnum.METAL:
                effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_Autocannon_Metal);
                break;

            case MySurfaceImpactEnum.DESTRUCTIBLE:
                effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_Autocannon_Destructible);
                break;

            case MySurfaceImpactEnum.INDESTRUCTIBLE:
                effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_Autocannon_Indestructible);
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }
            Matrix dirMatrix = MyMath.MatrixFromDir(reflectedDirection);

            effect.WorldMatrix = Matrix.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up);
        }
        static void CreateHitMaterialSmallParticles(ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MySurfaceImpactEnum surfaceImpact, MyEntity weapon, float scale)
        {
            if (weapon != null)
            {
                Vector3 reflectedDirection = Vector3.Reflect(direction, normal);

                MyParticleEffect effect = null;
                switch (surfaceImpact)
                {
                    case MySurfaceImpactEnum.METAL:
                        effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_MetalSmall);
                        break;
                    case MySurfaceImpactEnum.DESTRUCTIBLE:
                        effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_DestructibleSmall);
                        break;
                    case MySurfaceImpactEnum.INDESTRUCTIBLE:
                        effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_IndestructibleSmall);
                        break;
                    case MySurfaceImpactEnum.CHARACTER:
                        effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_CharacterSmall);
                        break;
                    default:
                        System.Diagnostics.Debug.Assert(false);
                        break;
                }
                if (effect != null)
                {
                    MatrixD dirMatrix = MatrixD.CreateFromDir(reflectedDirection);
                    effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up);
                    effect.UserScale = scale;
                }
            }
        }
Exemplo n.º 8
0
        private static void GetSurfaceAndMaterial(IMyEntity entity, ref Vector3D hitPosition, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
        {
            var voxelBase = entity as MyVoxelBase;

            if (voxelBase != null)
            {
                materialType  = MyMaterialType.ROCK;
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;

                var voxelDefinition = voxelBase.GetMaterialAt(ref hitPosition);
                if (voxelDefinition != null)
                {
                    materialType = MyStringHash.GetOrCompute(voxelDefinition.MaterialTypeName);
                }
            }
            else if (entity is MyCharacter)
            {
                surfaceImpact = MySurfaceImpactEnum.CHARACTER;
                materialType  = MyMaterialType.CHARACTER;
                if ((entity as MyCharacter).Definition.PhysicalMaterial != null)
                {
                    materialType = MyStringHash.GetOrCompute((entity as MyCharacter).Definition.PhysicalMaterial);
                }
            }
            else if (entity is MyFloatingObject)
            {
                MyFloatingObject obj = entity as MyFloatingObject;
                materialType  = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : (obj.ItemDefinition != null && obj.ItemDefinition.PhysicalMaterial != MyStringHash.NullOrEmpty ? obj.ItemDefinition.PhysicalMaterial : MyMaterialType.METAL);
                surfaceImpact = MySurfaceImpactEnum.METAL;
            }
            else if (entity is MyTrees)
            {
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
                materialType  = MyMaterialType.WOOD;
            }
            else if (entity is IMyHandheldGunObject <MyGunBase> )
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType  = MyMaterialType.METAL;
                var mat = (entity as IMyHandheldGunObject <MyGunBase>).GunBase;
                if (mat != null && mat.WeaponProperties != null && mat.WeaponProperties.WeaponDefinition != null)
                {
                    materialType = mat.WeaponProperties.WeaponDefinition.PhysicalMaterial;
                }
            }
            else
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType  = MyMaterialType.METAL;
                if (entity is MyCubeGrid)
                {
                    var grid = (entity as MyCubeGrid);
                    if (grid != null)
                    {
                        var block = grid.GetTargetedBlock(hitPosition);
                        if (block != null)
                        {
                            if (block.BlockDefinition.PhysicalMaterial != null)
                            {
                                materialType = MyStringHash.GetOrCompute(block.BlockDefinition.PhysicalMaterial.Id.SubtypeName);
                            }
                        }
                    }
                }
            }
            if (materialType.GetHashCode() == 0)
            {
                materialType = MyMaterialType.METAL;
            }
        }
Exemplo n.º 9
0
 private static void GetSurfaceAndMaterial(IMyEntity entity, out MySurfaceImpactEnum surfaceImpact, out MyStringId materialType)
 {
     if (entity is MyVoxelMap)
     {
         materialType = MyMaterialType.ROCK;
         surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
     }
     else if (entity is MyCharacter)
     {
         surfaceImpact = MySurfaceImpactEnum.CHARACTER;
         materialType = MyMaterialType.CHARACTER;
     }
     else if (entity is MyFloatingObject)
     {
         MyFloatingObject obj = entity as MyFloatingObject;
         materialType = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : MyMaterialType.METAL;
         surfaceImpact = MySurfaceImpactEnum.METAL;
     }
     else
     {
         surfaceImpact = MySurfaceImpactEnum.METAL;
         materialType = MyMaterialType.METAL;
     }
 }
Exemplo n.º 10
0
        private static void GetSurfaceAndMaterial(IMyEntity entity, ref Vector3D hitPosition, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
        {
            var voxelBase = entity as MyVoxelBase;

            if (voxelBase != null)
            {
                materialType  = MyMaterialType.ROCK;
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;

                var voxelDefinition = voxelBase.GetMaterialAt(ref hitPosition);
                if (voxelDefinition != null)
                {
                    materialType = MyStringHash.GetOrCompute(voxelDefinition.MaterialTypeName);
                }
            }
            else if (entity is MyCharacter)
            {
                surfaceImpact = MySurfaceImpactEnum.CHARACTER;
                materialType  = MyMaterialType.CHARACTER;
            }
            else if (entity is MyFloatingObject)
            {
                MyFloatingObject obj = entity as MyFloatingObject;
                materialType  = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : MyMaterialType.METAL;
                surfaceImpact = MySurfaceImpactEnum.METAL;
            }
            else
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType  = MyMaterialType.METAL;
            }
        }
Exemplo n.º 11
0
        private static void GetSurfaceAndMaterial(IMyEntity entity, ref Vector3D hitPosition, out MySurfaceImpactEnum surfaceImpact, out MyStringHash materialType)
        {
            var voxelBase = entity as MyVoxelBase;

            if (voxelBase != null)
            {
                materialType  = MyMaterialType.ROCK;
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;

                var voxelDefinition = voxelBase.GetMaterialAt(ref hitPosition);
                if (voxelDefinition != null)
                {
                    materialType = MyStringHash.GetOrCompute(voxelDefinition.MaterialTypeName);
                }
            }
            else if (entity is MyCharacter)
            {
                surfaceImpact = MySurfaceImpactEnum.CHARACTER;
                materialType  = MyMaterialType.CHARACTER;
                if ((entity as MyCharacter).Definition.PhysicalMaterial != null)
                {
                    materialType = MyStringHash.GetOrCompute((entity as MyCharacter).Definition.PhysicalMaterial);
                }
            }
            else if (entity is MyFloatingObject)
            {
                MyFloatingObject obj = entity as MyFloatingObject;
                materialType  = (obj.VoxelMaterial != null) ? MyMaterialType.ROCK : MyMaterialType.METAL;
                surfaceImpact = MySurfaceImpactEnum.METAL;
            }
            else if (entity is MyTrees)
            {
                surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE;
                materialType  = MyMaterialType.WOOD;
            }
            else
            {
                surfaceImpact = MySurfaceImpactEnum.METAL;
                materialType  = MyMaterialType.METAL;
                if (entity is MyCubeGrid)
                {
                    Vector3I blockPos;
                    var      grid = (entity as MyCubeGrid);
                    if (grid != null)
                    {
                        grid.FixTargetCube(out blockPos, Vector3D.Transform(hitPosition, grid.PositionComp.WorldMatrixNormalizedInv) / grid.GridSize);
                        var block = grid.GetCubeBlock(blockPos);
                        if (block != null)
                        {
                            if (block.BlockDefinition.PhysicalMaterial != null)
                            {
                                materialType = MyStringHash.GetOrCompute(block.BlockDefinition.PhysicalMaterial.Id.SubtypeName);
                            }
                        }
                    }
                }
                if (materialType.GetHashCode() == 0)
                {
                    materialType = MyMaterialType.METAL;
                }
            }
        }
Exemplo n.º 12
0
        static void CreateAutocannonHitMaterialParticles(ref Vector3 hitPoint, ref Vector3 normal, ref Vector3 direction, MyEntity physObject, MySurfaceImpactEnum surfaceImpact, MyEntity weapon)
        {
            Vector3 reflectedDirection = Vector3.Reflect(direction, normal);

            MyParticleEffect effect = null;
            switch (surfaceImpact)
            {
                case MySurfaceImpactEnum.METAL:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_Autocannon_Metal);
                    break;
                case MySurfaceImpactEnum.DESTRUCTIBLE:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_Autocannon_Destructible);
                    break;
                case MySurfaceImpactEnum.INDESTRUCTIBLE:
                    effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.MaterialHit_Autocannon_Indestructible);
                    break;
                default:
                    System.Diagnostics.Debug.Assert(false);
                    break;
            }
            Matrix dirMatrix = MyMath.MatrixFromDir(reflectedDirection);
            effect.WorldMatrix = Matrix.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up);
        }