func (polyline *polyLine) render(coords []float32) { var sleeve, current, next mgl32.Vec2 polyline.vertices = []mgl32.Vec2{} polyline.normals = []mgl32.Vec2{} coords_count := len(coords) is_looping := (coords[0] == coords[coords_count-2]) && (coords[1] == coords[coords_count-1]) if !is_looping { // virtual starting point at second point mirrored on first point sleeve = mgl32.Vec2{coords[2] - coords[0], coords[3] - coords[1]} } else { // virtual starting point at last vertex sleeve = mgl32.Vec2{coords[0] - coords[coords_count-4], coords[1] - coords[coords_count-3]} } for i := 0; i+3 < coords_count; i += 2 { current = mgl32.Vec2{coords[i], coords[i+1]} next = mgl32.Vec2{coords[i+2], coords[i+3]} polyline.renderEdge(sleeve, current, next) sleeve = next.Sub(current) } if is_looping { polyline.renderEdge(sleeve, next, mgl32.Vec2{coords[2], coords[3]}) } else { polyline.renderEdge(sleeve, next, next.Add(sleeve)) } if polyline.join == LINE_JOIN_NONE { polyline.vertices = polyline.vertices[2 : len(polyline.vertices)-2] } polyline.draw(is_looping) }
func (ai *AI) getPseudoMe() *agario.Cell { firstCell := ai.OwnCells[0] me := &agario.Cell{ ID: firstCell.ID, Name: firstCell.Name, Heading: firstCell.Heading, Color: firstCell.Color, IsVirus: firstCell.IsVirus, } var avgPosition mgl32.Vec2 for _, cell := range ai.OwnCells { me.Size += cell.Size if avgPosition.X() == 0 && avgPosition.Y() == 0 { avgPosition = cell.Position continue } avgPosition = avgPosition.Add(cell.Position) } n := float32(len(ai.OwnCells)) avgPosition[0] = avgPosition[0] / n avgPosition[1] = avgPosition[1] / n me.Position = avgPosition return me }
func tween(a, b mgl32.Vec2) (x, y float32) { v := b.Sub(a) v = v.Mul(0.5) v = a.Add(v) return v.Elem() }
func computeMiter(lineA, lineB mgl32.Vec2, halfThick float32) (miter mgl32.Vec2, length float32) { var ( tangent mgl32.Vec2 tmp mgl32.Vec2 ) tangent = lineA.Add(lineB).Normalize() miter = mgl32.Vec2{-tangent[1], tangent[0]} tmp = mgl32.Vec2{-lineA[1], lineA[0]} length = halfThick / miter.Dot(tmp) return }
func makeTriangle(n mesh.Number, d float32, o mgl32.Vec2) mesh.Mesh { return mesh.Mesh{ Nmbr: n, Dpth: d, Vrts: []mgl32.Vec2{ o.Add(mgl32.Vec2{0, 0}), o.Add(mgl32.Vec2{0, 100}), o.Add(mgl32.Vec2{100, 100}), }, Clrs: []mgl32.Vec4{ {0.7, 1.0, 0.0, 0.7}, }, Trngls: []mesh.Triangle{ {Vnd: mesh.Nd{0, 1, 2}}, }, } }
func (polyline *polyLine) generateEdges(current mgl32.Vec2, count int) { normal_count := len(polyline.normals) for i := count; i > 0; i-- { polyline.vertices = append(polyline.vertices, current.Add(polyline.normals[normal_count-i])) } }