backport imgui goodies from gl02

This commit is contained in:
2022-01-24 22:40:53 +08:00
parent 74283d7147
commit 13649fad18
7 changed files with 425 additions and 106 deletions

View File

@ -49,6 +49,33 @@ func (v Vec4i) MultiplyInt(mult int) Vec4i {
// Vec2f is a two-element float vector
type Vec2f [2]float32
func (v Vec2f) Add(add Vec2f) Vec2f {
return Vec2f{v[0] + add[0], v[1] + add[1]}
}
func (v Vec2f) Addv(x, y float32) Vec2f {
return Vec2f{v[0] + x, v[1] + y}
}
func (v Vec2f) Floor() Vec2i {
return Vec2i{
int(math.Floor(float64(v[0]))),
int(math.Floor(float64(v[1]))),
}
}
func (v Vec2f) Length() float32 {
return float32(math.Sqrt(float64(v[0]*v[0] + v[1]*v[1])))
}
func (v Vec2f) Normalize() Vec2f {
l := v.Length()
return Vec2f{v[0] / l, v[1] / l}
}
func (v Vec2f) ToFloat64() Vec2d {
return Vec2d{float64(v[0]), float64(v[1])}
}
// Vec3f is a three-element float vector
type Vec3f [3]float32
@ -91,6 +118,37 @@ type Vec4f [4]float32
// Vec2d is a two-element float64 vector
type Vec2d [2]float64
func (v Vec2d) Add(add Vec2d) Vec2d {
return Vec2d{v[0] + add[0], v[1] + add[1]}
}
func (v Vec2d) Addv(x, y float64) Vec2d {
return Vec2d{v[0] + x, v[1] + y}
}
func (v Vec2d) Multiply(x float64) Vec2d {
return Vec2d{v[0] * x, v[1] * x}
}
func (v Vec2d) Floor() Vec2i {
return Vec2i{
int(math.Floor(float64(v[0]))),
int(math.Floor(float64(v[1]))),
}
}
func (v Vec2d) Length() float64 {
return math.Sqrt(v[0]*v[0] + v[1]*v[1])
}
func (v Vec2d) Normalize() Vec2d {
l := v.Length()
return Vec2d{v[0] / l, v[1] / l}
}
func (v Vec2d) ToFloat32() Vec2f {
return Vec2f{float32(v[0]), float32(v[1])}
}
// Vec3d is a three-element float64 vector
type Vec3d [3]float64