Exemplo n.º 1
0
        private void AddVertexGraph(VertexGraph graph)
        {
            Individual = graph.Vertices.Select(vertex =>
            {
                var mass = 10000;
                var motionState = new DefaultMotionState();
                var collisionShape = new BoxShape(1);

                var info = new RigidBodyConstructionInfo(mass, motionState, collisionShape);
                var rigidBody = new VertexBoundRigidBody(vertex, info);

                return rigidBody;
            }).ToList();

            foreach (var body in Individual)
            {
                // Select the 3 nearest vertices, excluding this one
                var nearest = Individual.OrderBy(a => a.Binding.DistanceTo(body.Binding))
                                         .Where(a => a != body)
                                         .Take(3);
                foreach (var other in nearest)
                {
                    // TODO: What are these matrices supposed to be?
                    var frameInA = body.MotionState.WorldTransform;
                    var frameInB = other.MotionState.WorldTransform;

                    // TODO: How do you specify the spring's springiness?
                    var constraint = new Generic6DofSpringConstraint(body, other, frameInA, frameInB, true);

                    // TODO: Now how do I apply this to the bodies?
                    body.AddConstraintRef(constraint);
                    other.AddConstraintRef(constraint);
                }
            }
        }
Exemplo n.º 2
0
        public override Individual FromBinary(Stream stream)
        {
            var graph = new VertexGraph();

            using (stream)
            {
                var reader = new BinaryReader(stream);

                for (int i = 0; i < VertexCount; i++)
                {
                    var vertex = new Vertex(ReadNormalLong(reader), ReadNormalLong(reader), ReadNormalLong(reader), Max);
                    graph.Vertices.Add(vertex);
                }

                var individual = new SkyscraperIndividual(graph);

                return individual;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a random individual to be used in the initial population.
 /// </summary>
 public Individual()
 {
     Graph = new VertexGraph();
 }
Exemplo n.º 4
0
 public SkyscraperIndividual(VertexGraph graph)
 {
     Graph = graph;
 }
Exemplo n.º 5
0
        public VertexGraph Copy()
        {
            VertexGraph graph = new VertexGraph();

            foreach (var vertex in Vertices)
            {
                graph.Vertices.Add(vertex.Copy());
            }

            return graph;
        }
Exemplo n.º 6
0
 public DefaultRigidBodyWorld(VertexGraph initialState)
 {
     AddVertexGraph(initialState);
 }