Changeset 2889


Ignore:
Timestamp:
Sep 10, 2013, 11:18:49 PM (6 years ago)
Author:
touky
Message:

btphystest : cat movement update

Location:
trunk/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/btphystest.cpp

    r2885 r2889  
    2424#define CAT_MODE        1
    2525#define OBJ_SIZE        2.f
     26#define NB_SPRITE       4
     27#define PARTICLE_SIZE   4
    2628#include "physicobject.h"
    2729
     
    3032using namespace lol::phys;
    3133
    32 #define CUBE_HALF_EXTENTS .5f
    33 #define EXTRA_HEIGHT 1.f
    34 #define BASE_TIME 2.f
     34#define CUBE_HALF_EXTENTS   .5f
     35#define EXTRA_HEIGHT        1.f
     36#define BASE_TIME           2.f
    3537#define ZERO_TIME (BASE_TIME + rand(-BASE_TIME * .4f, BASE_TIME * .4f))
    36 #define ZERO_SPEED 3.5f
    37 #define JUMP_HEIGHT 30.f
    38 #define JUMP_STRAFE .5f
     38#define ZERO_SPEED          3.5f
     39#define JUMP_HEIGHT         30.f
     40#define JUMP_STRAFE         .5f
    3941
    4042int gNumObjects = 64;
     
    7779    /* Create a camera that matches the settings of XNA BtPhysTest */
    7880    m_camera = new Camera();
     81   
    7982#if CAT_MODE
    8083    m_camera->SetView(vec3(70.f, 50.f, 0.f),
    8184                      vec3(0.f, 0.f, 0.f),
    8285                      vec3(0, 1, 0));
    83     m_camera->SetProjection(mat4::perspective(60.f, 1280.f, 960.f, .1f, 1000.f));
     86    m_camera->SetProjection(mat4::perspective(60.f, (float)Video::GetSize().x, (float)Video::GetSize().y, .1f, 1000.f));
    8487#else
    8588    m_camera->SetView(vec3(50.f, 50.f, 0.f),
    8689                      vec3(0.f, 0.f, 0.f),
    8790                      vec3(0, 1, 0));
    88     m_camera->SetProjection(mat4::perspective(45.f, 1280.f, 960.f, .1f, 1000.f));
     91    m_camera->SetProjection(mat4::perspective(45.f, (float)Video::GetSize().x, (float)Video::GetSize().y, .1f, 1000.f));
    8992#endif
    9093    g_scene->PushCamera(m_camera);
     
    519522                                                m_cat_shader);
    520523            m_cat_sdata->m_shader_texture = m_cat_texture->GetTexture();
     524            m_cat_sdata->m_sprite_flip = ((rand(2) == 1)?(1.f):(0.f)) / (float)(NB_SPRITE * PARTICLE_SIZE);
    521525            PhysObj->SetCustomShaderData(m_cat_sdata);
     526            m_cat_sdata = NULL;
    522527        }
    523528#endif //USE_BODIES
    524 
    525 
    526529#endif //CAT_MODE
    527530
    528531        /* FIXME: this object never cleans up */
    529532        m_ready = true;
     533    }
     534    else
     535    {
     536#if CAT_MODE
     537        for (int i = 0; i < m_physobj_list.Count(); i++)
     538        {
     539            PhysicsObject* PhysObj = m_physobj_list[i].m1;
     540            CatShaderData* ShaderData = (CatShaderData*)PhysObj->GetCustomShaderData();
     541
     542            ShaderData->m_sprite_orientation = damp(ShaderData->m_sprite_orientation,
     543                                                    F_PI_4 * ((ShaderData->m_sprite_flip * 2.f * (float)(NB_SPRITE * PARTICLE_SIZE)) - 1.f) *
     544                                                    clamp(PhysObj->GetPhysic()->GetLinearVelocity().y / 20.0f, -1.f, 1.f),
     545                                                    0.1f, seconds);
     546        }
     547#endif //CAT_MODE
    530548    }
    531549
     
    542560#if CAT_MODE
    543561    /* cat datas setup */
    544     delete(m_cat_sdata);
    545562    Shader::Destroy(m_cat_shader);
    546563    Tiler::Deregister(m_cat_texture);
     
    599616    : GpuShaderData(vert_decl_flags, shader, DebugRenderMode::Default)
    600617{
     618    m_sprite_orientation = .0f;
     619    m_sprite_flip = .0f;
    601620    SetupDefaultData();
    602621}
     
    609628    AddUniform("in_proj");
    610629    AddUniform("in_texture");
     630    AddUniform("in_sprite_orientation");
     631    AddUniform("in_sprite_flip");
    611632}
    612633
     
    623644    m_shader->SetUniform(*GetUniform("in_normal_mat"), normalmat);
    624645    m_shader->SetUniform(*GetUniform("in_proj"), proj);
     646    m_shader->SetUniform(*GetUniform("in_texture"), m_shader_texture, 0);
     647    m_shader->SetUniform(*GetUniform("in_sprite_orientation"), m_sprite_orientation);
     648    m_shader->SetUniform(*GetUniform("in_sprite_flip"), m_sprite_flip);
    625649}
    626650
     
    629653    System::Init(argc, argv);
    630654
    631     Application app("BtPhysTest", ivec2(1280, 960), 60.0f);
     655    Application app("BtPhysTest", ivec2(1280, 720), 60.0f);
    632656
    633657    new BtPhysTest(argc > 1);
  • trunk/test/btphystest.h

    r2879 r2889  
    2626
    2727    ShaderTexture   m_shader_texture;
     28    float           m_sprite_orientation;
     29    float           m_sprite_flip;
    2830};
    2931
  • trunk/test/front_camera_sprite.lolfx

    r2885 r2889  
    77attribute vec4 in_texcoord;
    88
    9 uniform mat4 in_model_view;
    10 uniform mat3 in_normal_mat;
    11 uniform mat4 in_proj;
     9uniform mat4  in_model_view;
     10uniform mat3  in_normal_mat;
     11uniform mat4  in_proj;
     12uniform float in_sprite_orientation;
    1213
    1314varying vec4 pass_texcoord;
     
    1819    vec4 vertex = in_model_view * vec4(in_vertex - vec3(0.0,0.5,0.0), 1.0);
    1920
     21    vec3 v_offset = vec3(1.0 * in_texcoord.z, -1.0 * in_texcoord.w, 0.0);
     22
     23    float sinX = sin(in_sprite_orientation);
     24    float cosX = cos(in_sprite_orientation);
     25    float sinY = sinX;
     26    mat2 rotationMatrix = mat2(cosX, -sinX, sinY, cosX);
     27   
     28    v_offset.xy = rotationMatrix * v_offset.xy;
     29
    2030    //Billboard calculations
    21     vertex.x += (1.0 * in_texcoord.z);
    22     vertex.y += (- 1.0 * in_texcoord.w);
     31    vertex.xyz += v_offset;
    2332
    2433    //pass datas
     
    3645#endif
    3746
    38 uniform sampler2D in_texture;
     47uniform sampler2D   in_texture;
     48uniform float       in_sprite_flip;
    3949
    4050varying vec4 pass_texcoord;
     
    4656void main(void)
    4757{
    48     vec4 color = texture2D(in_texture, pass_texcoord.xy);
     58    vec4 color = texture2D(in_texture, pass_texcoord.xy -
     59                                         vec2(pass_texcoord.z * in_sprite_flip, 0.0)) *
     60                                         pass_color;
    4961    if (color.a < 0.01)
    5062        discard;
  • trunk/test/physicobject.h

    r2881 r2889  
    150150#if USE_SPHERE
    151151#if CAT_MODE
    152         int nb_sprite = 4;
     152        int nb_sprite = NB_SPRITE;
    153153        //SPRITE
    154154        vec2 start_point = vec2((float)rand(nb_sprite), (float)rand(nb_sprite)) / vec2((float)nb_sprite);
    155                            //vec2(2.f, .0f) / vec2((float)nb_sprite);
     155                           //vec2(0.f, .0f) / vec2((float)nb_sprite);
    156156        vec2 size = vec2(1.f) / vec2((float)nb_sprite);
    157157        m_mesh.BD()->SetTexCoordCustomBuild(MeshType::Quad, MeshFaceType::QuadDefault,
    158158                                            start_point, start_point + size);
    159159        m_mesh.BD()->SetTexCoordCustomBuild2(MeshType::Quad, MeshFaceType::QuadDefault,
    160                                              vec2(-4.f), vec2(4.f));
     160                                             vec2(-PARTICLE_SIZE), vec2(PARTICLE_SIZE));
    161161        MeshRand << "[sc#ffff aq 0 0]";
    162162        MeshRand << "[sc#faaf aq 0 0]";
     
    295295        m_custom_shader = custom_shader;
    296296    }
     297    GpuShaderData* GetCustomShaderData()
     298    {
     299        return m_custom_shader;
     300    }
    297301
    298302    EasyMesh *GetMesh() { return &m_mesh; }
Note: See TracChangeset for help on using the changeset viewer.