Exemple #1
0
        private void AddInterconnection(BaseGeneViewModel gene)
        {
            var interConnGene = (InterconnectionViewModel)gene;
            var model         = interConnGene.GetModelDuplicate();

            var body = WillHelper.TryAddInterconnectionBody(model, 5);
        }
Exemple #2
0
        private void AddBone(BaseGeneViewModel gene)
        {
            Will.Instance.RunPauseWilling(false);

            var boneGene = (BoneGeneViewModel)gene;

            var boneModel = boneGene.GetModelDuplicate();

            var boneBody = WillHelper.AddBoneBody(boneModel);

            Will.Instance.RunPauseWilling(true);
        }
Exemple #3
0
        private void AddCore(Guid geneApplicationId, BaseGeneViewModel gene)
        {
            var core  = (CoreGeneViewModel)gene;
            var model = core.GetModelDuplicate();

            model.Id = geneApplicationId;

            var coreBody = WillHelper.CreateCoreBody(model, geneApplicationId);

            var nodes = WillHelper.BuildNodeSlots(coreBody, geneApplicationId);

            coreBody.Children = nodes;
            var corePos = coreBody.State.Position;

            var joints = new List <Joint>();

            foreach (var node in nodes)
            {
                var hinge = new HingeJoint(coreBody, node, (2 * node.State.Position.Linear + 8 * corePos.Linear) * 0.1f, new Lifespan())
                {
                    DistanceTolerance = 10,
                    Softness          = 100.0
                };
                var angle = new AngleJoint(coreBody, node, new Lifespan())
                {
                    Softness = 0.0001, BiasFactor = 0.2f
                };

                joints.Add(hinge);
                joints.Add(angle);
            }


            Will.Instance.AddModelBodies(new List <BaseModelBody> {
                coreBody
            }.Concat(nodes).ToList());
            Will.Instance.AddJoints(joints);
        }
Exemple #4
0
        private void AddSlot(BaseGeneViewModel gene)
        {
            Will.Instance.RunPauseWilling(false);

            var slotGene = (NodeGeneViewModel)gene;

            var boneBody = Will.Instance.Bodies.RandomOrDefault <BoneBody>(b => b.Model.ChildSlots.Any(s => s.IsOccupied == false));

            if (boneBody == null)
            {
                Will.Instance.RunPauseWilling(true);
                return;
            }

            var parPos = boneBody.State.Position;

            var randSlot = boneBody.Model.ChildSlots.Where(s => s.IsOccupied == false).RandomOrDefault();

            var slot = slotGene.GetModelDuplicate();

            slot.Direction          = randSlot.Direction;
            slot.DistanceFromCenter = randSlot.DistanceFromCenter;
            slot.Orientation        = randSlot.Orientation;

            randSlot.IsOccupied = true;

            var slotBody = WillHelper.CreateConnectionSlotBody(slot, boneBody.ModelId);


            var slotXAngle = slot.Direction + parPos.Angular;
            var slotCenter = Vector2D.Rotate(slotXAngle, new Vector2D(slot.DistanceFromCenter, 0.0f));
            var slotPos    = new ALVector2D(slot.Orientation + slotXAngle, slotCenter + parPos.Linear);

            slotBody.State.Position = slotPos;
            slotBody.ApplyPosition();

            slotBody.Parent = boneBody;

            boneBody.Children.Add(slotBody);

            var joints = new List <Joint>();

            var nodePos = slotBody.State.Position;

            var hinge = new HingeJoint(boneBody, slotBody, (slot.Size * nodePos.Linear + boneBody.Model.Length * parPos.Linear) * (1 / (slot.Size + boneBody.Model.Length)), new Lifespan())
            {
                DistanceTolerance = 50,
                Softness          = 10.1
            };
            var angle = new AngleJoint(boneBody, slotBody, new Lifespan())
            {
                Softness = 0.00001
            };

            joints.Add(hinge);
            joints.Add(angle);

            Will.Instance.AddBody(slotBody);
            Will.Instance.AddJoints(joints);

            Will.Instance.RunPauseWilling(true);
        }