Ver código fonte

btphystest : cat movement update

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 anos atrás
pai
commit
40a1a18758
5 arquivos alterados com 64 adições e 22 exclusões
  1. +36
    -12
      test/btphystest.cpp
  2. +2
    -0
      test/btphystest.h
  3. BIN
      test/data/CatsSheet.png
  4. +19
    -7
      test/front_camera_sprite.lolfx
  5. +7
    -3
      test/physicobject.h

+ 36
- 12
test/btphystest.cpp Ver arquivo

@@ -23,19 +23,21 @@ using namespace lol;

#define CAT_MODE 1
#define OBJ_SIZE 2.f
#define NB_SPRITE 4
#define PARTICLE_SIZE 4
#include "physicobject.h"

#include "btphystest.h"

using namespace lol::phys;

#define CUBE_HALF_EXTENTS .5f
#define EXTRA_HEIGHT 1.f
#define BASE_TIME 2.f
#define CUBE_HALF_EXTENTS .5f
#define EXTRA_HEIGHT 1.f
#define BASE_TIME 2.f
#define ZERO_TIME (BASE_TIME + rand(-BASE_TIME * .4f, BASE_TIME * .4f))
#define ZERO_SPEED 3.5f
#define JUMP_HEIGHT 30.f
#define JUMP_STRAFE .5f
#define ZERO_SPEED 3.5f
#define JUMP_HEIGHT 30.f
#define JUMP_STRAFE .5f

int gNumObjects = 64;

@@ -76,16 +78,17 @@ BtPhysTest::BtPhysTest(bool editor)

/* Create a camera that matches the settings of XNA BtPhysTest */
m_camera = new Camera();
#if CAT_MODE
m_camera->SetView(vec3(70.f, 50.f, 0.f),
vec3(0.f, 0.f, 0.f),
vec3(0, 1, 0));
m_camera->SetProjection(mat4::perspective(60.f, 1280.f, 960.f, .1f, 1000.f));
m_camera->SetProjection(mat4::perspective(60.f, (float)Video::GetSize().x, (float)Video::GetSize().y, .1f, 1000.f));
#else
m_camera->SetView(vec3(50.f, 50.f, 0.f),
vec3(0.f, 0.f, 0.f),
vec3(0, 1, 0));
m_camera->SetProjection(mat4::perspective(45.f, 1280.f, 960.f, .1f, 1000.f));
m_camera->SetProjection(mat4::perspective(45.f, (float)Video::GetSize().x, (float)Video::GetSize().y, .1f, 1000.f));
#endif
g_scene->PushCamera(m_camera);

@@ -518,16 +521,31 @@ void BtPhysTest::TickDraw(float seconds)
(1 << VertexUsage::TexCoordExt)),
m_cat_shader);
m_cat_sdata->m_shader_texture = m_cat_texture->GetTexture();
m_cat_sdata->m_sprite_flip = ((rand(2) == 1)?(1.f):(0.f)) / (float)(NB_SPRITE * PARTICLE_SIZE);
PhysObj->SetCustomShaderData(m_cat_sdata);
m_cat_sdata = NULL;
}
#endif //USE_BODIES


#endif //CAT_MODE

/* FIXME: this object never cleans up */
m_ready = true;
}
else
{
#if CAT_MODE
for (int i = 0; i < m_physobj_list.Count(); i++)
{
PhysicsObject* PhysObj = m_physobj_list[i].m1;
CatShaderData* ShaderData = (CatShaderData*)PhysObj->GetCustomShaderData();

ShaderData->m_sprite_orientation = damp(ShaderData->m_sprite_orientation,
F_PI_4 * ((ShaderData->m_sprite_flip * 2.f * (float)(NB_SPRITE * PARTICLE_SIZE)) - 1.f) *
clamp(PhysObj->GetPhysic()->GetLinearVelocity().y / 20.0f, -1.f, 1.f),
0.1f, seconds);
}
#endif //CAT_MODE
}

//Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));

@@ -541,7 +559,6 @@ BtPhysTest::~BtPhysTest()

#if CAT_MODE
/* cat datas setup */
delete(m_cat_sdata);
Shader::Destroy(m_cat_shader);
Tiler::Deregister(m_cat_texture);
#endif //CAT_MODE
@@ -598,6 +615,8 @@ BtPhysTest::~BtPhysTest()
CatShaderData::CatShaderData(uint32_t vert_decl_flags, Shader* shader)
: GpuShaderData(vert_decl_flags, shader, DebugRenderMode::Default)
{
m_sprite_orientation = .0f;
m_sprite_flip = .0f;
SetupDefaultData();
}

@@ -608,6 +627,8 @@ void CatShaderData::SetupDefaultData()
AddUniform("in_normal_mat");
AddUniform("in_proj");
AddUniform("in_texture");
AddUniform("in_sprite_orientation");
AddUniform("in_sprite_flip");
}

//-----------------------------------------------------------------------------
@@ -622,13 +643,16 @@ void CatShaderData::SetupShaderDatas(mat4 const &model)
m_shader->SetUniform(*GetUniform("in_model_view"), modelview);
m_shader->SetUniform(*GetUniform("in_normal_mat"), normalmat);
m_shader->SetUniform(*GetUniform("in_proj"), proj);
m_shader->SetUniform(*GetUniform("in_texture"), m_shader_texture, 0);
m_shader->SetUniform(*GetUniform("in_sprite_orientation"), m_sprite_orientation);
m_shader->SetUniform(*GetUniform("in_sprite_flip"), m_sprite_flip);
}

int main(int argc, char **argv)
{
System::Init(argc, argv);

Application app("BtPhysTest", ivec2(1280, 960), 60.0f);
Application app("BtPhysTest", ivec2(1280, 720), 60.0f);

new BtPhysTest(argc > 1);
app.ShowPointer(false);


+ 2
- 0
test/btphystest.h Ver arquivo

@@ -25,6 +25,8 @@ public:
virtual lol::String GetInTexCoordName() { return lol::String("in_texcoord"); }

ShaderTexture m_shader_texture;
float m_sprite_orientation;
float m_sprite_flip;
};

class BtPhysTest : public WorldEntity


BIN
test/data/CatsSheet.png Ver arquivo

Antes Depois
Largura: 1024  |  Altura: 1024  |  Tamanho: 902 KiB Largura: 1024  |  Altura: 1024  |  Tamanho: 903 KiB

+ 19
- 7
test/front_camera_sprite.lolfx Ver arquivo

@@ -6,9 +6,10 @@ attribute vec3 in_vertex;
attribute vec4 in_color;
attribute vec4 in_texcoord;

uniform mat4 in_model_view;
uniform mat3 in_normal_mat;
uniform mat4 in_proj;
uniform mat4 in_model_view;
uniform mat3 in_normal_mat;
uniform mat4 in_proj;
uniform float in_sprite_orientation;

varying vec4 pass_texcoord;
varying vec4 pass_color;
@@ -17,9 +18,17 @@ void main(void)
{
vec4 vertex = in_model_view * vec4(in_vertex - vec3(0.0,0.5,0.0), 1.0);

vec3 v_offset = vec3(1.0 * in_texcoord.z, -1.0 * in_texcoord.w, 0.0);

float sinX = sin(in_sprite_orientation);
float cosX = cos(in_sprite_orientation);
float sinY = sinX;
mat2 rotationMatrix = mat2(cosX, -sinX, sinY, cosX);
v_offset.xy = rotationMatrix * v_offset.xy;

//Billboard calculations
vertex.x += (1.0 * in_texcoord.z);
vertex.y += (- 1.0 * in_texcoord.w);
vertex.xyz += v_offset;

//pass datas
pass_texcoord = in_texcoord;
@@ -35,7 +44,8 @@ void main(void)
precision highp float;
#endif

uniform sampler2D in_texture;
uniform sampler2D in_texture;
uniform float in_sprite_flip;

varying vec4 pass_texcoord;
varying vec4 pass_color;
@@ -45,7 +55,9 @@ const float PI = 3.14159265358979323846264;

void main(void)
{
vec4 color = texture2D(in_texture, pass_texcoord.xy);
vec4 color = texture2D(in_texture, pass_texcoord.xy -
vec2(pass_texcoord.z * in_sprite_flip, 0.0)) *
pass_color;
if (color.a < 0.01)
discard;
gl_FragColor = color * pass_color;


+ 7
- 3
test/physicobject.h Ver arquivo

@@ -149,15 +149,15 @@ public:

#if USE_SPHERE
#if CAT_MODE
int nb_sprite = 4;
int nb_sprite = NB_SPRITE;
//SPRITE
vec2 start_point = vec2((float)rand(nb_sprite), (float)rand(nb_sprite)) / vec2((float)nb_sprite);
//vec2(2.f, .0f) / vec2((float)nb_sprite);
//vec2(0.f, .0f) / vec2((float)nb_sprite);
vec2 size = vec2(1.f) / vec2((float)nb_sprite);
m_mesh.BD()->SetTexCoordCustomBuild(MeshType::Quad, MeshFaceType::QuadDefault,
start_point, start_point + size);
m_mesh.BD()->SetTexCoordCustomBuild2(MeshType::Quad, MeshFaceType::QuadDefault,
vec2(-4.f), vec2(4.f));
vec2(-PARTICLE_SIZE), vec2(PARTICLE_SIZE));
MeshRand << "[sc#ffff aq 0 0]";
MeshRand << "[sc#faaf aq 0 0]";
MeshRand << "[sc#afaf aq 0 0]";
@@ -294,6 +294,10 @@ public:
{
m_custom_shader = custom_shader;
}
GpuShaderData* GetCustomShaderData()
{
return m_custom_shader;
}

EasyMesh *GetMesh() { return &m_mesh; }
EasyPhysic *GetPhysic() { return m_physics; }


Carregando…
Cancelar
Salvar