hacked together sphere positioning from lua
This commit is contained in:
parent
dfb114b5fc
commit
1c2fad5a8a
@ -13,6 +13,7 @@ extern "C" {
|
|||||||
void draw_quad(int x1, int y1, int x2, int y2,
|
void draw_quad(int x1, int y1, int x2, int y2,
|
||||||
int x3, int y3, int x4, int y4);
|
int x3, int y3, int x4, int y4);
|
||||||
|
|
||||||
|
void set_sphere(float x, float y, float angle);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -39,6 +39,8 @@ namespace view {
|
|||||||
float delta_yaw, float delta_pitch);
|
float delta_yaw, float delta_pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMVECTOR get_normal();
|
||||||
|
XMVECTOR get_direction();
|
||||||
void apply_fov(float delta);
|
void apply_fov(float delta);
|
||||||
void update_transforms();
|
void update_transforms();
|
||||||
void load();
|
void load();
|
||||||
|
|||||||
@ -41,7 +41,7 @@ function system:draw()
|
|||||||
local text = e[debug_label.dict.debug_label].data
|
local text = e[debug_label.dict.debug_label].data
|
||||||
local x = e[transform.dict.position].data[1]
|
local x = e[transform.dict.position].data[1]
|
||||||
local y = e[transform.dict.position].data[2]
|
local y = e[transform.dict.position].data[2]
|
||||||
draw(text, x, y)
|
--draw(text, x, y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -74,7 +74,7 @@ function system:draw()
|
|||||||
local w = e[c_button.dict.collider].data.w
|
local w = e[c_button.dict.collider].data.w
|
||||||
local h = e[c_button.dict.collider].data.h
|
local h = e[c_button.dict.collider].data.h
|
||||||
local label = e[c_button.dict.label].data
|
local label = e[c_button.dict.label].data
|
||||||
draw(label, x, y, w, h)
|
--draw(label, x, y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@ end
|
|||||||
function system:draw()
|
function system:draw()
|
||||||
for _, e in ipairs(self.pool) do
|
for _, e in ipairs(self.pool) do
|
||||||
video = e[c_video.dict.video].data.video
|
video = e[c_video.dict.video].data.video
|
||||||
love.graphics.draw(video, 0, 0)
|
--love.graphics.draw(video, 0, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@ function wrapper:draw()
|
|||||||
local frame_i = v[animation.dict.frame_i].data
|
local frame_i = v[animation.dict.frame_i].data
|
||||||
local img = v[animation.dict.image_frame].data.images
|
local img = v[animation.dict.image_frame].data.images
|
||||||
if (img ~= nil) then
|
if (img ~= nil) then
|
||||||
love.graphics.draw(img[frame_i], v[transform.dict.position].data[1], v[transform.dict.position].data[2])
|
--love.graphics.draw(img[frame_i], v[transform.dict.position].data[1], v[transform.dict.position].data[2])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -88,7 +88,7 @@ function system:load()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
for _, e in ipairs(self.pool) do
|
for _, e in ipairs(self.pool) do
|
||||||
e:give("race.pos", 10, 10)
|
e:give("race.pos", 44.64, 10.87)
|
||||||
e:give("race.scale", 1, 1)
|
e:give("race.scale", 1, 1)
|
||||||
e:give("race.angle", 0)
|
e:give("race.angle", 0)
|
||||||
e:give("race.image", "love_src/asset/image/arrow_right.png")
|
e:give("race.image", "love_src/asset/image/arrow_right.png")
|
||||||
@ -247,18 +247,19 @@ end
|
|||||||
|
|
||||||
function system:draw()
|
function system:draw()
|
||||||
for _, f in ipairs(frictions) do
|
for _, f in ipairs(frictions) do
|
||||||
love.graphics.push()
|
-- love.graphics.push()
|
||||||
love.graphics.setColor(f.color)
|
-- love.graphics.setColor(f.color)
|
||||||
love.graphics.rectangle("fill", f.colliders[1], f.colliders[2], f.colliders[3], f.colliders[4])
|
-- love.graphics.rectangle("fill", f.colliders[1], f.colliders[2], f.colliders[3], f.colliders[4])
|
||||||
love.graphics.setColor(1, 1, 1)
|
-- love.graphics.setColor(1, 1, 1)
|
||||||
love.graphics.pop()
|
-- love.graphics.pop()
|
||||||
end
|
end
|
||||||
for _, e in ipairs(self.pool) do
|
for _, e in ipairs(self.pool) do
|
||||||
local accel, brake, grip, max_speed, steer, velocity = get(e)
|
local accel, brake, grip, max_speed, steer, velocity = get(e)
|
||||||
local x, y, sx, sy, angle = e["race.pos"].data[1], e["race.pos"].data[2], e["race.scale"].data[1], e["race.scale"].data[2], e["race.angle"].data
|
local x, y, sx, sy, angle = e["race.pos"].data[1], e["race.pos"].data[2], e["race.scale"].data[1], e["race.scale"].data[2], e["race.angle"].data
|
||||||
local image = e["race.image"].data.image
|
local image = e["race.image"].data.image
|
||||||
local origin = e["race.image"].data.origin
|
local origin = e["race.image"].data.origin
|
||||||
draw(velocity, x, y, sx, sy, angle, image, origin)
|
--draw(velocity, x, y, sx, sy, angle, image, origin)
|
||||||
|
test.set_sphere(x, y, angle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
109
game/main.lua
109
game/main.lua
@ -32,6 +32,8 @@ void update(float time);
|
|||||||
void draw_set_color(float r, float g, float b);
|
void draw_set_color(float r, float g, float b);
|
||||||
void draw_quad(int x1, int y1, int x2, int y2,
|
void draw_quad(int x1, int y1, int x2, int y2,
|
||||||
int x3, int y3, int x4, int y4);
|
int x3, int y3, int x4, int y4);
|
||||||
|
|
||||||
|
void set_sphere(float x, float y, float angle);
|
||||||
]]
|
]]
|
||||||
local source_path = love.filesystem.getSource()
|
local source_path = love.filesystem.getSource()
|
||||||
test = ffi.load(source_path .. "/test.so")
|
test = ffi.load(source_path .. "/test.so")
|
||||||
@ -185,8 +187,55 @@ local nico_draw = function()
|
|||||||
-- enough, and we should discuss this in more detail.
|
-- enough, and we should discuss this in more detail.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local wm = require("world_map")
|
||||||
|
|
||||||
|
world = {
|
||||||
|
["top_down_race"] = require("love_src.src.world.top_down_race")(),
|
||||||
|
["main_menu"] = require("love_src.src.world.main_menu")(),
|
||||||
|
["1_intro"] = require("love_src.src.world.1_intro")(),
|
||||||
|
["2_town_square"] = require("love_src.src.world.2_town_square")(),
|
||||||
|
["race"] = require("love_src.src.world.race")(),
|
||||||
|
["train"] = require("love_src.src.world.train")(),
|
||||||
|
};
|
||||||
|
|
||||||
|
current = wm["top_down_race"]
|
||||||
|
|
||||||
|
function load_world(world_to_load)
|
||||||
|
current = world_to_load
|
||||||
|
world[current]:reload()
|
||||||
|
end
|
||||||
|
|
||||||
|
function love_load()
|
||||||
|
world[current]:load()
|
||||||
|
end
|
||||||
|
|
||||||
|
function love_update(dt)
|
||||||
|
world[current]:update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love_draw()
|
||||||
|
world[current]:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
function love_keyreleased(key, scancode)
|
||||||
|
world[current]:keyreleased(key, scancode)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love_keypressed(key, scancode, isrepeat)
|
||||||
|
world[current]:keypressed(key, scancode, isrepeat)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love_mousereleased(x, y, button, istouch, presses)
|
||||||
|
world[current]:mousereleased(x, y, button, istouch, presses)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function love.run()
|
function love.run()
|
||||||
init()
|
init()
|
||||||
|
love_load()
|
||||||
|
|
||||||
|
local last_time = love.timer.getTime()
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
love.event.pump()
|
love.event.pump()
|
||||||
@ -196,7 +245,18 @@ function love.run()
|
|||||||
return a or 0, b
|
return a or 0, b
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if name == 'keyreleased' then
|
||||||
|
love_keyreleased(a,b,c,d,e,f,g,h)
|
||||||
end
|
end
|
||||||
|
if name == 'keypressed' then
|
||||||
|
love_keypressed(a,b,c,d,e,f,g,h)
|
||||||
|
end
|
||||||
|
if name == 'mousereleased' then
|
||||||
|
love_mousereleased(a,b,c,d,e,f,g,h)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local width
|
local width
|
||||||
local height
|
local height
|
||||||
@ -205,8 +265,13 @@ function love.run()
|
|||||||
test.update_window(width, height)
|
test.update_window(width, height)
|
||||||
|
|
||||||
local time = love.timer.getTime()
|
local time = love.timer.getTime()
|
||||||
update(time)
|
--update(time)
|
||||||
|
test.update(time)
|
||||||
|
local dt = last_time - time
|
||||||
|
last_time = time
|
||||||
|
love_update(dt)
|
||||||
|
|
||||||
|
love_draw()
|
||||||
draw()
|
draw()
|
||||||
|
|
||||||
local mouse_down = love.mouse.isDown(1)
|
local mouse_down = love.mouse.isDown(1)
|
||||||
@ -221,45 +286,3 @@ function love.run()
|
|||||||
love.timer.sleep(0.001)
|
love.timer.sleep(0.001)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local wm = require("world_map")
|
|
||||||
|
|
||||||
-- world = {
|
|
||||||
-- ["top_down_race"] = require("love_src.src.world.top_down_race")(),
|
|
||||||
-- -- ["main_menu"] = require("love_src.src.world.main_menu")(),
|
|
||||||
-- -- ["1_intro"] = require("love_src.src.world.1_intro")(),
|
|
||||||
-- -- ["2_town_square"] = require("love_src.src.world.2_town_square")(),
|
|
||||||
-- -- ["race"] = require("love_src.src.world.race")(),
|
|
||||||
-- -- ["train"] = require("love_src.src.world.train")(),
|
|
||||||
-- };
|
|
||||||
|
|
||||||
-- current = wm["top_down_race"]
|
|
||||||
|
|
||||||
-- function load_world(world_to_load)
|
|
||||||
-- current = world_to_load
|
|
||||||
-- world[current]:reload()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- function love.load()
|
|
||||||
-- world[current]:load()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- function love.update(dt)
|
|
||||||
-- world[current]:update(dt)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- function love.draw()
|
|
||||||
-- world[current]:draw()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- function love.keyreleased(key, scancode)
|
|
||||||
-- world[current]:keyreleased(key, scancode)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- function love.keypressed(key, scancode, isrepeat)
|
|
||||||
-- world[current]:keypressed(key, scancode, isrepeat)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- function love.mousereleased(x, y, button, istouch, presses)
|
|
||||||
-- world[current]:mousereleased(x, y, button, istouch, presses)
|
|
||||||
-- end
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "font/bitmap.h"
|
#include "font/bitmap.h"
|
||||||
#include "pixel_line_art.h"
|
#include "pixel_line_art.h"
|
||||||
|
#include "view.h"
|
||||||
|
|
||||||
#include "lua_api.h"
|
#include "lua_api.h"
|
||||||
|
|
||||||
@ -43,3 +44,14 @@ void draw_quad(int x1, int y1, int x2, int y2,
|
|||||||
pixel_line_art::draw_quad(x1, y1, x2, y2,
|
pixel_line_art::draw_quad(x1, y1, x2, y2,
|
||||||
x3, y3, x4, y4);
|
x3, y3, x4, y4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_sphere(float x, float y, float angle)
|
||||||
|
{
|
||||||
|
XMVECTOR unit = XMVectorSet(1, 0, 0, 0); // the angle==0 unit vector
|
||||||
|
view::state.forward = -XMVector3TransformNormal(unit, XMMatrixRotationZ(angle));
|
||||||
|
view::state.normal = view::get_normal();
|
||||||
|
view::state.direction = view::get_direction();
|
||||||
|
|
||||||
|
view::state.at = XMVectorSet(x, y, 52, 0);
|
||||||
|
view::state.eye = view::state.at - view::state.direction * view::at_distance;
|
||||||
|
}
|
||||||
|
|||||||
@ -269,7 +269,7 @@ namespace minecraft {
|
|||||||
continue;
|
continue;
|
||||||
per_world::load_world(&world::descriptors[i], world_state[i]);
|
per_world::load_world(&world::descriptors[i], world_state[i]);
|
||||||
}
|
}
|
||||||
current_world = &world_state[world::world_id::MIDNIGHTMEADOW];
|
current_world = &world_state[world::world_id::GRANDLECTURN];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int popcount(int x)
|
static inline int popcount(int x)
|
||||||
|
|||||||
@ -325,7 +325,7 @@ void update_joystick(int joystick_index,
|
|||||||
delta_yaw, delta_pitch);
|
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 (false) {
|
||||||
minecraft_view_update(direction);
|
minecraft_view_update(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,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)
|
||||||
|
|||||||
@ -32,12 +32,12 @@ namespace view {
|
|||||||
return pitch;
|
return pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline XMVECTOR get_normal()
|
XMVECTOR get_normal()
|
||||||
{
|
{
|
||||||
return XMVector3NormalizeEst(XMVector3Cross(state.forward, state.up));
|
return XMVector3NormalizeEst(XMVector3Cross(state.forward, state.up));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline XMVECTOR get_direction()
|
XMVECTOR get_direction()
|
||||||
{
|
{
|
||||||
XMMATRIX mrn = XMMatrixRotationAxis(state.normal, state.pitch);
|
XMMATRIX mrn = XMMatrixRotationAxis(state.normal, state.pitch);
|
||||||
return XMVector3Transform(state.forward, mrn);
|
return XMVector3Transform(state.forward, mrn);
|
||||||
@ -106,11 +106,13 @@ namespace view {
|
|||||||
// position
|
// position
|
||||||
// grandlecturn
|
// grandlecturn
|
||||||
//state.eye = XMVectorSet(4.71f, 65.30, 57.92, 1);
|
//state.eye = XMVectorSet(4.71f, 65.30, 57.92, 1);
|
||||||
|
state.at = XMVectorSet(44.64, 10.87, 50.98, 1);
|
||||||
|
view::state.eye = view::state.at - view::state.direction * view::at_distance;
|
||||||
|
|
||||||
// midnightmeadow
|
// midnightmeadow
|
||||||
state.eye = XMVectorSet(13.71f, -3.36, 90.92, 1);
|
//state.eye = XMVectorSet(13.71f, -3.36, 90.92, 1);
|
||||||
|
|
||||||
state.at = state.eye + state.direction * at_distance;
|
//state.at = state.eye + state.direction * at_distance;
|
||||||
//state.at = XMVectorSet(0, 0, 0, 1);
|
//state.at = XMVectorSet(0, 0, 0, 1);
|
||||||
//state.eye = XMVectorSet(0, -100, 0, 1);
|
//state.eye = XMVectorSet(0, -100, 0, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user