I’m lost and need help! I’m trying to attach a few cylinders to the top end of main cylinder. All cylinders are randomly rotated.
Somehow this is what I see on the screen:
http://bp3.blogger.com/_lyvscL5tWXE/SAjV8TycWVI/AAAAAAAAABY/Y2iF-flOf5w/s1600-h/GrownBr.PNG
Here’s the code of main:
protected void simpleInitGame()
{
lightState.setEnabled(false);
AxisRods ar = new AxisRods("rods", true, 1f);
rootNode.attachChild(ar);
ar.setLocalTranslation(2f,0f,2f);
Node tree=new Node("Tree");
rootNode.attachChild(tree);
GrownBranch trunk=new GrownBranch(tree,new Vector3f(5f,0,5f),1);
Vector3f worldTrunkTop=trunk.getWorldCoordsOfTheTop();
for(int i=2;i<4;i++)
{
new GrownBranch(tree,worldTrunkTop,i);
}
And the code of GrownBranch:
public class GrownBranch
{
protected Cylinder me;
private static final Logger log=Logger.getLogger(GrownBranch.class.getName());
public GrownBranch(Node tree, Vector3f attachToWorldCoords,int branchNum)
{
float seedlingLength= (float) (Math.random()*10f);
float seedlingRadius=0.25f-0.05f*(float)(branchNum);
me = new Cylinder("Branch:"+branchNum,10,10,seedlingRadius, seedlingLength);
tree.attachChild(me);
if(branchNum==1)
me.setSolidColor(ColorRGBA.green);
else
if(branchNum==2)
me.setSolidColor(ColorRGBA.blue);
else
if(branchNum=:3)
me.setSolidColor(ColorRGBA.cyan);
else
if(branchNum==4)
me.setSolidColor(ColorRGBA.yellow);
else
if(branchNum==5)
me.setSolidColor(ColorRGBA.white);
else
if(branchNum==6)
me.setSolidColor(ColorRGBA.red);
else
me.setSolidColor(ColorRGBA.pink);
Quaternion rotX = new Quaternion();
rotX.fromAngleAxis((float)(Math.random()*Math.PI)/6f,new Vector3f(1.0f,0f,0f));
Quaternion rotY = new Quaternion();
rotY.fromAngleAxis((float)(Math.random()*Math.PI)/6f,new Vector3f(0f,1.0f,0f));
Quaternion rotZ = new Quaternion();
rotZ.fromAngleAxis((float)(Math.random()*Math.PI)/6f,new Vector3f(0f,0f,1.0f));
me.setLocalRotation(rotX);
/**
* The middle after this is in the proper position
*/
Vector3f localTrans=new Vector3f();
me.worldToLocal(attachToWorldCoords,localTrans);
log.info("Moving new branch to:"+localTrans);
me.setLocalTranslation(localTrans);
me.setModelBound(new BoundingBox());
me.updateModelBound();
}
public Vector3f getWorldCoordsOfTheTop()
{
return me.localToWorld(new Vector3f(0f,0f,0.5f*me.getHeight()),null);
}
}