Very, very simple intersection help

So sorry if this is the wrong forum, but I'm just starting to learn how to use jME and am running into problems with intersection.  I modified one of the tutorial programs to see when the camera intersected with a square, but it's not working.  Here's the code -


import java.net.URL;
import java.nio.FloatBuffer;
 
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.scene.TexCoords;
import com.jme.scene.TriMesh;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.util.geom.BufferUtils;
import com.jme.bounding.BoundingBox;
import java.net.URL;
import java.util.Random;
import java.util.logging.Logger;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jme.renderer.ColorRGBA;
import com.jme.intersection.Intersection;



 
/**
 * Started Date: Jul 21, 2004<br>
 * <br>
 *
 * This program demonstrates using key inputs to change things.
 *
 * @author Jack Lindamood
 */
public class HelloWorld extends SimpleGame {
   // The TriMesh that I will change
   TriMesh square;
   // A scale of my current texture values
   float coordDelta;
 
   public static void main(String[] args) {
      HelloWorld app = new HelloWorld();
      app.setConfigShowMode(ConfigShowMode.NeverShow);
      app.start();
   }
 
   protected void simpleInitGame() {
      // Vertex positions for the mesh
      Vector3f[] vertexes = {
         new Vector3f(0, 0, 0),
         new Vector3f(1, 0, 0),
         new Vector3f(0, 1, 0),
         new Vector3f(1, 1, 0)
      };
 
      // Texture Coordinates for each position
      coordDelta = 1;
      Vector2f[] texCoords = {
         new Vector2f(0, 0),
         new Vector2f(coordDelta, 0),
         new Vector2f(0, coordDelta),
         new Vector2f(coordDelta, coordDelta)
      };
 
      // The indexes of Vertex/Normal/Color/TexCoord sets. Every 3 makes a
      // triangle.
      int[] indexes = { 0, 1, 2, 1, 2, 3 };
 
      // Create the square
      square = new TriMesh("My Mesh",
         BufferUtils.createFloatBuffer(vertexes),
         null,
         null,
         TexCoords.makeNew(texCoords),
         BufferUtils.createIntBuffer(indexes));
 
      
      
      // Point to the monkey image
      URL monkeyLoc = HelloWorld.class.getClassLoader().getResource(
            "jmetest/data/images/Monkey.jpg");
 
      // Get my TextureState
      TextureState ts = display.getRenderer().createTextureState();
 
      // Get my Texture
      Texture t = TextureManager.loadTexture(monkeyLoc,
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
 
      // Set a wrap for my texture so it repeats
      t.setWrap(Texture.WrapMode.Repeat);
 
      // Set the texture to the TextureState
      ts.setTexture(t);
      
      // Assign the TextureState to the square
      square.setRenderState(ts);
 
      // Scale my square 10x larger
      square.setLocalScale(10);
      
      square.setModelBound (new BoundingBox ());
      square.updateModelBound();
 
      // Attach my square to my rootNode
      rootNode.attachChild(square);
      System.out.println (square.getWorldBound());
 
   }
 
   // Called every frame update
   protected void simpleUpdate() {
      TriMesh m;
 
      // The indexes of Vertex/Normal/Color/TexCoord sets. Every 3 makes a
      // triangle.
      int[] indexes = { 0, 0, 0 };
      
      m = new TriMesh("My Mesh",
            BufferUtils.createFloatBuffer(cam.getLocation ()),
            null,
            null,
            null,
            BufferUtils.createIntBuffer(indexes));
       
      // Create a bounds
      m.setModelBound(new BoundingBox());
      m.updateModelBound();
      
      rootNode.attachChild(m);
      
      System.out.println (square.getWorldBound() + "tt" + m.getWorldBound());
      if (m.getWorldBound ().intersects (square.getWorldBound ())) {
         System.out.println ("guh");
      }
   }
}



I don't think I'm creating the TriMesh out of the camera's position correctly, but I'm not sure what's wrong.  Is this even the right way to go about doing this?

Thanks very much!

e:  I just tried replacing the intersection test with 'if (square.getWorldBound ().contains (cam.getLocation ()))' and that didn't work either.

e2:  I'm not sure why, but when I started using boxes instead of a flat square it worked.  But now, how would I make the camera stop moving forward when you hit the wall, even if you're still holding down the forward key?
Lunnies said:

e2:  I'm not sure why, but when I started using boxes instead of a flat square it worked.  But now, how would I make the camera stop moving forward when you hit the wall, even if you're still holding down the forward key?

You could give colliding with walls a go. It's completely based on a player type of character, but I bet you can change it to be versatile. I'm not sure how applicable it is though.

Now, as a fellow jME newbie, I think you can also attach your camera to a cameranode, and make it a physical object. Then making your wall a physical object with a mass of 0 (static), and you should be good to go.