finally got the ortho projection and some other stuff working
This commit is contained in:
parent
8eda3df225
commit
9db2490989
6 changed files with 70 additions and 25 deletions
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
//#include <pw/core/matrix.hpp>
|
||||
//#include <pw/core/quaternion.hpp>
|
||||
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -76,6 +102,7 @@ struct triangle_renderer
|
|||
|
||||
void main() {
|
||||
gl_Position = projection * view * model * vec4(vertex_p, 1.0);
|
||||
// gl_Position = model * vec4(vertex_p, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
|
@ -113,17 +140,21 @@ struct triangle_renderer
|
|||
matrix4x4f view_mat = matrix_transform<float>::look_at(vector3({0,0,0}),
|
||||
vector3::forward(),
|
||||
vector3::up());
|
||||
|
||||
view_mat.set_identity();
|
||||
|
||||
matrix4x4f proj_mat = matrix_transform<float>::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<float>::orthographic_projection(1.3,1.0,
|
||||
0.2f,100.f);
|
||||
|
||||
|
||||
//proj_mat = transform_tools<float>::orthographic_projection(0.5,0.2f,100.f);
|
||||
|
||||
// matrix4x4f proj_mat = matrix_transform<float>::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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -13,6 +13,7 @@ struct vertex_array::impl {
|
|||
|
||||
GLuint _vao = 0;
|
||||
std::vector<GLuint> _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::)
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue