示例#1
0
        // breakLimb
        public void breakLimb()
        {
            // Should never break a broken limb
            Debug.Assert(doBreak && !isBroken);

            doBreak = false;
            isBroken = true;

            // Destroy internode constraint
            internodeConstraint = null;

            // Build a list of metamers on this branch
            List<Metamer> metamersOnBranch = new List<Metamer>();
            findMetamersOnBranch(metamersOnBranch);

            // Break acropetal constraints
            breakUpwards(metamersOnBranch);
        }
示例#2
0
        public Metamer(Tree tree, Metamer previousMetamer, BudType activeBud, BudState terminalBudState, BudState lateralBudState, float axis, bool placeBudOnLeft)
        {
            this.tree = tree;
            this.activeBud = activeBud;
            this.previousMetamer = previousMetamer;
            this.terminalBudState = terminalBudState;
            this.lateralBudState = lateralBudState;
            this.axis = axis;
            this.placeBudOnLeft = placeBudOnLeft;

            aabb = new AABB();
            isRoot = previousMetamer == null;
            constraintPoints = new List<Metamer>();
            previousConstraintPoints = new List<Metamer>();
            associatedMarkers = new List<MetamerMarker>();
            fixturesToTest = new Fixture[MAX_FIXTURES_TO_TEST];
            localGridHalfWidth = (int)Math.Floor(tree.perceptionRadius / TreeSystem.PLANT_CELL_SIZE) + 2;
            localGridHalfHeight = (int)Math.Floor(tree.perceptionRadius / TreeSystem.PLANT_CELL_SIZE) + 2;
            currentAngle = axis;
            currentTextureAngle = axis;
            collisionVertices = new Vector2[FarseerPhysics.Settings.MaxPolygonVertices];
            collisionNormals = new Vector2[FarseerPhysics.Settings.MaxPolygonVertices];
            constraints = new List<MetamerConstraint>();
            relatedConstraints = new List<MetamerConstraint>();
            _vertices = new VertexPositionColorTexture[2];

            // Mass
            mass = 1f;
            inverseMass = 1f / mass;

            // Calculate position
            position = (isRoot ? tree.position : previousMetamer.position + new Vector2((float)Math.Cos(axis), (float)Math.Sin(axis)) * tree.internodeLength);
            oldPosition = position;

            // Trunk constraints
            if (!isRoot)
            {
                if (isApex() && tree.iterations < 2)
                {
                    // Create anchor constraints
                    Vector2 relative = position - tree.rootPosition;
                    Vector2 anchorA = tree.rootPosition + tree.anchorNormal * 3f;
                    float distance = (anchorA - position).Length();
                    constraints.Add(new TrunkMetamerConstraint(this, anchorA, distance));

                    Vector2 anchorB = tree.rootPosition + tree.anchorNormal * -3f;
                    distance = (anchorB - position).Length();
                    constraints.Add(new TrunkMetamerConstraint(this, anchorB, distance));
                }

                // Create metamer-metamer links
                if (!previousMetamer.isBroken)
                    internodeConstraint = new DistanceMetamerConstraint(this, previousMetamer, tree.internodeLength * 0.8f, 0.5f);
            }

            // Put this metamer in a cell in the metamer grid
            ci = tree.treeSystem.getPlantGridX(position.X);
            cj = tree.treeSystem.getPlantGridY(position.Y);
            if (!tree.treeSystem.metamerGrid.ContainsKey(tree.levelUid))
            {
                tree.treeSystem.metamerGrid.Add(tree.levelUid, new Dictionary<int, Dictionary<int, List<Metamer>>>());
            }
            if (!tree.treeSystem.metamerGrid[tree.levelUid].ContainsKey(ci))
            {
                tree.treeSystem.metamerGrid[tree.levelUid][ci] = new Dictionary<int, List<Metamer>>();
            }
            if (!tree.treeSystem.metamerGrid[tree.levelUid][ci].ContainsKey(cj))
            {
                tree.treeSystem.metamerGrid[tree.levelUid][ci][cj] = new List<Metamer>();
            }
            tree.treeSystem.metamerGrid[tree.levelUid][ci][cj].Add(this);

            // Destroy markers in the occupied zone
            destroyMarkersInOccupiedZone();

            // Expand level boundary
            tree.treeSystem.levelSystem.expandFallbackBoundary(tree.levelUid, position);

            // Determine z-index
            _z = tree.layerDepth + StasisMathHelper.floatBetween(-0.02f, 0.01f, tree.random);
        }