carpy-breakout/pkg/breakout/bounding_box.go

81 lines
1.7 KiB
Go

package breakout
import (
"github.com/go-gl/mathgl/mgl32"
"gitea.wisellama.rocks/Wisellama/carpy-breakout/pkg/gl_objects"
)
type BoundingBox struct {
Boxes []*gl_objects.Box
}
func NewBoundingBox(lowerLeft, topRight mgl32.Vec3, material gl_objects.Material) *BoundingBox {
var brickWidth float32 = 4.0
var brickHeight float32 = 1.0
var brickDepth float32 = 4.0
var widthOffset float32 = 0.5
var heightOffset float32 = 1
bw := brickWidth + widthOffset
bh := brickHeight + heightOffset
lowerLeftPos := mgl32.Vec3{
bw/2 - float32(numColumns)*(bw)/2,
bh/2 - float32(numRows)*(bh)/2,
0,
}
lowerLeftPos = lowerLeftPos.Add(adjustPos)
topRightPos := mgl32.Vec3{
bw/2 + float32(numColumns)*(bw)/2,
bh/2 + float32(numRows)*(bh)/2,
0,
}
topRightPos = topRightPos.Add(adjustPos)
targets.TopRight = topRightPos
targets.LowerLeft = lowerLeftPos
materials := make([]*gl_objects.Material, numColumns)
for i := 0; i < numColumns; i++ {
red := 0 + float32(i)/float32(numColumns)
blue := 1 - float32(i)/float32(numColumns)
m := gl_objects.NewMaterial()
m.Color = mgl32.Vec4{red, 0, blue, 1}
materials[i] = m
}
n := 0
for i := 0; i < numRows; i++ {
for j := 0; j < numColumns; j++ {
position := lowerLeftPos.Add(mgl32.Vec3{
float32(j) * bw,
float32(i) * bh,
0})
targets.Bricks[n] = NewBrick(brickWidth, brickHeight, brickDepth, position, materials[i])
n++
}
}
boundingBox := BoundingBox{
Boxes: boxes,
}
return &boundingBox
}
func (t *BoundingBox) GLInit(glProgram uint32) {
for _, brick := range t.Bricks {
brick.GLInit(glProgram)
}
}
func (t *BoundingBox) GLDraw() {
for _, brick := range t.Bricks {
brick.GLDraw()
}
}