Example #1
0
 internal Organ(Guid dnauid, Organism organism, Organ parent, Vector2 position, float radius)
 {
     DNAUID   = dnauid;
     Organism = organism;
     Parent   = parent;
     Radius   = radius;
     Body     = new Body(organism.World, position, 0, BodyType.Dynamic, this);
     Body.CreateFixture(new CircleShape(radius, 1), new OrganUserData()
     {
         Organ = this
     });
     Body.UserData = new OrganUserData()
     {
         Organ = this
     };
     if (parent != null)
     {
         Bone          = new DistanceJoint(parent.Body, Body, Vector2.Zero, Vector2.Zero);
         Bone.UserData = new BoneUserData()
         {
             From = parent, To = this
         };
         organism.World.AddJoint(Bone);
     }
 }
Example #2
0
        public Muscle(Organism organism, Organ from, Organ to, float fromRadialPosition, float toRadialPosition, float contractionFactor)
        {
            Organism          = organism;
            From              = from;
            To                = to;
            ContractionFactor = contractionFactor;
            var angle      = fromRadialPosition * Math.PI / 180.0;
            var x          = (float)Math.Cos(angle) * from.Radius;
            var y          = (float)Math.Sin(angle) * from.Radius;
            var anchorFrom = new Vector2(x, y);

            angle = toRadialPosition * Math.PI / 180.0;
            x     = (float)Math.Cos(angle) * to.Radius;
            y     = (float)Math.Sin(angle) * to.Radius;
            var anchorTo = new Vector2(x, y);

            Joint = new DistanceJoint(from.Body, to.Body, anchorFrom, anchorTo)
            {
                DampingRatio = 1, Frequency = 0.9f
            };
            Joint.UserData = new MuscleUserData()
            {
                Muscle = this
            };
            organism.World.AddJoint(Joint);
        }
Example #3
0
 private void WriteOrgan(BinaryWriter writer, Organ organ)
 {
     writer.Write(organ.UID.ToString());
     writer.Write(organ.Radius);
     writer.Write(organ.RadialOrientation);
     writer.Write(organ.Children.Count);
     foreach (var child in organ.Children)
     {
         WriteOrgan(writer, child);
     }
 }
Example #4
0
 private static void CreateChildrenOrgan(Organ root, DNA.Organ dna, Vector2 worldPos)
 {
     foreach (var leaf in dna.Children)
     {
         var distance = dna.Radius + leaf.Radius + MinimumOrganDistance;
         var angle    = leaf.RadialOrientation * Math.PI / 180.0;
         var x        = (float)Math.Cos(angle) * distance;
         var y        = (float)Math.Sin(angle) * distance;
         var position = new Vector2(x, y) + worldPos;
         var child    = new Organ(leaf.UID, root.Organism, root, position, leaf.Radius);
         root.m_children.Add(child);
         CreateChildrenOrgan(child, leaf, position);
     }
 }
Example #5
0
        private static Organ ReadOrgan(BinaryReader reader)
        {
            var organ = new Organ();

            organ.UID               = new Guid(reader.ReadString());
            organ.Radius            = reader.ReadSingle();
            organ.RadialOrientation = reader.ReadSingle();
            var c = reader.ReadInt32();

            for (var i = 0; i < c; ++i)
            {
                organ.Children.Add(ReadOrgan(reader));
            }
            return(organ);
        }
Example #6
0
 private static Organ FindOrgan(Organ root, Guid uid)
 {
     if (root.UID == uid)
     {
         return(root);
     }
     foreach (var child in root.Children)
     {
         var found = FindOrgan(child, uid);
         if (found != null)
         {
             return(found);
         }
     }
     return(null);
 }