Exemple #1
0
func (p *PerspectiveCamera) UpdateProjectionMatrix() {

	var fov = math3d.RadToDeg(2 * math.Atan(math.Tan(math3d.DegToRad(p.Fov)*0.5)/p.Zoom))

	if p.FullWidth > 0 {

		var aspect = p.FullWidth / p.FullHeight
		var top = math.Tan(math3d.DegToRad(fov*0.5)) * p.Near
		var bottom = -top
		var left = aspect * bottom
		var right = aspect * top
		var width = math.Abs(right - left)
		var height = math.Abs(top - bottom)

		p.ProjectionMatrix.MakeFrustum(
			left+p.X*width/p.FullWidth,
			left+(p.X+p.Width)*width/p.FullWidth,
			top-(p.Y+p.Height)*height/p.FullHeight,
			top-p.Y*height/p.FullHeight,
			p.Near,
			p.Far,
		)
	} else {
		p.ProjectionMatrix.MakePerspective(fov, p.Aspect, p.Near, p.Far)
	}
}
Exemple #2
0
/**
 * Uses Focal Length (in mm) to estimate and set FOV
 * 35mm (full-frame) camera is used if frame size is not specified;
 * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
 */
func (p *PerspectiveCamera) SetLens(focalLength, frameHeight float64) {
	if frameHeight == -1 {
		frameHeight = 24.0
	}

	p.Fov = 2 * math3d.RadToDeg(math.Atan(frameHeight/(focalLength*2)))
	p.UpdateProjectionMatrix()
}