Panning the camera

I am trying to write a method that pans the camera using keyboard shortcuts. I wrote the flycammethod but it doesn’t seem to pan well (it’s more orbitting than panning left and right). Can anyone please correct my thinking? It pans correctly from a 2D view but any other angle , it would pan wrong.

Well… panning involve translating the camera along its target, if you change the rotation, no wonder why it’s not working properly.



Hint : The FlyByCamera pans with wsad keys…

Hint 2 : JME is open source

1 Like

by panning I meant keeping the center of the origin of the cam fixed and not moving it like ASDW



my code is almost there , it just has a bug in it somewhere. I did the same for TILT and works like a charm

@homsi said:
by panning I meant keeping the center of the origin of the cam fixed and not moving it like ASDW

that's not panning, but anyway...
the FlyByCamera also does this but with the mouse move input.

that is panning: http://en.wikipedia.org/wiki/File:Pan1.gif

alright my bad!



But still, the code is in FlyByCamera.

homsi:



http://en.wikipedia.org/wiki/Panning_(camera)

if i good understand you want to make head shaking effect?



you can just create head shaking effect via changing camera rotation. what is your problem? Use Quaterion for example.



best code example you should see in FlyByCamera like nehon said.

its almost the same reasoning as mine but still the same results :frowning:



[java] Vector3f axis = projectXY(cam.getUp());



Matrix3f mat = new Matrix3f();

mat.fromAngleNormalAxis(rotationSpeed * value, axis);



Vector3f up = cam.getUp();

Vector3f left = cam.getLeft();

Vector3f dir = cam.getDirection();



mat.mult(up, up);

mat.mult(left, left);

mat.mult(dir, dir);



Quaternion q = new Quaternion();

q.fromAxes(left, up, dir);

q.normalize();



cam.setAxes(q);[/java]



it works only for a 2d view

it works only for a 2d view


as i good undertand you have platform game and you need to make panning effect.

problem is you have it all in 3d/2d view and something don't go on your mind(maybe you could want to change camera frustrum, or make objects always look at camera).

you need to show me video example how you need it to look like.(video from example platform game)

You are modifying the cam vectors… Clone them.

correct and there’s something wrong with my code that does not go well when attempting to pan right/left when looking at the object from a view other than 2D. I am missing something in my code or the code from Flycam that doesn’t go well when NOT in 2D view.



I’ll try to get a video up soon. best way is probably youtube link?

yeah, youtube is ok. understand me, it’s hard to know what exactly is wrong.



i cannot read in mind or im just blind to see the problem.



we need to define something:


  • i see projectXY, so i hope you use rootNode, but i need to ask: do you use rootNode for game objects? (hint: do not use guiNode for that!)
  • did you set good frustrum? [java]cam.setFrustumFar(angle);[/java]?


I am missing something in my code or the code from Flycam that doesn’t go well when NOT in 2D view.

i just don't understand you just project 3d to 2d, so when you use "NOT 2D view"?
  • 2d is when I set the cam above the plane looking directly at it… 3d is really just any other position of the camera. The worst one is being PARALLEL to the plane.


  • I use rootNode


  • not sure how the frustum is related in this, it’s just that the camera rotates in a diffferent way.



    To make the question simpler, look at the tiltCamera code, that code works GREAT from any cam angle, to rotate the cam up and down (again with a fixed center of the origin). What should I change in that code to make it rotate right/left (with a fixed center of origin)?



    i’ll upload video tonight.
- 2d is when I set the cam above the plane looking directly at it…. 3d is really just any other position of the camera. The worst one is being PARALLEL to the plane.


from this sentence frustum is in my mind, you can make it look like in guiNode.


To make the question simpler, look at the tiltCamera code, that code works GREAT from any cam angle, to rotate the cam up and down (again with a fixed center of the origin). What should I change in that code to make it rotate right/left (with a fixed center of origin)?


ahh i think i understand what you mean. but i need a testcase in this case to try to fix that. you just missed something in code like you said.

but a simple question:

why not to use ChaseCam with limited rotations and center of camera, it could make a trick?
1 Like

homsi:

now i understand what you exactly need to obtain. sorry for my earlier misunderstanding.



because i don’t know what you make wrong

i get a simpler idea: without quaterions and other Math stuff



why not just to use lookAt or lookAtDirection(but here normal vector needed if im not wrong) with projected vector as argument?



mouse go left: argument for lookAt vector.x–, mouse go right vector.x++, y and z : 0

i think it could work. camera will be in it’s place and it will make panning effect



but if you will need to move camera along x coord, then lookAt argument vector.x need to be changed too.



just need to add control for mouse.



BTW: JME have RecordingAppState :wink:

1 Like

@oxplay2 thanks for your help… but not sure I quite understood you. Could you give a code example or explain ur idea more?



Are you saying instead of rotating the cam, I let the cam look at a specific direction? fine but I dont understand how ur doing that.



sorry if im being slow :S a pseudo code will do i’m not asking fro you to write the code for me :slight_smile:

just an example to show what i mean. it can be made in many ways. camera have lookAt method that can make all math for you :wink:



that is why i proposed you simpler way to make it(but not necessarily better).



[java]

update(float tpf){ // tpf should be used to make it smooth

Vector2f mouseposition = inputManager.getCursorPosition();

Vector3f lookAtVector = camera.getLocation().add((mouseposition.x-camera.getWidth()/2)/100, 5, 0); // 5 or -5, 2 or -2 -> a number, just for good direction, /100 case to dont look too far ;p

camera.lookAt(lookAtVector, Vector3f.UNIT_Y);

}

[/java]



even not tested(dont know if i made a mistake), just to show an idea, should be edited to use tpf

but that will change the whole design. I am trying to pan the cam left and right using keyboard arrows left and right

@homsi:

using keyboard

yes yes, i forgot, just replace mouse with keyboard analog(with maximum and mininum value of x position).

remember, analog, case you can hold pressing key.

not sure I follow:



[java]

Vector3f lookAtVector = camera.getLocation().add((???);

camera.lookAt(lookAtVector, Vector3f.UNIT_Y);[/java]



what do I put in it?