* Fix camera direction
This commit is contained in:
parent
dbf260c48d
commit
7b2eb59f79
37
init.lua
37
init.lua
|
@ -46,11 +46,11 @@ local get_light = function( position )
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_fog = function( distance )
|
local get_fog = function( distance )
|
||||||
return clamp( math.pow ( distance / 64, 2 ), 0, 1 )
|
return clamp( math.pow ( distance / 128, 2 ), 0, 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
local shade = function( origin, direction, background_color )
|
local shade = function( origin, target, background_color )
|
||||||
local ray = minetest.raycast( origin, direction, false, true )
|
local ray = minetest.raycast( origin, target, false, true )
|
||||||
local color
|
local color
|
||||||
for pointed_thing in ray do
|
for pointed_thing in ray do
|
||||||
if "node" == pointed_thing.type then
|
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
|
local eye = girl:get_pos() + girl:get_eye_offset() / 10
|
||||||
eye.y = eye.y + girl:get_properties().eye_height
|
eye.y = eye.y + girl:get_properties().eye_height
|
||||||
local dir = girl:get_look_dir()
|
local dir = girl:get_look_dir()
|
||||||
local gaze = vector.normalize( girl:get_look_dir() ) + eye * -1
|
local right = vector.normalize(
|
||||||
local down = vector.new({ x=0, y=-1, z=0 }) * 4
|
vector.new( { x=dir.z, y=dir.y, z=-dir.x } )
|
||||||
local right = vector.normalize( gaze:cross( down ) ) * -4
|
)
|
||||||
local corner = gaze + ( right + down ) * width / 2
|
local down = vector.normalize(
|
||||||
|
dir:cross( right )
|
||||||
|
)
|
||||||
|
local corner = eye + dir + ( right + down )
|
||||||
local bg = 127
|
local bg = 127
|
||||||
local pixels = {}
|
local pixels = {}
|
||||||
for h = 1,height,1 do
|
for h = 1,height,1 do
|
||||||
local y = h - 1
|
local y = height - ( h - 1 )
|
||||||
pixels[h] = {}
|
pixels[h] = {}
|
||||||
for w = 1,width,1 do
|
for w = 1,width,1 do
|
||||||
local x = w - 1
|
local x = width - ( w - 1 )
|
||||||
local samples = 4 -- can be up to 9
|
local samples = 4 -- can be up to 9
|
||||||
local acc_color = 0
|
local acc_color = 0
|
||||||
for sample = 1,samples,1 do
|
for sample = 1,samples,1 do
|
||||||
local x_offset = x_offset_by_sample[sample] * 0.2
|
local x_offset = x_offset_by_sample[sample] * 0.2
|
||||||
local y_offset = y_offset_by_sample[sample] * 0.2
|
local y_offset = y_offset_by_sample[sample] * 0.2
|
||||||
local lens = (
|
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 ) +
|
right * ( width/2 - x + x_offset ) +
|
||||||
down * ( height/2 - y + y_offset )
|
down * ( height/2 - y + y_offset )
|
||||||
)
|
) * 2
|
||||||
local color = shade(
|
local pos1 = eye
|
||||||
eye,
|
local pos2 = eye + lens + ( dir * 128 )
|
||||||
direction,
|
local color = shade( pos1, pos2, bg )
|
||||||
bg
|
|
||||||
)
|
|
||||||
if nil == color then -- probably the sky
|
if nil == color then -- probably the sky
|
||||||
color = 191 - math.floor ( y / 2 )
|
color = 191 - math.floor ( y / 2 )
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue