Lua - 相机移动,计算Z
Lua - Camera movement, calculating Z
我遇到一道数学题,我无法通过。
我正在 Lua 中制作一个模型浏览器,其中鼠标移动与相机位置挂钩,相机位置有 2 种模式:固定和自由,自由工作完美,而固定似乎无法计算正确的 Z .
X 和 Y 计算正确并且没有任何问题,但 Z 似乎与 X、Y 的比例关系太大,如此处所示:http://puu.sh/oTN1v/5846343f82.webm(每当我单击鼠标右键时,这些相机扭曲都会发生,即使我不移动鼠标也会发生这种情况)
function self:RightMouseClick()
local cx, cy = mousepos()
local radius = math.sqrt( math.pow( campos.x, 2 ) + math.pow( campos.y, 2 ) )
local ang = ( camorigin - campos ):Angle()
function self:Think()
if input.IsMouseDown( MOUSE_RIGHT ) then
local x = camorigin.x + radius * math.cos( math.rad( 1 ) * ( 180 + ang.yaw + ( cx - mousex() ) * 0.5 ) )
local y = camorigin.y + radius * math.sin( math.rad( 1 ) * ( 180 + ang.yaw + ( cx - mousex() ) * 0.5 ) )
local z = camorigin.z + radius * math.sin( math.rad( 1 ) * ( ang.pitch + ( cy - mousey() ) * 0.5 ) )
campos = Vector( x, y, z )
end
end
结束
@编辑:如果你不知道这段代码是什么意思,你不妨告诉我如何正确计算相机绕轴移动的 Z
已从 x、y、z 的计算中删除 camorigin。
我遇到一道数学题,我无法通过。
我正在 Lua 中制作一个模型浏览器,其中鼠标移动与相机位置挂钩,相机位置有 2 种模式:固定和自由,自由工作完美,而固定似乎无法计算正确的 Z .
X 和 Y 计算正确并且没有任何问题,但 Z 似乎与 X、Y 的比例关系太大,如此处所示:http://puu.sh/oTN1v/5846343f82.webm(每当我单击鼠标右键时,这些相机扭曲都会发生,即使我不移动鼠标也会发生这种情况)
function self:RightMouseClick()
local cx, cy = mousepos()
local radius = math.sqrt( math.pow( campos.x, 2 ) + math.pow( campos.y, 2 ) )
local ang = ( camorigin - campos ):Angle()
function self:Think()
if input.IsMouseDown( MOUSE_RIGHT ) then
local x = camorigin.x + radius * math.cos( math.rad( 1 ) * ( 180 + ang.yaw + ( cx - mousex() ) * 0.5 ) )
local y = camorigin.y + radius * math.sin( math.rad( 1 ) * ( 180 + ang.yaw + ( cx - mousex() ) * 0.5 ) )
local z = camorigin.z + radius * math.sin( math.rad( 1 ) * ( ang.pitch + ( cy - mousey() ) * 0.5 ) )
campos = Vector( x, y, z )
end
end
结束
@编辑:如果你不知道这段代码是什么意思,你不妨告诉我如何正确计算相机绕轴移动的 Z
已从 x、y、z 的计算中删除 camorigin。