public TrunkMetamerConstraint(Metamer metamer, Vector2 anchorPoint, float distance) : base(ConstraintType.TRUNK) { this.metamer = metamer; this.anchorPoint = anchorPoint; this.distance = distance; }
public object MetamerGrow(Metamer meta) { return(Produce( new Internode(1, 1), StartBranch, TurnRight(meta.Angle), new Axis(-Delay, meta.Angle), EndBranch, new Internode(1, 1))); }
// addCompetition public void addCompetition(BudType budType, float distanceToBud, Metamer metamer) { if (competition == null) { competition = new MarkerCompetition(budType, distanceToBud, metamer); } else if (competition.budType == budType && competition.distanceToBud > distanceToBud) { competition.distanceToBud = distanceToBud; competition.metamer = metamer; } }
// Constructor public Tree(TreeSystem treeSystem, string levelUid, Texture2D barkTexture, List <List <Texture2D> > leafTextures, XElement data) { _treeSystem = treeSystem; _levelUid = levelUid; _leafTextures = leafTextures; _barkTexture = barkTexture; _angle = Loader.loadFloat(data.Attribute("angle"), 0f); _seed = Loader.loadInt(data.Attribute("seed"), 12345); _age = Loader.loadFloat(data.Attribute("age"), 0f); _internodeHalfLength = Loader.loadFloat(data.Attribute("internode_half_length"), 0.5f); _internodeLength = _internodeHalfLength * 2f; _maxShootLength = Loader.loadInt(data.Attribute("max_shoot_length"), 4); _maxBaseHalfWidth = Loader.loadFloat(data.Attribute("max_base_half_width"), 0.25f); _perceptionAngle = Loader.loadFloat(data.Attribute("perception_angle"), 0.6f); _perceptionRadius = Loader.loadFloat(data.Attribute("perception_radius"), 4f); _occupancyRadius = Loader.loadFloat(data.Attribute("occupancy_radius"), 1f); _lateralAngle = Loader.loadFloat(data.Attribute("lateral_angle"), 0.6f); _fullExposure = Loader.loadFloat(data.Attribute("full_exposure"), 1f); _penumbraA = Loader.loadFloat(data.Attribute("penumbra_a"), 1f); _penumbraB = Loader.loadFloat(data.Attribute("penumbra_b"), 2f); _optimalGrowthWeight = Loader.loadFloat(data.Attribute("optimal_growth_weight"), 1f); _tropismWeight = Loader.loadFloat(data.Attribute("tropism_weight"), 1f); _tropism = Loader.loadVector2(data.Attribute("tropism"), Vector2.Zero); _position = Loader.loadVector2(data.Attribute("position"), Vector2.Zero); _layerDepth = Loader.loadFloat(data.Attribute("layer_depth"), 0.1f); _entityId = int.Parse(data.Attribute("id").Value); _vertices = new VertexPositionColorTexture[MAX_VERTICES]; for (int i = 0; i < MAX_VERTICES; i++) { _vertices[i].Color = Color.White; } _random = new Random(_seed); _internodeLengthSq = _internodeLength * _internodeLength; _aabb = new AABB(); _aabb.LowerBound = _position; _aabb.UpperBound = _position; // Calculate root position float rootAngle = _angle + (StasisMathHelper.pi); _rootPosition = _position + new Vector2((float)Math.Cos(rootAngle), (float)Math.Sin(rootAngle)) * 5f; // Calculate anchor normals float anchorAngle = _angle - (StasisMathHelper.pi * 0.5f); _anchorNormal = new Vector2((float)Math.Cos(anchorAngle), (float)Math.Sin(anchorAngle)); // Create first metamer _rootMetamer = new Metamer(this, null, BudType.TERMINAL, BudState.DORMANT, BudState.DEAD, _angle, true); _rootMetamer.isTail = true; }
public List <MetamerMarker> getAssociatedMarkers(BudType budType, Metamer metamer) { List <MetamerMarker> associatedMarkers = new List <MetamerMarker>(); for (int n = 0; n < markers.Count; n++) { if (markers[n].competition != null && markers[n].competition.budType == budType && markers[n].competition.metamer == metamer) { associatedMarkers.Add(markers[n]); } } return(associatedMarkers); }
// prepareCollisions private void prepareCollisions() { string levelUid = LevelSystem.currentLevelUid; Dictionary <int, Dictionary <int, List <Metamer> > > levelMetamerGrid; Dictionary <int, List <Metamer> > gridX; List <Metamer> gridY; // Query the world using the screen's AABB _physicsSystem.getWorld(levelUid).QueryAABB((Fixture fixture) => { // Skip certain collisions int entityId = (int)fixture.Body.UserData; if (_entityManager.getComponent(levelUid, entityId, ComponentType.IgnoreTreeCollision) != null) { return(true); } AABB aabb; Transform transform; fixture.Body.GetTransform(out transform); fixture.Shape.ComputeAABB(out aabb, ref transform, 0); int Ax = getPlantGridX(aabb.LowerBound.X); int Ay = getPlantGridY(aabb.LowerBound.Y); int Bx = getPlantGridX(aabb.UpperBound.X) + 1; int By = getPlantGridY(aabb.UpperBound.Y) + 1; if (_metamerGrid.TryGetValue(levelUid, out levelMetamerGrid)) { for (int i = Ax; i < Bx; i++) { for (int j = Ay; j < By; j++) { if (levelMetamerGrid.TryGetValue(i, out gridX) && gridX.TryGetValue(j, out gridY)) { for (int n = 0; n < gridY.Count; n++) { Metamer metamer = gridY[n]; if (metamer.numFixturesToTest < Metamer.MAX_FIXTURES_TO_TEST) { metamer.fixturesToTest[metamer.numFixturesToTest] = fixture; metamer.numFixturesToTest++; } } } } } } return(true); }, ref treeAABB); }
public DistanceMetamerConstraint(Metamer metamerA, Metamer metamerB, float distance, float stiffness) : base(ConstraintType.DISTANCE) { this.metamerA = metamerA; this.metamerB = metamerB; this.distance = distance; this.stiffness = stiffness; Debug.Assert(!metamerA.isBroken); Debug.Assert(!metamerB.isBroken); // Square root approximations variables distanceSq = distance * distance; metamerB.relatedConstraints.Add(this); }
public Metamer findMetamer(string levelUid, Vector2 position) { Dictionary <int, Dictionary <int, List <Metamer> > > levelMetamerGrid; Dictionary <int, List <Metamer> > gridX; List <Metamer> gridY; int i = getPlantGridX(position.X); int j = getPlantGridY(position.Y); int padding = 2; float shortestDistanceSq = 99999f; Metamer result = null; if (metamerGrid.TryGetValue(levelUid, out levelMetamerGrid)) { for (int x = i - padding; x < i + padding; x++) { for (int y = j - padding; y < j + padding; y++) { if (levelMetamerGrid.TryGetValue(x, out gridX) && gridX.TryGetValue(y, out gridY)) { for (int n = 0; n < gridY.Count; n++) { if (gridY[n].isBranchingPoint() || gridY[n].isTail) { float distanceSq = (gridY[n].position - position).LengthSquared(); if (distanceSq < shortestDistanceSq) { shortestDistanceSq = distanceSq; result = gridY[n]; } } } } } } } return(result); }
public FollowMetamerComponent(Metamer metamer) { _metamer = metamer; }
public void addMarkerCompetition(int markerIndex, BudType budType, float distanceToBud, Metamer metamer) { markers[markerIndex].addCompetition(budType, distanceToBud, metamer); }
public MetamerComponent(Metamer metamer) { _metamer = metamer; }
public object MetamerGrow(Metamer meta) { return Produce( new Internode(1, 1), StartBranch, TurnRight(meta.Angle), new Axis(-Delay, meta.Angle), EndBranch, new Internode(1, 1)); }
public MarkerCompetition(BudType budType, float distanceToBud, Metamer metamer) { this.budType = budType; this.distanceToBud = distanceToBud; this.metamer = metamer; }