How to implement Panning in JavaFx - java

I am trying to implement the panning. I've a subScene with perspective camera and a Box inside it. I am able to pan the box relative to the camera (So camera is fixed and the box moves left right-left-top-down). How can I achieve panning by not moving the box relative to the camera. Is there any way to move the camera inside the subScene(Usually its position is fixed).
The problem in my current approach is that when I pan the box to left, its right face is revealed more because of the perspective. It seems like the box rotates a little bit on pan. I want to remove this slight rotation effect on panning for which I need to pan the box and camera simultaneously in same direction (without any relative movement between them). But I am not able to figure out how to move the camera as the camera position is fixed with respect to the subScene.
Thanks.

Related

Shape Rotation Issue - Java2d

I am developing one simple game in which i have encountered one small but important issue.
I have implemented absolute rotation in my logic.
When i start rotating an object when the object does not have any rotation , it works fine and i can rotate as in any direction without any problem as shown in the following link.
Initial Rotation Video
Now the problem arise when the object does have some rotation , and why i try to rotate in one of the direction , instead of being rotated in desire direction the rotation always starts from initial rotation as shown in the following link.
Rotation issue when shape has some rotation
I think the video shows everything , still if you have any questions please ask me.
I think the problem is , there should be a relative rotation in the direction of mouse pointer from whatever circle is selected .
Now about My Logic,
in mouse press event i just checked
Mouse Press
Whether the shape is selected on the canvas , if yes
if one of the four circles contains mouse point if yes
then initiateRotation
Mouse Drag
Using Vector Maths
I update the motion according to mouse points ,
calculate rotation angle according to the following method
Math.atan2(rotationVector.getY(), rotationVector.getX());
and apply rotation on this shape.
Rotation Vector i get from this class
Vector Rotation
I called above class startMotion in mouse press and updateMotion in mouse drag event.
What am i missing or doing anything wrong ?
We need to see some code to be able to help you out. It looks like you reset the rotation, whenever you initiateRotation, and then the object quickly rotates in place, according to your mouse position when you drag.

box2dlights set scale from box2d

I'm making a game in libGDX and I decided to use box2dlights to render the lights. I did not used cameras so much up to this point, because I already had most of the code done in pure LWJGL. There are two main operations that I need to do with the coordinates of everything.
The first is to translate the screen to the position of the map (the map is bigger than the screen, and the position of the player defines what portion of the map is visible). So for example, if the player is at (50, 30), I translate everything by (-50, -30), so that the player is in the middle.
The second thing is to multiply everything by a constant, that is the conversion from box2d meters to pixels on screen.
However, since I do not have access to box2dlights rendering, I need to pass these two information to the ray handler, and the only way to do that is via Camera. So I created an Orthographic Camera and translate it in deltaS every tick before drawing, instead of manually subtracting deltaS from every coordinate. That part works perfectly. On the other hand, the zoom thingy does not seem to work, because it zooms in and out based in the middle of the screen. For example, if I set zoom = 2, the screen is reduced twice, but it is centered on the screen. The coordinate (0,0) is not (0,0), as I would expect, but instead is screen.width/4.
Is there any way to set the camera so that it multiplies every coordinate by a number, you would assume zoom function should do OR is there any way to do it directly on box2dlights?
I don't know if my problem is very clear or common, but I can't find anything anywhere.
I finally figured it out! The problem was that I needed to set the zoom before I used
camera.setToOrtho(true, SCREEN_WIDTH, SCREEN_HEIGHT);
Because that method uses the current zoom to set its properties. Hope this helps!

Can I zoom just a part of my OrthograficCamera libgdx

imagine that, an imaginary minecraft, where you build cubes.
You have a panel where you have the diferents cubes(tool box),
and other big panel, the world where you build, but the world is bigger.
and all of this things are in the same screen, imagine how can i put a orthografic camera that only zoom the panel where you have the whole world, that it allows you to zoom and build cubes with details and presicion, but the tool box panel still the same position. always visible. ?
Use two cameras. One for the "game" and one for the "HUD".
During a render call, use one camera to render the game, then "switch" cameras and then render the HUD. How you switch cameras depends on what API you're using to render objects (for example use setProjectionMatrix on a SpriteBatch).
You could also create more than one SpriteBatch or more than one Stage (as each tracks camera state internally), but they're a bit heavy-weight.
Beware that when switching contexts, you will probably have to explicitly end/flush/complete the first context before starting the second.
You do not use one Camera to show the stuff. For example you use a Camera for the background of your game and you have a second camera for the game Hud that always has a fixed size. But the game in background can be zoomed in and out because its an different camera.
But for simple boxes on the screen you do not use a second camera. You just use one more Stage that get displayed or not where the new "ui" stuff is shown.
Hope this helps a bit.

Adding an adjustable rotating image to the knob of a Jslider.

The knob of the JSlider originally has only 1 degree of freedom (it translates on the track either horizontally or vertically). I want to add a 2nd degree of freedom to the knob and manually rotate it. In other words, I want to be able to move the knob left and right AND rotate it. Both of these movements should be able to be set by either dragging the mouse in a linear or rotational direction. I havent seen code for this and was wondering how I could go about this.
I'd extend BasicSliderUI and override the paintThumb method so that you can paint your thumb at an arbitrary rotation, either by applying a rotation transform to the thumb image, or by manually drawing the thumb rotated. Then apply this UI to your JSlider.
To control the rotation with the mouse and keyboard, it may be easiest to add a MouseWheelListener to the JSlider so that you control thumb rotation with the mouse wheel.

Android: Displaying a 2-D animation on top of Existing View/Activity

I've been banging my head against the wall for a couple hours trying to figure out the best way to overlay an animation on top of a current View. I have a ListView, and I want to display an animation (say a frame-by-frame bomb explosion) on top of the ListView when a user clicks a button.
Can someone point me in the right direction?
This is what your looking for:
http://developer.android.com/reference/android/view/SurfaceView.html
From the link:
The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.
Or you could subclass the ListView and use the canvas to draw what ever 2d stuff you want:
http://developer.android.com/guide/topics/graphics/2d-graphics.html

Categories