slight refactoring
This commit is contained in:
parent
e01df69575
commit
47d28b4f1e
8 changed files with 79 additions and 73 deletions
|
@ -6,7 +6,7 @@ add_subdirectory(system)
|
||||||
add_subdirectory(io)
|
add_subdirectory(io)
|
||||||
|
|
||||||
#add_subdirectory(ui)
|
#add_subdirectory(ui)
|
||||||
add_subdirectory(scripting)
|
add_subdirectory(binding)
|
||||||
add_subdirectory(visual)
|
add_subdirectory(visual)
|
||||||
add_subdirectory(geometry)
|
add_subdirectory(geometry)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ set(srcs
|
||||||
src/runtime_lua.cpp
|
src/runtime_lua.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(pwscripting
|
add_library(pwbinding
|
||||||
STATIC
|
STATIC
|
||||||
${hdrs}
|
${hdrs}
|
||||||
${srcs}
|
${srcs}
|
||||||
|
@ -22,7 +22,7 @@ add_library(pwscripting
|
||||||
|
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
pwscripting
|
pwbinding
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.5/src
|
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.5/src
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
|
${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
|
||||||
|
@ -30,7 +30,7 @@ target_include_directories(
|
||||||
include
|
include
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(pwscripting
|
target_link_libraries(pwbinding
|
||||||
lualib
|
lualib
|
||||||
pwcore
|
pwcore
|
||||||
pwsystem
|
pwsystem
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
|
|
||||||
void compute_normals();
|
void compute_normals();
|
||||||
|
|
||||||
|
void compute_bounds();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -90,10 +91,6 @@ protected:
|
||||||
|
|
||||||
// TODO add weights, tangents etc. pp.
|
// TODO add weights, tangents etc. pp.
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void compute_bounds();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ void mesh::compute_normals()
|
||||||
vertex3array_t normals; normals.resize(_vertices.size());
|
vertex3array_t normals; normals.resize(_vertices.size());
|
||||||
|
|
||||||
// for indexed-faceset
|
// for indexed-faceset
|
||||||
for (auto i = 1; i < _indices.size()-1;i++)
|
for (size_t i = 1; i < _indices.size()-1;i++)
|
||||||
{
|
{
|
||||||
// left index and right index
|
// left index and right index
|
||||||
auto il = (i - 1 + _indices.size()) % _indices.size();
|
auto il = (i - 1 + _indices.size()) % _indices.size();
|
||||||
|
@ -26,13 +26,12 @@ void mesh::compute_normals()
|
||||||
auto li = _indices[il];
|
auto li = _indices[il];
|
||||||
auto ri = _indices[ir];
|
auto ri = _indices[ir];
|
||||||
|
|
||||||
// calculate delta vectors
|
// calculate edges between vertices
|
||||||
auto dL = vector3( _vertices[li] - _vertices[ci] );
|
auto edgeLeft = vector3( _vertices[li] - _vertices[ci] );
|
||||||
auto dR = vector3( _vertices[ri] - _vertices[ci] );
|
auto edgeRight = vector3( _vertices[ri] - _vertices[ci] );
|
||||||
|
|
||||||
auto N = dR.cross(dL).normalized();
|
// calculate counter clockwise and normalize
|
||||||
|
auto N = edgeRight.cross(edgeLeft).normalized();
|
||||||
//auto dV = _vertices[idx0].cross(_vertices[idx1]);
|
|
||||||
|
|
||||||
// NOTE that addition is ugly
|
// NOTE that addition is ugly
|
||||||
normals[ci] = N + normals[ci];
|
normals[ci] = N + normals[ci];
|
||||||
|
|
|
@ -24,7 +24,7 @@ target_include_directories(pixwerx
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(pixwerx
|
target_link_libraries(pixwerx
|
||||||
pwscripting
|
pwbinding
|
||||||
# -Wl,--whole-archive -lpwscripting -Wl,--no-whole-archive
|
# -Wl,--whole-archive -lpwscripting -Wl,--no-whole-archive
|
||||||
pwcore
|
pwcore
|
||||||
pwsystem)
|
pwsystem)
|
||||||
|
|
|
@ -39,11 +39,11 @@ public:
|
||||||
void set_visible(bool is_visible);
|
void set_visible(bool is_visible);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
on_update_t _on_update;
|
|
||||||
|
|
||||||
struct impl;
|
struct impl;
|
||||||
std::unique_ptr<impl> _impl;
|
std::unique_ptr<impl> _impl;
|
||||||
|
|
||||||
|
on_update_t _on_update;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,9 +84,10 @@ std::string path::executable_path() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string path::find_file(const std::string& filename) const
|
std::string path::find_file(const std::string&) const
|
||||||
{
|
{
|
||||||
// for ()
|
// TODO: Implement
|
||||||
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
path::path()
|
path::path()
|
||||||
|
|
|
@ -48,6 +48,11 @@ struct window::impl {
|
||||||
|
|
||||||
// window_context _context;
|
// window_context _context;
|
||||||
|
|
||||||
|
static void error_callback(int error, const char* description)
|
||||||
|
{
|
||||||
|
debug::e() << "GLFW error: " << description;
|
||||||
|
}
|
||||||
|
|
||||||
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
static void drop_callback(GLFWwindow* window, int count, const char** paths)
|
||||||
{
|
{
|
||||||
// std::cout << __FUNCTION__ << std::endl;
|
// std::cout << __FUNCTION__ << std::endl;
|
||||||
|
@ -73,12 +78,13 @@ struct window::impl {
|
||||||
input::get()._mouse_position = pointd(xpos,ypos).cast<float>();
|
input::get()._mouse_position = pointd(xpos,ypos).cast<float>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
|
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
input::get()._key_code = scancode;
|
input::get()._key_code = scancode;
|
||||||
input::get()._key_pressed = action;
|
input::get()._key_pressed = action;
|
||||||
// action 0,1,2
|
// action 0,1,2
|
||||||
// std::cout << __FUNCTION__ << action << std::endl;
|
// std::cout << __FUNCTION__ << action << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
|
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
|
||||||
|
@ -107,66 +113,69 @@ struct window::impl {
|
||||||
// glViewport(0, 0, width, height);
|
// glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_display_list()
|
void update_display_list()
|
||||||
{
|
{
|
||||||
display::_displays.clear();
|
display::_displays.clear();
|
||||||
|
|
||||||
// fetch all monitors
|
// fetch all monitors
|
||||||
int monitor_count = 0;
|
int monitor_count = 0;
|
||||||
GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);
|
GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);
|
||||||
|
|
||||||
for (int i = 0; i < monitor_count;i++) {
|
for (int i = 0; i < monitor_count;i++) {
|
||||||
display d;
|
display d;
|
||||||
d._name = std::string(glfwGetMonitorName(monitors[i]));
|
d._name = std::string(glfwGetMonitorName(monitors[i]));
|
||||||
|
|
||||||
display::_displays.push_back(d);
|
display::_displays.push_back(d);
|
||||||
|
|
||||||
// debug::d() <<
|
// debug::d() <<
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFWvidmode
|
// GLFWvidmode
|
||||||
// glfwGetVideoModes() ... get all
|
// glfwGetVideoModes() ... get all
|
||||||
// glfwGetVideoMode( . get current
|
// glfwGetVideoMode( . get current
|
||||||
// glfwGetMonitorPos(
|
// glfwGetMonitorPos(
|
||||||
// glfwGetMonitorPhysicalSize(
|
// glfwGetMonitorPhysicalSize(
|
||||||
// glfwGetMonitorName();
|
// glfwGetMonitorName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(window& w)
|
impl(window& w)
|
||||||
: _parent(w)
|
: _parent(w)
|
||||||
{
|
{
|
||||||
// initialize
|
// initialize
|
||||||
glfwInit();
|
if (!glfwInit())
|
||||||
|
{
|
||||||
|
debug::e() << "Initalization error";
|
||||||
|
}
|
||||||
|
|
||||||
update_display_list();
|
update_display_list();
|
||||||
|
|
||||||
// request specific version 3.3
|
// request specific version 3.3
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
//
|
//
|
||||||
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
|
_window = glfwCreateWindow(640, 480, "pixwerx", nullptr, nullptr);
|
||||||
|
|
||||||
// make window current
|
// make window current
|
||||||
glfwMakeContextCurrent(_window);
|
glfwMakeContextCurrent(_window);
|
||||||
|
|
||||||
// load opengl
|
// load opengl
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||||
{
|
{
|
||||||
debug::e() << "glad couldn't get OpenGL API";
|
debug::e() << "glad couldn't get OpenGL API";
|
||||||
}
|
}
|
||||||
|
|
||||||
// check Version
|
// check Version
|
||||||
int major, minor, rev;
|
int major, minor, rev;
|
||||||
major = glfwGetWindowAttrib(_window, GLFW_CONTEXT_VERSION_MAJOR);
|
major = glfwGetWindowAttrib(_window, GLFW_CONTEXT_VERSION_MAJOR);
|
||||||
minor = glfwGetWindowAttrib(_window, GLFW_CONTEXT_VERSION_MINOR);
|
minor = glfwGetWindowAttrib(_window, GLFW_CONTEXT_VERSION_MINOR);
|
||||||
rev = glfwGetWindowAttrib(_window, GLFW_CONTEXT_REVISION);
|
rev = glfwGetWindowAttrib(_window, GLFW_CONTEXT_REVISION);
|
||||||
|
|
||||||
// maybe something to pass to the outside
|
// maybe something to pass to the outside
|
||||||
debug::d() << "OpenGL " << major << "." << minor << "." << rev;
|
debug::d() << "OpenGL " << major << "." << minor << "." << rev;
|
||||||
|
|
||||||
glfwSetWindowUserPointer(_window,this);
|
glfwSetWindowUserPointer(_window,this);
|
||||||
|
|
||||||
|
@ -182,7 +191,10 @@ struct window::impl {
|
||||||
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
glfwSetMouseButtonCallback(_window, mouse_button_callback);
|
||||||
glfwSetScrollCallback(_window, scroll_callback);
|
glfwSetScrollCallback(_window, scroll_callback);
|
||||||
|
|
||||||
// glfwSetWindowCloseCallback(_window,close_callback);
|
|
||||||
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
|
//glfwSetWindowCloseCallback(_window,close_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
~impl()
|
~impl()
|
||||||
|
@ -192,24 +204,23 @@ struct window::impl {
|
||||||
|
|
||||||
bool update()
|
bool update()
|
||||||
{
|
{
|
||||||
if (!glfwWindowShouldClose(_window)) {
|
if (_window && !glfwWindowShouldClose(_window))
|
||||||
|
{
|
||||||
|
|
||||||
|
// // reset input
|
||||||
// reset input
|
// input::get().reset();
|
||||||
input::get().reset();
|
|
||||||
|
|
||||||
// get new events
|
|
||||||
glfwPollEvents();
|
|
||||||
|
|
||||||
_parent._on_update(_parent);
|
_parent._on_update(_parent);
|
||||||
|
|
||||||
glfwSwapBuffers(_window);
|
glfwSwapBuffers(_window);
|
||||||
|
|
||||||
|
// // get new events
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_title(const std::string& title)
|
void set_title(const std::string& title)
|
||||||
|
@ -290,8 +301,6 @@ struct window::impl {
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
window::window()
|
window::window()
|
||||||
: _impl(std::make_unique<window::impl>(*this))
|
: _impl(std::make_unique<window::impl>(*this))
|
||||||
, _on_update([](window&){})
|
, _on_update([](window&){})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue