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


Golang Vec2.Scale方法代码示例

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


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

示例1: ComplexOperationsSpec

func ComplexOperationsSpec(c gospec.Context) {
	c.Specify("Vec2.DistToLine() works.", func() {
		centers := []linear.Vec2{
			linear.Vec2{10, 12},
			linear.Vec2{1, -9},
			linear.Vec2{-100, -42},
			linear.Vec2{0, 1232},
		}
		radiuses := []float64{3, 10.232, 435, 1}
		thetas := []float64{0.001, 0.1, 1, 1.01, 0.034241, 0.789, 90, 179, 180}
		angles := []float64{1.01, 1.0, 1.11111, 930142}
		for _, center := range centers {
			for _, radius := range radiuses {
				for _, angle := range angles {
					for _, theta := range thetas {
						a := linear.Vec2{math.Cos(angle), math.Sin(angle)}
						b := linear.Vec2{math.Cos(angle + theta), math.Sin(angle + theta)}
						seg := linear.Seg2{a.Scale(radius).Add(center), b.Scale(radius).Add(center)}
						dist := center.DistToLine(seg)
						real_dist := radius * math.Cos(theta/2)
						if real_dist < 0 {
							real_dist = -real_dist
						}
						c.Expect(dist, IsWithin(1e-9), real_dist)
					}
				}
			}
		}
	})
}
开发者ID:runningwild,项目名称:linear,代码行数:30,代码来源:linear_test.go

示例2: RenderLocalEditor

func (g *Game) RenderLocalEditor(region g2.Region) {
	g.editor.Lock()
	defer g.editor.Unlock()
	g.editor.region = region
	g.editor.camera.regionDims = linear.Vec2{float64(region.Dims.Dx), float64(region.Dims.Dy)}
	levelDims := linear.Vec2{float64(g.Level.Room.Dx), float64(g.Level.Room.Dy)}
	g.editor.camera.StandardRegion(levelDims.Scale(0.5), levelDims)
	g.editor.camera.approachTarget()

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	defer gl.PopMatrix()

	gl.PushAttrib(gl.VIEWPORT_BIT)
	gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy))
	defer gl.PopAttrib()

	current := &g.editor.camera.current
	gl.Ortho(
		gl.Double(current.mid.X-current.dims.X/2),
		gl.Double(current.mid.X+current.dims.X/2),
		gl.Double(current.mid.Y+current.dims.Y/2),
		gl.Double(current.mid.Y-current.dims.Y/2),
		gl.Double(1000),
		gl.Double(-1000),
	)
	defer func() {
		gl.MatrixMode(gl.PROJECTION)
		gl.PopMatrix()
		gl.MatrixMode(gl.MODELVIEW)
	}()
	gl.MatrixMode(gl.MODELVIEW)

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	g.renderWalls()
	g.renderEdges()
	g.renderBases()
	g.renderEntsAndAbilities()
	g.renderProcesses()

	g.editor.renderPathing(&g.Level.Room, g.local.pathingData)

	switch g.editor.action {
	case editorActionNone:
	case editorActionPlaceBlock:
		g.editor.renderPlaceBlock(g)
	default:
		base.Error().Printf("Unexpected editorAction: %v", g.editor.action)
	}
}
开发者ID:runningwild,项目名称:jota,代码行数:53,代码来源:editor_graphics.go

示例3: cursorPosInGameCoords

func (editor *editorData) cursorPosInGameCoords(room *Room) linear.Vec2 {
	x, y := editor.sys.GetCursorPos()
	pos := linear.Vec2{float64(x), float64(y)}
	regionPos := linear.Vec2{float64(editor.region.Pos.X), float64(editor.region.Pos.Y)}
	pos = pos.Sub(regionPos)
	pos = pos.Scale(float64(room.Dx) / float64(editor.region.Dims.Dx))
	cameraOffset := linear.Vec2{
		editor.camera.current.dims.X/2 - editor.camera.current.mid.X,
		editor.camera.current.dims.Y/2 - editor.camera.current.mid.Y,
	}
	pos = pos.Sub(cameraOffset)
	return pos
}
开发者ID:runningwild,项目名称:jota,代码行数:13,代码来源:editor_graphics.go

示例4: BasicPropertiesSpec

func BasicPropertiesSpec(c gospec.Context) {
	a := linear.Vec2{3, 4}
	b := linear.Vec2{5, 6}
	c.Specify("Check that (cross a) dot a == 0.", func() {
		c.Expect(a.Cross().Dot(a), Equals, 0.0)
	})
	c.Specify("Check that a normalize vector's magnitude is 1.", func() {
		c.Expect(a.Norm().Mag(), IsWithin(1e-9), 1.0)
	})
	c.Specify("Check that v.Mag2() == v.Mag()*v.Mag()", func() {
		c.Expect(a.Mag2(), IsWithin(1e-9), a.Mag()*a.Mag())
	})
	c.Specify("Check that a scaled vector's magnitude is appropriately scaled.", func() {
		c.Expect(a.Scale(3.5).Mag(), IsWithin(1e-9), a.Mag()*3.5)
	})
	c.Specify("Check that a-(a-b) == b.", func() {
		VecExpect(c, a.Sub(a.Sub(b)), IsWithin(1e-9), b)
	})
}
开发者ID:runningwild,项目名称:linear,代码行数:19,代码来源:linear_test.go

示例5: BasicOperationsSpec

func BasicOperationsSpec(c gospec.Context) {
	a := linear.Vec2{3, 4}
	b := linear.Vec2{5, 6}
	c.Specify("Make sure adding vectors works.", func() {
		VecExpect(c, a.Add(b), Equals, linear.Vec2{8, 10})
	})
	c.Specify("Make sure subtracting vectors works.", func() {
		VecExpect(c, a.Sub(b), Equals, linear.Vec2{-2, -2})
	})
	c.Specify("Make sure dotting vectors works.", func() {
		c.Expect(a.Dot(b), IsWithin(1e-9), 39.0)
	})
	c.Specify("Make sure crossing vectors works.", func() {
		VecExpect(c, a.Cross(), Equals, linear.Vec2{-4, 3})
	})
	c.Specify("Make sure taking the magnitude of vectors works.", func() {
		c.Expect(a.Mag(), IsWithin(1e-9), 5.0)
		c.Expect(a.Mag2(), IsWithin(1e-9), 25.0)
	})
	c.Specify("Make sure scaling vectors works.", func() {
		VecExpect(c, a.Scale(3), Equals, linear.Vec2{9, 12})
	})
}
开发者ID:runningwild,项目名称:linear,代码行数:23,代码来源:linear_test.go

示例6: ApplyForce

func (b *BaseEnt) ApplyForce(f linear.Vec2) {
	b.Velocity = b.Velocity.Add(f.Scale(1 / b.Mass()))
}
开发者ID:runningwild,项目名称:jota,代码行数:3,代码来源:base_ent.go

示例7: ApplyForce

func (p *Player) ApplyForce(f linear.Vec2) {
	dv := f.Scale(1 / p.Mass())
	p.Vx += dv.X
	p.Vy += dv.Y
}
开发者ID:dgthunder,项目名称:magnus,代码行数:5,代码来源:game.go


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