[noob] Controling the camera


Besides setting location of the camera I can't do anything else it seems. I created a grass field at 0,0,0,  on XZ plane. I then translate the camera 20 units up (0,20,0) and then wanted to change direction of the camera to straight down, so I could see my field. I've tried and tried and played with the code and nothing. My game extends SimpleGame.

setDirection(new Vector3f(0,-1,0)) … doesn't work, displays nothing, and when I tried to move with mouse and keyboard the world flips out and grass field is rendered different on every smallest input, different location/direction.

lookAt(new Vector3f(0,0,0), new Vector3f(0,1,0)) … doesn't work also, always blank screen even though counter says it is rendering stuff (meshes, vectors…)

so what am I missing here?

Thank you.


i'm new to JME also, so i can just guess.

do you have a light correctly set up ?

Maybe the Light is not affecting your Node with the grass field.

my "game" extends SimpleGame, so lightning, controls and other basic stuff is all configured. First of all I want to know if I'm using right methodes, setDirection and lookAt … setDirection has trivial documentation and lookAt is documented well but still it doesn't work as I expect.

I feel like total noob, can't even rotate the camera… I think it doesn't get more basic than this.

I just overriden simpleInitGame() as needed, here is the code:

    protected void simpleInitGame() {
        TerrainBlock field = new TerrainBlock("grass field",
                new Vector3f(100,0,100),
                new int[4],
                new Vector3f(-50,0,-50),
        field.setModelBound(new BoundingBox());
        TextureState tex_state = display.getRenderer().createTextureState();
        URL grassURL = this.getClass().getClassLoader().getResource("viktorije/data/grass.jpg");
        Texture tex_grass = TextureManager.loadTexture(grassURL,
        tex_grass.setScale(new Vector3f(10,10,10));
        cam.setLocation(new Vector3f(0,20,0));
        cam.setDirection(new Vector3f(0,-1,0));

edit: typo

using lookAt is very useful for positioning the camera…

for example to look down on a scene just use this

Vector3f   camLoc = new Vector3f();
camLoc.y = 100;
cam.lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, -1));

hope that helps you out...

thank you, that did the trick! :slight_smile: … but I still don't understand it, in JavaDoc for lookAt it says:

void lookAt(Vector3f pos, Vector3f worldUpVector)
    pos - where to look at in terms of world coordinates
    worldUpVector - a normalized vector indicating the up direction of the world. (typically {0, 1, 0} in jME.)

... so why is correct to give (0,0,-1) as world up vector when (0,1,0) is up?  :?

edit: and another thing... when I used (0,1,0) as world up vector, where did camera looket at? Guess when world up vector stuff becomes clear this will be also. I'm wondering why stuff gets rendered (info counter below says so) and I don't see anything on screen.

put you hand in front of you then your thumb in the air and your index point out away from you…

your thumb is the up vector (0, 1, 0) and your index finger is your viewing direction (looking down the z axis 0, 0, -1)…

now rotate your hand 90 degrees about x so that your index finger is pointing down, ie looking down…

your thumb is now facing down the z axis so to speak so therefore the world vector is 0, 0, -1…

sorry if the explanation is a bit simple :smiley:

the info on the screen relates to statistics in the screen graph and the number of frames per second…

it's not related to what is drawn on the screen…

ah… thank you for clarifying, the world up vector is relative then to camera, which is a bit unlogical to me since world doesn't change when you move the camera? It should be named cameraUpVector or something like that and javadoc should adress this also.

Thinking about it, is camera just a camera, or more, like a drawing tool? If I draw just a cube, rotate camera 45deg and draw another cube with same parametars, will cubes be identical or will second be 45deg rotated in comparison to first cube?

only thing left here I don't know is what is setDirection(). JavaDoc says "setDirection sets the direction the camera is facing.", which sounds something like lookAt, just without care where left/right will be.

about info counter at the bottom, usually when frostrum doesn't have any objects it says "nothing displaying", and when you look at something it counts meshes, triangles and so on.