use line points from eye position

This commit is contained in:
Zack Buhman 2026-03-09 23:24:34 -05:00
parent 175bf4a397
commit 91d86a4f85
4 changed files with 50 additions and 16 deletions

View File

@ -9,7 +9,8 @@ extern "C" {
void kb_update(int up, int down, int left, int right);
void update(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 a, int b, int x, int y,
int leftshoulder, int rightshoulder);
#ifdef __cplusplus
}

View File

@ -11,7 +11,8 @@ void draw();
void kb_update(int kbup, int kbdown, int kbleft, int kbright);
void update(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 a, int b, int x, int y,
int leftshoulder, int rightshoulder);
]]
local source_path = love.filesystem.getSource()
test = ffi.load(source_path .. "/test.so")
@ -35,10 +36,13 @@ local update = function(dt)
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")
test.update(lx, ly, rx, ry, tl, tr,
up, down, left, right,
a, b, x, y)
a, b, x, y,
leftshoulder, rightshoulder)
end
local up = love.keyboard.isDown("up")

View File

@ -32,9 +32,12 @@ void main()
//float attenuation = 1.0 / (1.0 + Linear * light_distance + Quadratic * light_distance * light_distance);
float attenuation = 1.0 / (1.0 + Quadratic * light_distance * light_distance);
out_color += color.xyz * attenuation * diffuse;
//out_color += color.xyz * attenuation * diffuse;
//out_color = vec3(diffuse);
}
vec3 light_direction = normalize(Eye.xyz - position.xyz);
float diffuse = max(dot(normal.xyz, light_direction), 0.0);
out_color = color.xyz * diffuse;
Color = vec4(out_color, 1.0);
}

View File

@ -470,7 +470,7 @@ static_assert((sizeof (short_point)) == 6);
short_point line_points[128];
static int line_point_ix = 0;
void line_point(int x, int y, int z)
void append_line_point(int x, int y, int z)
{
if (line_point_ix >= 128)
return;
@ -543,22 +543,38 @@ void load_line_instance_buffer()
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
struct line_state {
struct {
int x;
int y;
int z;
} point[2];
};
static line_state line_state = {};
void load_line()
{
int x1 = -55;
int z1 = 48;
int y1 = 50;
int x2 = -60;
int z2 = 55;
int y2 = 53;
line_point_ix = 0;
bresenham(x1, y1, z1, x2, y2, z2, line_point);
bresenham(line_state.point[0].x, line_state.point[0].y, line_state.point[0].z,
line_state.point[1].x, line_state.point[1].y, line_state.point[1].z,
append_line_point);
load_line_instance_buffer();
}
void load_line_point_from_eye(int point_ix)
{
int x = XMVectorGetX(view_state.eye);
int y = XMVectorGetY(view_state.eye);
int z = XMVectorGetZ(view_state.eye);
line_state.point[point_ix].x = x;
line_state.point[point_ix].y = z;
line_state.point[point_ix].z = y;
load_line();
}
void load(const char * source_path)
{
g_source_path_length = strlen(source_path);
@ -612,7 +628,6 @@ void load(const char * source_path)
load_line_vertex_attributes();
glGenBuffers(1, &line_instance_buffer);
load_line();
}
float _ry = 0.0;
@ -635,7 +650,8 @@ void kb_update(int up, int down, int left, int right)
void update(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 a, int b, int x, int y,
int leftshoulder, int rightshoulder)
{
//view_state.yaw += rx;
XMMATRIX mrz = XMMatrixRotationZ(rx * -0.035);
@ -662,6 +678,13 @@ void update(float lx, float ly, float rx, float ry, float tl, float tr,
lighting.linear += 0.01 * x + -0.01 * y;
if (lighting.linear < 0.0f)
lighting.linear = 0.0f;
if (leftshoulder) {
load_line_point_from_eye(0);
}
if (rightshoulder) {
load_line_point_from_eye(1);
}
}
static inline int popcount(int x)
@ -860,6 +883,9 @@ void draw_lighting()
void draw_line()
{
if (line_point_ix == 0)
return;
glUseProgram(line_program);
glBlendFunc(GL_ONE, GL_ZERO);