コード例 #1
0
 public void SetLoadDeformation(string name,
                                string loadPattern,
                                DegreesOfFreedomLocal degreesOfFreedom,
                                Deformations deformations,
                                eItemType itemType = eItemType.Object)
 {
 }
コード例 #2
0
        // === Get/Set
        /// <summary>
        /// This function retrieves the point objects and their scale factors from a generalized displacement definition.
        /// </summary>
        /// <param name="name">The name of an existing generalized displacement.</param>
        /// <param name="numberItems">The number of point objects included in the generalized displacement definition.</param>
        /// <param name="pointNames">The names of the point objects included in the generalized displacement definition.</param>
        /// <param name="scaleFactors">The unitless scale factors for each of the displacement degrees of freedom of the associated point objects that are included in the generalized displacement definition.</param>
        /// <exception cref="CSiException"></exception>
        public void GetPoint(string name,
                             ref int numberItems,
                             ref string[] pointNames,
                             ref Deformations[] scaleFactors)
        {
            double[] U1 = new double[0];
            double[] U2 = new double[0];
            double[] U3 = new double[0];
            double[] R1 = new double[0];
            double[] R2 = new double[0];
            double[] R3 = new double[0];

            _callCode = _sapModel.GDispl.GetPoint(name, ref numberItems, ref pointNames, ref U1, ref U2, ref U3, ref R1, ref R2, ref R3);
            if (throwCurrentApiException(_callCode))
            {
                throw new CSiException();
            }

            scaleFactors = new Deformations[U1.Length + 1];
            for (int i = 0; i < U1.Length; i++)
            {
                scaleFactors[i].U1 = U1[i];
                scaleFactors[i].U2 = U2[i];
                scaleFactors[i].U3 = U3[i];
                scaleFactors[i].R1 = R1[i];
                scaleFactors[i].R2 = R2[i];
                scaleFactors[i].R3 = R3[i];
            }
        }
コード例 #3
0
 /// <summary>
 /// This function adds a point object and its scale factors to a generalized displacement definition. , or, i
 /// If the point object already exists in the generalized displacement definition, it modifies the scale factors.
 /// </summary>
 /// <param name="name">The name of an existing generalized displacement.</param>
 /// <param name="pointName">The name of a point object to be included in the generalized displacement definition.</param>
 /// <param name="scaleFactors">Unitless scale factors for the point object displacement degrees of freedom.</param>
 /// <exception cref="CSiException"></exception>
 public void SetPoint(string name,
                      string pointName,
                      Deformations scaleFactors)
 {
     double[] csiScaleFators = scaleFactors.ToArray();
     _callCode = _sapModel.GDispl.SetPoint(name, pointName, ref csiScaleFators);
     if (throwCurrentApiException(_callCode))
     {
         throw new CSiException();
     }
 }
コード例 #4
0
ファイル: LinkElement.cs プロジェクト: uzbekdev1/MPT.Tools
        /// <summary>
        /// This function retrieves the deformation load assignments to elements.
        /// </summary>
        /// <param name="name">The name of an existing object, element or group of objects, depending on the value of <paramref name="itemType" />.</param>
        /// <param name="numberItems">The total number of deformation loads retrieved for the specified elements.</param>
        /// <param name="names">The name of the element associated with each deformation load.</param>
        /// <param name="loadPatterns">The name of the load pattern associated with each deformation load.</param>
        /// <param name="degreesOfFreedom">Indicates if the considered degree of freedom has a deformation load for each load pattern.</param>
        /// <param name="deformations">Deformation load values for each load pattern.
        /// The deformations specified for a given degree of freedom are applicable only if the corresponding DOF item for that degree of freedom is True.</param>
        /// <param name="itemType">If this item is <see cref="eItemTypeElement.ObjectElement" />, the load assignments are retrieved for the elements corresponding to the object specified by the <paramref name="name" /> item.
        /// If this item is <see cref="eItemTypeElement.Element" />, the load assignments are retrieved for the element specified by the <paramref name="name" /> item.
        /// If this item is <see cref="eItemTypeElement.GroupElement" />, the load assignments are retrieved for the elements corresponding to all objects included in the group specified by the <paramref name="name" /> item.
        /// If this item is <see cref="eItemTypeElement.SelectionElement" />, the load assignments are retrieved for elements corresponding to all selected objects, and the <paramref name="name" /> item is ignored.</param>
        /// <exception cref="CSiException"></exception>
        public void GetLoadDeformation(string name,
                                       ref int numberItems,
                                       ref string[] names,
                                       ref string[] loadPatterns,
                                       ref DegreesOfFreedomLocal[] degreesOfFreedom,
                                       ref Deformations[] deformations,
                                       eItemTypeElement itemType = eItemTypeElement.Element)
        {
            bool[] dof1 = new bool[0];
            bool[] dof2 = new bool[0];
            bool[] dof3 = new bool[0];
            bool[] dof4 = new bool[0];
            bool[] dof5 = new bool[0];
            bool[] dof6 = new bool[0];

            double[] u1Deformation = new double[0];
            double[] u2Deformation = new double[0];
            double[] u3Deformation = new double[0];
            double[] r1Deformation = new double[0];
            double[] r2Deformation = new double[0];
            double[] r3Deformation = new double[0];

            _callCode = _sapModel.LinkElm.GetLoadDeformation(name, ref numberItems, ref names, ref loadPatterns,
                                                             ref dof1, ref dof2, ref dof3, ref dof4, ref dof5, ref dof6,
                                                             ref u1Deformation, ref u2Deformation, ref u3Deformation, ref r1Deformation, ref r2Deformation, ref r3Deformation,
                                                             EnumLibrary.Convert <eItemTypeElement, CSiProgram.eItemTypeElm>(itemType));
            if (throwCurrentApiException(_callCode))
            {
                throw new CSiException();
            }

            degreesOfFreedom = new DegreesOfFreedomLocal[numberItems - 1];
            deformations     = new Deformations[numberItems - 1];
            for (int i = 0; i < numberItems; i++)
            {
                degreesOfFreedom[i].U1 = dof1[i];
                degreesOfFreedom[i].U2 = dof2[i];
                degreesOfFreedom[i].U3 = dof3[i];
                degreesOfFreedom[i].R1 = dof4[i];
                degreesOfFreedom[i].R2 = dof5[i];
                degreesOfFreedom[i].R3 = dof6[i];

                deformations[i].U1 = u1Deformation[i];
                deformations[i].U2 = u2Deformation[i];
                deformations[i].U3 = u3Deformation[i];
                deformations[i].R1 = r1Deformation[i];
                deformations[i].R2 = r2Deformation[i];
                deformations[i].R3 = r3Deformation[i];
            }
        }
コード例 #5
0
        public void Draw(SpriteBatch spriteBatch, Camera cam, Color?overrideColor = null)
        {
            float brightness = 1.0f - (burnOverLayStrength / 100.0f) * 0.5f;
            Color color      = new Color(brightness, brightness, brightness);

            color = overrideColor ?? color;

            if (isSevered)
            {
                if (severedFadeOutTimer > SeveredFadeOutTime)
                {
                    return;
                }
                else if (severedFadeOutTimer > SeveredFadeOutTime - 1.0f)
                {
                    color *= SeveredFadeOutTime - severedFadeOutTimer;
                }
            }

            body.Dir = Dir;

            bool hideLimb = wearingItems.Any(w => w != null && w.HideLimb);

            body.UpdateDrawPosition();

            if (!hideLimb)
            {
                var activeSprite = ActiveSprite;
                if (DeformSprite != null && activeSprite == DeformSprite.Sprite)
                {
                    if (Deformations != null && Deformations.Any())
                    {
                        var deformation = SpriteDeformation.GetDeformation(Deformations, DeformSprite.Size);
                        DeformSprite.Deform(deformation);
                    }
                    else
                    {
                        DeformSprite.Reset();
                    }
                    body.Draw(DeformSprite, cam, Vector2.One * Scale * TextureScale, color);
                }
                else
                {
                    body.Draw(spriteBatch, activeSprite, color, null, Scale * TextureScale);
                }
            }

            if (LightSource != null)
            {
                LightSource.Position          = body.DrawPosition;
                LightSource.LightSpriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipVertically;
            }
            float          depthStep    = 0.000001f;
            WearableSprite onlyDrawable = wearingItems.Find(w => w.HideOtherWearables);
            SpriteEffects  spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

            if (onlyDrawable == null)
            {
                if (HuskSprite != null && (character.SpeciesName == "Humanhusk" || (character.SpeciesName == "Human" &&
                                                                                    character.CharacterHealth.GetAffliction <AfflictionHusk>("huskinfection")?.State == AfflictionHusk.InfectionState.Active)))
                {
                    DrawWearable(HuskSprite, depthStep, spriteBatch, color, spriteEffect);
                }
                foreach (WearableSprite wearable in OtherWearables)
                {
                    DrawWearable(wearable, depthStep, spriteBatch, color, spriteEffect);
                    //if there are multiple sprites on this limb, make the successive ones be drawn in front
                    depthStep += 0.000001f;
                }
            }
            foreach (WearableSprite wearable in WearingItems)
            {
                if (onlyDrawable != null && onlyDrawable != wearable)
                {
                    continue;
                }
                DrawWearable(wearable, depthStep, spriteBatch, color, spriteEffect);
                //if there are multiple sprites on this limb, make the successive ones be drawn in front
                depthStep += 0.000001f;
            }

            if (damageOverlayStrength > 0.0f && DamagedSprite != null && !hideLimb)
            {
                float depth = ActiveSprite.Depth - 0.0000015f;

                // TODO: enable when the damage overlay textures have been remade.
                //DamagedSprite.Draw(spriteBatch,
                //    new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
                //    color * Math.Min(damageOverlayStrength, 1.0f), ActiveSprite.Origin,
                //    -body.DrawRotation,
                //    1.0f, spriteEffect, depth);
            }

            if (GameMain.DebugDraw)
            {
                if (pullJoint != null)
                {
                    Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
                }
                var bodyDrawPos = body.DrawPosition;
                bodyDrawPos.Y = -bodyDrawPos.Y;
                if (IsStuck)
                {
                    Vector2 from = ConvertUnits.ToDisplayUnits(attachJoint.WorldAnchorA);
                    from.Y = -from.Y;
                    Vector2 to = ConvertUnits.ToDisplayUnits(attachJoint.WorldAnchorB);
                    to.Y = -to.Y;
                    var localFront = body.GetLocalFront(MathHelper.ToRadians(limbParams.Ragdoll.SpritesheetOrientation));
                    var front      = ConvertUnits.ToDisplayUnits(body.FarseerBody.GetWorldPoint(localFront));
                    front.Y = -front.Y;
                    GUI.DrawLine(spriteBatch, bodyDrawPos, front, Color.Yellow, width: 2);
                    GUI.DrawLine(spriteBatch, from, to, Color.Red, width: 1);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)from.X, (int)from.Y, 12, 12), Color.White, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)to.X, (int)to.Y, 12, 12), Color.White, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)from.X, (int)from.Y, 10, 10), Color.Blue, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)to.X, (int)to.Y, 10, 10), Color.Red, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)front.X, (int)front.Y, 10, 10), Color.Yellow, true);

                    //Vector2 mainLimbFront = ConvertUnits.ToDisplayUnits(ragdoll.MainLimb.body.FarseerBody.GetWorldPoint(ragdoll.MainLimb.body.GetFrontLocal(MathHelper.ToRadians(ragdoll.RagdollParams.SpritesheetOrientation))));
                    //mainLimbFront.Y = -mainLimbFront.Y;
                    //var mainLimbDrawPos = ragdoll.MainLimb.body.DrawPosition;
                    //mainLimbDrawPos.Y = -mainLimbDrawPos.Y;
                    //GUI.DrawLine(spriteBatch, mainLimbDrawPos, mainLimbFront, Color.White, width: 5);
                    //GUI.DrawRectangle(spriteBatch, new Rectangle((int)mainLimbFront.X, (int)mainLimbFront.Y, 10, 10), Color.Yellow, true);
                }
                foreach (var modifier in damageModifiers)
                {
                    float   rotation = -body.TransformedRotation + GetArmorSectorRotationOffset(modifier.ArmorSector) * Dir;
                    Vector2 forward  = VectorExtensions.Forward(rotation);
                    float   size     = ConvertUnits.ToDisplayUnits(body.GetSize().Length() / 2);
                    color = modifier.DamageMultiplier > 1 ? Color.Red : Color.GreenYellow;
                    GUI.DrawLine(spriteBatch, bodyDrawPos, bodyDrawPos + Vector2.Normalize(forward) * size, color, width: (int)Math.Round(4 / cam.Zoom));
                    ShapeExtensions.DrawSector(spriteBatch, bodyDrawPos, size, GetArmorSectorSize(modifier.ArmorSector) * Dir, 40, color, rotation + MathHelper.Pi, thickness: 2 / cam.Zoom);
                }
            }
        }
コード例 #6
0
        partial void InitProjSpecific(XElement element)
        {
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    Sprite = new Sprite(subElement, "", GetSpritePath(subElement));
                    break;

                case "damagedsprite":
                    DamagedSprite = new Sprite(subElement, "", GetSpritePath(subElement));
                    break;

                case "conditionalsprite":
                    ConditionalSprites.Add(new ConditionalSprite(subElement, character, file: GetSpritePath(subElement)));
                    break;

                case "deformablesprite":
                    DeformSprite = new DeformableSprite(subElement, filePath: GetSpritePath(subElement));
                    foreach (XElement animationElement in subElement.Elements())
                    {
                        int sync = animationElement.GetAttributeInt("sync", -1);
                        SpriteDeformation deformation = null;
                        if (sync > -1)
                        {
                            // if the element is marked with the sync attribute, use a deformation of the same type with the same sync value, if there is one already.
                            string typeName = animationElement.GetAttributeString("type", "").ToLowerInvariant();
                            deformation = ragdoll.Limbs
                                          .Where(l => l != null)
                                          .SelectMany(l => l.Deformations)
                                          .Where(d => d.TypeName == typeName && d.Sync == sync)
                                          .FirstOrDefault();
                        }
                        if (deformation == null)
                        {
                            deformation = SpriteDeformation.Load(animationElement, character.SpeciesName);
                            if (deformation != null)
                            {
                                ragdoll.SpriteDeformations.Add(deformation);
                            }
                        }
                        if (deformation != null)
                        {
                            Deformations.Add(deformation);
                        }
                    }
                    break;

                case "lightsource":
                    LightSource             = new LightSource(subElement);
                    InitialLightSourceColor = LightSource.Color;
                    break;

                case "sound":
                    HitSoundTag = subElement.GetAttributeString("tag", "");
                    if (string.IsNullOrWhiteSpace(HitSoundTag))
                    {
                        //legacy support
                        HitSoundTag = subElement.GetAttributeString("file", "");
                    }
                    break;
                }
            }
        }
コード例 #7
0
ファイル: Limb.cs プロジェクト: jamiebidelia/Barotrauma
        public void Draw(SpriteBatch spriteBatch, Camera cam, Color?overrideColor = null)
        {
            float brightness = 1.0f - (burnOverLayStrength / 100.0f) * 0.5f;
            Color color      = new Color(brightness, brightness, brightness);

            color = overrideColor ?? color;

            if (isSevered)
            {
                if (severedFadeOutTimer > SeveredFadeOutTime)
                {
                    return;
                }
                else if (severedFadeOutTimer > SeveredFadeOutTime - 1.0f)
                {
                    color *= SeveredFadeOutTime - severedFadeOutTimer;
                }
            }

            body.Dir = Dir;

            bool  enableHuskSprite = character.IsHusk || character.CharacterHealth.GetAffliction <AfflictionHusk>("huskinfection")?.State == AfflictionHusk.InfectionState.Active;
            float herpesStrength   = character.CharacterHealth.GetAfflictionStrength("spaceherpes");

            bool hideLimb = Params.Hide ||
                            enableHuskSprite && HuskSprite != null && HuskSprite.HideLimb ||
                            OtherWearables.Any(w => w.HideLimb) ||
                            wearingItems.Any(w => w != null && w.HideLimb);

            var activeSprite = ActiveSprite;

            if (type == LimbType.Head)
            {
                CalculateHeadPosition(activeSprite);
            }

            // TODO: there's now two calls to this, because body.Draw() method calls this too -> is this an issue?
            body.UpdateDrawPosition();

            if (!hideLimb)
            {
                var deformSprite = DeformSprite;
                if (deformSprite != null)
                {
                    if (Deformations != null && Deformations.Any())
                    {
                        var deformation = SpriteDeformation.GetDeformation(Deformations, deformSprite.Size);
                        deformSprite.Deform(deformation);
                    }
                    else
                    {
                        deformSprite.Reset();
                    }
                    body.Draw(deformSprite, cam, Vector2.One * Scale * TextureScale, color, Params.MirrorHorizontally);
                }
                else
                {
                    body.Draw(spriteBatch, activeSprite, color, null, Scale * TextureScale, Params.MirrorHorizontally, Params.MirrorVertically);
                }
            }
            SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

            if (LightSource != null)
            {
                LightSource.Position = body.DrawPosition;
                if (LightSource.ParentSub != null)
                {
                    LightSource.Position -= LightSource.ParentSub.DrawPosition;
                }
                LightSource.LightSpriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipVertically;
            }
            if (damageOverlayStrength > 0.0f && DamagedSprite != null && !hideLimb)
            {
                DamagedSprite.Draw(spriteBatch,
                                   new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
                                   color * Math.Min(damageOverlayStrength, 1.0f), activeSprite.Origin,
                                   -body.DrawRotation,
                                   Scale, spriteEffect, activeSprite.Depth - 0.0000015f);
            }
            foreach (var decorativeSprite in DecorativeSprites)
            {
                if (!spriteAnimState[decorativeSprite].IsActive)
                {
                    continue;
                }
                float   rotation          = decorativeSprite.GetRotation(ref spriteAnimState[decorativeSprite].RotationState);
                Vector2 offset            = decorativeSprite.GetOffset(ref spriteAnimState[decorativeSprite].OffsetState) * Scale;
                var     ca                = (float)Math.Cos(-body.Rotation);
                var     sa                = (float)Math.Sin(-body.Rotation);
                Vector2 transformedOffset = new Vector2(ca * offset.X + sa * offset.Y, -sa * offset.X + ca * offset.Y);
                decorativeSprite.Sprite.Draw(spriteBatch, new Vector2(body.DrawPosition.X + transformedOffset.X, -(body.DrawPosition.Y + transformedOffset.Y)), color,
                                             -body.Rotation + rotation, Scale, spriteEffect,
                                             depth: decorativeSprite.Sprite.Depth);
            }
            float          depthStep    = 0.000001f;
            float          step         = depthStep;
            WearableSprite onlyDrawable = wearingItems.Find(w => w.HideOtherWearables);

            if (Params.MirrorHorizontally)
            {
                spriteEffect = spriteEffect == SpriteEffects.None ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
            }
            if (Params.MirrorVertically)
            {
                spriteEffect |= SpriteEffects.FlipVertically;
            }
            if (onlyDrawable == null)
            {
                if (HerpesSprite != null)
                {
                    DrawWearable(HerpesSprite, depthStep, spriteBatch, color * Math.Min(herpesStrength / 10.0f, 1.0f), spriteEffect);
                    depthStep += step;
                }
                if (HuskSprite != null && enableHuskSprite)
                {
                    DrawWearable(HuskSprite, depthStep, spriteBatch, color, spriteEffect);
                    depthStep += step;
                }
                foreach (WearableSprite wearable in OtherWearables)
                {
                    if (wearable.Type == WearableType.Beard && enableHuskSprite && HuskSprite != null)
                    {
                        continue;
                    }
                    DrawWearable(wearable, depthStep, spriteBatch, color, spriteEffect);
                    //if there are multiple sprites on this limb, make the successive ones be drawn in front
                    depthStep += step;
                }
            }
            foreach (WearableSprite wearable in WearingItems)
            {
                if (onlyDrawable != null && onlyDrawable != wearable)
                {
                    continue;
                }
                DrawWearable(wearable, depthStep, spriteBatch, color, spriteEffect);
                //if there are multiple sprites on this limb, make the successive ones be drawn in front
                depthStep += step;
            }

            if (GameMain.DebugDraw)
            {
                if (pullJoint != null)
                {
                    Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
                }
                var bodyDrawPos = body.DrawPosition;
                bodyDrawPos.Y = -bodyDrawPos.Y;
                if (IsStuck)
                {
                    Vector2 from = ConvertUnits.ToDisplayUnits(attachJoint.WorldAnchorA);
                    from.Y = -from.Y;
                    Vector2 to = ConvertUnits.ToDisplayUnits(attachJoint.WorldAnchorB);
                    to.Y = -to.Y;
                    var localFront = body.GetLocalFront(Params.GetSpriteOrientation());
                    var front      = ConvertUnits.ToDisplayUnits(body.FarseerBody.GetWorldPoint(localFront));
                    front.Y = -front.Y;
                    GUI.DrawLine(spriteBatch, bodyDrawPos, front, Color.Yellow, width: 2);
                    GUI.DrawLine(spriteBatch, from, to, Color.Red, width: 1);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)from.X, (int)from.Y, 12, 12), Color.White, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)to.X, (int)to.Y, 12, 12), Color.White, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)from.X, (int)from.Y, 10, 10), Color.Blue, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)to.X, (int)to.Y, 10, 10), Color.Red, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)front.X, (int)front.Y, 10, 10), Color.Yellow, true);

                    //Vector2 mainLimbFront = ConvertUnits.ToDisplayUnits(ragdoll.MainLimb.body.FarseerBody.GetWorldPoint(ragdoll.MainLimb.body.GetFrontLocal(MathHelper.ToRadians(limbParams.Orientation))));
                    //mainLimbFront.Y = -mainLimbFront.Y;
                    //var mainLimbDrawPos = ragdoll.MainLimb.body.DrawPosition;
                    //mainLimbDrawPos.Y = -mainLimbDrawPos.Y;
                    //GUI.DrawLine(spriteBatch, mainLimbDrawPos, mainLimbFront, Color.White, width: 5);
                    //GUI.DrawRectangle(spriteBatch, new Rectangle((int)mainLimbFront.X, (int)mainLimbFront.Y, 10, 10), Color.Yellow, true);
                }
                DrawDamageModifiers(spriteBatch, cam, bodyDrawPos, isScreenSpace: false);
            }
        }
コード例 #8
0
ファイル: Limb.cs プロジェクト: jamiebidelia/Barotrauma
        partial void InitProjSpecific(XElement element)
        {
            for (int i = 0; i < Params.decorativeSpriteParams.Count; i++)
            {
                var param            = Params.decorativeSpriteParams[i];
                var decorativeSprite = new DecorativeSprite(param.Element, file: GetSpritePath(param.Element, param));
                DecorativeSprites.Add(decorativeSprite);
                int groupID = decorativeSprite.RandomGroupID;
                if (!DecorativeSpriteGroups.ContainsKey(groupID))
                {
                    DecorativeSpriteGroups.Add(groupID, new List <DecorativeSprite>());
                }
                DecorativeSpriteGroups[groupID].Add(decorativeSprite);
                spriteAnimState.Add(decorativeSprite, new SpriteState());
            }
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    Sprite = new Sprite(subElement, file: GetSpritePath(subElement, Params.normalSpriteParams));
                    break;

                case "damagedsprite":
                    DamagedSprite = new Sprite(subElement, file: GetSpritePath(subElement, Params.damagedSpriteParams));
                    break;

                case "conditionalsprite":
                    var conditionalSprite = new ConditionalSprite(subElement, character, file: GetSpritePath(subElement, null));
                    ConditionalSprites.Add(conditionalSprite);
                    if (conditionalSprite.DeformableSprite != null)
                    {
                        CreateDeformations(subElement.GetChildElement("deformablesprite"));
                    }
                    break;

                case "deformablesprite":
                    _deformSprite = new DeformableSprite(subElement, filePath: GetSpritePath(subElement, Params.deformSpriteParams));
                    CreateDeformations(subElement);
                    break;

                case "lightsource":
                    LightSource             = new LightSource(subElement);
                    InitialLightSourceColor = LightSource.Color;
                    break;
                }

                void CreateDeformations(XElement e)
                {
                    foreach (XElement animationElement in e.GetChildElements("spritedeformation"))
                    {
                        int sync = animationElement.GetAttributeInt("sync", -1);
                        SpriteDeformation deformation = null;
                        if (sync > -1)
                        {
                            // if the element is marked with the sync attribute, use a deformation of the same type with the same sync value, if there is one already.
                            string typeName = animationElement.GetAttributeString("type", "").ToLowerInvariant();
                            deformation = ragdoll.Limbs
                                          .Where(l => l != null)
                                          .SelectMany(l => l.Deformations)
                                          .Where(d => d.TypeName == typeName && d.Sync == sync)
                                          .FirstOrDefault();
                        }
                        if (deformation == null)
                        {
                            deformation = SpriteDeformation.Load(animationElement, character.SpeciesName);
                            if (deformation != null)
                            {
                                ragdoll.SpriteDeformations.Add(deformation);
                            }
                        }
                        if (deformation != null)
                        {
                            Deformations.Add(deformation);
                        }
                    }
                }
            }
        }
コード例 #9
0
 public void SetPoint(string name,
                      string pointName,
                      Deformations scaleFactors)
 {
 }
コード例 #10
0
ファイル: LinkElement.cs プロジェクト: uzbekdev1/MPT.Tools
        /// <summary>
        /// This function retrieves the target force assignments to elements.
        /// </summary>
        /// <param name="name">The name of an existing object, element or group of objects, depending on the value of <paramref name="itemType" />.</param>
        /// <param name="numberItems">The total number of deformation loads retrieved for the specified elements.</param>
        /// <param name="names">The name of the element associated with each target force.</param>
        /// <param name="loadPatterns">The name of the load pattern associated with each target force.</param>
        /// <param name="forcesActive">Boolean values indicating if the considered degree of freedom has a target force assignment for each load pattern.</param>
        /// <param name="deformations">Target force values for each load pattern.
        /// The target forces specified for a given degree of freedom are only applicable if the corresponding DOF item for that degree of freedom is True.</param>
        /// <param name="relativeForcesLocation">Relative distances along the line elements where the target force values apply for each load pattern.
        /// The relative distances specified for a given degree of freedom are only applicable if the corresponding dofn item for that degree of freedom is True.</param>
        /// <param name="itemType">If this item is <see cref="eItemTypeElement.ObjectElement" />, the load assignments are retrieved for the elements corresponding to the object specified by the <paramref name="name" /> item.
        /// If this item is <see cref="eItemTypeElement.Element" />, the load assignments are retrieved for the element specified by the <paramref name="name" /> item.
        /// If this item is <see cref="eItemTypeElement.GroupElement" />, the load assignments are retrieved for the elements corresponding to all objects included in the group specified by the <paramref name="name" /> item.
        /// If this item is <see cref="eItemTypeElement.SelectionElement" />, the load assignments are retrieved for elements corresponding to all selected objects, and the <paramref name="name" /> item is ignored.</param>
        /// <exception cref="CSiException"></exception>
        public void GetLoadTargetForce(string name,
                                       ref int numberItems,
                                       ref string[] names,
                                       ref string[] loadPatterns,
                                       ref ForcesActive[] forcesActive,
                                       ref Deformations[] deformations,
                                       ref Forces[] relativeForcesLocation,
                                       eItemTypeElement itemType = eItemTypeElement.Element)
        {
            bool[] dof1 = new bool[0];
            bool[] dof2 = new bool[0];
            bool[] dof3 = new bool[0];
            bool[] dof4 = new bool[0];
            bool[] dof5 = new bool[0];
            bool[] dof6 = new bool[0];

            double[] u1Deformation = new double[0];
            double[] u2Deformation = new double[0];
            double[] u3Deformation = new double[0];
            double[] r1Deformation = new double[0];
            double[] r2Deformation = new double[0];
            double[] r3Deformation = new double[0];

            double[] T1 = new double[0];
            double[] T2 = new double[0];
            double[] T3 = new double[0];
            double[] T4 = new double[0];
            double[] T5 = new double[0];
            double[] T6 = new double[0];

            _callCode = _sapModel.LineElm.GetLoadTargetForce(name, ref numberItems, ref names, ref loadPatterns,
                                                             ref dof1, ref dof2, ref dof3, ref dof4, ref dof5, ref dof6,
                                                             ref u1Deformation, ref u2Deformation, ref u3Deformation, ref r1Deformation, ref r2Deformation, ref r3Deformation,
                                                             ref T1, ref T2, ref T3, ref T4, ref T5, ref T6,
                                                             EnumLibrary.Convert <eItemTypeElement, CSiProgram.eItemTypeElm>(itemType));
            if (throwCurrentApiException(_callCode))
            {
                throw new CSiException();
            }

            forcesActive           = new ForcesActive[numberItems - 1];
            deformations           = new Deformations[numberItems - 1];
            relativeForcesLocation = new Forces[numberItems - 1];
            for (int i = 0; i < numberItems; i++)
            {
                forcesActive[i].P  = dof1[i];
                forcesActive[i].V2 = dof2[i];
                forcesActive[i].V3 = dof3[i];
                forcesActive[i].T  = dof4[i];
                forcesActive[i].M2 = dof5[i];
                forcesActive[i].M3 = dof6[i];

                deformations[i].U1 = u1Deformation[i];
                deformations[i].U2 = u2Deformation[i];
                deformations[i].U3 = u3Deformation[i];
                deformations[i].R1 = r1Deformation[i];
                deformations[i].R2 = r2Deformation[i];
                deformations[i].R3 = r3Deformation[i];

                relativeForcesLocation[i].P  = T1[i];
                relativeForcesLocation[i].V2 = T2[i];
                relativeForcesLocation[i].V3 = T3[i];
                relativeForcesLocation[i].T  = T4[i];
                relativeForcesLocation[i].M2 = T5[i];
                relativeForcesLocation[i].M3 = T6[i];
            }
        }
コード例 #11
0
ファイル: Limb.cs プロジェクト: yaelatletl/Barotrauma
        public void Draw(SpriteBatch spriteBatch, Camera cam, Color?overrideColor = null)
        {
            float brightness = 1.0f - (burnOverLayStrength / 100.0f) * 0.5f;
            Color color      = new Color(brightness, brightness, brightness);

            color = overrideColor ?? color;

            if (isSevered)
            {
                if (severedFadeOutTimer > SeveredFadeOutTime)
                {
                    return;
                }
                else if (severedFadeOutTimer > SeveredFadeOutTime - 1.0f)
                {
                    color *= SeveredFadeOutTime - severedFadeOutTimer;
                }
            }

            body.Dir = Dir;

            bool hideLimb = wearingItems.Any(w => w != null && w.HideLimb);

            body.UpdateDrawPosition();

            if (!hideLimb)
            {
                if (DeformSprite != null)
                {
                    if (Deformations != null && Deformations.Any())
                    {
                        var deformation = SpriteDeformation.GetDeformation(Deformations, DeformSprite.Size);
                        DeformSprite.Deform(deformation);
                    }
                    else
                    {
                        DeformSprite.Reset();
                    }
                    body.Draw(DeformSprite, cam, Vector2.One * Scale * TextureScale, color);
                }
                else
                {
                    body.Draw(spriteBatch, Sprite, color, null, Scale * TextureScale);
                }
            }

            if (LightSource != null)
            {
                LightSource.Position          = body.DrawPosition;
                LightSource.LightSpriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipVertically;
            }
            float          depthStep    = 0.000001f;
            WearableSprite onlyDrawable = wearingItems.Find(w => w.HideOtherWearables);
            SpriteEffects  spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

            if (onlyDrawable == null)
            {
                foreach (WearableSprite wearable in OtherWearables)
                {
                    DrawWearable(wearable, depthStep, spriteBatch, color, spriteEffect);
                    //if there are multiple sprites on this limb, make the successive ones be drawn in front
                    depthStep += 0.000001f;
                }
            }
            foreach (WearableSprite wearable in WearingItems)
            {
                if (onlyDrawable != null && onlyDrawable != wearable)
                {
                    continue;
                }
                DrawWearable(wearable, depthStep, spriteBatch, color, spriteEffect);
                //if there are multiple sprites on this limb, make the successive ones be drawn in front
                depthStep += 0.000001f;
            }

            if (damageOverlayStrength > 0.0f && DamagedSprite != null && !hideLimb)
            {
                float depth = ActiveSprite.Depth - 0.0000015f;

                DamagedSprite.Draw(spriteBatch,
                                   new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
                                   color * Math.Min(damageOverlayStrength / 50.0f, 1.0f), ActiveSprite.Origin,
                                   -body.DrawRotation,
                                   1.0f, spriteEffect, depth);
            }

            if (GameMain.DebugDraw)
            {
                if (pullJoint != null)
                {
                    Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
                }
                if (IsStuck)
                {
                    Vector2 from = ConvertUnits.ToDisplayUnits(attachJoint.WorldAnchorA);
                    from.Y = -from.Y;
                    Vector2 to = ConvertUnits.ToDisplayUnits(attachJoint.WorldAnchorB);
                    to.Y = -to.Y;
                    var localFront = body.GetLocalFront(MathHelper.ToRadians(limbParams.Ragdoll.SpritesheetOrientation));
                    var front      = ConvertUnits.ToDisplayUnits(body.FarseerBody.GetWorldPoint(localFront));
                    front.Y = -front.Y;
                    var drawPos = body.DrawPosition;
                    drawPos.Y = -drawPos.Y;
                    GUI.DrawLine(spriteBatch, drawPos, front, Color.Yellow, width: 2);
                    GUI.DrawLine(spriteBatch, from, to, Color.Red, width: 1);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)from.X, (int)from.Y, 12, 12), Color.White, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)to.X, (int)to.Y, 12, 12), Color.White, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)from.X, (int)from.Y, 10, 10), Color.Blue, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)to.X, (int)to.Y, 10, 10), Color.Red, true);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)front.X, (int)front.Y, 10, 10), Color.Yellow, true);

                    //Vector2 mainLimbFront = ConvertUnits.ToDisplayUnits(ragdoll.MainLimb.body.FarseerBody.GetWorldPoint(ragdoll.MainLimb.body.GetFrontLocal(MathHelper.ToRadians(ragdoll.RagdollParams.SpritesheetOrientation))));
                    //mainLimbFront.Y = -mainLimbFront.Y;
                    //var mainLimbDrawPos = ragdoll.MainLimb.body.DrawPosition;
                    //mainLimbDrawPos.Y = -mainLimbDrawPos.Y;
                    //GUI.DrawLine(spriteBatch, mainLimbDrawPos, mainLimbFront, Color.White, width: 5);
                    //GUI.DrawRectangle(spriteBatch, new Rectangle((int)mainLimbFront.X, (int)mainLimbFront.Y, 10, 10), Color.Yellow, true);
                }
            }
        }
コード例 #12
0
ファイル: Limb.cs プロジェクト: shoter/Barotrauma
        public void Draw(SpriteBatch spriteBatch, Camera cam, Color?overrideColor = null)
        {
            float brightness = 1.0f - (burnOverLayStrength / 100.0f) * 0.5f;
            Color color      = new Color(brightness, brightness, brightness);

            color = overrideColor ?? color;

            if (isSevered)
            {
                if (severedFadeOutTimer > SeveredFadeOutTime)
                {
                    return;
                }
                else if (severedFadeOutTimer > SeveredFadeOutTime - 1.0f)
                {
                    color *= SeveredFadeOutTime - severedFadeOutTimer;
                }
            }

            body.Dir = Dir;

            bool hideLimb = wearingItems.Any(w => w != null && w.HideLimb);

            body.UpdateDrawPosition();

            if (!hideLimb)
            {
                if (DeformSprite != null)
                {
                    if (Deformations != null && Deformations.Any())
                    {
                        var deformation = SpriteDeformation.GetDeformation(Deformations, DeformSprite.Size);
                        DeformSprite.Deform(deformation);
                    }
                    else
                    {
                        DeformSprite.Reset();
                    }
                    body.Draw(DeformSprite, cam, Vector2.One * Scale * TextureScale, color);
                }
                else
                {
                    body.Draw(spriteBatch, Sprite, color, null, Scale * TextureScale);
                }
            }

            if (LightSource != null)
            {
                LightSource.Position          = body.DrawPosition;
                LightSource.LightSpriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipVertically;
            }
            float          depthStep    = 0.000001f;
            WearableSprite onlyDrawable = wearingItems.Find(w => w.HideOtherWearables);

            foreach (WearableSprite wearable in WearingItems)
            {
                if (onlyDrawable != null && onlyDrawable != wearable)
                {
                    continue;
                }

                SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

                Vector2 origin = wearable.InheritOrigin ? ActiveSprite.Origin : wearable.Sprite.Origin;
                // If the wearable inherits the origin, flipping is already handled.
                if (!wearable.InheritOrigin && body.Dir == -1.0f)
                {
                    origin.X = wearable.Sprite.SourceRect.Width - origin.X;
                }

                if (wearable.InheritSourceRect)
                {
                    wearable.Sprite.SourceRect = ActiveSprite.SourceRect;
                }

                float depth = wearable.Sprite.Depth;

                if (wearable.InheritLimbDepth)
                {
                    depth = ActiveSprite.Depth - depthStep;
                    if (wearable.DepthLimb != LimbType.None)
                    {
                        Limb depthLimb = character.AnimController.GetLimb(wearable.DepthLimb);
                        if (depthLimb != null)
                        {
                            depth = depthLimb.ActiveSprite.Depth - depthStep;
                        }
                    }
                }
                // Draw outer cloths on top of inner cloths.
                if (wearable.WearableComponent.AllowedSlots.Contains(InvSlotType.OuterClothes))
                {
                    depth -= depthStep;
                }
                //if there are multiple sprites on this limb, make the successive ones be drawn in front
                depthStep += 0.000001f;

                float textureScale  = wearable.InheritTextureScale ? TextureScale : 1;
                Color wearableColor = wearable.WearableComponent.Item.GetSpriteColor();
                wearable.Sprite.Draw(spriteBatch,
                                     new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
                                     new Color((color.R * wearableColor.R) / (255.0f * 255.0f), (color.G * wearableColor.G) / (255.0f * 255.0f), (color.B * wearableColor.B) / (255.0f * 255.0f)) * ((color.A * wearableColor.A) / (255.0f * 255.0f)),
                                     origin, -body.DrawRotation,
                                     Scale * textureScale, spriteEffect, depth);
            }

            if (damageOverlayStrength > 0.0f && DamagedSprite != null && !hideLimb)
            {
                SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

                float depth = ActiveSprite.Depth - 0.0000015f;

                DamagedSprite.Draw(spriteBatch,
                                   new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
                                   color * Math.Min(damageOverlayStrength / 50.0f, 1.0f), ActiveSprite.Origin,
                                   -body.DrawRotation,
                                   1.0f, spriteEffect, depth);
            }

            if (GameMain.DebugDraw)
            {
                if (pullJoint != null)
                {
                    Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
                    GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
                }
            }
        }