* Fix camera direction

This commit is contained in:
Nils Dagsson Moskopp 2023-11-08 19:57:29 +01:00
parent dbf260c48d
commit 7b2eb59f79
Signed by: erlehmann
GPG Key ID: A3BC671C35191080
1 changed files with 16 additions and 21 deletions

View File

@ -46,11 +46,11 @@ local get_light = function( position )
end
local get_fog = function( distance )
return clamp( math.pow ( distance / 64, 2 ), 0, 1 )
return clamp( math.pow ( distance / 128, 2 ), 0, 1 )
end
local shade = function( origin, direction, background_color )
local ray = minetest.raycast( origin, direction, false, true )
local shade = function( origin, target, background_color )
local ray = minetest.raycast( origin, target, false, true )
local color
for pointed_thing in ray do
if "node" == pointed_thing.type then
@ -81,37 +81,32 @@ local create_photo_pixels = function( player_name )
local eye = girl:get_pos() + girl:get_eye_offset() / 10
eye.y = eye.y + girl:get_properties().eye_height
local dir = girl:get_look_dir()
local gaze = vector.normalize( girl:get_look_dir() ) + eye * -1
local down = vector.new({ x=0, y=-1, z=0 }) * 4
local right = vector.normalize( gaze:cross( down ) ) * -4
local corner = gaze + ( right + down ) * width / 2
local right = vector.normalize(
vector.new( { x=dir.z, y=dir.y, z=-dir.x } )
)
local down = vector.normalize(
dir:cross( right )
)
local corner = eye + dir + ( right + down )
local bg = 127
local pixels = {}
for h = 1,height,1 do
local y = h - 1
local y = height - ( h - 1 )
pixels[h] = {}
for w = 1,width,1 do
local x = w - 1
local x = width - ( w - 1 )
local samples = 4 -- can be up to 9
local acc_color = 0
for sample = 1,samples,1 do
local x_offset = x_offset_by_sample[sample] * 0.2
local y_offset = y_offset_by_sample[sample] * 0.2
local lens = (
right * x_offset +
down * y_offset
) * 99
-- TODO: why does this point towards ( 0, 0, 0 )?
local direction = (
gaze +
right * ( width/2 - x + x_offset ) +
down * ( height/2 - y + y_offset )
)
local color = shade(
eye,
direction,
bg
)
) * 2
local pos1 = eye
local pos2 = eye + lens + ( dir * 128 )
local color = shade( pos1, pos2, bg )
if nil == color then -- probably the sky
color = 191 - math.floor ( y / 2 )
end