Changeset 2718


Ignore:
Timestamp:
Jun 4, 2013, 10:48:47 PM (7 years ago)
Author:
touky
Message:

MeshViewer : Fov compensation now works correctly (all is bound on Page{Up|Down}) First commit in a while.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/build/vs2010/Lol.sln

    r2700 r2718  
    107107Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Touky", "Touky", "{9EA99B18-D352-47F6-BC04-A0B49CAA2772}"
    108108EndProject
    109 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Touky_Demo", "..\..\people\touky\private\touky_demo\touky_demo.vcxproj", "{EE203B88-44CF-4859-9D42-7A5F43FECB52}"
     109Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "touky_demo", "..\..\people\touky\private\touky_demo\touky_demo.vcxproj", "{EE203B88-44CF-4859-9D42-7A5F43FECB52}"
    110110EndProject
    111111Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "btphystest", "..\..\test\btphystest.vcxproj", "{EE203B88-44CF-4859-9D42-7A1F43FECB52}"
     
    146146EndProject
    147147Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "the_unfortunate_voronoid", "..\..\people\touky\private\the_unfortunate_voronoid\the_unfortunate_voronoid.vcxproj", "{6BF81B39-EDC2-4127-9982-C2D8ABEA95AF}"
     148EndProject
     149Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "labyrinth", "..\..\people\touky\private\labyrinth\labyrinth.vcxproj", "{EE203B88-44CF-4859-9D42-7A5F45FEDB52}"
    148150EndProject
    149151Global
     
    806808                {6BF81B39-EDC2-4127-9982-C2D8ABEA95AF}.Release|x64.Build.0 = Release|x64
    807809                {6BF81B39-EDC2-4127-9982-C2D8ABEA95AF}.Release|Xbox 360.ActiveCfg = Release|x64
     810                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|Any CPU.ActiveCfg = Debug|x64
     811                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
     812                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|Mixed Platforms.Build.0 = Debug|Win32
     813                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|PS3.ActiveCfg = Debug|x64
     814                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|Win32.ActiveCfg = Debug|Win32
     815                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|Win32.Build.0 = Debug|Win32
     816                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|x64.ActiveCfg = Debug|x64
     817                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|x64.Build.0 = Debug|x64
     818                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Debug|Xbox 360.ActiveCfg = Debug|x64
     819                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|Any CPU.ActiveCfg = Release|x64
     820                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|Mixed Platforms.ActiveCfg = Release|Win32
     821                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|Mixed Platforms.Build.0 = Release|Win32
     822                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|PS3.ActiveCfg = Release|x64
     823                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|Win32.ActiveCfg = Release|Win32
     824                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|Win32.Build.0 = Release|Win32
     825                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|x64.ActiveCfg = Release|x64
     826                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|x64.Build.0 = Release|x64
     827                {EE203B88-44CF-4859-9D42-7A5F45FEDB52}.Release|Xbox 360.ActiveCfg = Release|x64
    808828        EndGlobalSection
    809829        GlobalSection(SolutionProperties) = preSolution
     
    846866                {25493FC8-75AC-4703-AD58-AB0C4A0FB79C} = {9EA99B18-D352-47F6-BC04-A0B49CAA2772}
    847867                {6BF81B39-EDC2-4127-9982-C2D8ABEA95AF} = {9EA99B18-D352-47F6-BC04-A0B49CAA2772}
     868                {EE203B88-44CF-4859-9D42-7A5F45FEDB52} = {9EA99B18-D352-47F6-BC04-A0B49CAA2772}
    848869                {A69411B3-6DE8-404E-8E70-0D3375A7492A} = {0A1651FC-322B-4B04-82CB-28E9046D9383}
    849870                {5A77DCDD-2CBA-43E9-8B45-00C281443F77} = {0A1651FC-322B-4B04-82CB-28E9046D9383}
  • trunk/test/data/mesh-buffer.txt

    r2450 r2718  
     1[sc#f8f afcb 10 10 10 .25 tx 0]
     2
     3//sc#fff
     4//[afcb 1 1 1 -.1 tx 1]
     5//[afcb 1 1 1 -.1 tx 0]
     6//[afcb 1 1 1 -.1 tx -1]
     7//[[afcb 1 1 1 -.1 tx 1]
     8//[afcb 1 1 1 -.1 tx 0]
     9//[afcb 1 1 1 -.1 tx -1]tz 1]
     10//[[afcb 1 1 1 -.1 tx 1]
     11//[afcb 1 1 1 -.1 tx 0]
     12//[afcb 1 1 1 -.1 tx -1]tz -1]
     13//[afcb 3 .2 3 -.05 ty -.6]
     14
     15
    116//[sc#fff scb#fff ato 20 8 12 rx0]
    217//[sc#fff scb#fff acg 8 2 5 1 6 8 4 2 .1 1]
    318
    4 [sc#fff ab 4 4 4 smth 0 1 1 ]//twy 45 0 bdxy 90 0 splt 5 tz 2
     19//[sc#fff ab 4 4 4 ]//twy 45 0 bdxy 90 0 splt 5 tz 2
    520//[sc#88f ab 4 4 4 tx 4 ab 4 4 4 tx -2 tax .4 .4 0]
    621//[sc#88f ab .25 1 1 tx .25 ab .25 1 1 tx .25 ab .25 1 1 tx .25 ab .25 1 1 tx .125 stx 10 0 0]
     
    2136//[sc#ff2 asph 2 10 10 10]
    2237//[sc#400 asph 2 10 10 10 t 2 2 2 csgs]
     38
    2339//[sc#88f afcb 10 10 10 .25 tx 0]
    24 //[sc#fff afcb 10 10 10 .25 t 2 2 2]
     40[sc#fff afcb 10 10 10 .25 t 2 2 2 csgs]
    2541//[sc#fff afcb 7 7 7 .25]
    26 //[sc#ff2 afcb 7 7 7 .25 t 1 1 1]
     42//[sc#ff2 afcb 7 7 7 .25 t 1 1 1 csgs]
  • trunk/test/meshviewer.cpp

    r2598 r2718  
    4949#define    IPT_MESH_ROT_DOWN      "Mesh_Rot_Down"
    5050
     51#define    MIN_FOV                1.f
     52
    5153#define    WITH_FUR               0
     54#define    WITH_TEXTURE           0
    5255
    5356class MeshViewer : public WorldEntity
    5457{
    5558public:
    56     void SetFov(float new_fov=60.0f)
    57     {
    58         //FOV compensation doesn't work
    59         ivec2 video_size = Video::GetSize();
    60         float near = (float)-video_size.x - video_size.y;
    61         float far = (float)video_size.x + video_size.y;
    62         float t1 = tanf(new_fov / 2);
    63         float dist = (float)video_size.x / (2.0f * t1);
    64         //m_fov_compensation = mat4::translate(-0.5f * video_size.x, -0.5f * video_size.y, -dist);
    65         m_fov_compensation = mat4::translate(vec3(.0f));
    66         if (new_fov > 0.1f)
    67             Scene::GetDefault()->GetCamera()->SetProjection(mat4::perspective(new_fov, (float)video_size.x, (float)video_size.y, .1f, 1000.f));
     59    void SetFov(float new_fov=60.0f, vec2 video_size = vec2(Video::GetSize()))
     60    {
     61        if (new_fov > MIN_FOV)
     62            Scene::GetDefault()->GetCamera()->SetProjection(mat4::perspective(new_fov, video_size.x, video_size.y, .1f, 1000.f));
    6863        else
    69             Scene::GetDefault()->GetCamera()->SetProjection(mat4::ortho((float)video_size.x, (float)video_size.y, .1f, 1000.f));
     64            Scene::GetDefault()->GetCamera()->SetProjection(mat4::ortho(video_size.x, video_size.y, .1f, 1000.f));
    7065    }
    7166
     
    7570        //Input setup
    7671        Input::LinkActionToKey(IPT_CAM_RESET,           Key::Return);
    77         Input::LinkActionToKey(IPT_CAM_FORWARD,         Key::PageUp);
    78         Input::LinkActionToKey(IPT_CAM_BACKWARD,        Key::PageDown);
    79         Input::LinkActionToKey(IPT_CAM_ZOOM_IN,         Key::Home);
    80         Input::LinkActionToKey(IPT_CAM_ZOOM_OUT,        Key::End);
     72        Input::LinkActionToKey(IPT_CAM_ZOOM_IN,         Key::PageUp);
     73        Input::LinkActionToKey(IPT_CAM_ZOOM_OUT,        Key::PageDown);
    8174
    8275        Input::LinkActionToKey(IPT_MESH_LEFT,           Key::Left);
     
    170163        }
    171164
     165        //--
    172166        //Update Mesh BBox - Get the Min/Max needed
     167        //--
     168        vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
    173169        vec3 min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
    174170        int mesh_id = m_meshes.Count() - 1;
     
    177173                break;
    178174
     175        mat4 world_screen = Scene::GetDefault()->GetCamera()->GetProjection() * Scene::GetDefault()->GetCamera()->GetView();
     176
    179177        if (m_meshes.Count() && mesh_id >= 0)
    180178        {
    181179            for (int i = 0; i < m_meshes[mesh_id].m1.GetVertexCount(); i++)
    182180            {
    183                 vec3 vpos = m_meshes[mesh_id].m1.GetVertexLocation(i);
     181                mat4 LocalPos = m_mat * mat4::translate(m_meshes[mesh_id].m1.GetVertexLocation(i));
     182                vec3 vpos = LocalPos.v3.xyz;
     183                //vec3 vpos = m_meshes[mesh_id].m1.GetVertexLocation(i);
     184
    184185                min_max[0] = min(vpos.xyz, min_max[0]);
    185186                min_max[1] = max(vpos.xyz, min_max[1]);
     187
     188                LocalPos = world_screen * LocalPos;
     189                vpos = (LocalPos.v3 / LocalPos.v3.w).xyz;
     190
     191                screen_min_max[0] = min(vpos.xy, screen_min_max[0]);
     192                screen_min_max[1] = max(vpos.xy, screen_min_max[1]);
    186193            }
    187194        }
    188195        else
    189196        {
     197            min_max[1] = vec3(.0f);
    190198            min_max[0] = vec3(.0f);
    191             min_max[1] = vec3(.0f);
     199            screen_min_max[0] = vec2(.0f);
     200            screen_min_max[1] = vec2(.0f);
    192201        }
    193202        //[0] : center, [1] : size.
     
    200209        //Camera movement handling
    201210        //--
    202         vec3 cam_move = BBox_mod * seconds *
    203                         vec3(.0f, .0f, (float)(Input::GetStatus(IPT_CAM_BACKWARD) - Input::GetStatus(IPT_CAM_FORWARD)));
    204 
    205211        if (Input::WasReleased(IPT_CAM_RESET))
    206212            SetFov();
    207213
     214        //Auto Fov
     215        float local_max = max(max(lol::abs(min_max[0].x), lol::abs(min_max[0].y)),
     216                          max(lol::abs(min_max[1].x),     lol::abs(min_max[1].y)));
     217        float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
     218                              max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
     219
     220        //Fov modification
    208221        float fov_zoom = (float)(Input::GetStatus(IPT_CAM_ZOOM_OUT) - Input::GetStatus(IPT_CAM_ZOOM_IN));
    209222        m_fov_zoom_damp = damp(m_fov_zoom_damp, fov_zoom, (fov_zoom == .0f)?(.15f):(0.5f), seconds);
    210223        m_fov = max(.0f, m_fov + seconds * 10.0f * m_fov_zoom_damp);
    211224        m_fov_damp = damp(m_fov_damp, m_fov, .2f, seconds);
    212         SetFov(m_fov_damp);
    213 
     225
     226        if (m_fov_damp < MIN_FOV)
     227        {
     228            vec2 tmp = vec2(Video::GetSize());
     229            SetFov(0, vec2(local_max * 2.2f) * (tmp / vec2(tmp.y)));
     230        }
     231        else
     232            SetFov(m_fov_damp);
     233
     234        //Move modification
    214235        vec3 campos = Scene::GetDefault()->GetCamera()->GetPosition();
    215         Scene::GetDefault()->GetCamera()->SetView(campos + cam_move, quat(1.f));
     236        if (m_fov_damp < MIN_FOV)
     237            Scene::GetDefault()->GetCamera()->SetView(vec3(campos.xy, 10.f), quat(1.f));
     238        else if (fov_ratio > .0f)
     239            Scene::GetDefault()->GetCamera()->SetView(vec3(campos.xy, campos.z * fov_ratio * 1.1f), quat(1.f));
    216240
    217241        //--
     
    351375#if WITH_FUR
    352376                m_meshes[i].m1.MeshConvert(Shader::Create(LOLFX_RESOURCE_NAME(shinyfur)));
    353 #else
     377#elif WITH_TEXTURE
    354378                //m_meshes[i].m1.MeshConvert(m_texture_shader);
    355379                //m_meshes[i].m1.MeshConvert();
     
    357381                                                                  (1 << VertexUsage::Color)    | (1 << VertexUsage::TexCoord)),
    358382                                                                  m_texture_shader, true));
     383#else
     384                m_meshes[i].m1.MeshConvert();
    359385#endif
    360386                m_meshes[i].m2 = true;
     
    378404                }
    379405                m_meshes[i].m4 = damp(m_meshes[i].m4, new_mesh_offset, .35f, seconds);
    380                 Scene::GetDefault()->GetCamera()->SetProjection(mat4::translate(m_meshes[i].m4) *
     406
     407                Scene::GetDefault()->GetCamera()->SetProjection(
     408                                                                mat4::translate(m_meshes[i].m4) *
    381409                                                                mat4::translate(vec3(m_mesh_screen_offset_damp, .0f)) *
    382410                                                                mat4::scale(vec3(vec2(m_meshes[i].m3), 1.0f)) *
    383                                                                 default_proj *
    384                                                                 m_fov_compensation);
     411                                                                default_proj);
    385412#if WITH_FUR
    386413                for (int j=0; j < 40; j++)
Note: See TracChangeset for help on using the changeset viewer.