コード例 #1
0
ファイル: linear_test.go プロジェクト: runningwild/linear
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)
					}
				}
			}
		}
	})
}
コード例 #2
0
ファイル: editor_graphics.go プロジェクト: runningwild/jota
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)
	}
}
コード例 #3
0
ファイル: editor_graphics.go プロジェクト: runningwild/jota
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
}
コード例 #4
0
ファイル: linear_test.go プロジェクト: runningwild/linear
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)
	})
}
コード例 #5
0
ファイル: linear_test.go プロジェクト: runningwild/linear
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})
	})
}
コード例 #6
0
ファイル: base_ent.go プロジェクト: runningwild/jota
func (b *BaseEnt) ApplyForce(f linear.Vec2) {
	b.Velocity = b.Velocity.Add(f.Scale(1 / b.Mass()))
}
コード例 #7
0
ファイル: game.go プロジェクト: dgthunder/magnus
func (p *Player) ApplyForce(f linear.Vec2) {
	dv := f.Scale(1 / p.Mass())
	p.Vx += dv.X
	p.Vy += dv.Y
}