2015-06-11 22 views
0

我剛剛拿起jMonkeyEngine,遇到了一個我似乎無法解決的問題。爲什麼我的幾何體不會出現? (jMonkeyEngine)

在主類的simpleInitApp方法,我可以使用下面的代碼成功地使一個盒子:

Box playerBase = new Box(Vector3f.ZERO,1f,1f,1f); 
    Geometry playerBaseGeom = new Geometry("playerBase", playerBase); 
    Transform fixBaseHeight = new Transform(
      new Vector3f(0f,(0.5f * 2f),0f)); 
    playerBaseGeom.setLocalTransform(fixBaseHeight); 
    Material playerBaseMaterial = new Material(assetManager, 
      "Common/MatDefs/Misc/Unshaded.j3md"); 
    playerBaseMaterial.setColor("Color", ColorRGBA.Yellow); 
    playerBaseGeom.setMaterial(playerBaseMaterial); 
    rootNode.attachChild(playerBaseGeom); 

我試圖用一種叫做Tower類能夠釀出代表塔好幾箱(爲一個簡單的塔防遊戲)。塔類看起來是這樣的:

public class Tower { 

    private static final float HEIGHT = 0.5f; 
    private static final float WIDTH = 0.2f; 
    private static final float DEPTH = 0.2f; 

    private Geometry towerGeom; 
    private Material towerMaterial; 
    private Box tower; 

    public Tower(AssetManager assetManager, float x_coord, float z_coord) { 

     tower = new Box(); 
     towerGeom = new Geometry("tower", tower); 
     towerMaterial = new Material(assetManager, 
       "Common/MatDefs/Misc/Unshaded.j3md"); 
     towerMaterial.setColor("Color", ColorRGBA.Green); 
     towerGeom.setMaterial(towerMaterial); 

     towerGeom.setLocalTranslation(x_coord, (0.5f * .5f),z_coord); 
     towerGeom.setLocalScale(WIDTH, HEIGHT, DEPTH); 
    } 

    public Geometry getGeometry() { 
     return towerGeom; 
    } 
} 

在主類,在simpleInitApp的方法,我試圖用我的新Tower類是這樣的:

List <Tower> towers = new ArrayList<Tower>(); 
    towers.add(new Tower(assetManager, 10f,8f)); 
    for(Tower t:towers) { 
     rootNode.attachChild(t.getGeometry()); 
    } 

但是,沒有立方體呈現。爲什麼?我使用了開始時顯示的完全相同的過程,它的工作。

+0

不要忘記照明。 – markspace

回答

1

構造函數Box()僅用於序列化,不初始化網格。上面的示例中的構造函數已被棄用。使用:

tower = new Box(0.5f, 0.5f, 0.5f); 

這將創建一個以[0,0,0]爲中心的大小爲1x1x1的立方體。

另外,請確保你看看塔。在默認的攝像頭位置和塔杆位於[10,0,8]時,它將放置在你身後。

getCamera().lookAt(new Vector3f(10f, 0, 8f), Vector3f.UNIT_Y); 

我建議諮詢這類問題的jME源代碼,以便您可以確定發生了什麼事情。

相關問題