Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (727)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (796)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simple orthographic camera controls  (Read 838 times)
0 Members and 1 Guest are viewing this topic.
Offline KaiHH

JGO Kernel


Medals: 409



« Posted 2017-04-19 20:41:02 »

Just built a basic orthographic/2D camera control:

https://github.com/JOML-CI/joml-camera/blob/master/src/org/joml/camera/OrthoCameraControl.java

Supports:
- panning with mouse (cursor stays at the same world position while panning)
- zooming (cursor stays at the same world position while zooming, i.e. "zoom into the mouse cursor")
- centering the view onto a given point

Interface:
- Provides methods onMouseDown/onMouseUp/onMouseMove to make wiring with your preferred windowing framework (for example GLFW with LWJGL3 or simple Java2D) really easy
- obtain the view-projection matrix to submit to a shader or the GL fixed-function pipeline, or use with Java 2D and its AffineTransform
- (more info on the JavaDocs of the class)

Example with LWJGL3/GLFW: https://github.com/JOML-CI/joml-lwjgl3-demos/blob/master/src/org/joml/lwjgl/OrthoDemo.java
Offline KaiHH

JGO Kernel


Medals: 409



« Reply #1 - Posted 2017-04-20 12:08:32 »

Added support for rotation:
- left mouse button is now for panning
- right mouse button selects the rotation center and moving the mouse (beyond the minimum rotation circle radius) rotates the view
- middle mouse button resets rotation (with mouse position as rotation center)

Interface of the onMouseDown/onMouseUp methods now have a "button" parameter, which is 0 = left, 1 = right, 2 = middle (just like the GLFW button mappings)
Offline Riven
Administrator

« JGO Overlord »


Medals: 1277
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2017-04-20 17:48:54 »

Post a video of a demo Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KaiHH

JGO Kernel


Medals: 409



« Reply #3 - Posted 2017-04-20 20:43:51 »

Post a video of a demo Pointing
Here you go Smiley
<a href="http://www.youtube.com/v/1Xf9T52L9bI?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/1Xf9T52L9bI?version=3&amp;hl=en_US&amp;start=</a>
Offline Riven
Administrator

« JGO Overlord »


Medals: 1277
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2017-04-22 16:10:29 »

When I did something similar for the SpriteEngine for Cas, the target scale was pow(constant, targetZoomLevel), the actual scale was a float which converged to targetZoomLevel over time: pow(contant, currentZoomLevel), where currentZoomLevel simply linearly approached or accelerated to targetZoomLevel. Using this approach you get smooth zooming across arbitrary orders of magnitude in linear time, similar to, say, zooming in Google Maps.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline KaiHH

JGO Kernel


Medals: 409



« Reply #5 - Posted 2017-04-22 16:15:26 »

Yeah, it is the same here: When calling
zoom(factor)
it does:
targetScale *= factor
within the camera.
When the client uses the scroll wheel tick to zoom (as in the example), he would use something like:
1  
2  
3  
4  
if (tick < 0)
  zoom(1.1);
else
  zoom(1.0/1.1);
Offline Riven
Administrator

« JGO Overlord »


Medals: 1277
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2017-04-22 16:16:16 »

It's not smooth Smiley (changing the zoom level at 60fps)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline KaiHH

JGO Kernel


Medals: 409



« Reply #7 - Posted 2017-04-22 16:18:39 »

Ohh... that's what you meant! That's right. Thanks! Smiley Gonna think about adding it.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1277
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2017-04-22 16:20:41 »

And with 1.1 or 1.0/1.1 you easily get into inaccuracies in the zoom factors, accumulating errors (you might be zooming in/out for hours, ingame), which will ultimately cause off-by-one rendering issues where sprite-texels drift into unwanted neighbouring screen-pixels.

When the scrollwheel only controls an integer, and a float is converging to it (and actually reaching it, with a bit of nudging), it will always end up at exact zoom-levels in arbitrary orders of magnitude.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Pages: [1]
  ignore  |  Print  
 
 

 
Archive (294 views)
2017-04-27 17:45:51

buddyBro (483 views)
2017-04-05 03:38:00

CopyableCougar4 (927 views)
2017-03-24 15:39:42

theagentd (941 views)
2017-03-24 15:32:08

Rule (952 views)
2017-03-19 12:43:22

Rule (921 views)
2017-03-19 12:42:17

Rule (922 views)
2017-03-19 12:36:21

theagentd (984 views)
2017-03-16 05:07:07

theagentd (897 views)
2017-03-15 22:37:06

theagentd (692 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!