diff --git a/test/data/mesh-buffer.txt b/test/data/mesh-buffer.txt index b1b6254c..ee0deff4 100644 --- a/test/data/mesh-buffer.txt +++ b/test/data/mesh-buffer.txt @@ -1,4 +1,8 @@ -sc#fff ab 4 +addlight 0.0 position (-0.2 -1 -0.5) color (.0 .2 .5 1) +addlight 0.0 position (0.6 0.5 1) color #ddd + +custom setmesh " +sc#fff ab 4 ty 4 ab 2 //splt 0 //test @@ -46,3 +50,4 @@ sc#fff ab 4 //[sc#fff afcb 10 10 10 .25 t 2 2 2 csgs] //[sc#fff afcb 7 7 7 .25] //[sc#ff2 afcb 7 7 7 .25 t 1 1 1 csgs] +" \ No newline at end of file diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 73608ba9..dee2bc4b 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -227,6 +227,9 @@ public: m_hist_scale_mesh = vec2(.0f); m_hist_scale_speed = vec2(.0f); + m_mat_prev = mat4(quat::fromeuler_xyz(vec3::zero)); + m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f))); + m_camera = new Camera(); m_camera->SetView(vec3(0.f, 0.f, 10.f), vec3(0.f, 0.f, 0.f), vec3(0.f, 1.f, 0.f)); m_camera->SetProjection(0.f, .0001f, 2000.f, WIDTH * SCREEN_W, RATIO_HW); @@ -273,6 +276,13 @@ public: #endif //NO_NACL_EM m_mesh_id1 = damp(m_mesh_id1, (float)m_mesh_id, .2f, seconds); + //Update light position + for (int i = 0; i < m_ssetup->m_lights.Count(); ++i) + { + vec4 v = m_ssetup->m_lights[i]->GetPosition(); + m_ssetup->m_lights[i]->SetPosition(vec4((m_mat * inverse(m_mat_prev) * vec4(v.xyz, 1.f)).xyz, v.w)); + } + //Camera update bool is_pos = false; bool is_fov = false; @@ -364,6 +374,7 @@ public: m_hist_scale_mesh = damp(m_hist_scale_mesh, hist_scale_mesh, .2f, seconds); //Mesh mat calculation + m_mat_prev = m_mat; m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f))); //Target List Setup @@ -420,7 +431,7 @@ public: { vec2 new_screen_scale = m_camera->GetScreenScale(); m_camera->SetScreenScale(max(vec2(0.001f), new_screen_scale * ((1.0f + m_zoom_mesh) / (scale_ratio * SCREEN_LIMIT)))); - m_camera->m_position.z = damp(m_camera->m_position.z, z_pos + screen_ratio * 2.f, .1f, seconds); + m_camera->SetPosition(vec3(vec2::zero, damp(m_camera->m_position.z, z_pos + screen_ratio * 2.f, .1f, seconds)), true); m_camera->SetFov(m_fov_mesh); m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio), 1.2f, seconds)); } @@ -441,6 +452,7 @@ public: delete(m_ssetup); m_ssetup = new_ssetup; m_ssetup->Startup(); + m_mat_prev = mat4(quat::fromeuler_xyz(vec3::zero)); for (int i = 0; i < m_ssetup->m_custom_cmd.Count(); ++i) { if (m_ssetup->m_custom_cmd[i].m1 == "setmesh") @@ -493,9 +505,11 @@ public: && (!m_cmdlist.Count() || cmd != m_cmdlist.Last())) { m_cmdlist << cmd; + /* cmd = String(" addlight 0.0 position (4 -1 -4) color (.0 .2 .5 1) \ addlight 0.0 position (8 2 6) color #ffff \ custom setmesh \"") + cmd + "\""; + */ MessageService::Send(MessageBucket::AppIn, cmd); } } @@ -591,6 +605,7 @@ private: short m_input_usage; Controller* m_controller; mat4 m_mat; + mat4 m_mat_prev; bool m_init; //Camera Setup