add camera:look_at optional interpolation parameter
This commit is contained in:
parent
e0cb57a10a
commit
058daf6117
@ -61,6 +61,9 @@ cam:get_up() -> vec3
|
|||||||
|
|
||||||
-- makes camera look to a given point
|
-- makes camera look to a given point
|
||||||
cam:look_at(point:vec3)
|
cam:look_at(point:vec3)
|
||||||
|
|
||||||
|
-- makes camera look to a given point with given interpolation factor
|
||||||
|
cam:look_at(point: vec3, t: number)
|
||||||
```
|
```
|
||||||
|
|
||||||
Use player.set_camera to switch cameras.
|
Use player.set_camera to switch cameras.
|
||||||
|
|||||||
@ -61,6 +61,9 @@ cam:get_up() -> vec3
|
|||||||
|
|
||||||
-- направляет камеру на заданную точку
|
-- направляет камеру на заданную точку
|
||||||
cam:look_at(point: vec3)
|
cam:look_at(point: vec3)
|
||||||
|
|
||||||
|
-- направляет камеру на заданную точку с фактором интерполяции
|
||||||
|
cam:look_at(point: vec3, t: number)
|
||||||
```
|
```
|
||||||
|
|
||||||
Переключение камеры возможно через функцию player.set_camera.
|
Переключение камеры возможно через функцию player.set_camera.
|
||||||
|
|||||||
@ -16,7 +16,7 @@ local Camera = {__index={
|
|||||||
get_front=function(self) return cameras.get_front(self.cid) end,
|
get_front=function(self) return cameras.get_front(self.cid) end,
|
||||||
get_right=function(self) return cameras.get_right(self.cid) end,
|
get_right=function(self) return cameras.get_right(self.cid) end,
|
||||||
get_up=function(self) return cameras.get_up(self.cid) end,
|
get_up=function(self) return cameras.get_up(self.cid) end,
|
||||||
look_at=function(self, v) return cameras.look_at(self.cid, v) end,
|
look_at=function(self, v, f) return cameras.look_at(self.cid, v, f) end,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
local wrappers = {}
|
local wrappers = {}
|
||||||
|
|||||||
@ -92,7 +92,14 @@ static int l_look_at(lua::State* L) {
|
|||||||
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
|
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
|
||||||
auto& camera = *level->cameras.at(index);
|
auto& camera = *level->cameras.at(index);
|
||||||
auto center = lua::tovec<3>(L, 2);
|
auto center = lua::tovec<3>(L, 2);
|
||||||
camera.rotation = glm::inverse(glm::lookAt(glm::vec3(), center-camera.position, glm::vec3(0, 1, 0)));
|
auto matrix = glm::inverse(glm::lookAt(glm::vec3(), center-camera.position, glm::vec3(0, 1, 0)));
|
||||||
|
if (lua::isnumber(L, 3)) {
|
||||||
|
matrix = glm::mat4_cast(glm::slerp(
|
||||||
|
glm::quat(camera.rotation),
|
||||||
|
glm::quat(matrix),
|
||||||
|
static_cast<float>(lua::tonumber(L, 3))));
|
||||||
|
}
|
||||||
|
camera.rotation = matrix;
|
||||||
camera.updateVectors();
|
camera.updateVectors();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user