mirror of
https://github.com/bloeys/gglm.git
synced 2025-12-29 13:38:20 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 300c699e65 | |||
| 175d05420c |
@ -2,6 +2,7 @@ package gglm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
var _ Mat = &TrMat{}
|
||||
@ -110,7 +111,34 @@ func LookAt(pos, targetPos, worldUp *Vec3) *TrMat {
|
||||
{right.Data[0], up.Data[0], forward.Data[0], 0},
|
||||
{right.Data[1], up.Data[1], forward.Data[1], 0},
|
||||
{right.Data[2], up.Data[2], forward.Data[2], 0},
|
||||
{-DotVec3(pos, right), -DotVec3(pos, up), -DotVec3(pos, forward), 1},
|
||||
{-DotVec3(pos, right), -DotVec3(pos, up), DotVec3(pos, forward), 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//Perspective creates a perspective projection matrix
|
||||
func Perspective(fov, aspectRatio, nearClip, farClip float32) *Mat4 {
|
||||
halfFovTan := float32(math.Tan(float64(fov * 0.5)))
|
||||
return &Mat4{
|
||||
Data: [4][4]float32{
|
||||
{1 / (aspectRatio * halfFovTan), 0, 0, 0},
|
||||
{0, 1 / halfFovTan, 0, 0},
|
||||
{0, 0, -(nearClip + farClip) / (farClip - nearClip), -1},
|
||||
{0, 0, -(2 * farClip * nearClip) / (farClip - nearClip), 0},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//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},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user