mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +00:00
Merge pull request #934 from Neveix/feat-quat-improvements
add mul* functions to quats & fix to_string
This commit is contained in:
commit
585b8247d5
1 changed files with 38 additions and 4 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <iostream>
|
||||||
|
#include <glm/gtx/string_cast.hpp>
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
@ -31,14 +33,14 @@ static int l_tostring(lua::State* L) {
|
||||||
lua::check_argc(L, 1);
|
lua::check_argc(L, 1);
|
||||||
auto quat = lua::toquat(L, 1);
|
auto quat = lua::toquat(L, 1);
|
||||||
|
|
||||||
|
float components[4] = {quat.w, quat.x, quat.y, quat.z};
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "quat"
|
ss << "quat {";
|
||||||
<< "{";
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
ss << ", ";
|
ss << ", ";
|
||||||
}
|
}
|
||||||
ss << quat[i];
|
ss << components[i];
|
||||||
}
|
}
|
||||||
ss << "}";
|
ss << "}";
|
||||||
return lua::pushstring(L, ss.str());
|
return lua::pushstring(L, ss.str());
|
||||||
|
|
@ -52,10 +54,42 @@ static int l_from_euler(lua::State *L) {
|
||||||
return lua::pushquat(L, glm::quat(euler));
|
return lua::pushquat(L, glm::quat(euler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_mul(lua::State* L) {
|
||||||
|
uint argc = lua::check_argc(L, 2, 3);
|
||||||
|
glm::quat a = lua::toquat(L, 1);
|
||||||
|
glm::quat b = lua::toquat(L, 2);
|
||||||
|
|
||||||
|
glm::quat result = a * b;
|
||||||
|
|
||||||
|
if (argc == 3) {
|
||||||
|
lua::setquat(L, 3, result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lua::pushquat(L, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_mul_vec3(lua::State* L) {
|
||||||
|
uint argc = lua::check_argc(L, 2, 3);
|
||||||
|
glm::quat q = lua::toquat(L, 1);
|
||||||
|
glm::vec3 v = lua::tovec3(L, 2);
|
||||||
|
|
||||||
|
glm::vec3 result = q * v;
|
||||||
|
|
||||||
|
if (argc == 3) {
|
||||||
|
lua::setvec(L, 3, result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lua::pushvec3(L, result);
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg quatlib[] = {
|
const luaL_Reg quatlib[] = {
|
||||||
{"from_mat4", lua::wrap<l_from_mat4>},
|
{"from_mat4", lua::wrap<l_from_mat4>},
|
||||||
{"from_euler", lua::wrap<l_from_euler>},
|
{"from_euler", lua::wrap<l_from_euler>},
|
||||||
{"slerp", lua::wrap<l_slerp>},
|
{"slerp", lua::wrap<l_slerp>},
|
||||||
{"tostring", lua::wrap<l_tostring>},
|
{"tostring", lua::wrap<l_tostring>},
|
||||||
|
{"mul", lua::wrap<l_mul>},
|
||||||
|
{"mul_vec3", lua::wrap<l_mul_vec3>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue