Property definitions

gamnit $ ParallelLightCamera :: defaultinit
private class ParallelLightCamera
	super Camera

	var light: ParallelLight

	# Rotation matrix produced by the current rotation of the camera
	fun rotation_matrix: Matrix
	do
		var view = new Matrix.identity(4)
		view.rotate(light.yaw,   0.0, 1.0, 0.0)
		view.rotate(light.pitch, 1.0, 0.0, 0.0)
		return view
	end

	private fun create_mvp_matrix: Matrix
	do
		var near = -light.depth/2.0
		var far = light.depth/2.0

		var view = new Matrix.identity(4)
		view.translate(-position.x, -position.y, -position.z)
		view = view * rotation_matrix
		var projection = new Matrix.orthogonal(-light.width/2.0, light.width/2.0,
		                                       -light.height/2.0, light.height/2.0,
		                                       near, far)
		return view * projection
	end

	redef fun mvp_matrix
	do
		var m = mvp_matrix_cache
		if m == null or check_position_changed then
			m = create_mvp_matrix
			mvp_matrix_cache = m
		end
		return m
	end

	private var pitch_cache = 0.0
	private var yaw_cache = 0.0
	private var width_cache = 0.0
	private var height_cache = 0.0
	private var depth_cache = 0.0

	redef fun check_position_changed
	do
		if super then return true

		if light.pitch != pitch_cache or
		   light.yaw != yaw_cache or
		   light.width != width_cache or
		   light.height != height_cache or
		   light.depth != depth_cache then
			pitch_cache = light.pitch
			yaw_cache = light.yaw
			width_cache = light.width
			height_cache = light.height
			depth_cache = light.depth
			return true
		end

		return false
	end
end
lib/gamnit/depth/more_lights.nit:47,1--110,3