Slick Forums

Discuss the Slick 2D Library
It is currently Sun Dec 09, 2018 11:49 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: [RFE] Camera
PostPosted: Wed Jun 20, 2012 1:59 am 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
LibGdx has OrthographicCamera. Its awesome.
I would really need a camera in Slick which translates the whole graphic context, and is able to zoom.


Last edited by ArtificialZero on Fri Jul 13, 2012 9:51 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Wed Jun 20, 2012 2:08 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
If you write something that is in line with Slick's code style we can add it in. :)


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Wed Jun 20, 2012 9:59 pm 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
well you know, if all I care about is translating and zooming then it should be too hard right ?
graphics.translate and .scale I guess
just that with scale, I would need a focus(?) point, otherwise its also scaling from 0,0


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jun 21, 2012 8:13 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1340
Location: Italy
a general camera need a target, for example player and a "smooth" factor when moving world, for example when mario jump, camera can move immediately or better after some time move with player, for a more smooth experience

_________________
Blog | Last game Drone Swarm


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jun 21, 2012 11:14 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
A camera that can use simple spring physics or smoothing like you describe would be awesome.


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jun 21, 2012 11:34 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
This is nothing hard to do imho. The thing is, it needs to be kinda generic right? Since we want the developer to have some control over the camera.

Here is some basic cam with smooth movement (not tested against anything, missing methods for stting the world bounds):
Code:
public class Camera {
   
   public Vector2f currentPosition;
   public Vector2f targetPosition;
   
   public float normalSpeed;
   
   public Camera() {
      currentPosition = new Vector2f();
      targetPosition = new Vector2f();
      
      normalSpeed = 0.1f;
   }
   
   public void update(World world, int delta) {
      currentPosition.x = fadeOut(currentPosition.x, targetPosition.x, normalSpeed);
      currentPosition.y = fadeOut(currentPosition.y, targetPosition.y, normalSpeed);
   }
   public void translate(World world, Graphics g) {
      g.translate(-currentPosition.x, -currentPosition.y);
   }
   public void translateMap(World world, Graphics g) {
      g.scale(2, 2);
      g.translate(-(currentPosition.x % world.getTileSize()), -(currentPosition.y % world.getTileSize()));
   }
   
   
   private float fadeOut(float current, float target, float ratio) {
      return target * (ratio ) + (1 - ratio ) * current;
   }
   
   
   public Vector2f getCurrent() {
      return currentPosition;
   }
   public float getCurrentX() {
      return currentPosition.x;
   }
   public float getCurrentY() {
      return currentPosition.y;
   }
   public Vector2f getTarget() {
      return targetPosition;
   }
   public float getTargetX() {
      return targetPosition.x;
   }
   public float getTargetY() {
      return targetPosition.y;
   }
   public float getSpeed() {
      return normalSpeed;
   }
   
   public void setCurrent(float x, float y) {}
   public void setTarget(float x, float y, int time) {}
   
   public void setSpeed(float speed) {
      
   }
}


It should kinda work because this is a trimmed down version of the camera I use in Mr. Hat I. World could be replaced by some other stuff.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jun 21, 2012 1:37 pm 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
Well the camera system in libgdx is very opengl; I think it directly uses a camera system which opengl already has

one problem I would encounter in Slick: If you try to zoom out, it doesnt really zoom out, but indeed scale (like the method says) the graphic output.
this causes of course to have a black border around your game... but you cannot see MORE as you would hope.
Actually I have a culling system that I wrote myself in my Slick2D project - so it could be that it's because of that...
But I dont think so.

Maybe a look into Libgdx's Camera and OrthographicCamera will help.
With matrices and vertices and viewports... I'm no opengl pro - but I think a Slick camera system should be similarly sophisticated / powerful.


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jun 21, 2012 2:08 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
OpenGL doesn't have any notion of "camera" -- everything is based on the matrices you provide to it. I haven't noticed any black borders regarding scaling; scaling down a scene is the same as "zooming out."

Matrix math is not really present at all in Slick, so IMO it would be inconsistent to add it into a Camera object. It would also require vector/matrix math utility classes; either writing our own or depending on another library.

We also don't need the full abstraction of LibGDX's camera since Slick is a 2D-only library. :)

But otherwise yep, LibGDX is always a good point of reference.

P.S. It took me a while to realize you and AtomizerZero are different users... :lol:


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jun 21, 2012 8:31 pm 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
Actually works - like I thought my culling was in the way

davedes wrote:
P.S. It took me a while to realize you and AtomizerZero are different users... :lol:

I would actually prefer a name change, since this one is obsolete, but forums hardly ever allow that =P


Top
 Profile  
 
 Post subject: Re: [RFE] Camera
PostPosted: Thu Jul 05, 2012 12:07 pm 
Offline

Joined: Mon May 07, 2012 11:36 pm
Posts: 93
....I thought I felt my ears burning... :P


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group