ruby2d-camera 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.mdown +4 -0
- data/README.mdown +5 -0
- data/lib/ruby2d/camera.rb +17 -0
- data/lib/ruby2d/camera/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06037a9f51eba2e45da347b87365f4a58a62aa5c08408aab3a782cdcf377bb77
|
4
|
+
data.tar.gz: 692821b9a6bbc5a1635d480abd8260359bd8cc5df8bb6dd534235b62c3892ab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a36731f90ce30ac654a70e047d978c9db839e642d4d0b13a17d6c33b2d92c296dd4e4627f64777c2beaf48ade923d742e931e8b90c353abdc8d0480e8fa18cf2
|
7
|
+
data.tar.gz: 867f0ddcc5147a7e58abf89f600c3dd7e5a38d2b0829d63ac6527b24f0a4cfc3c047082a200887db3164cc4d562d1bb9201b90c5c7a733ec1f214dbc61618221
|
data/CHANGELOG.mdown
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
![Deprecated](https://img.shields.io/badge/-Deprecated-orange)
|
7
7
|
![Removed](https://img.shields.io/badge/-Removed-red)
|
8
8
|
|
9
|
+
## [1.1.0](https://github.com/realtradam/ruby2d-camera/releases/tag/1.1.0) - 2021-08-09
|
10
|
+
![Added](https://img.shields.io/badge/-Added-brightgreen)
|
11
|
+
- Added Camera functions `Camera.coordinate_to_screenspace` and `Camera.coordinate_to_worldspace`
|
12
|
+
|
9
13
|
## [1.0.0](https://github.com/realtradam/ruby2d-camera/releases/tag/1.0.0) - 2021-08-08
|
10
14
|
![Added](https://img.shields.io/badge/-Added-brightgreen)
|
11
15
|
- Initial release
|
data/README.mdown
CHANGED
@@ -19,6 +19,11 @@ Create your object as if you would create it in Ruby2D except you need to prefix
|
|
19
19
|
- `Camera.x` and `Camera.y` Default: 0. This is the position the camera is centered on in the "world"
|
20
20
|
- `Camera.angle` Default: 0. This is the angle of how much the camera is rotated(in degrees). It ranges from 0-360. Giving values outside of this range will automagically convert them to fit within the 0-360 range.
|
21
21
|
|
22
|
+
### There are also 2 helpful functions:
|
23
|
+
|
24
|
+
- `Camera.coordinate_to_worldspace(x,y)` You pass coordinates on the screen(for example where a player clicked in the window) and it will return the coordinates(in a 2d array) what the coordinates are in the world
|
25
|
+
- `Camera.coordinate_to_screenspace(x,y)` You pass in a coordinate in the world(for example an enemy in your game) and it will give you the coordinates(in a 2d array) of where on the screen this character appears. Note this function may return values that are outside of the screen if the object is not in view of the camera
|
26
|
+
|
22
27
|
## How it works:
|
23
28
|
|
24
29
|
A single `Camera` module exists which keeps track of objects created with it. When you create an object with the camera it creates a special object that inherits the original object from Ruby2D and then adds additional functions. The Camera module then uses these functions to draw the various objects on the screen each frame, using the parameters you gave it.
|
data/lib/ruby2d/camera.rb
CHANGED
@@ -94,6 +94,23 @@ module Ruby2D
|
|
94
94
|
angle %= 360
|
95
95
|
@angle = angle
|
96
96
|
end
|
97
|
+
|
98
|
+
# Convert screenspace coordinates into worldspace camera ones
|
99
|
+
def self.coordinate_to_worldspace(x, y)
|
100
|
+
angle = Camera.angle * (Math::PI / 180)
|
101
|
+
half_width = Window.width * 0.5
|
102
|
+
half_height = Window.height * 0.5
|
103
|
+
|
104
|
+
[(((x - half_width) / zoom) * Math.cos(-angle)) - (((y - half_height) / zoom) * Math.sin(-angle)) + self.x,
|
105
|
+
(((x - half_width) / zoom) * Math.sin(-angle)) + (((y - half_height) / zoom) * Math.cos(-angle)) + self.y]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Convert worldspace camera coordinates into screenspace ones
|
109
|
+
def self.coordinate_to_screenspace(x, y)
|
110
|
+
angle = Camera.angle * (Math::PI / 180)
|
111
|
+
[(((x - Camera.x) * Math.cos(angle)) - ((y - Camera.y) * Math.sin(angle))) * Camera.zoom + (Window.width * 0.5),
|
112
|
+
(((x - Camera.x) * Math.sin(angle)) + ((y - Camera.y) * Math.cos(angle))) * Camera.zoom + (Window.height * 0.5)]
|
113
|
+
end
|
97
114
|
end
|
98
115
|
end
|
99
116
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2d-camera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tradam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby2d
|