当前位置: 首页>>代码示例>>Golang>>正文


Golang Vec2.Add方法代码示例

本文整理汇总了Golang中github.com/go-gl/mathgl/mgl32.Vec2.Add方法的典型用法代码示例。如果您正苦于以下问题:Golang Vec2.Add方法的具体用法?Golang Vec2.Add怎么用?Golang Vec2.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/go-gl/mathgl/mgl32.Vec2的用法示例。


在下文中一共展示了Vec2.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: render

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)
}
开发者ID:tanema,项目名称:amore,代码行数:32,代码来源:polyline.go

示例2: getPseudoMe

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
}
开发者ID:chendrak,项目名称:agariobot,代码行数:31,代码来源:ai.go

示例3: tween

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()
}
开发者ID:philetus,项目名称:flyspek,代码行数:7,代码来源:beetle_example.go

示例4: computeMiter

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
}
开发者ID:pikkpoiss,项目名称:twodee,代码行数:11,代码来源:lines.go

示例5: makeTriangle

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}},
		},
	}
}
开发者ID:philetus,项目名称:flyspek,代码行数:17,代码来源:mesh_example.go

示例6: generateEdges

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]))
	}
}
开发者ID:tanema,项目名称:amore,代码行数:6,代码来源:polyline.go


注:本文中的github.com/go-gl/mathgl/mgl32.Vec2.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。