• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang mgl32.Vec2类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: mouseClick

func (c *Container) mouseClick(button int, release bool, position mgl32.Vec2) {
	offsetPos := position.Sub(c.offset)
	c.Hitbox.MouseClick(button, release, offsetPos.Sub(c.backgroundOffset))
	for _, child := range c.children {
		child.mouseClick(button, release, offsetPos.Sub(c.elementsOffset))
	}
}
开发者ID:walesey,项目名称:go-engine,代码行数:7,代码来源:container.go


示例3: makeDot

func makeDot(v mgl32.Vec2, a float32, i int, clr mgl32.Vec4) mesh.Mesh {
	m := mesh.Mesh{
		Nmbr: mesh.Number(i),
		Dpth: 0.5,
		Vrts: []mgl32.Vec2{
			{-dotx, 0}, // 0
			{0, -doty}, // 1
			{dotx, 0},  // 2
			{0, doty},  // 3
		},
		Clrs: []mgl32.Vec4{
			clr,
		},
		Trngls: []mesh.Triangle{
			{
				Vnd:  mesh.Nd{0, 1, 2},
				Flvr: mesh.CONVEX,
			},
			{
				Vnd:  mesh.Nd{2, 3, 0},
				Flvr: mesh.CONVEX,
			},
		},
	}
	m.Transform(mgl32.HomogRotate2D(a))      // rotate by a
	m.Transform(mgl32.Translate2D(v.Elem())) // translate by v
	return m
}
开发者ID:philetus,项目名称:flyspek,代码行数:28,代码来源:beetle_example.go


示例4: renderBevelEdge

/** Calculate line boundary points.
 *
 * Sketch:
 *
 *     uh1___uh2
 *      .'   '.
 *    .'   q   '.
 *  .'   '   '   '.
 *.'   '  .'.  '   '.
 *   '  .' ul'.  '
 * p  .'       '.  r
 *
 *
 * ul can be found as above, uh1 and uh2 are much simpler:
 *
 * uh1 = q + ns * w/2, uh2 = q + nt * w/2
 */
func (polyline *polyLine) renderBevelEdge(sleeve, current, next mgl32.Vec2) {
	t := next.Sub(current)
	len_t := t.Len()

	det := determinant(sleeve, t)
	if mgl32.Abs(det)/(sleeve.Len()*len_t) < LINES_PARALLEL_EPS && sleeve.Dot(t) > 0 {
		// lines parallel, compute as u1 = q + ns * w/2, u2 = q - ns * w/2
		n := getNormal(t, polyline.halfwidth/len_t)
		polyline.normals = append(polyline.normals, n)
		polyline.normals = append(polyline.normals, n.Mul(-1))
		polyline.generateEdges(current, 2)
		return // early out
	}

	// cramers rule
	sleeve_normal := getNormal(sleeve, polyline.halfwidth/sleeve.Len())
	nt := getNormal(t, polyline.halfwidth/len_t)
	lambda := determinant(nt.Sub(sleeve_normal), t) / det
	d := sleeve_normal.Add(sleeve.Mul(lambda))

	if det > 0 { // 'left' turn -> intersection on the top
		polyline.normals = append(polyline.normals, d)
		polyline.normals = append(polyline.normals, sleeve_normal.Mul(-1))
		polyline.normals = append(polyline.normals, d)
		polyline.normals = append(polyline.normals, nt.Mul(-1))
	} else {
		polyline.normals = append(polyline.normals, sleeve_normal)
		polyline.normals = append(polyline.normals, d.Mul(-1))
		polyline.normals = append(polyline.normals, nt)
		polyline.normals = append(polyline.normals, d.Mul(-1))
	}
	polyline.generateEdges(current, 4)
}
开发者ID:tanema,项目名称:amore,代码行数:50,代码来源:polyline.go


示例5: moveAlongPath

func (ai *AI) moveAlongPath(targetPosition mgl32.Vec2, path []graph.Node) {
	minDistance2 := square(float32(ai.Me.Size) + costMapReduction*1.3)

	var pathNode *mapNode
	var pathVecs []mgl32.Vec2
	for _, rawNode := range path {
		node := rawNode.(*mapNode)
		pos := mgl32.Vec2{float32(node.X) * costMapReduction, float32(node.Y) * costMapReduction}

		if pathNode == nil && dist2(ai.Me.Position, pos) >= minDistance2 {
			pathNode = node
		}

		pathVecs = append(pathVecs, pos)
	}

	if pathNode == nil {
		ai.addStatusMessage("Failed to find path node that was far enough away. Moving directly to objective.")

		ai.Path = []mgl32.Vec2{ai.Me.Position, targetPosition}
		ai.g.SetTargetPos(targetPosition.X(), targetPosition.Y())
		return
	}

	ai.Path = pathVecs
	ai.g.SetTargetPos(float32(pathNode.X*costMapReduction), float32(pathNode.Y*costMapReduction))
}
开发者ID:chendrak,项目名称:agariobot,代码行数:27,代码来源:ai.go


示例6: mouseMove

func (c *Container) mouseMove(position mgl32.Vec2) {
	offsetPos := position.Sub(c.offset)
	c.Hitbox.MouseMove(offsetPos.Sub(c.backgroundOffset))
	for _, child := range c.children {
		child.mouseMove(offsetPos.Sub(c.elementsOffset))
	}
}
开发者ID:walesey,项目名称:go-engine,代码行数:7,代码来源:container.go


示例7: 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


示例8: project

func (c *Camera) project(pt mgl32.Vec2) mgl32.Vec2 {
	var (
		screen = pt.Vec4(1, 1)
		out    mgl32.Vec4
	)
	out = c.Projection.Mul4x1(screen)
	return out.Vec2()
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:8,代码来源:camera.go


示例9: unproject

func (c *Camera) unproject(pt mgl32.Vec2) mgl32.Vec2 {
	var (
		screen = pt.Vec4(1, 1)
		out    mgl32.Vec4
	)
	out = c.Inverse.Mul4x1(screen)
	out = out.Mul(1.0 / out[3])
	return out.Vec2()
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:9,代码来源:camera.go


示例10: normalize

func normalize(v1 mgl32.Vec2, length float32) mgl32.Vec2 {
	length_current := v1.Len()

	if length_current > 0 {
		v1 = v1.Mul(length / length_current)
	}

	return v1
}
开发者ID:tanema,项目名称:amore,代码行数:9,代码来源:polyline.go


示例11: updateImage

func (te *TextElement) updateImage(size mgl32.Vec2) {
	// Initialize the context.
	bg := image.Transparent
	c := te.getContext()

	text := te.GetHiddenText()
	if len(text) == 0 {
		text = te.props.placeholder
		r, g, b, _ := te.props.textColor.RGBA()
		placeholderColor := color.RGBA{uint8(r), uint8(g), uint8(b), 80}
		c.SetSrc(image.NewUniform(placeholderColor))
	}

	// Establish image dimensions and do word wrap
	textHeight := c.PointToFixed(float64(te.props.textSize))
	var width int
	var height int = int(textHeight >> 6)
	words := strings.Split(text, " ")
	lines := []string{""}
	lineNb := 0
	for _, word := range words {
		wordWithSpace := fmt.Sprintf("%v ", word)
		dimensions, _ := c.StringDimensions(wordWithSpace)
		width += int(dimensions.X >> 6)
		if width > int(size.X()) {
			width = int(dimensions.X >> 6)
			height += int(dimensions.Y>>6) + 1
			lines = append(lines, "")
			lineNb += 1
		}
		lines[lineNb] = fmt.Sprintf("%v%v", lines[lineNb], wordWithSpace)
	}
	if te.props.height > 0 {
		height = int(te.props.height)
	}

	rgba := image.NewRGBA(image.Rect(0, 0, int(size.X()), height+int(textHeight>>6)/3))
	draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src)
	c.SetClip(rgba.Bounds())
	c.SetDst(rgba)

	// Draw the text.
	pt := freetype.Pt(0, int(textHeight>>6))
	for _, line := range lines {
		_, err := c.DrawString(line, pt)
		if err != nil {
			log.Printf("Error drawing string: %v\n", err)
			return
		}
		pt.Y += textHeight
	}

	te.img.SetImage(imaging.FlipV(rgba))
	te.img.SetWidth(float32(rgba.Bounds().Size().X))
	te.img.SetHeight(float32(rgba.Bounds().Size().Y))
}
开发者ID:walesey,项目名称:go-engine,代码行数:56,代码来源:text.go


示例12: ScreenToWorldCoords

func (c *Camera) ScreenToWorldCoords(screenCoords mgl32.Vec2) mgl32.Vec2 {
	// http://stackoverflow.com/questions/7692988/
	var (
		half = c.ScreenSize.Mul(0.5)
		pt   = mgl32.Vec2{
			(screenCoords.X() - half.X()) / half.X(),
			(half.Y() - screenCoords.Y()) / half.Y(),
		}
	)
	return c.unproject(pt)
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:11,代码来源:camera.go


示例13: splashConfig

func (r *SplashRenderer) splashConfig(sheet *twodee.Spritesheet, pt mgl32.Vec2, name string) twodee.SpriteConfig {
	frame := sheet.GetFrame(name)
	return twodee.SpriteConfig{
		View: twodee.ModelViewConfig{
			pt.X() + frame.Width/2.0, pt.Y() + frame.Height/2.0, 0.0, // Center
			0, 0, 0,
			1.0, 1.0, 1.0,
		},
		Frame: frame.Frame,
	}
}
开发者ID:pikkpoiss,项目名称:ld33,代码行数:11,代码来源:splashrenderer.go


示例14: highlightSpriteConfig

func (h *HudLayer) highlightSpriteConfig(sheet *twodee.Spritesheet, pt mgl32.Vec2, name string) twodee.SpriteConfig {
	frame := sheet.GetFrame(name)
	return twodee.SpriteConfig{
		View: twodee.ModelViewConfig{
			pt.X() + frame.Width/2.0, pt.Y() + frame.Height/6.0, 0.0, // Left aligned
			0, 0, 0,
			1.0, 1.0, 1.0,
		},
		Frame: frame.Frame,
	}
}
开发者ID:pikkpoiss,项目名称:ld33,代码行数:11,代码来源:hudlayer.go


示例15: 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


示例16: cursorSpriteConfig

func (h *HudLayer) cursorSpriteConfig(sheet *twodee.Spritesheet, pt mgl32.Vec2, cursor string) twodee.SpriteConfig {
	frame := sheet.GetFrame(cursor)
	return twodee.SpriteConfig{
		View: twodee.ModelViewConfig{
			pt.X(), pt.Y(), 0.0,
			0, 0, 0,
			1.0, 1.0, 1.0,
		},
		Frame: frame.Frame,
	}
}
开发者ID:pikkpoiss,项目名称:ld33,代码行数:11,代码来源:hudlayer.go


示例17: textureBounds

func (s *Sprite) textureBounds(textureBounds mgl32.Vec2) render.UniformSprite {
	return render.NewUniformSprite(
		s.bounds.X()/textureBounds.X(),
		s.bounds.Y()/textureBounds.Y(),
		s.offset.X()/textureBounds.X(),
		1.0-(s.offset.Y()+s.bounds.Y()-1.0)/textureBounds.Y(),
	)
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:8,代码来源:sprite.go


示例18: Render

func (te *TextElement) Render(size, offset mgl32.Vec2) mgl32.Vec2 {
	te.props.size, te.props.offset = size, offset
	textWidth, textHeight := size.X(), size.Y()
	if te.props.width > 0 {
		textWidth = te.props.width
	}
	if te.props.height > 0 {
		textHeight = te.props.height
	}
	if te.previousProps != te.props {
		te.updateImage(mgl32.Vec2{textWidth, textHeight})
		te.previousProps = te.props
	}
	return te.img.Render(size, offset)
}
开发者ID:walesey,项目名称:go-engine,代码行数:15,代码来源:text.go


示例19: TwoSegmentIntersect

// TwoSegmentIntersect - find the intersection point of two line segments <p11-p12> and <p21-p22>
func TwoSegmentIntersect(p11, p12, p21, p22 mgl32.Vec2) (mgl32.Vec2, error) {
	p := p11
	q := p21
	r := p12.Sub(p11)
	s := p22.Sub(p21)
	if math.Abs(float64(Vec2Cross(r, s))) < 0.0000001 {
		return mgl32.Vec2{}, fmt.Errorf("No intersections: lines parallel")
	}
	t := Vec2Cross(q.Sub(p), s) / Vec2Cross(r, s)
	u := Vec2Cross(p.Sub(q), r) / Vec2Cross(s, r)
	if t >= 0 && t <= 1 && u >= 0 && u <= 1 {
		return p.Add(r.Mul(t)), nil
	}
	return mgl32.Vec2{}, fmt.Errorf("No intersections")
}
开发者ID:walesey,项目名称:go-engine,代码行数:16,代码来源:math.go


示例20: Render

func (c *Container) Render(size, offset mgl32.Vec2) mgl32.Vec2 {
	c.size, c.offset = size, offset
	padding := convertMargin(c.padding, c.paddingPercent, size.X())
	margin := convertMargin(c.margin, c.marginPercent, size.X())
	sizeMinusMargins := size.Sub(mgl32.Vec2{
		margin.Left + margin.Right + padding.Left + padding.Right,
		margin.Top + margin.Bottom + padding.Top + padding.Bottom,
	})
	containerSize := sizeMinusMargins
	if c.width > 0 {
		containerSize[0] = c.getWidth(size.X()) - padding.Left - padding.Right
	}
	if c.height > 0 {
		containerSize[1] = c.getHeight(size.X()) - padding.Top - padding.Bottom
	}
	var width, height, highest float32 = 0, 0, 0
	for _, child := range c.children {
		childSize := child.Render(containerSize, mgl32.Vec2{width, height})
		width += childSize.X()
		if width > containerSize.X() {
			height += highest
			highest = 0
			childSize = child.Render(containerSize, mgl32.Vec2{0, height})
			width = childSize.X()
		}
		if childSize.Y() > highest {
			highest = childSize.Y()
		}
	}
	height += highest
	if mgl32.FloatEqual(c.height, 0) {
		containerSize[1] = height
	}
	//offsets and sizes
	c.backgroundOffset = mgl32.Vec2{margin.Left, margin.Top}
	c.elementsOffset = mgl32.Vec2{margin.Left + padding.Left, margin.Top + padding.Top}
	backgroundSize := containerSize.Add(mgl32.Vec2{padding.Left + padding.Right, padding.Top + padding.Bottom})
	totalSize := backgroundSize.Add(mgl32.Vec2{margin.Left + margin.Right, margin.Top + margin.Bottom})

	c.background.SetScale(backgroundSize.Vec3(0))
	c.background.SetTranslation(c.backgroundOffset.Vec3(0))
	c.elementsNode.SetTranslation(c.elementsOffset.Vec3(0))
	c.node.SetTranslation(c.offset.Vec3(0))
	c.Hitbox.SetSize(backgroundSize)
	return totalSize
}
开发者ID:walesey,项目名称:go-engine,代码行数:46,代码来源:container.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mgl32.Vec3类代码示例发布时间:2022-05-23
下一篇:
Golang mgl32.Mat4类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap