mirror of
https://github.com/bloeys/gglm.git
synced 2025-12-29 05:28:20 +00:00
Add Ortho func
This commit is contained in:
@ -117,6 +117,7 @@ func LookAt(pos, targetPos, worldUp *Vec3) *TrMat {
|
||||
}
|
||||
}
|
||||
|
||||
//Perspective creates a perspective projection matrix
|
||||
func Perspective(fov, aspectRatio, nearClip, farClip float32) *Mat4 {
|
||||
halfFovTan := float32(math.Tan(float64(fov * 0.5)))
|
||||
return &Mat4{
|
||||
@ -129,6 +130,20 @@ func Perspective(fov, aspectRatio, nearClip, farClip float32) *Mat4 {
|
||||
}
|
||||
}
|
||||
|
||||
//Perspective creates an orthographic projection matrix
|
||||
func Ortho(left, right, top, bottom, nearClip, farClip float32) *TrMat {
|
||||
return &TrMat{
|
||||
Mat4: Mat4{
|
||||
Data: [4][4]float32{
|
||||
{2 / (right - left), 0, 0, 0},
|
||||
{0, 2 / (top - bottom), 0, 0},
|
||||
{0, 0, -2 / (farClip - nearClip), 0},
|
||||
{-(right + left) / (right - left), -(top + bottom) / (top - bottom), -(farClip + nearClip) / (farClip - nearClip), 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrMatId() *TrMat {
|
||||
return &TrMat{
|
||||
Mat4: *NewMat4Id(),
|
||||
|
||||
Reference in New Issue
Block a user