collada: draw animated eidelwind

This commit is contained in:
Zack Buhman 2026-03-31 19:07:00 -05:00
parent c7df1ed578
commit 5724fde489
24 changed files with 17820 additions and 428 deletions

View File

@ -37,6 +37,13 @@ MINECRAFT_OBJS = \
src/world/world.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 = \
src/gl.o \
src/opengl.o \
@ -61,10 +68,7 @@ OBJS = \
src/collada/animate.o \
src/flame.o \
src/audio.o \
data/scenes/ship20/ship20.o \
data/scenes/noodle/noodle.o \
data/scenes/shadow_test/shadow_test.o \
data/scenes/book/book.o \
$(COLLADA_SCENES) \
$(MINECRAFT_OBJS)
ifdef READ_PACK_FILE

4
collada.sh Normal file
View 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

View File

@ -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

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -33,8 +33,6 @@ font/bitmap/terminus_256x256_16x32.data
shader/font.vert
shader/font_outline.frag
font/outline/uncial_antiqua_36.data
shader/pixel_line_art.vert
shader/pixel_line_art.frag
shader/quad.vert
shader/quad.frag
shader/quad.vert
@ -49,10 +47,10 @@ shader/collada/static.vert
shader/collada/generic.frag
shader/collada/skinned.vert
shader/collada/generic.frag
data/scenes/book/book.vtx
data/scenes/book/book.vjw
data/scenes/book/book.idx
data/scenes/eidelwind/scene.vtx
data/scenes/eidelwind/scene.vjw
data/scenes/eidelwind/scene.idx
data/scenes/eidelwind/images/0_map_face_only.dds
shader/flame.vert
shader/flame.frag
minecraft/flame.data
audio/Suite.opus.bin

View File

@ -24,6 +24,9 @@ namespace collada::scene {
unsigned int * textures;
// mutable state
int node_draw_type;
// drawing
void load_layouts();
void load_images();

View File

@ -0,0 +1,3 @@
namespace eidelwind {
extern collada::types::descriptor const descriptor;
}

View File

@ -1,10 +1,23 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "font/bitmap.h"
#include "font/outline.h"
#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 love2d_state_load();
void love2d_state_restore();
@ -21,6 +34,4 @@ extern "C" {
int start);
void update(float time);
#ifdef __cplusplus
}
#endif

274
main.lua
View File

@ -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

View File

@ -36,6 +36,35 @@ namespace collada::animate {
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)
{
return f * f * f;
@ -173,12 +202,25 @@ namespace collada::animate {
target_attributes = rotate_target_attributes;
target_attributes_count = 4;
break;
case types::transform_type::MATRIX:
break;
default:
assert(false);
break;
}
}
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];
assert(interpolation == types::interpolation::LINEAR);
float iv = linear_interpolate_iv(channel.source_sampler->input, frame_ix, t);
XMMATRIX matrix = linear_interpolate_matrix(channel.source_sampler->output, frame_ix, iv);
transform.matrix = matrix;
} else {
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];
@ -194,6 +236,7 @@ namespace collada::animate {
apply_transform_target(transform, target_attributes[parameter_ix], value);
}
}
}
void animate_node(instance_types::node& node_instance, float t)
{

View File

@ -22,7 +22,7 @@ namespace collada::node_state {
instance_transform->lookat.up = XMLoadFloat3((XMFLOAT3 *)&transform.lookat.up);
break;
case types::transform_type::MATRIX:
instance_transform->matrix = XMLoadFloat4x4((XMFLOAT4X4 *)&transform.matrix);
instance_transform->matrix = XMMatrixTranspose(XMLoadFloat4x4((XMFLOAT4X4 *)&transform.matrix));
break;
case types::transform_type::ROTATE:
instance_transform->vector = XMLoadFloat4((XMFLOAT4 *)&transform.rotate);
@ -61,6 +61,9 @@ namespace collada::node_state {
for (int i = 0; i < nodes_count; i++) {
allocate_node_instance(node_instances[i], nodes[i]);
}
for (int i = 0; i < nodes_count; i++) {
update_node_world_transform(node_instances[i]);
}
}
//////////////////////////////////////////////////////////////////////

View File

@ -200,6 +200,7 @@ namespace collada::scene {
glGenVertexArrays(2 * descriptor->inputs_list_count, (unsigned int *)vertex_arrays);
for (int i = 0; i < descriptor->inputs_list_count; i++) {
printf("LOAD LAYOUT %d\n", i);
// static
int stride = load_layout(descriptor->inputs_list[i],
0, // binding
@ -296,6 +297,8 @@ namespace collada::scene {
load_images();
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,
@ -455,19 +458,21 @@ namespace collada::scene {
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++) {
XMMATRIX ibm = XMLoadFloat4x4((XMFLOAT4X4*)&skin.inverse_bind_matrices[joint_index]);
int node_index = instance_controller.joint_node_indices[joint_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;
glBindBuffer(GL_UNIFORM_BUFFER, joint_uniform_buffer);
glBufferData(GL_UNIFORM_BUFFER, joints_size, (void *)&joints[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glBindBufferRange(GL_UNIFORM_BUFFER, layout.binding.joint, joint_uniform_buffer, 0, joints_size);
draw_skin(skin,
@ -489,6 +494,10 @@ namespace collada::scene {
}
if (node.instance_controllers_count) {
XMMATRIX transform = view::state.transform;
XMFLOAT4X4 float_transform;
XMStoreFloat4x4(&float_transform, transform);
glUseProgram(collada::effect::program_skinned);
glUniformMatrix4fv(layout.uniform.transform, 1, false, (float *)&float_transform);
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++) {
types::node const & node = *descriptor->nodes[i];
// joints are not drawn
if (node.type != types::node_type::NODE)
if (((node_draw_type & 0b01) == 0) && (node.type == types::node_type::NODE))
continue;
if (((node_draw_type & 0b10) == 0) && (node.type == types::node_type::JOINT))
continue;
draw_node(node, node_state.node_instances[i]);
@ -524,7 +534,7 @@ namespace collada::scene {
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++) {
animate::animate_node(node_state.node_instances[i], t);

View File

@ -8,9 +8,6 @@
#include "file.h"
namespace file {
char const * source_path = NULL;
int source_path_length = 0;
#ifdef READ_PACK_FILE
#include "pack.h"
extern "C" {
@ -42,28 +39,9 @@ namespace file {
(void)buf;
}
#else
static char const * join_path(char * buf, const char * filename)
void const * read_file(const char * filename, int * out_size)
{
if (filename[0] == '/')
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);
fprintf(stderr, "filename: %s\n", filename);
FILE * f = fopen(filename, "rb");
if (f == NULL) {

View File

@ -8,14 +8,11 @@
#include "flame.h"
#include "view.h"
extern unsigned int quad_index_buffer;
extern unsigned int empty_vertex_array_object;
#include "test.h"
namespace flame {
static unsigned int program;
static unsigned int flame_texture;
static unsigned int vertex_array_object;
const int per_instance_size = 4 * (sizeof (float));
@ -97,8 +94,8 @@ namespace flame {
glBindBufferBase(GL_UNIFORM_BUFFER, layout.binding.lights, light_uniform_buffer);
glBindVertexArray(empty_vertex_array_object);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_index_buffer);
glBindVertexArray(test::empty_vertex_array_object);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, test::quad_index_buffer);
glDrawElementsInstanced(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0, light_count);
}

View File

@ -8,14 +8,7 @@
#include "font/outline.h"
#include "view.h"
#include "window.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;
#include "test.h"
// depends on:
// - font::bitmap::load
@ -23,9 +16,6 @@ extern float last_frame_time;
// - load_quad_index_buffer
// - empty_vertex_array_object
extern float mouse_position[3];
extern float mouse_block[3];
namespace hud {
template <typename T, typename... Args>
@ -93,12 +83,13 @@ namespace hud {
float y = 10.0f;
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::draw_start(ter_best, empty_vertex_array_object, quad_index_buffer);
font::bitmap::font const& ter_best = test::terminus_fonts[font_ix];
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<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, " 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;
@ -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, " 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;
*/
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;
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat4((XMFLOAT4*)mouse_position));
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat4((XMFLOAT4*)mouse_block));
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat4((XMFLOAT4*)test::mouse_position));
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat4((XMFLOAT4*)test::mouse_block));
if (frame++ > 60 * 10)
return;
/*
font::outline::draw_start(uncial_antiqua_fonts[0], empty_vertex_array_object, quad_index_buffer);
char const * title = "Technical demo: Bibliotheca";
int const title_length = strlen(title);
@ -132,6 +132,7 @@ namespace hud {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
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);
@ -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));
*/
}
}

View File

@ -8,10 +8,7 @@
#include "view.h"
#include "lighting.h"
#include "geometry_buffer.h"
extern unsigned int empty_vertex_array_object;
extern unsigned int quad_index_buffer;
extern geometry_buffer<4> geometry_buffer_pnc;
#include "test.h"
namespace lighting {
@ -85,11 +82,11 @@ namespace lighting {
glDepthFunc(GL_ALWAYS);
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);
glBindTexture(GL_TEXTURE_2D, geometry_buffer_pnc.target[1]);
glBindTexture(GL_TEXTURE_2D, test::geometry_buffer_pnc.target[1]);
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.normal_sampler, 1);
@ -107,8 +104,8 @@ namespace lighting {
glUniform1i(location.uniform.light_count, light_count);
glBindBufferBase(GL_UNIFORM_BUFFER, location.binding.lights, light_uniform_buffer);
glBindVertexArray(empty_vertex_array_object);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_index_buffer);
glBindVertexArray(test::empty_vertex_array_object);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, test::quad_index_buffer);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0);
}

View File

@ -33,7 +33,9 @@ void remove_gamepad(SDL_JoystickID instance_id)
for (int i = 0; i < gamepad_count; i++) {
if (SDL_GetGamepadID(gamepads[i]) == instance_id) {
int tail = (gamepad_count - i) - 1;
SDL_CloseGamepad(gamepads[i]);
memcpy(&gamepads[i], &gamepads[i+1], tail * (sizeof (gamepads[0])));
gamepad_count -= 1;
return;
}
}
@ -68,7 +70,7 @@ void update()
bool start = SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
float scale = 1.0f / 32767.0f;
update_joystick((float)leftx * scale,
test::update_joystick((float)leftx * scale,
(float)lefty * scale,
(float)rightx * scale,
(float)righty * scale,
@ -125,12 +127,15 @@ int main()
fprintf(stderr, "gladLoadGL\n");
}
load(".");
test::load();
//audio::init();
//audio::load();
update_window(1024, 1024);
int64_t start_time;
SDL_GetCurrentTime(&start_time);
while (true) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
@ -152,7 +157,7 @@ int main()
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
if (event.button.button == 1) {
update_mouse(event.button.x, event.button.y);
test::update_mouse(event.button.x, event.button.y);
}
break;
default:
@ -161,7 +166,14 @@ int main()
}
update();
draw();
int64_t current_time;
SDL_GetCurrentTime(&current_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();

View File

@ -38,6 +38,9 @@
#include "data/scenes/noodle.h"
#include "data/scenes/shadow_test.h"
#include "data/scenes/book.h"
#include "data/scenes/eidelwind.h"
namespace test {
struct line_location {
struct {
@ -116,14 +119,8 @@ void load_quad_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);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -187,14 +184,20 @@ void load(const char * source_path)
// collada
//////////////////////////////////////////////////////////////////////
//collada::effect::load_effects();
//scene_state.load_scene(&book::descriptor);
//node_eye = scene_state.find_node_by_name("Camera");
//assert(node_eye != nullptr);
//view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
collada::effect::load_effects();
scene_state.load_scene(&eidelwind::descriptor);
node_eye = scene_state.find_node_by_name("Camera001");
assert(node_eye != nullptr);
view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
//node_at = scene_state.find_node_by_name("Camera001.Target");
//assert(node_at != nullptr);
node_at = scene_state.find_node_by_name("Camera001.Target");
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
@ -317,22 +320,6 @@ void update_keyboard(int up, int down, int left, int right,
int i, int k, int j, int l,
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 strafe = (d - a) * 0.5;
float elevation = (q - e) * 0.5;
@ -363,22 +350,36 @@ void update_joystick(float lx, float ly,
int leftshoulder, int rightshoulder,
int start)
{
float forward = -ly * 0.5;
float strafe = lx * 0.5;
float elevation = (tl - tr) * 0.5;
float translate_rate = 2.0;
float forward = -ly * translate_rate;
float strafe = lx * translate_rate;
float elevation = (tl - tr) * translate_rate;
float delta_yaw = rx * -0.035;
float delta_pitch = ry * -0.035;
XMVECTOR direction = view::third_person::apply_transform(forward, strafe, elevation,
/*
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);
if (true) {
minecraft_view_update(direction);
}
*/
if (a && last_a == 0) {
next_world();
//next_world();
scene_state.node_draw_type += 1;
scene_state.node_draw_type %= 4;
}
last_a = a;
@ -402,7 +403,7 @@ void update(float time)
{
current_time = time;
//scene_state.update(time);
scene_state.update(time);
/*
view::state.eye = XMVector3Transform(XMVectorZero(), node_eye->world);
if (node_at == nullptr)
@ -475,7 +476,8 @@ void draw()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(-1.0f);
if (true) {
if (false) {
// possibly re-initialize geometry buffer if window width/height changes
init_geometry_buffer(geometry_buffer_pnc, geometry_buffer_pnc_types);
@ -504,10 +506,12 @@ void draw()
} else {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//collision_scene::draw();
//boids_scene::draw();
scene_state.draw();
hud::draw();
}
last_frame_time = current_time;
}
}