コード例 #1
0
ファイル: SpringSkeleton.cs プロジェクト: winterdl/LD10
        private void AccumulateForces()
        {
            Vector3 source, dest, resultant;

            float distance;

            foreach (SpringNode node in nodes)
            {
                resultant = Vector3.Zero;
                source    = node.Position;

                foreach (SpringNode neighborNode in node.Neighbors.Keys)
                {
                    dest     = neighborNode.Position;
                    distance = node.Neighbors[neighborNode];

                    Vector3 force = SpringNode.ComputeSingleForce(
                        source,
                        dest,
                        k,
                        distance);

                    resultant += force;
                }

                node.Force = resultant;
            }
        }
コード例 #2
0
ファイル: SpringNode.cs プロジェクト: winterdl/LD10
        public static bool IsAnchor(SpringNode node, SpringSkeleton skeleton)
        {
            // necessary to store the reference somewhere
            SpringNodeAnchor anchor;

            return(SpringNode.IsAnchor(node, skeleton, out anchor));
        }
コード例 #3
0
ファイル: SpringNode.cs プロジェクト: winterdl/LD10
        public static bool IsAnchor(SpringNode node, SpringSkeleton skeleton, out SpringNodeAnchor anchor)
        {
            anchor = null;
            for (int i = 0; i < skeleton.Anchors.Count; i++)
            {
                if (skeleton.Anchors[i].Node == node)
                {
                    anchor = skeleton.Anchors[i];

                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        public static void CreateChain(SpringSkeleton skeleton, int parts, float partDistance, Vector3 origin, bool right)
        {
            SpringNode start = new SpringNode(origin);

            skeleton.Nodes.Add(start);

            SpringNode previous = start;

            for (int i = 0; i < parts; i++)
            {
                // hack
                Vector3 newPosition = Vector3.Zero;

                if (right)
                {
                    newPosition =
                        previous.Position +
                        new Vector3(partDistance, 0, 0);
                }
                else
                {
                    newPosition =
                        previous.Position -
                        new Vector3(partDistance, 0, 0);
                }

                SpringNode next = new SpringNode(newPosition);

                previous.Neighbors[next] = partDistance;
                next.Neighbors[previous] = partDistance;

                skeleton.Nodes.Add(next);

                previous = next;
            }

            SpringNode end = new SpringNode(previous.Position + new Vector3(partDistance, 0, 0));

            previous.Neighbors[end] = partDistance;
            end.Neighbors[previous] = partDistance;

            skeleton.Nodes.Add(end);
        }
コード例 #5
0
        public static void CreateChain(SpringSkeleton skeleton, int parts, float partDistance, Vector3 origin, bool right)
        {
            SpringNode start = new SpringNode(origin);

            skeleton.Nodes.Add(start);

            SpringNode previous = start;

            for (int i = 0; i < parts; i++) {
                // hack
                Vector3 newPosition = Vector3.Zero;

                if (right) {
                    newPosition =
                        previous.Position +
                        new Vector3(partDistance, 0, 0);
                } else {
                    newPosition =
                        previous.Position -
                        new Vector3(partDistance, 0, 0);
                }

                SpringNode next = new SpringNode(newPosition);

                previous.Neighbors[next] = partDistance;
                next.Neighbors[previous] = partDistance;

                skeleton.Nodes.Add(next);

                previous = next;
            }

            SpringNode end = new SpringNode(previous.Position + new Vector3(partDistance, 0, 0));

            previous.Neighbors[end] = partDistance;
            end.Neighbors[previous] = partDistance;

            skeleton.Nodes.Add(end);
        }
コード例 #6
0
 public SpringNodeAnchor(SpringNode node)
 {
     this.node = node;
     this.position = node.Position;
 }
コード例 #7
0
 public SpringNodeAnchor(SpringNode node)
 {
     this.node     = node;
     this.position = node.Position;
 }
コード例 #8
0
ファイル: GoalVisual.cs プロジェクト: jhauberg-archived/LD10
        public override void Initialize()
        {
            base.Initialize();

            skeleton.Enabled = true;

            skeleton.Coefficient = 0.3f;
            skeleton.Elasticity = 0.01f;
            skeleton.EnergyLoss = 0.86f;

            float width = 2;
            float height = 2;
            float depth = 3;
            float w = width / 2;
            float h = height / 2;
            float d = depth / 2;

            Vector3 offset = Vector3.Zero;//transform.Position;

            PlayingField field = GameContainer.Scene.Coordinator.Select("Playing Field")[0].Get<PlayingField>();

            if (goal.PlayerIndex == PlayerIndex.One) {
                offset = new Vector3(-(field.Width / 2) - (goal.Extents.X / 2) + 1.5f, 1, 0);
            } else if (goal.PlayerIndex == PlayerIndex.Two) {
                // hacky, i've messed something up with positioning, so the right goal seems further away..
                offset = new Vector3((field.Width / 2) + (goal.Extents.X / 2) - 3.5f, 1, 0);
            }

            // goal

            SpringNode a1 = null;

            // :>
            if (goal.PlayerIndex == PlayerIndex.One) {
                a1 = new SpringNode(offset + new Vector3(-w, -h, d));
            } else if (goal.PlayerIndex == PlayerIndex.Two) {
                a1 = new SpringNode(offset + new Vector3(w * 3, -h, d));
            }

            SpringNode a2 = new SpringNode(offset + new Vector3(w, -h, d));
            SpringNode a3 = new SpringNode(offset + new Vector3(w, h, d));

            SpringNode b1 = null;

            // :>
            if (goal.PlayerIndex == PlayerIndex.One) {
                b1 = new SpringNode(offset + new Vector3(-w, -h, -d));
            } else if (goal.PlayerIndex == PlayerIndex.Two) {
                b1 = new SpringNode(offset + new Vector3(w * 3, -h, -d));
            }

            SpringNode b2 = new SpringNode(offset + new Vector3(w, -h, -d));
            SpringNode b3 = new SpringNode(offset + new Vector3(w, h, -d));

            SpringNodeAnchor a1Anchor = new SpringNodeAnchor(a1);
            SpringNodeAnchor a2Anchor = new SpringNodeAnchor(a2);
            SpringNodeAnchor a3Anchor = new SpringNodeAnchor(a3);

            SpringNodeAnchor b1Anchor = new SpringNodeAnchor(b1);
            SpringNodeAnchor b2Anchor = new SpringNodeAnchor(b2);
            SpringNodeAnchor b3Anchor = new SpringNodeAnchor(b3);

            a1.Neighbors.Add(a2, Vector3.Distance(a1.Position, a2.Position));
            a1.Neighbors.Add(a3, Vector3.Distance(a1.Position, a3.Position));
            a1.Neighbors.Add(b1, Vector3.Distance(a1.Position, b1.Position));

            a2.Neighbors.Add(a1, Vector3.Distance(a2.Position, a1.Position));
            a2.Neighbors.Add(a3, Vector3.Distance(a2.Position, a3.Position));

            a3.Neighbors.Add(a1, Vector3.Distance(a3.Position, a1.Position));
            a3.Neighbors.Add(a2, Vector3.Distance(a3.Position, a2.Position));
            a3.Neighbors.Add(b3, Vector3.Distance(a3.Position, b3.Position));

            b1.Neighbors.Add(b2, Vector3.Distance(b1.Position, b2.Position));
            b1.Neighbors.Add(b3, Vector3.Distance(b1.Position, b3.Position));
            b1.Neighbors.Add(a1, Vector3.Distance(b1.Position, a1.Position));

            b2.Neighbors.Add(b1, Vector3.Distance(b2.Position, b1.Position));
            b2.Neighbors.Add(b3, Vector3.Distance(b2.Position, b3.Position));

            b3.Neighbors.Add(b1, Vector3.Distance(b3.Position, b1.Position));
            b3.Neighbors.Add(b2, Vector3.Distance(b3.Position, b2.Position));
            b3.Neighbors.Add(a3, Vector3.Distance(b3.Position, a3.Position));

            // net
            float dist = 0.5f;

            SpringNode na1 = new SpringNode(new Vector3(0, 0, 0));
            SpringNode na2 = new SpringNode(new Vector3(dist, 0, 0));
            SpringNode na3 = new SpringNode(new Vector3(dist * 2, 0, 0));
            SpringNode na4 = new SpringNode(new Vector3(dist * 3, 0, 0));
            SpringNode na5 = new SpringNode(new Vector3(0, dist, 0));
            SpringNode na6 = new SpringNode(new Vector3(dist, dist, 0));
            SpringNode na7 = new SpringNode(new Vector3(dist * 2, dist, 0));
            SpringNode na8 = new SpringNode(new Vector3(dist * 3, dist, 0));

            na1.Neighbors.Add(na2, dist);
            na1.Neighbors.Add(na5, dist);

            na2.Neighbors.Add(na1, dist);
            na2.Neighbors.Add(na6, dist);
            na2.Neighbors.Add(na3, dist);

            na3.Neighbors.Add(na2, dist);
            na3.Neighbors.Add(na4, dist);
            na3.Neighbors.Add(na7, dist);

            na4.Neighbors.Add(na3, dist);
            na4.Neighbors.Add(na8, dist);

            na5.Neighbors.Add(na1, dist);
            na5.Neighbors.Add(na6, dist);

            na6.Neighbors.Add(na5, dist);
            na6.Neighbors.Add(na2, dist);
            na6.Neighbors.Add(na7, dist);

            na7.Neighbors.Add(na6, dist);
            na7.Neighbors.Add(na3, dist);
            na7.Neighbors.Add(na8, dist);

            na8.Neighbors.Add(na7, dist);
            na8.Neighbors.Add(na4, dist);

            a1.Neighbors.Add(na4, dist);
            na4.Neighbors.Add(a1, dist);

            b1.Neighbors.Add(na1, dist);
            na1.Neighbors.Add(b1, dist);

            a3.Neighbors.Add(na8, dist);
            na8.Neighbors.Add(a3, dist);

            b3.Neighbors.Add(na5, dist);
            na5.Neighbors.Add(b3, dist);

            skeleton.Nodes.AddRange(
                new SpringNode[] {
                    a1, a2, a3, b1, b2, b3,
                    na1, na2, na3, na4, na5, na6, na7, na8 });
            skeleton.Anchors.AddRange(new SpringNodeAnchor[] { a1Anchor, a2Anchor, a3Anchor, b1Anchor, b2Anchor, b3Anchor });
        }
コード例 #9
0
ファイル: SpringNode.cs プロジェクト: jhauberg-archived/LD10
        public static bool IsAnchor(SpringNode node, SpringSkeleton skeleton, out SpringNodeAnchor anchor)
        {
            anchor = null;
            for (int i = 0; i < skeleton.Anchors.Count; i++) {
                if (skeleton.Anchors[i].Node == node) {
                    anchor = skeleton.Anchors[i];

                    return true;
                }
            }

            return false;
        }
コード例 #10
0
ファイル: SpringNode.cs プロジェクト: jhauberg-archived/LD10
        public static bool IsAnchor(SpringNode node, SpringSkeleton skeleton)
        {
            // necessary to store the reference somewhere
            SpringNodeAnchor anchor;

            return SpringNode.IsAnchor(node, skeleton, out anchor);
        }