forked from Yao-class-cpp-studio/battle_game_2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.cpp
32 lines (27 loc) · 957 Bytes
/
object.cpp
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
#include "battle_game/core/object.h"
#include "glm/gtc/matrix_transform.hpp"
namespace battle_game {
glm::vec2 Object::LocalToWorld(const glm::vec2 p) const {
return glm::vec2{
glm::translate(glm::mat4{1.0f}, glm::vec3{position_, 0.0f}) *
glm::rotate(glm::mat4{1.0f}, rotation_, glm::vec3{0.0f, 0.0f, 1.0f}) *
glm::vec4{p, 0.0f, 1.0f}};
}
glm::vec2 Object::WorldToLocal(const glm::vec2 p) const {
return glm::vec2{
glm::inverse(glm::translate(glm::mat4{1.0f}, glm::vec3{position_, 0.0f}) *
glm::rotate(glm::mat4{1.0f}, rotation_,
glm::vec3{0.0f, 0.0f, 1.0f})) *
glm::vec4{p, 0.0f, 1.0f}};
}
Object::Object(GameCore *game_core,
uint32_t id,
glm::vec2 position,
float rotation) {
game_core_ = game_core;
position_ = position;
rotation_ = rotation;
id_ = id;
}
Object::~Object() = default;
} // namespace battle_game