Ok. I've attached my source.
To see my problem, press "W" to go to the quad-wall. When you're far enough and look back you see a wall to, making the whole into a corridor.
Walk to the right. When you're almost at the end of the corridor all the quads turn black. When you take a small step back they're all visible again. How is this possible and how can I fix it?
Thanks!
package com.techdemo;
import java.io.IOException;
import java.net.URL;
import java.nio.FloatBuffer;
import java.util.HashMap;
import javax.swing.ImageIcon;
import com.jme.scene.state.LightState;
import com.jme.math.Quaternion;
import jmetest.TutorialGuide.HelloStates;
import jmetest.renderer.ShadowTweaker;
import jmetest.renderer.TestAnisotropic;
import jmetest.renderer.TestSkybox;
import jmetest.terrain.TestTerrain;
import com.jme.app.SimpleGame;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Quad;
import com.jme.scene.shape.Sphere;
import com.jme.math.Vector3f;
import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.bounding.BoundingVolume;
import com.jme.image.Texture;
import com.jme.scene.state.LightState;
import com.jme.input.ChaseCamera;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.joystick.JoystickInput;
import com.jme.input.thirdperson.ThirdPersonMouseLook;
import com.jme.light.DirectionalLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.app.SimpleGame;
import com.jme.app.BaseGame;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.SharedMesh;
import com.jme.scene.Text;
import com.jme.scene.shape.Box;
import com.jme.scene.state.*;
import com.jme.input.*;
import com.jme.util.Timer;
import com.jme.util.TextureManager;
import com.jme.util.LoggingSystem;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import java.util.logging.Level;
import com.jme.input.MouseInput;
public class techDemoTest1 extends BaseGame
{
private int width, height, depth, freq;
private boolean fullscreen;
private Camera cam;
protected Timer timer;
private Node scene;
protected InputHandler input;
protected float interpolation;
private Quad wall;
private Quad smallerWall;
private Quad floor;
//private Vector3f axis = new Vector3f(0f, 0f, 1f);
//public URL monkeyLoc=techDemoTest3.class.getClassLoader().getResource("jmetest/data/images/Monkey.jpg");
public static void main(String[] args)
{
techDemoTest1 app = new techDemoTest1();
app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, techDemoTest1.class.getClassLoader().getResource("jmetest/data/images/Monkey.jpg"));
app.start();
}
protected void update(float interpolation)
{
timer.update();
interpolation = timer.getTimePerFrame();
input.update(interpolation);
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit"))
{
finished = true;
}
}
protected void render(float interpolation)
{
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
}
protected void initSystem()
{
//store the properties information
width = properties.getWidth();
height = properties.getHeight();
depth = properties.getDepth();
freq = properties.getFreq();
fullscreen = properties.getFullscreen();
try {
display = DisplaySystem.getDisplaySystem(properties.getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
e.printStackTrace();
System.exit(1);
}
//set the background to black
display.getRenderer().setBackgroundColor(ColorRGBA.black);
//initialize the camera
cam.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
// Move our camera to a correct place and orientation.
cam.setFrame(loc, left, up, dir);
/** Signal that we've changed our camera's location/frustum. */
cam.update();
/** Create a basic input controller. */
FirstPersonHandler firstPersonHandler = new FirstPersonHandler( cam, properties.getRenderer() );
/** Signal to all key inputs they should work 10x faster. */
firstPersonHandler.getKeyboardLookHandler().setActionSpeed(10f);
firstPersonHandler.getMouseLookHandler().setActionSpeed(1f);
input = firstPersonHandler;
/** Get a high resolution timer for FPS updates. */
timer = Timer.getTimer(properties.getRenderer());
display.getRenderer().setCamera(cam);
KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
}
protected void initGame()
{
scene = new Node("Scene graph node");
//Set the Z-buffer up correctly
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.CF_LEQUAL);
scene.setRenderState(buf);
//Implementation of "Culling"; render only objects visible.
CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
scene.setRenderState(cs);
//Initialization time!
buildWorld();
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
}
protected void reinit()
{
display.recreateWindow(width, height, depth, freq, fullscreen);
}
protected void cleanup()
{
LoggingSystem.getLogger().log(Level.INFO, "Cleaning up resources.");
KeyInput.destroyIfInitalized();
MouseInput.destroyIfInitalized();
JoystickInput.destroyIfInitalized();
}
private void buildWorld()
{
// Create box, create a bound and update the bound to fix the box accordingly.
//Box /*corridorWall*/ wall = new Box("UpperCorridor", new Vector3f(5,0,-100), new Vector3f(10, 0.1f, 100));
wall = new Quad("Quad", 60, 15);
smallerWall = new Quad ("Quad2", 40, 15);
floor = new Quad ("Quad3", 120, 120);
FloatBuffer tBuf = wall.getTextureBuffer();
tBuf.clear();
tBuf.put(0).put(2);
tBuf.put(0).put(0);
tBuf.put(2).put(0);
tBuf.put(2).put(2);
Quaternion q = new Quaternion();
wall.setLocalRotation(q);
wall.setModelBound(new BoundingBox());
wall.updateModelBound();
wall.setLightCombineMode(LightState.OFF);
// axis = new Vector3f(1f, 0, 0); // changed
// q.fromAngleAxis(40.0f, axis);
SharedMesh corridorRight = new SharedMesh("corridorRight", wall);
corridorRight.setLocalTranslation(new Vector3f(0,0,-2));
corridorRight.setLocalRotation(new Quaternion(new float[] {180*FastMath.DEG_TO_RAD,0,0}));
SharedMesh corridorTop = new SharedMesh("corridorTop", wall);
corridorTop.setLocalTranslation(new Vector3f(0,7,-9));
corridorTop.setLocalRotation(new Quaternion(new float[] {90*FastMath.DEG_TO_RAD,0,0}));
SharedMesh corridorLeft = new SharedMesh("corridorLeft", wall);
corridorLeft.setLocalTranslation(new Vector3f(0,0,-16));
SharedMesh corridorFloor = new SharedMesh("corridorFloor", wall);
corridorFloor.setLocalTranslation(new Vector3f(0,-7,-9));
corridorFloor.setLocalRotation(new Quaternion(new float[] {270*FastMath.DEG_TO_RAD,0,0}));
SharedMesh mainHallOneLeft = new SharedMesh("mainHallLeft", smallerWall);
mainHallOneLeft.setLocalTranslation(new Vector3f(44.5f,0,-29.7f));
mainHallOneLeft.setLocalRotation(new Quaternion(new float[] {FastMath.DEG_TO_RAD,0.75f,0}));
//mainHallOne.setLocalRotation(new Quaternion(new float[] {90*FastMath.DEG_TO_RAD,0,0}));
SharedMesh mainHallTwoLeft = new SharedMesh("mainHallTwoLeft", smallerWall);
mainHallTwoLeft.setLocalTranslation(new Vector3f(70f, 0, -43.0f));
//mainHallTwoLeft.setLocalRotation(new Quaternion(new float[] {FastMath.DEG_TO_RAD, 0.75f,0}));
SharedMesh mainHallOneRight = new SharedMesh("mainHallOneRight", smallerWall);
mainHallOneRight.setLocalRotation(new Quaternion(new float[] {FastMath.DEG_TO_RAD,2.5f,0}));
mainHallOneRight.setLocalTranslation(new Vector3f(45.5f, 0, 9.8f));
SharedMesh mainHallFloor = new SharedMesh("mainHallFloor", smallerWall);
mainHallFloor.setLocalRotation( new Quaternion(new float[] {270*FastMath.DEG_TO_RAD, 0, 0} ));
mainHallFloor.setLocalTranslation(new Vector3f(30f, -6f, 0f));
Node wallNode = new Node("walls");
wallNode.attachChild(corridorLeft);
wallNode.attachChild(corridorTop);
wallNode.attachChild(corridorRight);
wallNode.attachChild(corridorFloor);
wallNode.attachChild(mainHallOneLeft);
wallNode.attachChild(mainHallOneRight);
wallNode.attachChild(mainHallTwoLeft);
wallNode.attachChild(mainHallFloor);
scene.attachChild(wallNode);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
Texture regTexture =TextureManager.loadTexture(TestAnisotropic.class.getClassLoader().getResource("jmetest/data/images/rockwall2.png"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,
ts.getMaxAnisotropic(),
true);
regTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);
ts.setTexture(regTexture);
scene.setRenderState(ts);
}
}