Hello, this is my first post!
I'm trying to generate many copies of the same tree model (that I've managed to import from 3Dsmax) and place them randomly on the map. I've only ever been able to get one tree in, but its floating in the air and doesn't rotate like I tell it to :?
Here is my source code for the class I made:
public class Trees extends Node {
int t = 0;
TerrainPage tp;
ArrayList<Vector3f> olde;
Node TreeA;
Quaternion rotate90;
public Trees(TerrainPage tp)
{
super("tree");
children = new ArrayList<Spatial>(21);
rotate90 = new Quaternion();
rotate90.fromAngleAxis(FastMath.PI/2, new Vector3f(0,1,0));
this.tp = tp;
TreeA = LoadModel.loadModel("Models/tree.3ds");
System.out.println(TreeA.getTriangleCount());
olde = new ArrayList<Vector3f>();
}
public void plantTree()
{
float x = 0 + FastMath.nextRandomFloat() * 10;
float z = 0 + FastMath.nextRandomFloat() * 10;
float y = tp.getHeight(x,z) + 0f;
if(t==0)
{
t++;
olde.add(new Vector3f(x,y,z));
TreeA.setLocalTranslation(x, y, z);
Node tree = new Node();
tree = TreeA;
tree.setLocalRotation(rotate90);
children.add(tree);
}
else
{
check:
for(int i = 0;i<t;i++)
{
if(new Vector3f(x,y,z).equals(olde.get(i))==false)
{
t++;
olde.add(new Vector3f(x,y,z));
TreeA.setLocalTranslation(x, y, z);
Node tree = new Node();
tree = TreeA;
tree.setLocalRotation(rotate90);
children.add(tree);
break check;
}
else
{
plantTree();
}
}
}
}
public void plantTree(float x, float z)
{
float y = tp.getHeight(x,z) + 0f;
t++;
olde.add(new Vector3f(x,y,z));
TreeA.setLocalTranslation(x, y, z);
Node tree = new Node();
tree = TreeA;
tree.setLocalRotation(rotate90);
children.add(tree);
}
As well, setting the local scale lower doesn't seem to affect the size of the tree. Its absolutely gigantic.
Help would be very much appreciated!