Compare commits

..

No commits in common. "391010b4c49c9860a363d404e9d7da5fb89db39f" and "dfb114b5fceb3b2a02d605d1845ca744c0be10a9" have entirely different histories.

13 changed files with 71 additions and 166 deletions

View File

@ -13,7 +13,6 @@ 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

View File

@ -39,8 +39,6 @@ namespace view {
float delta_yaw, float delta_pitch);
}
XMVECTOR get_normal();
XMVECTOR get_direction();
void apply_fov(float delta);
void update_transforms();
void load();

View File

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

View File

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

View File

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

View File

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

View File

@ -32,10 +32,10 @@ function wrapper:load(_args)
assemblage = racer.assemble,
data = {
accel = 20.0,
brake = 10.0,
brake = 1.0,
grip = 1.0,
max_speed = 50.0,
steer = 5.0,
steer = 1.0,
velocity = 0.0,
inertia = {0.0, 0.0},
drag = 1.0,

View File

@ -88,7 +88,7 @@ function system:load()
end)
for _, e in ipairs(self.pool) do
e:give("race.pos", 44.64, 10.87)
e:give("race.pos", 10, 10)
e:give("race.scale", 1, 1)
e:give("race.angle", 0)
e:give("race.image", "love_src/asset/image/arrow_right.png")
@ -144,50 +144,20 @@ local function grip_force(grip, friction)
return friction * grip
end
local function add_friction(force, friction_direction, grip, friction, tire_c, floor_c)
local f_grip = grip_force(grip, friction)
if (force > 0) then
-- tire - floor
force = force + friction_direction * tire_c * f_grip - friction_direction * floor_c * f_grip
elseif (force < 0) then
force = force + friction_direction * tire_c * f_grip - friction_direction * floor_c * f_grip
else
force = force
end
return force
end
local function add_friction_lateral(force, grip, friction, tire_c, floor_c)
local function add_friction(force, grip, friction, tire_c, floor_c)
local f_grip = grip_force(grip, friction)
if (force > 0) then
-- tire - floor
force = force + tire_c * f_grip - floor_c * f_grip
if (force < 0) then
force = 0.1
end
elseif (force < 0) then
force = force - tire_c * f_grip + floor_c * f_grip
if (force > 0) then
force = -0.1
end
else
force = force
end
return force
end
local function add_drag(force, drag_direction, drag)
if (force > 0) then
force = force + drag_direction * drag
elseif (force < 0) then
force = force + drag_direction * drag
else
force = force
end
return force
end
local function add_drag_lateral(force, drag)
local function add_drag(force, drag)
if (force > 0) then
force = force - drag
elseif (force < 0) then
@ -231,16 +201,6 @@ local function get_friction(pos_x, pos_y, floors)
return friction
end
local magic_n = {
tire_c = 1.0,
floor_c = 1.5,
scale_x = 1000.0,
scale_y = 1000.0,
centrifugal_r = 1.0,
magic_slowdown = 10.0,
magic_boost = 1000.0
}
function system:update(dt)
for _, e in ipairs(self.pool) do
local accel, brake, grip, max_speed, steer, velocity, drag, inertia, mass = get(e)
@ -257,32 +217,18 @@ function system:update(dt)
local f_forward = accel_force(up, down, accel, brake, inertia[1])
local f_lateral = steer_force(left, right, steer, inertia[2])
if (not up) then
f_forward = f_forward - magic_n.magic_slowdown
elseif (up and velocity == 0) then
f_forward = f_forward + magic_n.magic_boost
end
f_forward = add_friction(f_forward, grip, friction, 1.0, 0.5)
f_lateral = add_friction(f_lateral, grip, friction, 1.0, 0.5)
if (velocity > 0) then
f_forward = add_friction(f_forward, 1.0, grip, friction, magic_n.tire_c, magic_n.floor_c)
elseif (velocity < 0) then
f_forward = add_friction(f_forward, -1.0, grip, friction, magic_n.tire_c, magic_n.floor_c)
end
f_lateral = add_friction_lateral(f_lateral, grip, friction, magic_n.tire_c, magic_n.floor_c)
if (velocity > 0) then
f_forward = add_drag(f_forward, -1.0, drag)
elseif (velocity < 0) then
f_forward = add_drag(f_forward, 1.0, drag)
end
f_lateral = add_drag_lateral(f_lateral, drag)
f_forward = add_drag(f_forward, drag)
f_lateral = add_drag(f_lateral, drag)
if (mass == 0) then
mass = 1
end
local new_velocity = racing_phy.accelerate(dt, 1, velocity, max_speed, f_forward*dt/mass, 0)
local centrifugal = racing_phy.centrifugal_force(dt, mass, new_velocity * magic_n.centrifugal_r, max_speed)
local centrifugal = racing_phy.centrifugal_force(dt, mass, new_velocity, max_speed)
f_lateral = add_centrifugal(f_lateral, centrifugal)
e[race.dict.inertia].data = {f_forward * dt, f_lateral * dt}
@ -291,7 +237,7 @@ function system:update(dt)
e["race.angle"].data = new_angle
e[race.dict.velocity].data = new_velocity
local goal_x, goal_y = racing_phy.drift(dt, pos_x, pos_y, new_velocity, max_speed, new_angle, magic_n.scale_x, magic_n.scale_y)
local goal_x, goal_y = racing_phy.drift(dt, pos_x, pos_y, new_velocity, max_speed, new_angle, 100000, 100000)
-- print("force_forward", f_forward, "f_lateral", f_lateral, "velocity", new_velocity, "angle", new_angle, "goal_x", goal_x, "goal_y", goal_y)
e["race.pos"].data[1] = goal_x
@ -301,19 +247,18 @@ 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)
test.set_sphere(x, y, angle)
draw(velocity, x, y, sx, sy, angle, image, origin)
end
end

View File

@ -32,8 +32,6 @@ 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")
@ -187,55 +185,8 @@ 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()
@ -245,18 +196,7 @@ 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
@ -265,13 +205,8 @@ function love.run()
test.update_window(width, height)
local time = love.timer.getTime()
--update(time)
test.update(time)
local dt = last_time - time
last_time = time
love_update(dt)
update(time)
love_draw()
draw()
local mouse_down = love.mouse.isDown(1)
@ -286,3 +221,45 @@ 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

View File

@ -1,6 +1,5 @@
#include "font/bitmap.h"
#include "pixel_line_art.h"
#include "view.h"
#include "lua_api.h"
@ -44,14 +43,3 @@ 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;
}

View File

@ -269,7 +269,7 @@ namespace minecraft {
continue;
per_world::load_world(&world::descriptors[i], world_state[i]);
}
current_world = &world_state[world::world_id::GRANDLECTURN];
current_world = &world_state[world::world_id::MIDNIGHTMEADOW];
}
static inline int popcount(int x)

View File

@ -325,7 +325,7 @@ void update_joystick(int joystick_index,
delta_yaw, delta_pitch);
view::apply_fov(0.01 * up + -0.01 * down);
if (false) {
if (true) {
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)

View File

@ -32,12 +32,12 @@ namespace view {
return pitch;
}
XMVECTOR get_normal()
static inline XMVECTOR get_normal()
{
return XMVector3NormalizeEst(XMVector3Cross(state.forward, state.up));
}
XMVECTOR get_direction()
static inline XMVECTOR get_direction()
{
XMMATRIX mrn = XMMatrixRotationAxis(state.normal, state.pitch);
return XMVector3Transform(state.forward, mrn);
@ -106,13 +106,11 @@ 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);
}