-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcamera.cc
More file actions
35 lines (27 loc) · 683 Bytes
/
Copy pathcamera.cc
File metadata and controls
35 lines (27 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "camera.hh"
Camera::Camera() :
pos(0.0, 0.0),
ppm(1.0)
{
}
void Camera::PointToScreen(SDL_Window *window, b2Vec2 p, int &x, int &y) const {
x = (p.x - this->pos.x) * this->ppm;
y = (p.y - this->pos.y) * this->ppm;
int w, h;
SDL_GetWindowSize(window, &w, &h);
y = h - y;
}
float Camera::LengthToScreen(float length) const {
return length * this->ppm;
}
b2Vec2 Camera::PointToWorld(int x, int y, SDL_Window *window) const {
int w, h;
SDL_GetWindowSize(window, &w, &h);
y = h - y;
b2Vec2 p(x / ppm, y / ppm);
p += b2Vec2(this->pos.x, this->pos.y);
return p;
}
float Camera::LengthToWorld(float length) const {
return length / this->ppm;
}