GetMouseOffset and GetMouseScale.

This commit is contained in:
jussi
2024-07-02 20:49:25 +03:00
parent fd18b5526e
commit 61c932f260
16 changed files with 121 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
local Vec2 = require( "vector2" )
local Vec3 = require( "vector3" )
local Vector2 = Vector2 or require( "vector2" )
local Vector3 = Vector3 or require( "vector3" )
Camera3D = {}
Camera3D.meta = {
@@ -62,15 +62,15 @@ function Camera3D:setProjection( projection )
end
function Camera3D:getPosition()
return Vec3:newT( RL.GetCamera3DPosition( self.camera ) )
return Vector3:newT( RL.GetCamera3DPosition( self.camera ) )
end
function Camera3D:getTarget()
return Vec3:newT( RL.GetCamera3DTarget( self.camera ) )
return Vector3:newT( RL.GetCamera3DTarget( self.camera ) )
end
function Camera3D:getUp()
return Vec3:newT( RL.GetCamera3DUp( self.camera ) )
return Vector3:newT( RL.GetCamera3DUp( self.camera ) )
end
function Camera3D:getFoyv()
@@ -83,12 +83,12 @@ end
--- Returns the cameras forward vector ( normalized )
function Camera3D:getForward()
return Vec3:newT( RL.GetCamera3DForward( self.camera ) )
return Vector3:newT( RL.GetCamera3DForward( self.camera ) )
end
--- Returns the cameras up vector ( normalized ) Note: The up vector might not be perpendicular to the forward vector
function Camera3D:getUpward()
return Vec3:newT( RL.GetCamera3DUpNormalized( self.camera ) )
return Vector3:newT( RL.GetCamera3DUpNormalized( self.camera ) )
end
function Camera3D:update( delta )
@@ -96,7 +96,7 @@ function Camera3D:update( delta )
if self.mode == self.MODES.FREE then
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then
local mouseDelta = Vec2:newT( RL.GetMouseDelta() )
local mouseDelta = Vector2:newT( RL.GetMouseDelta() )
if RL.IsKeyDown( self.KEYS.PAN ) then
mouseDelta = mouseDelta:scale( self.MOUSE_MOVE_SPEED * delta )
@@ -119,13 +119,13 @@ function Camera3D:update( delta )
RL.Camera3DMoveToTarget( self.camera, self.ZOOM_AMOUNT * self:getTargetDistance() * -mouseScroll )
end
elseif self.mode == self.MODES.FIRST_PERSON then
local mouseDelta = Vec2:newT( RL.GetMouseDelta() )
local mouseDelta = Vector2:newT( RL.GetMouseDelta() )
mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta )
RL.Camera3DYaw( self.camera, -mouseDelta.x, false )
RL.Camera3DPitch( self.camera, -mouseDelta.y, false, false, false )
RL.SetMousePosition( Vec2:newT( RL.GetScreenSize() ):scale( 0.5 ) )
RL.SetMousePosition( Vector2:newT( RL.GetScreenSize() ):scale( 0.5 ) )
local distance = self.KEYBOARD_MOVE_SPEED * delta
local forward = RL.GetCamera3DForward( self.camera )[2]
@@ -162,9 +162,9 @@ end
function Camera3D:draw()
local targetPos = self:getTarget()
RL.DrawLine3D( targetPos + Vec3:new( -0.5, 0, 0 ), targetPos + Vec3:new( 0.5, 0, 0 ), RL.GREEN )
RL.DrawLine3D( targetPos + Vec3:new( 0, -0.5, 0 ), targetPos + Vec3:new( 0, 0.5, 0 ), RL.BLUE )
RL.DrawLine3D( targetPos + Vec3:new( 0, 0, -0.5 ), targetPos + Vec3:new( 0, 0, 0.5 ), RL.RED )
RL.DrawLine3D( targetPos + Vector3:new( -0.5, 0, 0 ), targetPos + Vector3:new( 0.5, 0, 0 ), RL.GREEN )
RL.DrawLine3D( targetPos + Vector3:new( 0, -0.5, 0 ), targetPos + Vector3:new( 0, 0.5, 0 ), RL.BLUE )
RL.DrawLine3D( targetPos + Vector3:new( 0, 0, -0.5 ), targetPos + Vector3:new( 0, 0, 0.5 ), RL.RED )
end
function Camera3D:getTargetDistance()