소스 검색

touky_demo : various fixes & tweaks.

meshviewer : Full revamp, now bigger & better.
undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 년 전
부모
커밋
721d114e3a
2개의 변경된 파일252개의 추가작업 그리고 326개의 파일을 삭제
  1. +4
    -2
      test/data/mesh-buffer.txt
  2. +248
    -324
      test/meshviewer.cpp

+ 4
- 2
test/data/mesh-buffer.txt 파일 보기

@@ -1,4 +1,6 @@
[sc#f8f afcb 10 10 10 .25 tx 0]
[sc#f8f afcb 1 1 1 0]
// splt 5 twy 90 0
//[sc#f8f afcb 10 10 10 .25 tx 0 splt 3 twy 1.6 0 ]
//sc#fff
//[afcb 1 1 1 -.1 tx 1]
@@ -37,6 +39,6 @@
//[sc#400 asph 2 10 10 10 t 2 2 2 csgs]
//[sc#88f afcb 10 10 10 .25 tx 0]
[sc#fff afcb 10 10 10 .25 t 2 2 2 csgs]
//[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]

+ 248
- 324
test/meshviewer.cpp 파일 보기

@@ -23,34 +23,41 @@ using namespace lol;

static int const TEXTURE_WIDTH = 256;

#define R_M 2.f
#define WIDTH (770.f * R_M)
#define HEIGHT (200.f * R_M)
#define SCREEN_W (10.f / WIDTH)
#define SCREEN_LIMIT 1.1f
#define RATIO_HW (HEIGHT / WIDTH)
#define RATIO_WH (WIDTH / HEIGHT)

#define ROT_SPEED vec2(50.f)
#define ROT_CLAMP 89.f
#define POS_SPEED vec2(1.2f)
#define POS_CLAMP 1.f
#define FOV_SPEED 20.f
#define FOV_CLAMP 120.f
#define ZOM_SPEED 3.f
#define ZOM_CLAMP 20.f

#define WITH_TEXTURE 0

LOLFX_RESOURCE_DECLARE(shinyfur);
LOLFX_RESOURCE_DECLARE(shinymvtexture);

enum
{
KEY_CAM_RESET,
KEY_CAM_FORWARD,
KEY_CAM_BACKWARD,
KEY_CAM_ZOOM_OUT,
KEY_CAM_ZOOM_IN,
KEY_CAM_POS,
KEY_CAM_FOV,

KEY_MESH_UPDATE,
KEY_MESH_RESET,
KEY_MESH_PREV,
KEY_MESH_NEXT,
KEY_CAM_UP,
KEY_CAM_DOWN,
KEY_CAM_LEFT,
KEY_CAM_RIGHT,

KEY_MESH_LEFT,
KEY_MESH_RIGHT,
KEY_MESH_UP,
KEY_MESH_DOWN,
KEY_MESH_SCALE_UP,
KEY_MESH_SCALE_DOWN,
KEY_MESH_OFFSET_UP,
KEY_MESH_OFFSET_DOWN,
KEY_MESH_ROT_LEFT,
KEY_MESH_ROT_RIGHT,
KEY_MESH_ROT_UP,
KEY_MESH_ROT_DOWN,
KEY_MESH_NEXT,
KEY_MESH_PREV,

KEY_F1,
KEY_F2,
@@ -62,52 +69,41 @@ enum
KEY_MAX,
};

#define MIN_FOV 0.1f
enum
{
MSG_IN,
MSG_OUT,

#define WITH_FUR 0
#define WITH_TEXTURE 0
MSG_MAX
} MessageType;

class MeshViewer : public WorldEntity
{
public:
void SetFov(float new_fov=60.0f, vec2 video_size = vec2(Video::GetSize()))
{
if (new_fov > MIN_FOV)
g_scene->GetCamera()->SetProjection(mat4::perspective(new_fov, video_size.x, video_size.y, .1f, 1000.f));
else
g_scene->GetCamera()->SetProjection(mat4::ortho(video_size.x, video_size.y, .1f, 1000.f));
}

MeshViewer(char const *file_name = "data/mesh-buffer.txt")
: m_file_name(file_name)
{
/* Register an input controller for the keyboard */
m_controller = new Controller("Default", KEY_MAX, 0);

m_controller->GetKey(KEY_CAM_RESET).Bind("Keyboard", "Return");
m_controller->GetKey(KEY_CAM_ZOOM_IN).Bind("Keyboard", "PageUp");
m_controller->GetKey(KEY_CAM_ZOOM_OUT).Bind("Keyboard", "PageDown");

m_controller->GetKey(KEY_MESH_LEFT).Bind("Keyboard", "Left");
m_controller->GetKey(KEY_MESH_RIGHT).Bind("Keyboard", "Right");
m_controller->GetKey(KEY_MESH_UP).Bind("Keyboard", "Up");
m_controller->GetKey(KEY_MESH_DOWN).Bind("Keyboard", "Down");
//Camera keyboard rotation
m_controller->GetKey(KEY_CAM_UP ).Bind("Keyboard", "Up");
m_controller->GetKey(KEY_CAM_DOWN ).Bind("Keyboard", "Down");
m_controller->GetKey(KEY_CAM_LEFT ).Bind("Keyboard", "Left");
m_controller->GetKey(KEY_CAM_RIGHT).Bind("Keyboard", "Right");

m_controller->GetKey(KEY_MESH_UPDATE).Bind("Keyboard", "Space");
m_controller->GetKey(KEY_MESH_RESET).Bind("Keyboard", "KP0");
m_controller->GetKey(KEY_MESH_PREV).Bind("Keyboard", "KPPlus");
m_controller->GetKey(KEY_MESH_NEXT).Bind("Keyboard", "KPMinus");
//Camera keyboard position switch
m_controller->GetKey(KEY_CAM_POS ).Bind("Keyboard", "LeftShift");
m_controller->GetKey(KEY_CAM_FOV ).Bind("Keyboard", "LeftCtrl");

m_controller->GetKey(KEY_MESH_OFFSET_DOWN).Bind("Keyboard", "KP1");
m_controller->GetKey(KEY_MESH_OFFSET_UP).Bind("Keyboard", "KP3");
m_controller->GetKey(KEY_MESH_SCALE_DOWN).Bind("Keyboard", "KP7");
m_controller->GetKey(KEY_MESH_SCALE_UP).Bind("Keyboard", "KP9");
//Camera unzoom switch
m_controller->GetKey(KEY_CAM_RESET).Bind("Keyboard", "Space");

m_controller->GetKey(KEY_MESH_ROT_LEFT).Bind("Keyboard", "KP4");
m_controller->GetKey(KEY_MESH_ROT_RIGHT).Bind("Keyboard", "KP6");
m_controller->GetKey(KEY_MESH_ROT_UP).Bind("Keyboard", "KP8");
m_controller->GetKey(KEY_MESH_ROT_DOWN).Bind("Keyboard", "KP5");
//Mesh change
m_controller->GetKey(KEY_MESH_NEXT).Bind("Keyboard", "PageUp");
m_controller->GetKey(KEY_MESH_PREV).Bind("Keyboard", "PageDown");

//Base setup
m_controller->GetKey(KEY_F1).Bind("Keyboard", "F1");
m_controller->GetKey(KEY_F2).Bind("Keyboard", "F2");
m_controller->GetKey(KEY_F3).Bind("Keyboard", "F3");
@@ -115,51 +111,48 @@ public:
m_controller->GetKey(KEY_F5).Bind("Keyboard", "F5");
m_controller->GetKey(KEY_ESC).Bind("Keyboard", "Escape");

// State
m_mesh_shown = 0;
m_angle = 0;
// Message Service
MessageService::Setup(MSG_MAX);

// Mesh Setup
m_mesh_id = 0;
m_mesh_id1 = 0.f;
m_default_texture = NULL;

//Camera Setup
m_fov_zoom_damp = .0f;
m_fov_damp = 60.0f;
m_fov = 60.0f;
m_fov = -100.f;
m_fov_mesh = 0.f;
m_fov_speed = 0.f;
m_zoom = -100.f;
m_zoom_mesh = 0.f;
m_zoom_speed = 0.f;
m_rot = vec2(0.f);
m_rot_mesh = vec2(0.f);
m_rot_speed = vec2(0.f);
m_pos = vec2(0.f);
m_pos_mesh = vec2(0.f);
m_pos_speed = vec2(0.f);
m_screen_offset = vec2(0.f);

m_camera = new Camera();
SetFov(m_fov_damp);
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->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);
//m_camera->SetScreenScale(vec2(10.f));
m_camera->UseShift(true);
g_scene->PushCamera(m_camera);

//Lights setup
m_lights << new Light();
m_lights.Last()->SetPosition(vec4(4.f, -1.f, -4.f, 0.f));
m_lights.Last()->SetPosition(vec4(4.f, -1.f, -4.f, 1.f));
m_lights.Last()->SetColor(vec4(.0f, .2f, .5f, 1.f));
Ticker::Ref(m_lights.Last());

m_lights << new Light();
m_lights.Last()->SetPosition(vec4(8.f, 2.f, 6.f, 1.f));
m_lights.Last()->SetColor(vec4(.5f, .3f, .0f, 1.f));
m_lights.Last()->SetColor(vec4(1.f, 1.f, 1.f, 1.f));
Ticker::Ref(m_lights.Last());

//Speed damp
m_mesh_rotate_damp = vec2(.0f);
m_mesh_screen_move_damp = vec2(.0f);
m_mesh_move_damp = vec2(.0f);

//Actual values
SetDefaultMeshTransform();

//Actual values damp
m_mesh_rotation_damp = vec2(.0f);
m_mesh_screen_offset_damp = vec2(.0f);
m_mesh_offset_damp = vec2(.0f);


m_mat = mat4::rotate(m_mesh_rotation.x, vec3(1, 0, 0)) *
mat4::rotate(m_angle, vec3(0, 1, 0)) *
mat4::rotate(m_mesh_rotation.y, vec3(0, 1, 0));

//stream update
m_stream_update_time = 2.0f;
m_stream_update_timer = 1.0f;
}
@@ -169,13 +162,7 @@ public:
g_scene->PopCamera(m_camera);
for (int i = 0; i < m_lights.Count(); ++i)
Ticker::Unref(m_lights[i]);
}

void SetDefaultMeshTransform()
{
m_mesh_rotation = vec2(25.0f, .0f);
m_mesh_screen_offset = vec2(.54f, .0f);
m_mesh_offset = vec2(-.64f, .07f);
MessageService::Destroy();
}

virtual void TickGame(float seconds)
@@ -189,192 +176,155 @@ public:
Ticker::Shutdown();
}

//--
//Update Mesh BBox - Get the Min/Max needed
//--
vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
vec3 cam_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
vec3 world_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
int mesh_id = m_meshes.Count() - 1;
for (; mesh_id >= 0; mesh_id--)
if (m_meshes[mesh_id].m2)
break;

mat4 world_cam = g_scene->GetCamera()->GetView();
mat4 cam_screen = g_scene->GetCamera()->GetProjection();
//Mesh Change
m_mesh_id = clamp(m_mesh_id + ((int)m_controller->GetKey(KEY_MESH_PREV).IsPressed() - (int)m_controller->GetKey(KEY_MESH_NEXT).IsPressed()), 0, m_meshes.Count() - 1);
m_mesh_id1 = damp(m_mesh_id1, (float)m_mesh_id, .2f, seconds);

if (m_meshes.Count() && mesh_id >= 0)
{
for (int i = 0; i < m_meshes[mesh_id].m1.GetVertexCount(); i++)
{
//--
mat4 LocalPos = m_mat * mat4::translate(m_meshes[mesh_id].m1.GetVertexLocation(i));
vec3 vpos = LocalPos.v3.xyz;
//Camera update
bool is_pos = m_controller->GetKey(KEY_CAM_POS).IsDown();
bool is_fov = m_controller->GetKey(KEY_CAM_FOV).IsDown();

world_min_max[0] = min(vpos.xyz, world_min_max[0]);
world_min_max[1] = max(vpos.xyz, world_min_max[1]);
vec2 tmp = vec2((float)m_controller->GetKey(KEY_CAM_UP ).IsDown() - (float)m_controller->GetKey(KEY_CAM_DOWN).IsDown(),
((float)m_controller->GetKey(KEY_CAM_RIGHT ).IsDown() - (float)m_controller->GetKey(KEY_CAM_LEFT).IsDown()));

//--
LocalPos = world_cam * LocalPos;
vpos = LocalPos.v3.xyz;
//Base data
vec2 rot = (!is_pos && !is_fov)?(tmp):(vec2(.0f)); rot = vec2(rot.x, rot.y);
vec2 pos = (is_pos && !is_fov)?(tmp):(vec2(.0f)); pos = -vec2(pos.y, pos.x);
vec2 fov = (!is_pos && is_fov)?(tmp):(vec2(.0f)); fov = vec2(-fov.x, fov.y);

cam_min_max[0] = min(vpos.xyz, cam_min_max[0]);
cam_min_max[1] = max(vpos.xyz, cam_min_max[1]);
//speed
m_rot_speed = damp(m_rot_speed, rot * ROT_SPEED, .2f, seconds);
float pos_factor = 1.f / (1.f + m_zoom_mesh * .5f);
m_pos_speed = damp(m_pos_speed, pos * POS_SPEED * pos_factor, .2f, seconds);
float fov_factor = 1.f + lol::pow((m_fov_mesh / FOV_CLAMP) * 1.f, 2.f);
m_fov_speed = damp(m_fov_speed, fov.x * FOV_SPEED * fov_factor, .2f, seconds);
float zom_factor = 1.f + lol::pow((m_zoom_mesh / ZOM_CLAMP) * 1.f, 2.f);
m_zoom_speed = damp(m_zoom_speed, fov.y * ZOM_SPEED, .2f, seconds);

//--
LocalPos = cam_screen * LocalPos;
vpos = (LocalPos.v3 / LocalPos.v3.w).xyz;
m_rot += m_rot_speed * seconds;

screen_min_max[0] = min(vpos.xy, screen_min_max[0]);
screen_min_max[1] = max(vpos.xy, screen_min_max[1]);
}
//Transform update
if (!m_controller->GetKey(KEY_CAM_RESET).IsDown())
{
m_pos += m_pos_speed * seconds;
m_fov += m_fov_speed * seconds;
m_zoom += m_zoom_speed * seconds;
}
else

//clamp
vec2 rot_mesh = vec2(SmoothClamp(m_rot.x, -ROT_CLAMP, ROT_CLAMP, ROT_CLAMP * .1f), m_rot.y);
vec2 pos_mesh = vec2(SmoothClamp(m_pos.x, -POS_CLAMP, POS_CLAMP, POS_CLAMP * .1f),
SmoothClamp(m_pos.y, -POS_CLAMP, POS_CLAMP, POS_CLAMP * .1f));
float fov_mesh = SmoothClamp(m_fov, 0.f, FOV_CLAMP, FOV_CLAMP * .1f);
float zoom_mesh = SmoothClamp(m_zoom, 0.f, ZOM_CLAMP, ZOM_CLAMP * .1f);

if (m_controller->GetKey(KEY_CAM_RESET).IsDown())
{
world_min_max[1] = vec3(.0f);
world_min_max[0] = vec3(.0f);
cam_min_max[1] = vec3(.0f);
cam_min_max[0] = vec3(.0f);
screen_min_max[0] = vec2(.0f);
screen_min_max[1] = vec2(.0f);
pos_mesh = vec2(0.f);
zoom_mesh = 0.f;
}
//[0] : center, [1] : size.
vec3 BBox[2] = { vec3(.0f), vec3(.0f) };
BBox[1] = world_min_max[1] - world_min_max[0];
BBox[0] = world_min_max[0] + BBox[1] * .5f;
vec3 BBox_mod = BBox[1];
#if 0

m_rot_mesh = vec2(damp(m_rot_mesh.x, rot_mesh.x, .2f, seconds), damp(m_rot_mesh.y, rot_mesh.y, .2f, seconds));
m_pos_mesh = vec2(damp(m_pos_mesh.x, pos_mesh.x, .2f, seconds), damp(m_pos_mesh.y, pos_mesh.y, .2f, seconds));
m_fov_mesh = damp(m_fov_mesh, fov_mesh, .2f, seconds);
m_zoom_mesh = damp(m_zoom_mesh, zoom_mesh, .2f, seconds);

//Mesh mat calculation
m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f)));

//Target List Setup
Array<vec3> target_list;
if (m_meshes.Count() && m_mesh_id >= 0)
for (int i = 0; i < m_meshes[m_mesh_id].m1.GetVertexCount(); i++)
target_list << (m_mat * mat4::translate(m_meshes[m_mesh_id].m1.GetVertexLocation(i))).v3.xyz;

//--
//Camera movement handling
//Update mesh screen location - Get the Min/Max needed
//--
if (m_controller->GetKey(KEY_CAM_RESET).IsReleased())
SetFov();

//Auto Fov
float local_max = max(max(lol::abs(world_min_max[0].x), lol::abs(world_min_max[0].y)),
max( lol::abs(world_min_max[1].x), lol::abs(world_min_max[1].y)));
float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));

//Fov modification
float fov_zoom = (float)(Input::GetStatus(IPT_CAM_ZOOM_OUT) - Input::GetStatus(IPT_CAM_ZOOM_IN));
m_fov_zoom_damp = damp(m_fov_zoom_damp, fov_zoom, (fov_zoom == .0f)?(.15f):(0.5f), seconds);
m_fov = max(.0f, m_fov + seconds * 10.0f * m_fov_zoom_damp);
m_fov_damp = damp(m_fov_damp, m_fov, .2f, seconds);

if (m_fov_damp < MIN_FOV)
vec2 cam_center(0.f);
float cam_factor = .0f;
vec3 local_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
mat4 world_cam = m_camera->GetView();
mat4 cam_screen = m_camera->GetProjection();

//target on-screen computation
for (int i = 0; i < target_list.Count(); i++)
{
vec2 tmp = vec2(Video::GetSize());
SetFov(0, vec2(local_max * 2.2f) * (tmp / vec2(tmp.y)));
vec3 obj_loc = target_list[i];
{
//Debug::DrawBox(obj_loc - vec3(4.f), obj_loc + vec3(4.f), vec4(1.f, 0.f, 0.f, 1.f));
mat4 target_mx = mat4::translate(obj_loc);
vec3 vpos;

//Get location in cam coordinates
target_mx = world_cam * target_mx;
vpos = target_mx.v3.xyz;
local_min_max[0] = min(vpos.xyz, local_min_max[0]);
local_min_max[1] = max(vpos.xyz, local_min_max[1]);

//Get location in screen coordinates
target_mx = cam_screen * target_mx;
vpos = (target_mx.v3 / target_mx.v3.w).xyz;
screen_min_max[0] = min(screen_min_max[0], vpos.xy * vec2(RATIO_WH, 1.f));
screen_min_max[1] = max(screen_min_max[1], vpos.xy * vec2(RATIO_WH, 1.f));

//Build Barycenter
cam_center += vpos.xy;
cam_factor += 1.f;
}
}
else
SetFov(m_fov_damp);

//Move modification
vec3 campos = g_scene->GetCamera()->GetPosition();
if (m_fov_damp < MIN_FOV)
g_scene->GetCamera()->SetView(vec3(campos.xy, 10.f), quat(1.f));
else if (fov_ratio > .0f)
g_scene->GetCamera()->SetView(vec3(campos.xy, campos.z * fov_ratio * 1.1f), quat(1.f));
#else
Camera* cur_cam = g_scene->GetCamera();
vec3 min_max_diff = (cam_min_max[1] - cam_min_max[0]);
float screen_size = max(max(lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)),
max( lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)));
float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));

float fov_zoom = 0.f;
fov_zoom += m_controller->GetKey(KEY_CAM_ZOOM_OUT).IsDown() ? 1.f : 0.f;
fov_zoom -= m_controller->GetKey(KEY_CAM_ZOOM_IN).IsDown() ? 1.f : 0.f;
m_fov_zoom_damp = damp(m_fov_zoom_damp, fov_zoom, (fov_zoom == .0f)?(.15f):(0.5f), seconds);
m_fov = max(.0f, m_fov + seconds * 10.0f * m_fov_zoom_damp);
m_fov_damp = damp(m_fov_damp, m_fov, .2f, seconds);

if (m_fov_damp < MIN_FOV)
cur_cam->SetProjection(mat4::ortho(screen_size * fov_ratio * 1.1f, 1600.f / 600.f, 1000.f));
else if (fov_ratio > .0f)
cur_cam->SetProjection(mat4::shifted_perspective(m_fov_damp, screen_size * fov_ratio * 1.1f, 1600.f / 600.f, .00001f, 1000.f));

vec3 cam_center = cam_min_max[0] + min_max_diff * .5f;

vec4 test = inverse(world_cam) * vec4(.0f,.0f,-1.0f,1.f);
test = test;
test = inverse(world_cam) * vec4(.0f,.0f,.0f,1.f);
test = inverse(world_cam) * vec4(.0f,.0f,1.0f,1.f);

vec3 eye = (inverse(world_cam) * vec4(vec3(cam_center.xy, cam_min_max[1].z), 1.f)).xyz;
vec3 target = (inverse(world_cam) * vec4(vec3(cam_center.xy, cam_min_max[0].z), 1.f)).xyz;
if (eye == target)
cur_cam->SetView(vec3(.0f), vec3(.0f, .0f, -1.f), vec3(0.f, 1.f, 0.f));
else
cur_cam->SetView(eye, target, vec3(0,1,0));
#endif

float screen_ratio = max(max(lol::abs(local_min_max[0].x), lol::abs(local_min_max[0].y)),
max(lol::abs(local_min_max[1].x), lol::abs(local_min_max[1].y)));
float scale_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
vec2 screen_offset = vec2(0.f, -(screen_min_max[1].y + screen_min_max[0].y) * .5f);
m_screen_offset = damp(m_screen_offset, screen_offset, .9f, seconds);
float z_pos = (inverse(world_cam) * mat4::translate(vec3(0.f, 0.f, max(local_min_max[0].z, local_min_max[1].z)))).v3.z;

if (cam_factor > 0.f)
{
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->SetFov(m_fov_mesh);
m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio), 1.2f, seconds));
}
//--
//Mesh movement handling
//Message Service
//--
if (m_controller->GetKey(KEY_MESH_RESET).IsReleased())
SetDefaultMeshTransform();

m_mesh_shown += m_controller->GetKey(KEY_MESH_NEXT).IsReleased() ? 1 : 0;
m_mesh_shown -= m_controller->GetKey(KEY_MESH_PREV).IsReleased() ? 1 : 0;
m_mesh_shown = clamp(m_mesh_shown, 0, max(m_meshes.Count(), 1) - 1);

vec2 new_move = vec2(.0f);
new_move.x += m_controller->GetKey(KEY_MESH_RIGHT).IsDown() ? 1.f : 0.f;
new_move.x -= m_controller->GetKey(KEY_MESH_LEFT).IsDown() ? 1.f : 0.f;
new_move.y += m_controller->GetKey(KEY_MESH_UP).IsDown() ? 1.f : 0.f;
new_move.y -= m_controller->GetKey(KEY_MESH_DOWN).IsDown() ? 1.f : 0.f;

m_mesh_screen_move_damp = vec2(damp(m_mesh_screen_move_damp.x, new_move.x, (new_move.x == .0f)?(.15f):(0.5f), seconds),
damp(m_mesh_screen_move_damp.y, new_move.y, (new_move.y == .0f)?(.15f):(0.5f), seconds));

new_move.x = m_controller->GetKey(KEY_MESH_OFFSET_UP).IsDown() ? 1.f : 0.f;
new_move.x -= m_controller->GetKey(KEY_MESH_OFFSET_DOWN).IsDown() ? 1.f : 0.f;
new_move.y = m_controller->GetKey(KEY_MESH_SCALE_UP).IsDown() ? 1.f : 0.f;
new_move.y -= m_controller->GetKey(KEY_MESH_SCALE_DOWN).IsDown() ? 1.f : 0.f;
m_mesh_move_damp = vec2(damp(m_mesh_move_damp.x, new_move.x, (new_move.x == .0f)?(.15f):(0.5f), seconds),
damp(m_mesh_move_damp.y, new_move.y, (new_move.y == .0f)?(.15f):(0.5f), seconds));

new_move.x = m_controller->GetKey(KEY_MESH_ROT_UP).IsDown() ? 1.f : 0.f;
new_move.x -= m_controller->GetKey(KEY_MESH_ROT_DOWN).IsDown() ? 1.f : 0.f;
new_move.y = m_controller->GetKey(KEY_MESH_ROT_RIGHT).IsDown() ? 1.f : 0.f;
new_move.y -= m_controller->GetKey(KEY_MESH_ROT_LEFT).IsDown() ? 1.f : 0.f;
m_mesh_rotate_damp = vec2(damp(m_mesh_rotate_damp.x, new_move.x, (new_move.x == .0f)?(.15f):(0.5f), seconds),
damp(m_mesh_rotate_damp.y, new_move.y, (new_move.y == .0f)?(.15f):(0.5f), seconds));

vec2 mesh_screen_move = seconds * 0.6f * m_mesh_screen_move_damp;
vec2 mesh_offset_move = seconds * vec2(.6f, .2f) * m_mesh_move_damp;
vec2 mesh_rotate = seconds * vec2(40.0f, 60.0f) * m_mesh_rotate_damp;

//Add movement
m_mesh_screen_offset += mesh_screen_move;
m_mesh_offset += mesh_offset_move;
m_mesh_rotation += mesh_rotate;

//Compute damp
m_mesh_rotation_damp = damp(m_mesh_rotation_damp, m_mesh_rotation, .2f, seconds);
m_mesh_screen_offset_damp = damp(m_mesh_screen_offset_damp, m_mesh_screen_offset, .2f, seconds);
m_mesh_offset_damp = damp(m_mesh_offset_damp, m_mesh_offset, .2f, seconds);

//Clamp necessary
m_mesh_rotation.x = clamp(m_mesh_rotation.x, -90.0f, 90.0f);
m_mesh_offset.y = max(.0f, m_mesh_offset.y);

//m_angle += seconds * 70.0f;
m_mat = mat4::rotate(m_mesh_rotation.x, vec3(1, 0, 0)) *
mat4::rotate(m_angle, vec3(0, 1, 0)) *
mat4::rotate(m_mesh_rotation.y, vec3(0, 1, 0));
String mesh("");
int u = 4;
while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh))
{
int o = 1;
while (o-- > 0)
{
if (m_mesh_id == m_meshes.Count() - 1)
m_mesh_id++;
//Create a new mesh
m_meshes.Push(EasyMesh(), false);
if (!m_meshes.Last().m1.Compile(mesh.C()))
m_meshes.Pop();
//else
// m_meshes.Last().m1.ComputeTexCoord(0.2f, 2);
}
}

#if __native_client__
if (m_stream_update_time > .0f)
{
m_stream_update_time = -1.f;
MessageService::Send(MSG_IN, "[sc#f8f afcb 1 1 1 0]");
MessageService::Send(MSG_IN, "[sc#8ff afcb 1 1 1 0]");
MessageService::Send(MSG_IN, "[sc#ff8 afcb 1 1 1 0]");
}
#elif WIN32
//--
//File management
//--
if (m_controller->GetKey(KEY_MESH_UPDATE).IsReleased())
m_stream_update_time = m_stream_update_timer + 1.0f;
m_stream_update_time += seconds;

if (m_stream_update_time > m_stream_update_timer)
{
m_stream_update_time = 0.f;
@@ -406,15 +356,10 @@ public:
&& (!m_cmdlist.Count() || cmd != m_cmdlist.Last()))
{
m_cmdlist << cmd;

//Create a new mesh
m_meshes.Push(EasyMesh(), false, .0f, vec3(.0f));
if (!m_meshes.Last().m1.Compile(cmd.C()))
m_meshes.Pop();
//else
// m_meshes.Last().m1.ComputeTexCoord(0.2f, 2);
MessageService::Send(MSG_IN, cmd);
}
}
#endif //WINDOWS
}

virtual void TickDraw(float seconds)
@@ -439,14 +384,7 @@ public:
{
m_texture_shader = Shader::Create(LOLFX_RESOURCE_NAME(shinymvtexture));
m_texture_uni = m_texture_shader->GetUniformLocation("u_Texture");
//m_image = new Image("data/test-texture.png");
m_default_texture = Tiler::Register("data/test-texture.png", ivec2(0), ivec2(0,1));

//ivec2 size = m_image->GetSize();
//// m_image->GetFormat()
//m_texture = new Texture(m_image->GetSize(), PixelFormat::ABGR_8);
//m_texture->SetData(m_image->GetData());
// PixelFormat::ABGR_8
}
else if (m_texture && m_default_texture)
m_texture_shader->SetUniform(m_texture_uni, m_default_texture->GetTexture(), 0);
@@ -455,12 +393,7 @@ public:
{
if (!m_meshes[i].m2)
{
//Fur support
#if WITH_FUR
m_meshes[i].m1.MeshConvert(Shader::Create(LOLFX_RESOURCE_NAME(shinyfur)));
#elif WITH_TEXTURE
//m_meshes[i].m1.MeshConvert(m_texture_shader);
//m_meshes[i].m1.MeshConvert();
#if WITH_TEXTURE
m_meshes[i].m1.MeshConvert(new DefaultShaderData(((1 << VertexUsage::Position) | (1 << VertexUsage::Normal) |
(1 << VertexUsage::Color) | (1 << VertexUsage::TexCoord)),
m_texture_shader, true));
@@ -473,63 +406,60 @@ public:

g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));

mat4 default_proj = g_scene->GetCamera()->GetProjection();
int max_drawn = m_meshes.Count() - m_mesh_shown;
for (int i = max_drawn; i < m_meshes.Count(); i++)
m_meshes[i].m4 = vec3(.0f);
for (int i = 0; i < max_drawn; i++)
vec3 x = vec3(1.f,0.f,0.f);
vec3 y = vec3(0.f,1.f,0.f);
for (int i = 0; i < m_meshes.Count(); i++)
{
float new_scale = max(.0f, 1.0f - (m_mesh_offset_damp.y * (float)(max_drawn - (i + 1))));
m_meshes[i].m3 = damp(m_meshes[i].m3, new_scale, .35f, seconds);
if (m_meshes[i].m3 > .0f)
mat4 save_proj = m_camera->GetProjection();
float j = -(float)(m_meshes.Count() - (i + 1)) + (-m_mesh_id1 + (float)(m_meshes.Count() - 1));
if (m_meshes[i].m2)
{
vec3 new_mesh_offset = vec3(.0f);
//damping calculations
for (int j = max_drawn - 1; j > i; j--)
{
float ofs_scale = max(.0f, 1.0f - (m_mesh_offset_damp.y * (float)(max_drawn - (j + 0))));
new_mesh_offset = new_mesh_offset + vec3(m_meshes[j].m3 * ofs_scale * ofs_scale * m_mesh_offset_damp.x, .0f, .0f);
}
m_meshes[i].m4 = damp(m_meshes[i].m4, new_mesh_offset, .35f, seconds);

g_scene->GetCamera()->SetProjection(
mat4::translate(m_meshes[i].m4) *
mat4::translate(vec3(m_mesh_screen_offset_damp, .0f)) *
mat4::scale(vec3(vec2(m_meshes[i].m3), 1.0f)) *
default_proj);
#if WITH_FUR
for (int j=0; j < 40; j++)
m_meshes[i].m1.Render(m_mat, 0.1 * j);
#else
mat4 new_proj =
//Y object Offset
mat4::translate(x * m_screen_offset.x + y * m_screen_offset.y) *
//Mesh Pos Offset
mat4::translate((x * m_pos_mesh.x * RATIO_HW + y * m_pos_mesh.y) * 2.f * (1.f + .5f * m_zoom_mesh / SCREEN_LIMIT)) *
//Mesh count offset
mat4::translate(x * RATIO_HW * 2.f * j) *
//Align right meshes
mat4::translate(x - x * RATIO_HW) *
//Mesh count scale
//mat4::scale(1.f - .2f * j * (1.f / (float)m_meshes.Count())) *
//Camera projection
save_proj;
m_camera->SetProjection(new_proj);
m_meshes[i].m1.Render(m_mat);
#endif
g_renderer->Clear(ClearMask::Depth);
}
m_camera->SetProjection(save_proj);
}
g_scene->GetCamera()->SetProjection(default_proj);
}

private:
Array<Light *> m_lights;
Controller *m_controller;
Camera *m_camera;
float m_angle;
mat4 m_mat;

//Mesh infos
//Move damping
vec2 m_mesh_rotate_damp;
vec2 m_mesh_screen_move_damp;
vec2 m_mesh_move_damp;

//Move transform damping
vec2 m_mesh_rotation_damp;
vec2 m_mesh_screen_offset_damp;
vec2 m_mesh_offset_damp;
//Camera Setup
Camera *m_camera;
float m_fov;
float m_fov_mesh;
float m_fov_speed;
float m_zoom;
float m_zoom_mesh;
float m_zoom_speed;
vec2 m_rot;
vec2 m_rot_mesh;
vec2 m_rot_speed;
vec2 m_pos;
vec2 m_pos_mesh;
vec2 m_pos_speed;
vec2 m_screen_offset;

vec2 m_mesh_rotation; //Meshes rotation
vec2 m_mesh_screen_offset;//Meshes screen offset
vec2 m_mesh_offset; //Mesh Offset after first mesh (x: offset, y: scale)
int m_mesh_shown;
//Mesh infos
int m_mesh_id;
float m_mesh_id1;
Array<EasyMesh, bool> m_meshes;

//File data
String m_file_name;
@@ -538,17 +468,11 @@ private:
float m_stream_update_timer;

//misc datas
Array<EasyMesh, bool, float, vec3> m_meshes;
Array<Light *> m_lights;
Shader * m_texture_shader;
TileSet * m_default_texture;
Texture * m_texture;
ShaderUniform m_texture_uni;
Image * m_image;
float m_fov;
float m_fov_damp;
float m_fov_zoom_damp;
mat4 m_fov_compensation;
};

//The basic main :
@@ -556,7 +480,7 @@ int main(int argc, char **argv)
{
System::Init(argc, argv);

Application app("MeshViewer", ivec2(1600, 600), 60.0f);
Application app("MeshViewer", ivec2((int)WIDTH, (int)HEIGHT), 60.0f);
if (argc > 1)
new MeshViewer(argv[1]);
else


불러오는 중...
취소
저장