diff --git a/src/core/include/pw/core/math.hpp b/src/core/include/pw/core/math.hpp index 16afc9d..677d6cf 100644 --- a/src/core/include/pw/core/math.hpp +++ b/src/core/include/pw/core/math.hpp @@ -25,6 +25,8 @@ #include #include +//#include +//#include namespace pw { @@ -58,6 +60,12 @@ inline T ping_pong(const T& t,const T& length) { } +//void extractRotation(const matrix &A, Quaterniond &q,const unsigned int maxIter) +//{ +// for (auto iter = 0; iter < maxIter; iter++){ +// auto R = q.matrix(); +// Vector3d omega = (R.col(0).cross(A.col(0)) + R.col(1).cross(A.col(1)) + R.col(2).cross(A.col(2)))*(1.0 / fabs(R.col(0).dot(A.col(0)) + R.col(1).dot(A.col(1)) + R.col(2).dot(A.col(2))) +1.0e-9);double w = omega.norm();if (w < 1.0e-9)break;q = Quaterniond(AngleAxisd(w, (1.0 / w)*omega))*q;q.normalize();}} + } #endif diff --git a/src/core/include/pw/core/matrix_transform.hpp b/src/core/include/pw/core/matrix_transform.hpp index da53132..cf8e7c2 100644 --- a/src/core/include/pw/core/matrix_transform.hpp +++ b/src/core/include/pw/core/matrix_transform.hpp @@ -97,10 +97,10 @@ struct matrix_transform { } inline static - matrix_<4,4,T> orthographic_projection(T size,T z_near, T z_far) + matrix_<4,4,T> orthographic_projection(T width,T height,T z_near, T z_far) { - return orthographic_frustum(-size / 2, size / 2, - -size / 2, size / 2, + return orthographic_frustum(-width / 2, width / 2, + -height / 2, height / 2, z_near,z_far); } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index cf094f2..39ec9f5 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -14,9 +14,10 @@ w.visible = false w.title = "pixwerx 0.1" -- set size -w.size = pw.size.new(800,600) +--w.size = pw.size.new(640,480) + -- move window -w.position = pw.point.new(100,100) +--w.position = pw.point.new(100,100) print("client size after resize: ",w.client_size.width,w.client_size.height) diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index ded9da6..22ab49d 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -51,7 +51,10 @@ struct triangle_renderer { const float z_val = -5.f; + const float s = 1.0f; + +#if 0 mesh::vertex3array_t vertices = { { 0.0f, 0.5f, z_val} // 0 ,{ 0.5f, 0.0f, z_val} // 1 @@ -61,6 +64,29 @@ struct triangle_renderer // actual indices mesh::indexarray_t indices = { 0, 1, 2}; +#else + + + // + // 0 -- 1 + // | / | + // 2 -- 3 + + // geometry + mesh::vertex3array_t vertices = { + {-s, s, z_val} // 0 + ,{ s, s, z_val} // 1 + ,{-s, -s, z_val} // 2 + ,{ s, -s, z_val} // 3 + }; + + // topology / indices + mesh::indexarray_t indices = { 2, 1, 0, + 2, 3, 1}; + + +#endif + amesh.set_indices(indices); amesh.set_vertices(vertices); @@ -75,7 +101,8 @@ struct triangle_renderer in vec3 vertex_p; void main() { - gl_Position = projection * view * model * vec4(vertex_p, 1.0); + gl_Position = projection * view * model * vec4(vertex_p, 1.0); +// gl_Position = model * vec4(vertex_p, 1.0); } )"; @@ -84,7 +111,7 @@ struct triangle_renderer uniform vec4 input_color = vec4(1.0, 0.0, 0.0, 1.0); out vec4 frag_colour; void main() { - frag_colour = input_color; + frag_colour = input_color; })"; shader_p.set_source(vertex_shader_2,shader::code_type::vertex); @@ -113,17 +140,21 @@ struct triangle_renderer matrix4x4f view_mat = matrix_transform::look_at(vector3({0,0,0}), vector3::forward(), vector3::up()); - - view_mat.set_identity(); - - matrix4x4f proj_mat = matrix_transform::perspective_projection(deg_to_rad(33.0f), - 1.3f, - 0.2f,1000.f); // materials should carry this -// glEnable(GL_CULL_FACE); +#if 1 + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glFrontFace(GL_CCW); +#endif + + auto proj_mat = matrix_transform::orthographic_projection(1.3,1.0, + 0.2f,100.f); - //proj_mat = transform_tools::orthographic_projection(0.5,0.2f,100.f); + +// matrix4x4f proj_mat = matrix_transform::perspective_projection(deg_to_rad(33.0f), +// 1.3f, +// 0.2f,1000.f); // highly inefficient - should be cached - shader_p.set("input_color",col); @@ -238,16 +269,12 @@ bool pipeline::impl::create(sizei size) void pipeline::impl::draw() { - glClearColor(0,0,0,1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa); - glClearColor(1,1,1,1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +// glClearColor(0,0,0,1); +// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glViewport(0,0,800,600); +// glViewport(0,0,800,600); // // draw pass @@ -290,8 +317,6 @@ void pipeline::impl::draw() GL_COLOR_BUFFER_BIT, // buffer mask GL_LINEAR); // scale filter - - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); diff --git a/src/visual/src/shader.cpp b/src/visual/src/shader.cpp index e6f5718..3a2a164 100644 --- a/src/visual/src/shader.cpp +++ b/src/visual/src/shader.cpp @@ -149,6 +149,11 @@ struct shader::impl return glGetUniformLocation(_shader_program,name.c_str()); } + void bind(int location,const matrix3x3f& m) + { + glUniformMatrix3fv(location,1,GL_FALSE,m.data); + } + void bind(int location,const matrix4x4f& m) { glUniformMatrix4fv(location,1,GL_FALSE,m.data); diff --git a/src/visual/src/vertex_array.cpp b/src/visual/src/vertex_array.cpp index 60b7478..2747d5b 100644 --- a/src/visual/src/vertex_array.cpp +++ b/src/visual/src/vertex_array.cpp @@ -13,6 +13,7 @@ struct vertex_array::impl { GLuint _vao = 0; std::vector _vbos; + std::size_t _mesh_elements = {0}; impl() { @@ -44,6 +45,9 @@ struct vertex_array::impl { if (!m.vertices().empty()) arrays_needed++; if (!m.indices().empty()) arrays_needed++; + + _mesh_elements = m.indices().size(); + // TODO: implement the other arrays _vbos.resize(arrays_needed); @@ -81,9 +85,11 @@ struct vertex_array::impl { void draw() { glBindVertexArray(_vao); - glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr); + glDrawElements(GL_TRIANGLES, _mesh_elements, GL_UNSIGNED_INT, nullptr); } +// GLint get_mode(vertex_array::) + }; //