carpy-breakout/pkg/breakout/sidewalls.go

50 lines
1.3 KiB
Go

package breakout
import (
"git.wisellama.rocks/Wisellama/carpy-breakout/pkg/globject"
"github.com/go-gl/mathgl/mgl32"
)
type SideWalls struct {
Boxes []*globject.Box
}
func NewSideWalls(aabb *globject.AABB, material *globject.Material) *SideWalls {
topRight := aabb.TopRight
bottomLeft := aabb.BottomLeft
var depth float32 = 6.0
var height float32 = 4.0
var offset float32 = height / 2.0
boxes := make([]*globject.Box, 4)
// Top
topPos := mgl32.Vec3{0, topRight.Y() + offset, topRight.Z()}
boxes[0] = globject.NewBox(topRight.X()-bottomLeft.X()+height*2, height, depth, topPos, material)
// Bottom
bottomPos := mgl32.Vec3{0, bottomLeft.Y() - offset, bottomLeft.Z()}
boxes[1] = globject.NewBox(topRight.X()-bottomLeft.X()+height*2, height, depth, bottomPos, material)
// Left
leftPos := mgl32.Vec3{bottomLeft.X() - offset, 0, bottomLeft.Z()}
boxes[2] = globject.NewBox(height, topRight.Y()-bottomLeft.Y(), depth, leftPos, material)
// Right
rightPos := mgl32.Vec3{topRight.X() + offset, 0, topRight.Z()}
boxes[3] = globject.NewBox(height, topRight.Y()-bottomLeft.Y(), depth, rightPos, material)
sideWalls := SideWalls{
Boxes: boxes,
}
return &sideWalls
}
func (self *SideWalls) GLInit(glProgram uint32) {
for _, box := range self.Boxes {
box.GLInit(glProgram)
}
}