hacked together sphere positioning from lua
This commit is contained in:
parent
045f2707f7
commit
30168029d2
@ -13,6 +13,7 @@ extern "C" {
|
||||
void draw_quad(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4);
|
||||
|
||||
void set_sphere(float x, float y, float angle);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -39,6 +39,8 @@ namespace view {
|
||||
float delta_yaw, float delta_pitch);
|
||||
}
|
||||
|
||||
XMVECTOR get_normal();
|
||||
XMVECTOR get_direction();
|
||||
void apply_fov(float delta);
|
||||
void update_transforms();
|
||||
void load();
|
||||
|
||||
@ -41,7 +41,7 @@ function system:draw()
|
||||
local text = e[debug_label.dict.debug_label].data
|
||||
local x = e[transform.dict.position].data[1]
|
||||
local y = e[transform.dict.position].data[2]
|
||||
draw(text, x, y)
|
||||
--draw(text, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ function system:draw()
|
||||
local w = e[c_button.dict.collider].data.w
|
||||
local h = e[c_button.dict.collider].data.h
|
||||
local label = e[c_button.dict.label].data
|
||||
draw(label, x, y, w, h)
|
||||
--draw(label, x, y, w, h)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ end
|
||||
function system:draw()
|
||||
for _, e in ipairs(self.pool) do
|
||||
video = e[c_video.dict.video].data.video
|
||||
love.graphics.draw(video, 0, 0)
|
||||
--love.graphics.draw(video, 0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ function wrapper:draw()
|
||||
local frame_i = v[animation.dict.frame_i].data
|
||||
local img = v[animation.dict.image_frame].data.images
|
||||
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
|
||||
|
||||
@ -88,7 +88,7 @@ function system:load()
|
||||
end)
|
||||
|
||||
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.angle", 0)
|
||||
e:give("race.image", "love_src/asset/image/arrow_right.png")
|
||||
@ -301,18 +301,19 @@ end
|
||||
|
||||
function system:draw()
|
||||
for _, f in ipairs(frictions) do
|
||||
love.graphics.push()
|
||||
love.graphics.setColor(f.color)
|
||||
love.graphics.rectangle("fill", f.colliders[1], f.colliders[2], f.colliders[3], f.colliders[4])
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.pop()
|
||||
-- love.graphics.push()
|
||||
-- love.graphics.setColor(f.color)
|
||||
-- love.graphics.rectangle("fill", f.colliders[1], f.colliders[2], f.colliders[3], f.colliders[4])
|
||||
-- love.graphics.setColor(1, 1, 1)
|
||||
-- love.graphics.pop()
|
||||
end
|
||||
for _, e in ipairs(self.pool) do
|
||||
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 image = e["race.image"].data.image
|
||||
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
|
||||
|
||||
|
||||
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_quad(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4);
|
||||
|
||||
void set_sphere(float x, float y, float angle);
|
||||
]]
|
||||
local source_path = love.filesystem.getSource()
|
||||
test = ffi.load(source_path .. "/test.so")
|
||||
@ -185,8 +187,55 @@ local nico_draw = function()
|
||||
-- enough, and we should discuss this in more detail.
|
||||
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()
|
||||
init()
|
||||
love_load()
|
||||
|
||||
local last_time = love.timer.getTime()
|
||||
|
||||
return function()
|
||||
love.event.pump()
|
||||
@ -196,8 +245,19 @@ function love.run()
|
||||
return a or 0, b
|
||||
end
|
||||
end
|
||||
|
||||
if name == 'keyreleased' then
|
||||
love_keyreleased(a,b,c,d,e,f,g,h)
|
||||
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 height
|
||||
local flags
|
||||
@ -205,8 +265,13 @@ function love.run()
|
||||
test.update_window(width, height)
|
||||
|
||||
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()
|
||||
|
||||
local mouse_down = love.mouse.isDown(1)
|
||||
@ -221,45 +286,3 @@ function love.run()
|
||||
love.timer.sleep(0.001)
|
||||
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 "pixel_line_art.h"
|
||||
#include "view.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,
|
||||
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;
|
||||
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)
|
||||
|
||||
@ -325,7 +325,7 @@ void update_joystick(int joystick_index,
|
||||
delta_yaw, delta_pitch);
|
||||
view::apply_fov(0.01 * up + -0.01 * down);
|
||||
|
||||
if (true) {
|
||||
if (false) {
|
||||
minecraft_view_update(direction);
|
||||
}
|
||||
|
||||
@ -349,7 +349,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)
|
||||
|
||||
@ -32,12 +32,12 @@ namespace view {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
static inline XMVECTOR get_normal()
|
||||
XMVECTOR get_normal()
|
||||
{
|
||||
return XMVector3NormalizeEst(XMVector3Cross(state.forward, state.up));
|
||||
}
|
||||
|
||||
static inline XMVECTOR get_direction()
|
||||
XMVECTOR get_direction()
|
||||
{
|
||||
XMMATRIX mrn = XMMatrixRotationAxis(state.normal, state.pitch);
|
||||
return XMVector3Transform(state.forward, mrn);
|
||||
@ -106,11 +106,13 @@ namespace view {
|
||||
// position
|
||||
// grandlecturn
|
||||
//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
|
||||
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.eye = XMVectorSet(0, -100, 0, 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user