Hi… this actually is an attempt of mine of transferring core-dump's example of a box's localsize being controlled by GBUI components in SimpleGame into my project in BaseGame… It works in SimpleGame, coz I tried writing it again in simplegame other than the code core-dump gave me and it seems to work fine… but when I transfer it back to BaseGame, the controls are missing… am I lacking something? please tell… help appreciated
import com.jme.app.BaseGame;
import com.jme.image.Texture;
import com.jme.input.InputHandler;
import com.jme.input.MouseInput;
import com.jme.light.DirectionalLight;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jme.bounding.BoundingBox;
import com.jmex.bui.BButton;
import com.jmex.bui.BDecoratedWindow;
import com.jmex.bui.BLabel;
import com.jmex.bui.BSlider;
import com.jmex.bui.BWindow;
import com.jmex.bui.BuiSystem;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.enumeratedConstants.Orientation;
import com.jmex.bui.event.ActionEvent;
import com.jmex.bui.event.ActionListener;
import com.jmex.bui.event.ChangeEvent;
import com.jmex.bui.event.ChangeListener;
import com.jmex.bui.layout.TableLayout;
import com.jmex.bui.layout.AbsoluteLayout;
public class TerrainModeler3 extends BaseGame{
/*
* global declarations within class
*/
private int width, height, depth, freq;
private boolean fullscreen;
private Camera cam;
private Node scene;
protected Timer timer;
private Skybox skybox;
/*
* BaseGame system modules
*/
public static void main(String args[]){
TerrainModeler3 app = new TerrainModeler3();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void initSystem(){
width = settings.getWidth();
height = settings.getHeight();
depth = settings.getDepth();
freq = settings.getFrequency();
fullscreen = settings.isFullscreen();
try{
display = DisplaySystem.getDisplaySystem(this.settings.getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
}catch(JmeException e){
e.printStackTrace();
System.exit(1);
}
display.getRenderer().setBackgroundColor(ColorRGBA.black);
cam.setFrustumPerspective(45.0f, (float)width/(float)height,1, 1000);
Vector3f loc = new Vector3f(250.0f, 150.0f, 500.0f);
Vector3f left = new Vector3f(-0.5f, 0.0f, 0.5f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(-0.5f, 0.0f, -0.5f);
cam.setFrame(loc, left,up,dir);
display.getRenderer().setCamera(cam);
display.setTitle("AUTOMATOS: RCX Robotics Simulator - Terrain Modeler");
timer = Timer.getTimer();
MouseInput.get().setCursorVisible(true);
}
protected void initGame(){
scene = new Node("TerrainModelerScene");
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
scene.setRenderState(buf);
buildSkyBox();
buildLighting();
Box box = new Box("",new Vector3f(0,0,0),10,10,10);
box.setModelBound(new BoundingBox());
box.updateModelBound();
box.updateRenderState();
scene.attachChild(box);
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
InputHandler input = new InputHandler();
BuiSystem.init(new PolledRootNode(timer, input), "/rsrc/style2.bss");
createGUI();
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
}
protected void render(float interpolation){
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
DisplaySystem.getDisplaySystem().getRenderer().draw(BuiSystem.getRootNode());
}
protected void update(float interpolation){
timer.update();
interpolation = timer.getTimePerFrame();
skybox.setLocalTranslation(cam.getLocation());
scene.updateGeometricState(interpolation, true);
}
protected void reinit(){
display.recreateWindow(width, height, depth, freq, fullscreen);
}
protected void cleanup(){
}
/*
* User - Defined Modules
*/
private void buildSkyBox(){
skybox = new Skybox("skybox",10,10,10);
String skyImage = "images/skybox.png";
Texture north = TextureManager.loadTexture(TerrainModeler.class.getClassLoader().getResource(skyImage),Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
Texture south = TextureManager.loadTexture(TerrainModeler.class.getClassLoader().getResource(skyImage),Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
Texture east = TextureManager.loadTexture(TerrainModeler.class.getClassLoader().getResource(skyImage),Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
Texture west = TextureManager.loadTexture(TerrainModeler.class.getClassLoader().getResource(skyImage),Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear);
skybox.setTexture(Skybox.Face.North, north);
skybox.setTexture(Skybox.Face.East, east);
skybox.setTexture(Skybox.Face.South, south);
skybox.setTexture(Skybox.Face.West, west);
skybox.preloadTextures();
skybox.updateRenderState();
scene.attachChild(skybox);
scene.updateRenderState();
}
private void buildLighting() {
/** Set up a basic, default light. */
DirectionalLight light = new DirectionalLight();
light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setDirection(new Vector3f(1,-1,0));
light.setEnabled(true);
/** Attach the light to a lightState and the lightState to rootNode. */
LightState lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
scene.setRenderState(lightState);
}
private void createGUI() {
BWindow window = new BDecoratedWindow(BuiSystem.getStyle(), null);
TableLayout layout = new TableLayout(1, 10, 0);
layout.setEqualRows(true);
layout.setHorizontalAlignment(TableLayout.STRETCH);
window.setLayoutManager(layout);
BuiSystem.addWindow(window);
window.setSize(250, display.getHeight());
window.setAlpha(100.0f);
// the exit Button, calls BaseGame.quit() when executed
BButton btnExit = new BButton("Exit");
btnExit.addListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
quit();
}
});
window.add(btnExit);
// the slider changes the box's local scale
window.add(new BLabel("LocalScale slider:"));
final BSlider boxSlider = new BSlider(Orientation.HORIZONTAL, 1, 500, 100);
boxSlider.getModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent event) {
//box.setLocalScale(boxSlider.getModel().getValue()/(float)100);
}
});
window.add(boxSlider);
}
}