collada: draw animated eidelwind
This commit is contained in:
parent
c7df1ed578
commit
5724fde489
12
Makefile
12
Makefile
@ -37,6 +37,13 @@ MINECRAFT_OBJS = \
|
|||||||
src/world/world.o \
|
src/world/world.o \
|
||||||
src/world/entry_table.o
|
src/world/entry_table.o
|
||||||
|
|
||||||
|
COLLADA_SCENES = \
|
||||||
|
data/scenes/ship20/ship20.o \
|
||||||
|
data/scenes/noodle/noodle.o \
|
||||||
|
data/scenes/shadow_test/shadow_test.o \
|
||||||
|
data/scenes/book/book.o \
|
||||||
|
data/scenes/eidelwind/scene.o
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
src/gl.o \
|
src/gl.o \
|
||||||
src/opengl.o \
|
src/opengl.o \
|
||||||
@ -61,10 +68,7 @@ OBJS = \
|
|||||||
src/collada/animate.o \
|
src/collada/animate.o \
|
||||||
src/flame.o \
|
src/flame.o \
|
||||||
src/audio.o \
|
src/audio.o \
|
||||||
data/scenes/ship20/ship20.o \
|
$(COLLADA_SCENES) \
|
||||||
data/scenes/noodle/noodle.o \
|
|
||||||
data/scenes/shadow_test/shadow_test.o \
|
|
||||||
data/scenes/book/book.o \
|
|
||||||
$(MINECRAFT_OBJS)
|
$(MINECRAFT_OBJS)
|
||||||
|
|
||||||
ifdef READ_PACK_FILE
|
ifdef READ_PACK_FILE
|
||||||
|
|||||||
4
collada.sh
Normal file
4
collada.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
cd data/scenes/eidelwind
|
||||||
|
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main eidelwind eidelwind32.DAE scene.cpp scene.vtx scene.vjw scene.idx
|
||||||
|
PYTHONPATH=~/d3d10 python -m collada.main eidelwind ../../../include/data/scenes/eidelwind.h
|
||||||
8
conf.lua
8
conf.lua
@ -1,8 +0,0 @@
|
|||||||
function love.conf(t)
|
|
||||||
t.identity = "love-demo2"
|
|
||||||
t.window.width = 1024
|
|
||||||
t.window.height = 1024
|
|
||||||
t.window.depth = true
|
|
||||||
t.window.resizable = true
|
|
||||||
t.graphics.excluderenderers = {"vulkan", "metal"}
|
|
||||||
end
|
|
||||||
5147
data/scenes/eidelwind/eidelwind32.DAE
Normal file
5147
data/scenes/eidelwind/eidelwind32.DAE
Normal file
File diff suppressed because one or more lines are too long
BIN
data/scenes/eidelwind/images/0_map_face_only.dds
Normal file
BIN
data/scenes/eidelwind/images/0_map_face_only.dds
Normal file
Binary file not shown.
BIN
data/scenes/eidelwind/images/0_map_face_only.png
Normal file
BIN
data/scenes/eidelwind/images/0_map_face_only.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 586 KiB |
12465
data/scenes/eidelwind/scene.cpp
Normal file
12465
data/scenes/eidelwind/scene.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
data/scenes/eidelwind/scene.idx
Normal file
BIN
data/scenes/eidelwind/scene.idx
Normal file
Binary file not shown.
BIN
data/scenes/eidelwind/scene.vjw
Normal file
BIN
data/scenes/eidelwind/scene.vjw
Normal file
Binary file not shown.
BIN
data/scenes/eidelwind/scene.vtx
Normal file
BIN
data/scenes/eidelwind/scene.vtx
Normal file
Binary file not shown.
@ -33,8 +33,6 @@ font/bitmap/terminus_256x256_16x32.data
|
|||||||
shader/font.vert
|
shader/font.vert
|
||||||
shader/font_outline.frag
|
shader/font_outline.frag
|
||||||
font/outline/uncial_antiqua_36.data
|
font/outline/uncial_antiqua_36.data
|
||||||
shader/pixel_line_art.vert
|
|
||||||
shader/pixel_line_art.frag
|
|
||||||
shader/quad.vert
|
shader/quad.vert
|
||||||
shader/quad.frag
|
shader/quad.frag
|
||||||
shader/quad.vert
|
shader/quad.vert
|
||||||
@ -49,10 +47,10 @@ shader/collada/static.vert
|
|||||||
shader/collada/generic.frag
|
shader/collada/generic.frag
|
||||||
shader/collada/skinned.vert
|
shader/collada/skinned.vert
|
||||||
shader/collada/generic.frag
|
shader/collada/generic.frag
|
||||||
data/scenes/book/book.vtx
|
data/scenes/eidelwind/scene.vtx
|
||||||
data/scenes/book/book.vjw
|
data/scenes/eidelwind/scene.vjw
|
||||||
data/scenes/book/book.idx
|
data/scenes/eidelwind/scene.idx
|
||||||
|
data/scenes/eidelwind/images/0_map_face_only.dds
|
||||||
shader/flame.vert
|
shader/flame.vert
|
||||||
shader/flame.frag
|
shader/flame.frag
|
||||||
minecraft/flame.data
|
minecraft/flame.data
|
||||||
audio/Suite.opus.bin
|
|
||||||
|
|||||||
@ -24,6 +24,9 @@ namespace collada::scene {
|
|||||||
|
|
||||||
unsigned int * textures;
|
unsigned int * textures;
|
||||||
|
|
||||||
|
// mutable state
|
||||||
|
int node_draw_type;
|
||||||
|
|
||||||
// drawing
|
// drawing
|
||||||
void load_layouts();
|
void load_layouts();
|
||||||
void load_images();
|
void load_images();
|
||||||
|
|||||||
3
include/data/scenes/eidelwind.h
Normal file
3
include/data/scenes/eidelwind.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace eidelwind {
|
||||||
|
extern collada::types::descriptor const descriptor;
|
||||||
|
}
|
||||||
@ -1,10 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#include "font/bitmap.h"
|
||||||
extern "C" {
|
#include "font/outline.h"
|
||||||
#endif
|
#include "geometry_buffer.h"
|
||||||
|
|
||||||
void load(const char * source_path);
|
namespace test {
|
||||||
|
|
||||||
|
extern unsigned int empty_vertex_array_object;
|
||||||
|
extern unsigned int quad_index_buffer;
|
||||||
|
|
||||||
|
extern float mouse_position[4];
|
||||||
|
extern float mouse_block[4];
|
||||||
|
|
||||||
|
extern font::bitmap::font * terminus_fonts;
|
||||||
|
extern font::outline::font * uncial_antiqua_fonts;
|
||||||
|
|
||||||
|
extern geometry_buffer<4> geometry_buffer_pnc;
|
||||||
|
|
||||||
|
void load();
|
||||||
void draw();
|
void draw();
|
||||||
void love2d_state_load();
|
void love2d_state_load();
|
||||||
void love2d_state_restore();
|
void love2d_state_restore();
|
||||||
@ -21,6 +34,4 @@ extern "C" {
|
|||||||
int start);
|
int start);
|
||||||
void update(float time);
|
void update(float time);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|||||||
274
main.lua
274
main.lua
@ -1,274 +0,0 @@
|
|||||||
local ffi = require 'ffi'
|
|
||||||
local joysticks = {}
|
|
||||||
|
|
||||||
function init_joysticks()
|
|
||||||
joysticks = {}
|
|
||||||
for i, joystick in ipairs(love.joystick.getJoysticks()) do
|
|
||||||
if joystick:isGamepad() then
|
|
||||||
table.insert(joysticks, joystick)
|
|
||||||
print(#joysticks, joystick:getName())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function init()
|
|
||||||
|
|
||||||
ffi.cdef[[
|
|
||||||
void load(const char * source_path);
|
|
||||||
void update_window(int width, int height);
|
|
||||||
void draw();
|
|
||||||
void update_keyboard(int up, int down, int left, int right,
|
|
||||||
int w, int s, int a, int d,
|
|
||||||
int t, int g, int f, int h,
|
|
||||||
int i, int k, int j, int l,
|
|
||||||
int q, int e);
|
|
||||||
void update_mouse(int x, int y);
|
|
||||||
void update_joystick(int joystick_index,
|
|
||||||
float lx, float ly, float rx, float ry, float tl, float tr,
|
|
||||||
int up, int down, int left, int right,
|
|
||||||
int a, int b, int x, int y,
|
|
||||||
int leftshoulder, int rightshoulder,
|
|
||||||
int start);
|
|
||||||
void update(float time);
|
|
||||||
|
|
||||||
int draw_font_start();
|
|
||||||
int draw_font(int font_ix, char const * text, int x, int y);
|
|
||||||
|
|
||||||
void draw_line_quad_start();
|
|
||||||
void draw_line(int x1, int y1, int x2, int y2);
|
|
||||||
void draw_set_color(float r, float g, float b);
|
|
||||||
void draw_quad(int x1, int y1, int x2, int y2,
|
|
||||||
int x3, int y3, int x4, int y4);
|
|
||||||
]]
|
|
||||||
local source_path = love.filesystem.getSource()
|
|
||||||
local is_zip = source_path:sub(-#".zip") == ".zip"
|
|
||||||
local is_love = source_path:sub(-#".love") == ".love"
|
|
||||||
|
|
||||||
local platform = love.system.getOS()
|
|
||||||
|
|
||||||
local lib_name
|
|
||||||
if platform == "Linux" then
|
|
||||||
lib_name = "test.so"
|
|
||||||
elseif platform == "Windows" then
|
|
||||||
lib_name = "test.dll"
|
|
||||||
else
|
|
||||||
assert(false, "unsupported platform " .. platform)
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_zip or is_love then
|
|
||||||
if love.filesystem.isFused() then
|
|
||||||
local archive = love.filesystem.getSourceBaseDirectory()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- there is nothing wrong with the following 5 lines from an API
|
|
||||||
-- design/usability perspective
|
|
||||||
local identity = love.filesystem.getIdentity()
|
|
||||||
local non_existing_identity = "https://github.com/love2d/love/issues/2295"
|
|
||||||
love.filesystem.setIdentity(non_existing_identity:gsub("/", "_"))
|
|
||||||
local contents, size = love.filesystem.read("data", lib_name)
|
|
||||||
love.filesystem.setIdentity(identity)
|
|
||||||
|
|
||||||
assert(contents ~= nil, size)
|
|
||||||
local write_success, message = love.filesystem.write(lib_name, contents, size)
|
|
||||||
assert(write_success, lib_name, message)
|
|
||||||
local lib_directory = love.filesystem.getRealDirectory(lib_name)
|
|
||||||
test = ffi.load(lib_directory .. "/" .. lib_name)
|
|
||||||
else
|
|
||||||
test = ffi.load("./" .. lib_name)
|
|
||||||
end
|
|
||||||
test.load(source_path)
|
|
||||||
|
|
||||||
local bgm = love.audio.newSource("Suite.mp3", "stream")
|
|
||||||
bgm:setLooping(true)
|
|
||||||
bgm:play()
|
|
||||||
end
|
|
||||||
|
|
||||||
local update = function(time)
|
|
||||||
for joystick_index, joystick in ipairs(joysticks) do
|
|
||||||
if joystick_index > 8 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local lx = joystick:getGamepadAxis("leftx")
|
|
||||||
local ly = joystick:getGamepadAxis("lefty")
|
|
||||||
local rx = joystick:getGamepadAxis("rightx")
|
|
||||||
local ry = joystick:getGamepadAxis("righty")
|
|
||||||
local tl = joystick:getGamepadAxis("triggerleft")
|
|
||||||
local tr = joystick:getGamepadAxis("triggerright")
|
|
||||||
local up = joystick:isGamepadDown("dpup")
|
|
||||||
local down = joystick:isGamepadDown("dpdown")
|
|
||||||
local left = joystick:isGamepadDown("dpleft")
|
|
||||||
local right = joystick:isGamepadDown("dpright")
|
|
||||||
local a = joystick:isGamepadDown("a")
|
|
||||||
local b = joystick:isGamepadDown("b")
|
|
||||||
local x = joystick:isGamepadDown("x")
|
|
||||||
local y = joystick:isGamepadDown("y")
|
|
||||||
local leftshoulder = joystick:isGamepadDown("leftshoulder")
|
|
||||||
local rightshoulder = joystick:isGamepadDown("rightshoulder")
|
|
||||||
local start = joystick:isGamepadDown("start")
|
|
||||||
--print("start", i, start)
|
|
||||||
test.update_joystick(joystick_index - 1,
|
|
||||||
lx, ly, rx, ry, tl, tr,
|
|
||||||
up, down, left, right,
|
|
||||||
a, b, x, y,
|
|
||||||
leftshoulder, rightshoulder,
|
|
||||||
start)
|
|
||||||
end
|
|
||||||
|
|
||||||
local up = love.keyboard.isDown("up")
|
|
||||||
local down = love.keyboard.isDown("down")
|
|
||||||
local left = love.keyboard.isDown("left")
|
|
||||||
local right = love.keyboard.isDown("right")
|
|
||||||
local w = love.keyboard.isDown("w")
|
|
||||||
local s = love.keyboard.isDown("s")
|
|
||||||
local a = love.keyboard.isDown("a")
|
|
||||||
local d = love.keyboard.isDown("d")
|
|
||||||
local t = love.keyboard.isDown("t")
|
|
||||||
local g = love.keyboard.isDown("g")
|
|
||||||
local f = love.keyboard.isDown("f")
|
|
||||||
local h = love.keyboard.isDown("h")
|
|
||||||
local i = love.keyboard.isDown("i")
|
|
||||||
local k = love.keyboard.isDown("k")
|
|
||||||
local j = love.keyboard.isDown("j")
|
|
||||||
local l = love.keyboard.isDown("l")
|
|
||||||
local q = love.keyboard.isDown("q")
|
|
||||||
local e = love.keyboard.isDown("e")
|
|
||||||
test.update_keyboard(up, down, left, right,
|
|
||||||
w, s, a, d,
|
|
||||||
t, g, f, h,
|
|
||||||
i, k, j, l,
|
|
||||||
q, e)
|
|
||||||
|
|
||||||
test.update(time)
|
|
||||||
end
|
|
||||||
|
|
||||||
local draw = function()
|
|
||||||
test.draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
local nico_draw = function()
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
-- font drawing
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- call "draw_font_start()" prior each "group" of "draw_font()" calls
|
|
||||||
--
|
|
||||||
-- a "group" of draw_font() calls are back-to-back/consecutive,
|
|
||||||
-- with no non-font drawing between them.
|
|
||||||
--
|
|
||||||
-- For example:
|
|
||||||
|
|
||||||
local font_ix = test.draw_font_start()
|
|
||||||
local x = 512
|
|
||||||
local y = 50
|
|
||||||
y = y + test.draw_font(font_ix, "lua test", x, y)
|
|
||||||
y = y + test.draw_font(font_ix, "cool", x, y)
|
|
||||||
|
|
||||||
-- note that "font_ix" is the current "best font" as calculated
|
|
||||||
-- from the current window size, and might change next frame if the
|
|
||||||
-- window is resized.
|
|
||||||
--
|
|
||||||
-- Any of this of course could be changed to match your precise
|
|
||||||
-- requirements.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
-- line drawing
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- call "draw_line_quad_start()" prior to each "group" of
|
|
||||||
-- "draw_line()" or "draw_quad()" calls
|
|
||||||
--
|
|
||||||
-- a "group" of draw_line()/draw_quad() calls are
|
|
||||||
-- back-to-back/consecutive, with no non-line/quad drawing between
|
|
||||||
-- them.
|
|
||||||
--
|
|
||||||
-- For example:
|
|
||||||
|
|
||||||
test.draw_line_quad_start()
|
|
||||||
test.draw_set_color(1.0, 0.0, 0.0) -- r, g, b (0.0 to 1.0)
|
|
||||||
test.draw_line(0, 0, 1024, 1024) -- x1, y1, x2, y2
|
|
||||||
test.draw_line(700, 300, 400, 500)
|
|
||||||
test.draw_set_color(0.0, 1.0, 0.0)
|
|
||||||
test.draw_line(700, 300, 400, 700)
|
|
||||||
|
|
||||||
-- x1, y1, x2, y2,
|
|
||||||
-- x3, y3, x4, y4,
|
|
||||||
--
|
|
||||||
-- vertices must be specified In "counter clockwise" order, as in:
|
|
||||||
--
|
|
||||||
-- 2──1
|
|
||||||
-- │ │ valid (counter clockwise)
|
|
||||||
-- 3──4
|
|
||||||
--
|
|
||||||
-- these can also be rotated, as in:
|
|
||||||
--
|
|
||||||
-- 3
|
|
||||||
-- ╱ ╲
|
|
||||||
-- 4 2 valid (counter clockwise)
|
|
||||||
-- ╲ ╱
|
|
||||||
-- 1
|
|
||||||
--
|
|
||||||
-- however "mirroring" is not valid, as in:
|
|
||||||
--
|
|
||||||
-- 1──2
|
|
||||||
-- │ │ not valid (clockwise)
|
|
||||||
-- 4──3
|
|
||||||
--
|
|
||||||
test.draw_set_color(0.0, 0.0, 1.0)
|
|
||||||
test.draw_quad(
|
|
||||||
600, 600, -- top right
|
|
||||||
500, 600, -- top left
|
|
||||||
500, 700, -- bottom left
|
|
||||||
600, 700 -- bottom right
|
|
||||||
)
|
|
||||||
test.draw_set_color(0.0, 0.5, 1.0)
|
|
||||||
test.draw_quad(
|
|
||||||
900, 900, -- bottom
|
|
||||||
950, 850, -- right
|
|
||||||
900, 800, -- top
|
|
||||||
850, 850 -- left
|
|
||||||
)
|
|
||||||
|
|
||||||
-- If you want to draw a large number of lines or quads in bulk
|
|
||||||
-- (e.g: 10,000+ lines/quads per frame), this interface might not be good
|
|
||||||
-- enough, and we should discuss this in more detail.
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.run()
|
|
||||||
init()
|
|
||||||
|
|
||||||
return function()
|
|
||||||
love.event.pump()
|
|
||||||
for name, a,b,c,d,e,f,g,h in love.event.poll() do
|
|
||||||
if name == "joystickadded" or name == "joystickremoved" then
|
|
||||||
init_joysticks()
|
|
||||||
end
|
|
||||||
if name == "quit" then
|
|
||||||
if c or not love.quit or not love.quit() then
|
|
||||||
return a or 0, b
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local width
|
|
||||||
local height
|
|
||||||
local flags
|
|
||||||
width, height, flags = love.window.getMode()
|
|
||||||
test.update_window(width, height)
|
|
||||||
|
|
||||||
local time = love.timer.getTime()
|
|
||||||
update(time)
|
|
||||||
|
|
||||||
draw()
|
|
||||||
|
|
||||||
local mouse_down = love.mouse.isDown(1)
|
|
||||||
if mouse_down then
|
|
||||||
local x, y = love.mouse.getPosition()
|
|
||||||
test.update_mouse(x, y)
|
|
||||||
end
|
|
||||||
|
|
||||||
--nico_draw()
|
|
||||||
|
|
||||||
love.graphics.present()
|
|
||||||
love.timer.sleep(0.001)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -36,6 +36,35 @@ namespace collada::animate {
|
|||||||
return prev + iv * (next - prev);
|
return prev + iv * (next - prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline XMMATRIX linear_interpolate_matrix(types::source const& source, frame_ix frame_ix, float iv)
|
||||||
|
{
|
||||||
|
XMFLOAT4X4 const * prev = (XMFLOAT4X4 const *)&source.float_array[(frame_ix.f0) * source.stride];
|
||||||
|
XMFLOAT4X4 const * next = (XMFLOAT4X4 const *)&source.float_array[(frame_ix.f1) * source.stride];
|
||||||
|
|
||||||
|
XMVECTOR prev_scale;
|
||||||
|
XMVECTOR prev_rotate;
|
||||||
|
XMVECTOR prev_translate;
|
||||||
|
|
||||||
|
bool prev_srt = XMMatrixDecompose(&prev_scale, &prev_rotate, &prev_translate, XMMatrixTranspose(XMLoadFloat4x4(prev)));
|
||||||
|
assert(prev_srt == true);
|
||||||
|
|
||||||
|
XMVECTOR next_scale;
|
||||||
|
XMVECTOR next_rotate;
|
||||||
|
XMVECTOR next_translate;
|
||||||
|
|
||||||
|
bool next_srt = XMMatrixDecompose(&next_scale, &next_rotate, &next_translate, XMMatrixTranspose(XMLoadFloat4x4(next)));
|
||||||
|
assert(next_srt == true);
|
||||||
|
|
||||||
|
XMVECTOR scale = XMVectorLerp(prev_scale, next_scale, iv);
|
||||||
|
XMVECTOR rotate = XMQuaternionSlerp(prev_rotate, next_rotate, iv);
|
||||||
|
XMVECTOR translate = XMVectorLerp(prev_translate, next_translate, iv);
|
||||||
|
|
||||||
|
return XMMatrixAffineTransformation(scale,
|
||||||
|
XMVectorZero(),
|
||||||
|
rotate,
|
||||||
|
translate);
|
||||||
|
}
|
||||||
|
|
||||||
static inline float pow3(float f)
|
static inline float pow3(float f)
|
||||||
{
|
{
|
||||||
return f * f * f;
|
return f * f * f;
|
||||||
@ -173,25 +202,39 @@ namespace collada::animate {
|
|||||||
target_attributes = rotate_target_attributes;
|
target_attributes = rotate_target_attributes;
|
||||||
target_attributes_count = 4;
|
target_attributes_count = 4;
|
||||||
break;
|
break;
|
||||||
|
case types::transform_type::MATRIX:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int parameter_ix = 0; parameter_ix < target_attributes_count; parameter_ix++) {
|
assert(channel.source_sampler->interpolation.stride == 1);
|
||||||
|
|
||||||
|
if (transform.type == types::transform_type::MATRIX) {
|
||||||
enum types::interpolation interpolation = channel.source_sampler->interpolation.interpolation_array[frame_ix.f0];
|
enum types::interpolation interpolation = channel.source_sampler->interpolation.interpolation_array[frame_ix.f0];
|
||||||
|
assert(interpolation == types::interpolation::LINEAR);
|
||||||
|
|
||||||
float value;
|
float iv = linear_interpolate_iv(channel.source_sampler->input, frame_ix, t);
|
||||||
if (interpolation == types::interpolation::BEZIER) {
|
XMMATRIX matrix = linear_interpolate_matrix(channel.source_sampler->output, frame_ix, iv);
|
||||||
value = bezier_sampler(channel.source_sampler, frame_ix, parameter_ix, t);
|
transform.matrix = matrix;
|
||||||
} else {
|
|
||||||
float iv = linear_interpolate_iv(channel.source_sampler->input, frame_ix, t);
|
} else {
|
||||||
value = linear_interpolate_value(channel.source_sampler->output, frame_ix, parameter_ix, iv);
|
for (int parameter_ix = 0; parameter_ix < target_attributes_count; parameter_ix++) {
|
||||||
|
|
||||||
|
enum types::interpolation interpolation = channel.source_sampler->interpolation.interpolation_array[frame_ix.f0];
|
||||||
|
|
||||||
|
float value;
|
||||||
|
if (interpolation == types::interpolation::BEZIER) {
|
||||||
|
value = bezier_sampler(channel.source_sampler, frame_ix, parameter_ix, t);
|
||||||
|
} else {
|
||||||
|
float iv = linear_interpolate_iv(channel.source_sampler->input, frame_ix, t);
|
||||||
|
value = linear_interpolate_value(channel.source_sampler->output, frame_ix, parameter_ix, iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
apply_transform_target(transform, target_attributes[parameter_ix], value);
|
||||||
}
|
}
|
||||||
|
|
||||||
apply_transform_target(transform, target_attributes[parameter_ix], value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ namespace collada::node_state {
|
|||||||
instance_transform->lookat.up = XMLoadFloat3((XMFLOAT3 *)&transform.lookat.up);
|
instance_transform->lookat.up = XMLoadFloat3((XMFLOAT3 *)&transform.lookat.up);
|
||||||
break;
|
break;
|
||||||
case types::transform_type::MATRIX:
|
case types::transform_type::MATRIX:
|
||||||
instance_transform->matrix = XMLoadFloat4x4((XMFLOAT4X4 *)&transform.matrix);
|
instance_transform->matrix = XMMatrixTranspose(XMLoadFloat4x4((XMFLOAT4X4 *)&transform.matrix));
|
||||||
break;
|
break;
|
||||||
case types::transform_type::ROTATE:
|
case types::transform_type::ROTATE:
|
||||||
instance_transform->vector = XMLoadFloat4((XMFLOAT4 *)&transform.rotate);
|
instance_transform->vector = XMLoadFloat4((XMFLOAT4 *)&transform.rotate);
|
||||||
@ -61,6 +61,9 @@ namespace collada::node_state {
|
|||||||
for (int i = 0; i < nodes_count; i++) {
|
for (int i = 0; i < nodes_count; i++) {
|
||||||
allocate_node_instance(node_instances[i], nodes[i]);
|
allocate_node_instance(node_instances[i], nodes[i]);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < nodes_count; i++) {
|
||||||
|
update_node_world_transform(node_instances[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -200,6 +200,7 @@ namespace collada::scene {
|
|||||||
glGenVertexArrays(2 * descriptor->inputs_list_count, (unsigned int *)vertex_arrays);
|
glGenVertexArrays(2 * descriptor->inputs_list_count, (unsigned int *)vertex_arrays);
|
||||||
|
|
||||||
for (int i = 0; i < descriptor->inputs_list_count; i++) {
|
for (int i = 0; i < descriptor->inputs_list_count; i++) {
|
||||||
|
printf("LOAD LAYOUT %d\n", i);
|
||||||
// static
|
// static
|
||||||
int stride = load_layout(descriptor->inputs_list[i],
|
int stride = load_layout(descriptor->inputs_list[i],
|
||||||
0, // binding
|
0, // binding
|
||||||
@ -296,6 +297,8 @@ namespace collada::scene {
|
|||||||
load_images();
|
load_images();
|
||||||
|
|
||||||
node_state.allocate_node_instances(descriptor->nodes, descriptor->nodes_count);
|
node_state.allocate_node_instances(descriptor->nodes, descriptor->nodes_count);
|
||||||
|
|
||||||
|
node_draw_type = 0b01; // nodes only
|
||||||
}
|
}
|
||||||
|
|
||||||
void state::set_color_or_texture(types::color_or_texture const& color_or_texture,
|
void state::set_color_or_texture(types::color_or_texture const& color_or_texture,
|
||||||
@ -455,19 +458,21 @@ namespace collada::scene {
|
|||||||
|
|
||||||
XMMATRIX bsm = XMLoadFloat4x4((XMFLOAT4X4*)&skin.bind_shape_matrix);
|
XMMATRIX bsm = XMLoadFloat4x4((XMFLOAT4X4*)&skin.bind_shape_matrix);
|
||||||
|
|
||||||
assert(instance_controller.joint_count < max_joints);
|
assert(instance_controller.joint_count < (max_joints - 1));
|
||||||
for (int joint_index = 0; joint_index < instance_controller.joint_count; joint_index++) {
|
for (int joint_index = 0; joint_index < instance_controller.joint_count; joint_index++) {
|
||||||
XMMATRIX ibm = XMLoadFloat4x4((XMFLOAT4X4*)&skin.inverse_bind_matrices[joint_index]);
|
XMMATRIX ibm = XMLoadFloat4x4((XMFLOAT4X4*)&skin.inverse_bind_matrices[joint_index]);
|
||||||
int node_index = instance_controller.joint_node_indices[joint_index];
|
int node_index = instance_controller.joint_node_indices[joint_index];
|
||||||
instance_types::node& node_instance = node_state.node_instances[node_index];
|
instance_types::node& node_instance = node_state.node_instances[node_index];
|
||||||
|
|
||||||
XMStoreFloat4x4(&joints[joint_index], bsm * ibm * node_instance.world);
|
XMStoreFloat4x4(&joints[joint_index],
|
||||||
|
XMMatrixTranspose(bsm) * XMMatrixTranspose(ibm) * node_instance.world);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int joints_size = (sizeof (XMFLOAT4X4)) * instance_controller.joint_count;
|
int joints_size = (sizeof (XMFLOAT4X4)) * instance_controller.joint_count;
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, joint_uniform_buffer);
|
glBindBuffer(GL_UNIFORM_BUFFER, joint_uniform_buffer);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, joints_size, (void *)&joints[0], GL_DYNAMIC_DRAW);
|
glBufferData(GL_UNIFORM_BUFFER, joints_size, (void *)&joints[0], GL_DYNAMIC_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
glBindBufferRange(GL_UNIFORM_BUFFER, layout.binding.joint, joint_uniform_buffer, 0, joints_size);
|
glBindBufferRange(GL_UNIFORM_BUFFER, layout.binding.joint, joint_uniform_buffer, 0, joints_size);
|
||||||
|
|
||||||
draw_skin(skin,
|
draw_skin(skin,
|
||||||
@ -489,6 +494,10 @@ namespace collada::scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.instance_controllers_count) {
|
if (node.instance_controllers_count) {
|
||||||
|
XMMATRIX transform = view::state.transform;
|
||||||
|
XMFLOAT4X4 float_transform;
|
||||||
|
XMStoreFloat4x4(&float_transform, transform);
|
||||||
|
|
||||||
glUseProgram(collada::effect::program_skinned);
|
glUseProgram(collada::effect::program_skinned);
|
||||||
glUniformMatrix4fv(layout.uniform.transform, 1, false, (float *)&float_transform);
|
glUniformMatrix4fv(layout.uniform.transform, 1, false, (float *)&float_transform);
|
||||||
draw_instance_controllers(node.instance_controllers, node.instance_controllers_count);
|
draw_instance_controllers(node.instance_controllers, node.instance_controllers_count);
|
||||||
@ -514,8 +523,9 @@ namespace collada::scene {
|
|||||||
for (int i = 0; i < descriptor->nodes_count; i++) {
|
for (int i = 0; i < descriptor->nodes_count; i++) {
|
||||||
types::node const & node = *descriptor->nodes[i];
|
types::node const & node = *descriptor->nodes[i];
|
||||||
|
|
||||||
// joints are not drawn
|
if (((node_draw_type & 0b01) == 0) && (node.type == types::node_type::NODE))
|
||||||
if (node.type != types::node_type::NODE)
|
continue;
|
||||||
|
if (((node_draw_type & 0b10) == 0) && (node.type == types::node_type::JOINT))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
draw_node(node, node_state.node_instances[i]);
|
draw_node(node, node_state.node_instances[i]);
|
||||||
@ -524,7 +534,7 @@ namespace collada::scene {
|
|||||||
|
|
||||||
void state::update(float t)
|
void state::update(float t)
|
||||||
{
|
{
|
||||||
t = animate::loop(t / 4.0f, 1.8333333333333333f);
|
t = animate::loop(t / 1.0f, 1.0f);
|
||||||
|
|
||||||
for (int i = 0; i < descriptor->nodes_count; i++) {
|
for (int i = 0; i < descriptor->nodes_count; i++) {
|
||||||
animate::animate_node(node_state.node_instances[i], t);
|
animate::animate_node(node_state.node_instances[i], t);
|
||||||
|
|||||||
28
src/file.cpp
28
src/file.cpp
@ -8,9 +8,6 @@
|
|||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
|
||||||
namespace file {
|
namespace file {
|
||||||
char const * source_path = NULL;
|
|
||||||
int source_path_length = 0;
|
|
||||||
|
|
||||||
#ifdef READ_PACK_FILE
|
#ifdef READ_PACK_FILE
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -22,7 +19,7 @@ namespace file {
|
|||||||
void const * read_file(const char * r_filename, int * out_size)
|
void const * read_file(const char * r_filename, int * out_size)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "(pack) filename: %s\n", r_filename);
|
fprintf(stderr, "(pack) filename: %s\n", r_filename);
|
||||||
|
|
||||||
pack::header const * header = (pack::header const *)&_binary_test_pack_start[0];
|
pack::header const * header = (pack::header const *)&_binary_test_pack_start[0];
|
||||||
assert(header->magic == pack::magic_value);
|
assert(header->magic == pack::magic_value);
|
||||||
ptrdiff_t data = (ptrdiff_t)&_binary_test_pack_start[header->header_size];
|
ptrdiff_t data = (ptrdiff_t)&_binary_test_pack_start[header->header_size];
|
||||||
@ -42,28 +39,9 @@ namespace file {
|
|||||||
(void)buf;
|
(void)buf;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static char const * join_path(char * buf, const char * filename)
|
void const * read_file(const char * filename, int * out_size)
|
||||||
{
|
{
|
||||||
if (filename[0] == '/')
|
fprintf(stderr, "filename: %s\n", filename);
|
||||||
return filename;
|
|
||||||
|
|
||||||
int filename_length = strlen(filename);
|
|
||||||
assert(filename_length + source_path_length + 2 < 1024);
|
|
||||||
|
|
||||||
memcpy(buf, source_path, source_path_length);
|
|
||||||
buf[source_path_length] = '/';
|
|
||||||
|
|
||||||
memcpy(&buf[source_path_length + 1], filename, filename_length);
|
|
||||||
buf[source_path_length + 1 + filename_length] = 0;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void const * read_file(const char * r_filename, int * out_size)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "r_filename: %s\n", r_filename);
|
|
||||||
|
|
||||||
char tmp[1024];
|
|
||||||
char const * filename = join_path(tmp, r_filename);
|
|
||||||
|
|
||||||
FILE * f = fopen(filename, "rb");
|
FILE * f = fopen(filename, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
|
|||||||
@ -8,14 +8,11 @@
|
|||||||
|
|
||||||
#include "flame.h"
|
#include "flame.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
#include "test.h"
|
||||||
extern unsigned int quad_index_buffer;
|
|
||||||
extern unsigned int empty_vertex_array_object;
|
|
||||||
|
|
||||||
namespace flame {
|
namespace flame {
|
||||||
static unsigned int program;
|
static unsigned int program;
|
||||||
static unsigned int flame_texture;
|
static unsigned int flame_texture;
|
||||||
static unsigned int vertex_array_object;
|
|
||||||
|
|
||||||
const int per_instance_size = 4 * (sizeof (float));
|
const int per_instance_size = 4 * (sizeof (float));
|
||||||
|
|
||||||
@ -97,8 +94,8 @@ namespace flame {
|
|||||||
|
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, layout.binding.lights, light_uniform_buffer);
|
glBindBufferBase(GL_UNIFORM_BUFFER, layout.binding.lights, light_uniform_buffer);
|
||||||
|
|
||||||
glBindVertexArray(empty_vertex_array_object);
|
glBindVertexArray(test::empty_vertex_array_object);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_index_buffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, test::quad_index_buffer);
|
||||||
|
|
||||||
glDrawElementsInstanced(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0, light_count);
|
glDrawElementsInstanced(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0, light_count);
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/hud.cpp
37
src/hud.cpp
@ -8,14 +8,7 @@
|
|||||||
#include "font/outline.h"
|
#include "font/outline.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "test.h"
|
||||||
extern font::bitmap::font * terminus_fonts;
|
|
||||||
extern font::outline::font * uncial_antiqua_fonts;
|
|
||||||
extern unsigned int empty_vertex_array_object;
|
|
||||||
extern unsigned int quad_index_buffer;
|
|
||||||
|
|
||||||
extern float current_time;
|
|
||||||
extern float last_frame_time;
|
|
||||||
|
|
||||||
// depends on:
|
// depends on:
|
||||||
// - font::bitmap::load
|
// - font::bitmap::load
|
||||||
@ -23,9 +16,6 @@ extern float last_frame_time;
|
|||||||
// - load_quad_index_buffer
|
// - load_quad_index_buffer
|
||||||
// - empty_vertex_array_object
|
// - empty_vertex_array_object
|
||||||
|
|
||||||
extern float mouse_position[3];
|
|
||||||
extern float mouse_block[3];
|
|
||||||
|
|
||||||
namespace hud {
|
namespace hud {
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
@ -93,12 +83,13 @@ namespace hud {
|
|||||||
float y = 10.0f;
|
float y = 10.0f;
|
||||||
|
|
||||||
int font_ix = font::bitmap::best_font(font::bitmap::terminus, font::bitmap::terminus_length);
|
int font_ix = font::bitmap::best_font(font::bitmap::terminus, font::bitmap::terminus_length);
|
||||||
font::bitmap::font const& ter_best = terminus_fonts[font_ix];
|
font::bitmap::font const& ter_best = test::terminus_fonts[font_ix];
|
||||||
font::bitmap::draw_start(ter_best, empty_vertex_array_object, quad_index_buffer);
|
font::bitmap::draw_start(ter_best, test::empty_vertex_array_object, test::quad_index_buffer);
|
||||||
|
|
||||||
//y = draw_label<float>(ter_best, buf, 10, y, "fov: ", "%.3f", view::state.fov);
|
//y = draw_label<float>(ter_best, buf, 10, y, "fov: ", "%.3f", view::state.fov);
|
||||||
//y = draw_label<int>(ter_best, buf, 10, y, "font_height: ", "%d", ter_best.desc->glyph_height);
|
//y = draw_label<int>(ter_best, buf, 10, y, "font_height: ", "%d", ter_best.desc->glyph_height);
|
||||||
|
|
||||||
|
/*
|
||||||
font::bitmap::draw_string(ter_best, "keyboard:", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, "keyboard:", 10, y); y += ter_best.desc->glyph_height;
|
||||||
font::bitmap::draw_string(ter_best, " move: w/a/s/d", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, " move: w/a/s/d", 10, y); y += ter_best.desc->glyph_height;
|
||||||
font::bitmap::draw_string(ter_best, " look: up/down/left/right", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, " look: up/down/left/right", 10, y); y += ter_best.desc->glyph_height;
|
||||||
@ -109,16 +100,25 @@ namespace hud {
|
|||||||
font::bitmap::draw_string(ter_best, " look: right stick", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, " look: right stick", 10, y); y += ter_best.desc->glyph_height;
|
||||||
font::bitmap::draw_string(ter_best, " elevate: left/right trigger", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, " elevate: left/right trigger", 10, y); y += ter_best.desc->glyph_height;
|
||||||
font::bitmap::draw_string(ter_best, " warp: a", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, " warp: a", 10, y); y += ter_best.desc->glyph_height;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
y = draw_vector(ter_best, buf, y, "eye", XMVectorSetW(view::state.eye, 0));
|
||||||
|
y = draw_vector(ter_best, buf, y, "at", XMVectorSetW(view::state.at, 0));
|
||||||
|
y = draw_vector(ter_best, buf, y, "forward", XMVectorSetW(view::state.forward, 0));
|
||||||
|
|
||||||
|
y = draw_label<float>(ter_best, buf, 10, y, "pitch: ", "%.4f", view::state.pitch);
|
||||||
|
//y = draw_label<float>(ter_best, buf, 10, y, "frame_rate_avg: ", "%.2f", 1.0f / update_average(current_time - last_frame_time));
|
||||||
|
|
||||||
font::bitmap::draw_string(ter_best, "mouse:", 10, y); y += ter_best.desc->glyph_height;
|
font::bitmap::draw_string(ter_best, "mouse:", 10, y); y += ter_best.desc->glyph_height;
|
||||||
|
|
||||||
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat4((XMFLOAT4*)mouse_position));
|
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat4((XMFLOAT4*)test::mouse_position));
|
||||||
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat4((XMFLOAT4*)mouse_block));
|
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat4((XMFLOAT4*)test::mouse_block));
|
||||||
|
|
||||||
if (frame++ > 60 * 10)
|
if (frame++ > 60 * 10)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
font::outline::draw_start(uncial_antiqua_fonts[0], empty_vertex_array_object, quad_index_buffer);
|
font::outline::draw_start(uncial_antiqua_fonts[0], empty_vertex_array_object, quad_index_buffer);
|
||||||
char const * title = "Technical demo: Bibliotheca";
|
char const * title = "Technical demo: Bibliotheca";
|
||||||
int const title_length = strlen(title);
|
int const title_length = strlen(title);
|
||||||
@ -132,6 +132,7 @@ namespace hud {
|
|||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
font::outline::draw_string(uncial_antiqua_fonts[0], title, title_x + 0, title_y + 0);
|
font::outline::draw_string(uncial_antiqua_fonts[0], title, title_x + 0, title_y + 0);
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
y = draw_label<float>(ter_best, buf, 10, y, "lighting.quadratic: ", "%.2f", lighting.quadratic);
|
y = draw_label<float>(ter_best, buf, 10, y, "lighting.quadratic: ", "%.2f", lighting.quadratic);
|
||||||
@ -139,12 +140,6 @@ namespace hud {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
y = draw_vector(ter_best, buf, y, "eye", XMVectorSetW(view::state.eye, 0));
|
|
||||||
y = draw_vector(ter_best, buf, y, "at", XMVectorSetW(view::state.at, 0));
|
|
||||||
y = draw_vector(ter_best, buf, y, "forward", XMVectorSetW(view::state.forward, 0));
|
|
||||||
|
|
||||||
y = draw_label<float>(ter_best, buf, 10, y, "pitch: ", "%.4f", view::state.pitch);
|
|
||||||
y = draw_label<float>(ter_best, buf, 10, y, "frame_rate_avg: ", "%.2f", 1.0f / update_average(current_time - last_frame_time));
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,10 +8,7 @@
|
|||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "lighting.h"
|
#include "lighting.h"
|
||||||
#include "geometry_buffer.h"
|
#include "geometry_buffer.h"
|
||||||
|
#include "test.h"
|
||||||
extern unsigned int empty_vertex_array_object;
|
|
||||||
extern unsigned int quad_index_buffer;
|
|
||||||
extern geometry_buffer<4> geometry_buffer_pnc;
|
|
||||||
|
|
||||||
namespace lighting {
|
namespace lighting {
|
||||||
|
|
||||||
@ -85,11 +82,11 @@ namespace lighting {
|
|||||||
glDepthFunc(GL_ALWAYS);
|
glDepthFunc(GL_ALWAYS);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, geometry_buffer_pnc.target[0]);
|
glBindTexture(GL_TEXTURE_2D, test::geometry_buffer_pnc.target[0]);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, geometry_buffer_pnc.target[1]);
|
glBindTexture(GL_TEXTURE_2D, test::geometry_buffer_pnc.target[1]);
|
||||||
glActiveTexture(GL_TEXTURE2);
|
glActiveTexture(GL_TEXTURE2);
|
||||||
glBindTexture(GL_TEXTURE_2D, geometry_buffer_pnc.target[2]);
|
glBindTexture(GL_TEXTURE_2D, test::geometry_buffer_pnc.target[2]);
|
||||||
|
|
||||||
glUniform1i(location.uniform.position_sampler, 0);
|
glUniform1i(location.uniform.position_sampler, 0);
|
||||||
glUniform1i(location.uniform.normal_sampler, 1);
|
glUniform1i(location.uniform.normal_sampler, 1);
|
||||||
@ -107,8 +104,8 @@ namespace lighting {
|
|||||||
glUniform1i(location.uniform.light_count, light_count);
|
glUniform1i(location.uniform.light_count, light_count);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, location.binding.lights, light_uniform_buffer);
|
glBindBufferBase(GL_UNIFORM_BUFFER, location.binding.lights, light_uniform_buffer);
|
||||||
|
|
||||||
glBindVertexArray(empty_vertex_array_object);
|
glBindVertexArray(test::empty_vertex_array_object);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_index_buffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, test::quad_index_buffer);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0);
|
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0);
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/main.cpp
38
src/main.cpp
@ -33,7 +33,9 @@ void remove_gamepad(SDL_JoystickID instance_id)
|
|||||||
for (int i = 0; i < gamepad_count; i++) {
|
for (int i = 0; i < gamepad_count; i++) {
|
||||||
if (SDL_GetGamepadID(gamepads[i]) == instance_id) {
|
if (SDL_GetGamepadID(gamepads[i]) == instance_id) {
|
||||||
int tail = (gamepad_count - i) - 1;
|
int tail = (gamepad_count - i) - 1;
|
||||||
|
SDL_CloseGamepad(gamepads[i]);
|
||||||
memcpy(&gamepads[i], &gamepads[i+1], tail * (sizeof (gamepads[0])));
|
memcpy(&gamepads[i], &gamepads[i+1], tail * (sizeof (gamepads[0])));
|
||||||
|
gamepad_count -= 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,16 +70,16 @@ void update()
|
|||||||
bool start = SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
|
bool start = SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
|
||||||
|
|
||||||
float scale = 1.0f / 32767.0f;
|
float scale = 1.0f / 32767.0f;
|
||||||
update_joystick((float)leftx * scale,
|
test::update_joystick((float)leftx * scale,
|
||||||
(float)lefty * scale,
|
(float)lefty * scale,
|
||||||
(float)rightx * scale,
|
(float)rightx * scale,
|
||||||
(float)righty * scale,
|
(float)righty * scale,
|
||||||
(float)left_trigger * scale,
|
(float)left_trigger * scale,
|
||||||
(float)right_trigger * scale,
|
(float)right_trigger * scale,
|
||||||
dpad_up, dpad_down, dpad_left, dpad_right,
|
dpad_up, dpad_down, dpad_left, dpad_right,
|
||||||
a, b, x, y,
|
a, b, x, y,
|
||||||
left_shoulder, right_shoulder,
|
left_shoulder, right_shoulder,
|
||||||
start);
|
start);
|
||||||
}
|
}
|
||||||
|
|
||||||
view::update_transforms();
|
view::update_transforms();
|
||||||
@ -125,12 +127,15 @@ int main()
|
|||||||
fprintf(stderr, "gladLoadGL\n");
|
fprintf(stderr, "gladLoadGL\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
load(".");
|
test::load();
|
||||||
//audio::init();
|
//audio::init();
|
||||||
//audio::load();
|
//audio::load();
|
||||||
|
|
||||||
update_window(1024, 1024);
|
update_window(1024, 1024);
|
||||||
|
|
||||||
|
int64_t start_time;
|
||||||
|
SDL_GetCurrentTime(&start_time);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
@ -152,7 +157,7 @@ int main()
|
|||||||
break;
|
break;
|
||||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||||
if (event.button.button == 1) {
|
if (event.button.button == 1) {
|
||||||
update_mouse(event.button.x, event.button.y);
|
test::update_mouse(event.button.x, event.button.y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -161,7 +166,14 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
draw();
|
int64_t current_time;
|
||||||
|
SDL_GetCurrentTime(¤t_time);
|
||||||
|
int64_t time = current_time - start_time;
|
||||||
|
double ftime = (double)(time / 1000) * 0.000001;
|
||||||
|
//printf("time %ld %f\n", time / 1000000, ftime);
|
||||||
|
|
||||||
|
test::update(ftime);
|
||||||
|
test::draw();
|
||||||
|
|
||||||
//audio::update();
|
//audio::update();
|
||||||
|
|
||||||
|
|||||||
84
src/test.cpp
84
src/test.cpp
@ -38,6 +38,9 @@
|
|||||||
#include "data/scenes/noodle.h"
|
#include "data/scenes/noodle.h"
|
||||||
#include "data/scenes/shadow_test.h"
|
#include "data/scenes/shadow_test.h"
|
||||||
#include "data/scenes/book.h"
|
#include "data/scenes/book.h"
|
||||||
|
#include "data/scenes/eidelwind.h"
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
struct line_location {
|
struct line_location {
|
||||||
struct {
|
struct {
|
||||||
@ -116,14 +119,8 @@ void load_quad_program()
|
|||||||
quad_program = program;
|
quad_program = program;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(const char * source_path)
|
void load()
|
||||||
{
|
{
|
||||||
file::source_path_length = strlen(source_path);
|
|
||||||
assert(source_path[file::source_path_length - 1] != '/');
|
|
||||||
file::source_path = source_path;
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
@ -187,14 +184,20 @@ void load(const char * source_path)
|
|||||||
// collada
|
// collada
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//collada::effect::load_effects();
|
collada::effect::load_effects();
|
||||||
//scene_state.load_scene(&book::descriptor);
|
scene_state.load_scene(&eidelwind::descriptor);
|
||||||
//node_eye = scene_state.find_node_by_name("Camera");
|
node_eye = scene_state.find_node_by_name("Camera001");
|
||||||
//assert(node_eye != nullptr);
|
assert(node_eye != nullptr);
|
||||||
//view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
|
view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
|
||||||
|
|
||||||
//node_at = scene_state.find_node_by_name("Camera001.Target");
|
node_at = scene_state.find_node_by_name("Camera001.Target");
|
||||||
//assert(node_at != nullptr);
|
assert(node_at != nullptr);
|
||||||
|
view::state.at = XMVector3Transform(XMVectorZero(), node_at->world);
|
||||||
|
|
||||||
|
view::state.direction = XMVector3Normalize(view::state.at - view::state.eye);
|
||||||
|
view::state.normal = XMVector3Cross(view::state.direction, view::state.up);
|
||||||
|
view::state.forward = -XMVector3Cross(view::state.normal, view::state.up);
|
||||||
|
view::state.pitch = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// flame
|
// flame
|
||||||
@ -317,22 +320,6 @@ void update_keyboard(int up, int down, int left, int right,
|
|||||||
int i, int k, int j, int l,
|
int i, int k, int j, int l,
|
||||||
int q, int e)
|
int q, int e)
|
||||||
{
|
{
|
||||||
//float forward = (0.1f * up + -0.1f * down);
|
|
||||||
//float strafe = (-0.1f * left + 0.1f * right);
|
|
||||||
//view::third_person::apply_translation(forward, strafe, 0);
|
|
||||||
/*
|
|
||||||
collision_scene::update(up, down, left, right,
|
|
||||||
w, s, a, d,
|
|
||||||
t, g, f, h,
|
|
||||||
i, k, j, l);
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
boids_scene::update(up, down, left, right,
|
|
||||||
w, s, a, d,
|
|
||||||
t, g, f, h,
|
|
||||||
i, k, j, l);
|
|
||||||
*/
|
|
||||||
|
|
||||||
float forward = (w - s) * 0.5;
|
float forward = (w - s) * 0.5;
|
||||||
float strafe = (d - a) * 0.5;
|
float strafe = (d - a) * 0.5;
|
||||||
float elevation = (q - e) * 0.5;
|
float elevation = (q - e) * 0.5;
|
||||||
@ -363,22 +350,36 @@ void update_joystick(float lx, float ly,
|
|||||||
int leftshoulder, int rightshoulder,
|
int leftshoulder, int rightshoulder,
|
||||||
int start)
|
int start)
|
||||||
{
|
{
|
||||||
float forward = -ly * 0.5;
|
float translate_rate = 2.0;
|
||||||
float strafe = lx * 0.5;
|
|
||||||
float elevation = (tl - tr) * 0.5;
|
float forward = -ly * translate_rate;
|
||||||
|
float strafe = lx * translate_rate;
|
||||||
|
float elevation = (tl - tr) * translate_rate;
|
||||||
float delta_yaw = rx * -0.035;
|
float delta_yaw = rx * -0.035;
|
||||||
float delta_pitch = ry * -0.035;
|
float delta_pitch = ry * -0.035;
|
||||||
|
|
||||||
XMVECTOR direction = view::third_person::apply_transform(forward, strafe, elevation,
|
/*
|
||||||
delta_yaw, delta_pitch);
|
view::first_person::apply_transform(forward, strafe, elevation,
|
||||||
|
delta_yaw, delta_pitch);
|
||||||
|
*/
|
||||||
|
//view::state.eye += XMVector3Normalize(view::state.at - view::state.eye) * forward * 100;
|
||||||
|
view::apply_fov(0.01 * up + -0.01 * down);
|
||||||
|
|
||||||
|
view::first_person::apply_transform(forward, strafe, elevation,
|
||||||
|
delta_yaw, delta_pitch);
|
||||||
|
|
||||||
|
/*
|
||||||
view::apply_fov(0.01 * up + -0.01 * down);
|
view::apply_fov(0.01 * up + -0.01 * down);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
minecraft_view_update(direction);
|
minecraft_view_update(direction);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (a && last_a == 0) {
|
if (a && last_a == 0) {
|
||||||
next_world();
|
//next_world();
|
||||||
|
scene_state.node_draw_type += 1;
|
||||||
|
scene_state.node_draw_type %= 4;
|
||||||
}
|
}
|
||||||
last_a = a;
|
last_a = a;
|
||||||
|
|
||||||
@ -402,7 +403,7 @@ void update(float time)
|
|||||||
{
|
{
|
||||||
current_time = time;
|
current_time = time;
|
||||||
|
|
||||||
//scene_state.update(time);
|
scene_state.update(time);
|
||||||
/*
|
/*
|
||||||
view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
|
view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
|
||||||
if (node_at == nullptr)
|
if (node_at == nullptr)
|
||||||
@ -475,7 +476,8 @@ void draw()
|
|||||||
{
|
{
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClearDepth(-1.0f);
|
glClearDepth(-1.0f);
|
||||||
if (true) {
|
|
||||||
|
if (false) {
|
||||||
// possibly re-initialize geometry buffer if window width/height changes
|
// possibly re-initialize geometry buffer if window width/height changes
|
||||||
init_geometry_buffer(geometry_buffer_pnc, geometry_buffer_pnc_types);
|
init_geometry_buffer(geometry_buffer_pnc, geometry_buffer_pnc_types);
|
||||||
|
|
||||||
@ -504,10 +506,12 @@ void draw()
|
|||||||
} else {
|
} else {
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
//collision_scene::draw();
|
|
||||||
//boids_scene::draw();
|
|
||||||
scene_state.draw();
|
scene_state.draw();
|
||||||
|
|
||||||
|
hud::draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
last_frame_time = current_time;
|
last_frame_time = current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user