barsuift.simLife.tree.TreeBranchStateFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simLifeCore Show documentation
Show all versions of simLifeCore Show documentation
Core module of the simLife project, containing main logic code
/**
* barsuift-simlife is a life simulator programm
*
* Copyright (C) 2010 Cyrille GACHOT
*
* This file is part of barsuift-simlife.
*
* barsuift-simlife is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* barsuift-simlife is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with barsuift-simlife. If not, see
* .
*/
package barsuift.simLife.tree;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import barsuift.simLife.Randomizer;
import barsuift.simLife.j3d.tree.TreeBranch3DState;
import barsuift.simLife.j3d.tree.TreeBranch3DStateFactory;
import barsuift.simLife.j3d.util.BarycentreHelper;
import barsuift.simLife.j3d.util.PointHelper;
public class TreeBranchStateFactory {
private static long BRANCH_COUNT = 1;
public TreeBranchState createRandomBranchState(Vector3d translationVector, Point3d branchEndPoint) {
int age = Randomizer.randomBetween(0, 100);
BigDecimal energy = new BigDecimal(Randomizer.randomBetween(0, 100));
BigDecimal freeEnergy = new BigDecimal(Randomizer.randomBetween(0, 50));
TreeBranchPartStateFactory treeBranchPartStateFactory = new TreeBranchPartStateFactory();
List treeBranchPartStates = new ArrayList();
// TODO 080. the number of parts should be related to the length of the branch
// TODO 050. the parts should be removed entirely and branches should be added to branches
int nbParts = 3;
for (int i = 0; i < nbParts; i++) {
Point3d branchPartEndPoint = computeBranchPartEndPoint(branchEndPoint, nbParts);
treeBranchPartStates.add(treeBranchPartStateFactory.createRandomBranchPartState(branchPartEndPoint));
}
TreeBranch3DStateFactory branch3DStateFactory = new TreeBranch3DStateFactory();
TreeBranch3DState branch3DState = branch3DStateFactory.createRandomTreeBranch3DState(translationVector);
return new TreeBranchState(BRANCH_COUNT++, age, energy, freeEnergy, treeBranchPartStates, branch3DState);
}
protected Point3d computeBranchPartEndPoint(Point3d branchEndPoint, int nbParts) {
Point3d startPoint = new Point3d(0, 0, 0);
double maxDistance = startPoint.distance(branchEndPoint);
double averagePartLength = maxDistance / nbParts;
Point3d partEndPoint = BarycentreHelper.getBarycentre(new Point3d(0, 0, 0), branchEndPoint, (Randomizer
.random2() + 1)
* averagePartLength);
partEndPoint = PointHelper.shiftPoint(partEndPoint, maxDistance / 10);
return partEndPoint;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy