I haven't thought too hard about this - but big fan of cam11 but here's my next challenge.
My whole world (all tiles) can be seen when zoom = 1 (normal zoom) and half the world can be seen when zoomed in at zoom = 2 (approximately). I need to play audio (sound effects) only for the things in the frame at that time. I need to know what is in frame, or on screen, and what is not, and play different audio accordingly.
My brain started thinking about screen width / zoom factor and then measure each entity from the current screen focal point etc etc but then thought the author of cam11 might happen upon this and give me a clue. Perhaps some funky world co-ordinate or screen co-ordinate check or ... idk - it's late. lolz. I'll sleep now!
cam11: how to tell what is in 'frame'
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
cam11: how to tell what is in 'frame'
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Re: cam11: how to tell what is in 'frame'
https://github.com/kikito/gamera/blob/master/gamera.lua line 39, gamera have this kind function. It will return visible area, accounting for scale and zoom.togFox wrote: ↑Mon May 23, 2022 11:10 am I haven't thought too hard about this - but big fan of cam11 but here's my next challenge.
My whole world (all tiles) can be seen when zoom = 1 (normal zoom) and half the world can be seen when zoomed in at zoom = 2 (approximately). I need to play audio (sound effects) only for the things in the frame at that time. I need to know what is in frame, or on screen, and what is not, and play different audio accordingly.
My brain started thinking about screen width / zoom factor and then measure each entity from the current screen focal point etc etc but then thought the author of cam11 might happen upon this and give me a clue. Perhaps some funky world co-ordinate or screen co-ordinate check or ... idk - it's late. lolz. I'll sleep now!
Cam11 should have something similar, but if it didn't, then perhaps you can port it to cam11?
Re: cam11: how to tell what is in 'frame'
Convert the corners of the viewport from screen to world coordinates, then you can check the objects in your world against that rectangle.
For example, if your viewport is the whole screen, then you would convert (0,0) to world and obtain (w1x,w1y), then (love.graphics.getWidth(), love.graphics.getHeight()) to obtain (w4x, w4y). If you also use rotation, convert (love.graphics.getWidth(), 0) to world and obtain (w2x, w2y), then (0, love.graphics.getHeight()) and obtain (w3x, w3y).
If you don't use rotation, and your objects are axis-aligned bounding boxes, you only need a simple AABB intersection check of your objects against (w1x, w1y, w4x, w4y). In other case, it's a polygon vs polygon intersection check; let me know if that's the case and I'll try to lend a hand.
If your objects are points instead of rectangles, things are simpler. But without these details I can't give better advice:
- Are you using rotation?
- Are your objects represented by points? By axis-aligned boxes? By convex polygons? By non-convex polygons?
For example, if your viewport is the whole screen, then you would convert (0,0) to world and obtain (w1x,w1y), then (love.graphics.getWidth(), love.graphics.getHeight()) to obtain (w4x, w4y). If you also use rotation, convert (love.graphics.getWidth(), 0) to world and obtain (w2x, w2y), then (0, love.graphics.getHeight()) and obtain (w3x, w3y).
If you don't use rotation, and your objects are axis-aligned bounding boxes, you only need a simple AABB intersection check of your objects against (w1x, w1y, w4x, w4y). In other case, it's a polygon vs polygon intersection check; let me know if that's the case and I'll try to lend a hand.
If your objects are points instead of rectangles, things are simpler. But without these details I can't give better advice:
- Are you using rotation?
- Are your objects represented by points? By axis-aligned boxes? By convex polygons? By non-convex polygons?
Re: cam11: how to tell what is in 'frame'
No rotation.
Points.
The AABB thing is super easy with x/y points so I'll look into understanding how the viewport can be mapped to world co-ordinates.
Example:
My monitor is 640x480 so my world is 640x480 by design (world = monitor size).
The camera is centred in the middle and zoom = 2 so I can now see only 320x240 around the middle of the world.
How to compute the point at 100,100 is outside the viewport?
Points.
The AABB thing is super easy with x/y points so I'll look into understanding how the viewport can be mapped to world co-ordinates.
Example:
My monitor is 640x480 so my world is 640x480 by design (world = monitor size).
The camera is centred in the middle and zoom = 2 so I can now see only 320x240 around the middle of the world.
How to compute the point at 100,100 is outside the viewport?
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Re: cam11: how to tell what is in 'frame'
Okay, easy peasy.
Imagine how the viewport looks like in the map. By converting (0, 0) from screen to world coordinates, and (640, 480) from screen to world coordinates, you have the corners of the viewport rectangle as projected in the world. Now just check which points are within that rectangle. For your example, check if (100, 100) is within that rectangle.
Imagine how the viewport looks like in the map. By converting (0, 0) from screen to world coordinates, and (640, 480) from screen to world coordinates, you have the corners of the viewport rectangle as projected in the world. Now just check which points are within that rectangle. For your example, check if (100, 100) is within that rectangle.
Re: cam11: how to tell what is in 'frame'
I see. Simple enough!
I shall try. Thanks!
I shall try. Thanks!
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 172 guests