Skip to content

Commit ad736ff

Browse files
committed
Model now automatically updates view and projection matrices
1 parent 3e54a20 commit ad736ff

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

g3d/camera.lua

+3-18
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,18 @@ function camera.lookInDirection(x,y,z, directionTowards,pitchTowards)
9191
end
9292

9393
-- recreate the camera's view matrix from its current values
94-
-- and send the matrix to the shader specified, or the default shader
95-
function camera.updateViewMatrix(shaderGiven)
96-
local shader = shaderGiven or g3d.shader
94+
function camera.updateViewMatrix()
9795
camera.viewMatrix:setViewMatrix(camera.position, camera.target, camera.up)
98-
shader:send("viewMatrix", camera.viewMatrix)
9996
end
10097

10198
-- recreate the camera's projection matrix from its current values
102-
-- and send the matrix to the shader specified, or the default shader
103-
function camera.updateProjectionMatrix(shaderGiven)
104-
local shader = shaderGiven or g3d.shader
99+
function camera.updateProjectionMatrix()
105100
camera.projectionMatrix:setProjectionMatrix(camera.fov, camera.nearClip, camera.farClip, camera.aspectRatio)
106-
shader:send("projectionMatrix", camera.projectionMatrix)
107101
end
108102

109103
-- recreate the camera's orthographic projection matrix from its current values
110-
-- and send the matrix to the shader specified, or the default shader
111-
function camera.updateOrthographicMatrix(shaderGiven, size)
112-
local shader = shaderGiven or g3d.shader
104+
function camera.updateOrthographicMatrix(size)
113105
camera.projectionMatrix:setOrthographicMatrix(camera.fov, size or 5, camera.nearClip, camera.farClip, camera.aspectRatio)
114-
shader:send("projectionMatrix", camera.projectionMatrix)
115-
end
116-
117-
-- sends the camera's view and projection matrices to the given shader
118-
function camera.sendMatricesToShader(shader)
119-
shader:send("viewMatrix", camera.viewMatrix)
120-
shader:send("projectionMatrix", camera.projectionMatrix)
121106
end
122107

123108
-- simple first person camera movement with WASD

g3d/model.lua

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local newMatrix = require(g3d.path .. "/matrices")
66
local loadObjFile = require(g3d.path .. "/objloader")
77
local collisions = require(g3d.path .. "/collisions")
88
local vectors = require(g3d.path .. "/vectors")
9+
local camera = require(g3d.path .. "/camera")
910
local vectorCrossProduct = vectors.crossProduct
1011
local vectorNormalize = vectors.normalize
1112

@@ -144,6 +145,8 @@ function model:draw(shader)
144145
local shader = shader or self.shader
145146
love.graphics.setShader(shader)
146147
shader:send("modelMatrix", self.matrix)
148+
shader:send("viewMatrix", camera.viewMatrix)
149+
shader:send("projectionMatrix", camera.projectionMatrix)
147150
if shader:hasUniform "isCanvasEnabled" then
148151
shader:send("isCanvasEnabled", love.graphics.getCanvas() ~= nil)
149152
end

0 commit comments

Comments
 (0)