Request for Camera Example in Love

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Request for Camera Example in Love

Post by weilies »

Good day all,

i am trying to create a scroll basis game and looking for a function which can ZOOM in any point of the my viewport
So that the visual effect is stunning. But to clarify, a zoom in doesn't mean to increase scale of all my sprites on screen

and looking at http://love2d.org/wiki/love.graphics.scale
love.graphics.scale( sx, sy )

it doesn't really mean to zoom at any point of the viewport.
Maybe we need some offset param, and based on that offset as zoom reference point?

Appreciate for the guiding.

Thanks!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Request for Camera Example in Love

Post by kikito »

That's easy:

love.graphics.translate

You are welcome!
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Request for Camera Example in Love

Post by Robin »

kikito is right. Mind, scale and translate are rather low-level functions, so they're not exactly written for ease of use. You can, of course, write a much higher lib on top of them, much like CAMERA did in the pre-0.6 days.
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Request for Camera Example in Love

Post by zac352 »

Robin wrote:kikito is right. Mind, scale and translate are rather low-level functions, so they're not exactly written for ease of use. You can, of course, write a much higher lib on top of them, much like CAMERA did in the pre-0.6 days.
love.graphics.push() and love.graphics.pop() are the most useful functions for making layered guis... :3
Hello, I am not dead.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Request for Camera Example in Love

Post by vrld »

weilies wrote:But to clarify, a zoom in doesn't mean to increase scale of all my sprites on screen
So, just that I understand you correctly:
You want to have a zoom function, that preserves the size of your objects, but increases the distance between them, much like this?
Image

Then, love.graphics.zoom/love.graphics.translate is not what you want. You will need to implement the zoom yourself:
I assume your camera looks at point (cx,cy) and has zoom z.

For every image with position (x,y), you need to calculate the zoomed position (x',y'):
  1. Move (x,y) so that (cx,cy) would be at point (0,0): (x1,y1) = (x,y) - (cx,cy)
  2. Then you zoom, which is just multiplying the coordinates (x1,y1) with zoom value z: (x2,y2) = z * (x1,y1)
  3. Move (x2,y2), so that (0,0) would be at (cx,cy): (x',y') = (x2,y2) + (cx,cy)
You can collapse the tree steps into one:
(x',y') = z * [ (x,y) - (cx,cy) ] + (cx, cy)

You can also add rotation, but this is a bit more complicated.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Request for Camera Example in Love

Post by Robin »

vrld wrote:(x',y') = z * [ (x,y) - (cx,cy) ] + (cx, cy)
Or, in Lua:

Code: Select all

x = z * (x - cx) + cx
y = z * (y - cy) + cy
Help us help you: attach a .love.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Request for Camera Example in Love

Post by vrld »

You're making it too easy for him :ehem:
Last edited by vrld on Mon Oct 11, 2010 4:20 pm, edited 1 time in total.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Request for Camera Example in Love

Post by kikito »

Interesting interpretation of the question. I still think he just needs simple translation, though.
When I write def I mean function.
User avatar
weilies
Prole
Posts: 28
Joined: Sat Oct 09, 2010 6:16 am

Re: Request for Camera Example in Love

Post by weilies »

hi all,

Thanks for all the guiding,
I am actually come from 3D Game Authoring Software like Shiva Engine, Blender

So, what i know bout Camera Zoom in, is while we put object to screen, we define their X, Y (2D), or X, Y, Z (3D)
Then in order to SEE the object, we need to define a Camera Object, same, we need to define XYZ/XY position for it

So, when we need ZOOM, we actually do not change the position or scale any object that we put on screen, so there

Vrld
You want to have a zoom function, that preserves the size of your objects, but increases the distance between them, much like this?
isn't a ZOOM ( move camera closer i mean), we shouldn't change the distance between two object, but yet, we can see the object getting bigger

Robin
kikito is right. Mind, scale and translate are rather low-level functions, so they're not exactly written for ease of use. You can, of course, write a much higher lib on top of them, much like CAMERA did in the pre-0.6 days.
Yea, it would be good if the framework does provided with camera object. I am not so hardcore framework developer, and all i can do is put my idea into game by using available function

looks like i have missed out this http://love2d.org/wiki/HUMP
can only comment further after i try out this baby
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Request for Camera Example in Love

Post by vrld »

OK, so I misunderstood you ;)
For understanding our answers, note that there is (mathematically) really no difference between a camera transformation, i.e. "see what the camera sees", and moving/scaling/rotating objects in a scene. In order to do the transformation, you need to move every object in the scene, so that the camera would be at the origin of the coordinate system (point (0,0)), scale everything to the zoom level and rotate all objects so that the camera would not be rotated anymore.
That is what actually happens in hump's camera:predraw(). The function camera:postdraw() reverts the transformations, so you can f.e. draw gui-elements after drawing the scene.

The cameras in Blender (and other tools) work just the same. It's just a handy abstraction of all the moving, scaling and translating.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 7 guests