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


Golang vect.Float函数代码示例

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


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

示例1: step

func step(dt float32) {
	space.Step(vect.Float(dt))

	for i := 0; i < len(rooms); i++ {
		rooms[i].Box.Body.SetAngle(vect.Float(0))
	}
}
开发者ID:hatajoe,项目名称:go-procedural-dungeon-generation,代码行数:7,代码来源:main.go

示例2: circle2circleQuery

func circle2circleQuery(p1, p2 vect.Vect, r1, r2 vect.Float, con *Contact) int {
	minDist := r1 + r2

	delta := vect.Sub(p2, p1)
	distSqr := delta.LengthSqr()

	if distSqr >= minDist*minDist {
		return 0
	}

	dist := vect.Float(math.Sqrt(float64(distSqr)))

	pDist := dist
	if dist == 0.0 {
		pDist = vect.Float(math.Inf(1))
	}

	pos := vect.Add(p1, vect.Mult(delta, 0.5+(r1-0.5*minDist)/pDist))

	norm := vect.Vect{1, 0}

	if dist != 0.0 {
		norm = vect.Mult(delta, 1.0/dist)
	}

	con.reset(pos, norm, dist-minDist, 0)

	return 1
}
开发者ID:niksaak,项目名称:chipmunk,代码行数:29,代码来源:collide.go

示例3: newBox

func newBox(width, height float32) *box {
	var err error

	box := new(box)

	// Sound player

	box.player, err = mandala.NewAudioPlayer()
	if err != nil {
		mandala.Fatalf("%s\n", err.Error())
	}

	// Chipmunk body

	box.physicsShape = chipmunk.NewBox(
		vect.Vect{0, 0},
		vect.Float(width),
		vect.Float(height),
	)

	box.physicsShape.SetElasticity(BoxElasticity)
	box.physicsBody = chipmunk.NewBody(vect.Float(BoxMass), box.physicsShape.Moment(float32(BoxMass)))
	box.physicsBody.AddShape(box.physicsShape)
	box.physicsBody.CallbackHandler = callbacks{}

	// OpenGL shape

	box.openglShape = shapes.NewBox(width, height)

	return box
}
开发者ID:TimothyKlim,项目名称:mandala-examples,代码行数:31,代码来源:box.go

示例4: jump

func jump() {
	// add a computer beep on jump.
	fmt.Print("\x07")
	for _, flappyBird := range flappyBirds {
		flappyBird.Body.UpdateVelocity(space.Gravity, vect.Float(-.1), vect.Float(-.3))
	}
}
开发者ID:himanshushekhar,项目名称:golang-flappybirdclone,代码行数:7,代码来源:main.go

示例5: dropBox

func (w *world) dropBox(x, y float32) {
	box := newBox(20, 20)
	box.physicsBody.SetMass(200)
	box.physicsBody.AddAngularVelocity(10)
	box.physicsBody.SetAngle(vect.Float(2 * math.Pi * chipmunk.DegreeConst * rand.Float32()))
	box.physicsBody.SetPosition(vect.Vect{vect.Float(x), vect.Float(float32(w.height) - y)})
	w.addBox(box)
}
开发者ID:TimothyKlim,项目名称:mandala-examples,代码行数:8,代码来源:world.go

示例6: CreateFromSvg

func (w *World) CreateFromSvg(filename string) {
	var svg svgFile

	responseCh := make(chan mandala.LoadResourceResponse)
	mandala.ReadResource(filename, responseCh)
	response := <-responseCh

	if response.Error != nil {
		mandala.Fatalf(response.Error.Error())
	}
	buf := response.Buffer

	err := xml.Unmarshal(buf, &svg)
	if err != nil {
		mandala.Fatalf(err.Error())
	}

	scaleX := float32(w.width) / svg.Width
	scaleY := float32(w.height) / svg.Height

	for _, group := range svg.Groups {
		for _, rect := range group.Rects {
			rX := (rect.X + rect.Width/2) * scaleX
			rY := float32(w.height) - (rect.Y+rect.Height/2)*scaleY
			rW := rect.Width * scaleX
			rH := rect.Height * scaleY
			box := newBox(w, rW, rH)
			pos := vect.Vect{
				vect.Float(rX),
				vect.Float(rY),
			}

			box.physicsBody.SetPosition(pos)

			if rect.Transform != "" {
				var a, b, c float32
				_, err = fmt.Sscanf(rect.Transform, "rotate(%f %f,%f)", &a, &b, &c)
				if err != nil {
					mandala.Fatalf(err.Error())
				}
				box.physicsBody.SetAngle(90 / chipmunk.DegreeConst)
			}

			box.openglShape.SetColor(colorful.HappyColor())
			w.addBox(box)
		}
	}
	line := svg.Groups[0].Line
	w.setGround(newGround(
		w,
		0,
		float32(w.height)-float32(line.Y1*scaleY),
		float32(w.width),
		float32(w.height)-float32(line.Y2*scaleY),
	))
}
开发者ID:remogatto,项目名称:mandala-examples,代码行数:56,代码来源:svg.go

示例7: addPipe

// add a row of 7 pipe boxes to the space
func addPipe() {
	// pick a random position for hole in the pipe
	hole := int(math.Floor(rand.Float64()*6)) + 1
	// add pipe boxes
	for i := 0; i < 9; i++ {
		if i != hole && i != hole+1 {
			addOnePipeBox(vect.Vect{vect.Float(winWidth), vect.Float(i*60 + 30 + i*10)})
		}
	}
}
开发者ID:himanshushekhar,项目名称:golang-flappybirdclone,代码行数:11,代码来源:main.go

示例8: preStepGameObject

func preStepGameObject(g *GameObject) {
	if g.Physics != nil && g.active && !g.Physics.Body.IsStatic() && g.Physics.started() {
		pos := g.Transform().WorldPosition()
		angle := g.Transform().Angle() * RadianConst

		if g.Physics.Interpolate {
			//Interpolation check: if position/angle has been changed directly and not by the physics engine, change g.Physics.lastPosition/lastAngle
			if vect.Float(pos.X) != g.Physics.interpolatedPosition.X || vect.Float(pos.Y) != g.Physics.interpolatedPosition.Y {
				g.Physics.interpolatedPosition = vect.Vect{vect.Float(pos.X), vect.Float(pos.Y)}
				g.Physics.Body.SetPosition(g.Physics.interpolatedPosition)
			}
			if vect.Float(angle) != g.Physics.interpolatedAngle {
				g.Physics.interpolatedAngle = vect.Float(angle)
				g.Physics.Body.SetAngle(g.Physics.interpolatedAngle)
			}
		} else {
			var pPos vect.Vect
			pPos.X, pPos.Y = vect.Float(pos.X), vect.Float(pos.Y)

			g.Physics.Body.SetAngle(vect.Float(angle))
			g.Physics.Body.SetPosition(pPos)
		}
		g.Physics.lastPosition = g.Physics.Body.Position()
		g.Physics.lastAngle = g.Physics.Body.Angle()
	}
}
开发者ID:gulinfang,项目名称:GarageEngine,代码行数:26,代码来源:EngineLoops.go

示例9: explosion

func (w *world) explosion(x, y float32) {
	w.explosionPlayer.Play(w.explosionBuffer, nil)
	y = float32(w.height) - y
	for _, box := range w.boxes {
		cx, cy := box.openglShape.Center()
		force := vect.Sub(vect.Vect{vect.Float(cx), vect.Float(cy)}, vect.Vect{vect.Float(x), vect.Float(y)})
		length := force.Length()
		force.Normalize()
		force.Mult(vect.Float(1 / length * 3e6))
		box.physicsBody.SetForce(float32(force.X), float32(force.Y))
	}
}
开发者ID:TimothyKlim,项目名称:mandala-examples,代码行数:12,代码来源:world.go

示例10: addBall

func addBall() {
	x := rand.Intn(350-115) + 115
	ball := chipmunk.NewCircle(vect.Vector_Zero, float32(ballRadius))
	ball.SetElasticity(0.95)

	body := chipmunk.NewBody(vect.Float(ballMass), ball.Moment(float32(ballMass)))
	body.SetPosition(vect.Vect{vect.Float(x), 600.0})
	body.SetAngle(vect.Float(rand.Float32() * 2 * math.Pi))

	body.AddShape(ball)
	space.AddBody(body)
	balls = append(balls, ball)
}
开发者ID:niksaak,项目名称:chipmunk,代码行数:13,代码来源:bouncing_balls.go

示例11: addOnePipeBox

// add a pipe box to the space
func addOnePipeBox(pos vect.Vect) {
	pipeBox := chipmunk.NewBox(vect.Vector_Zero, vect.Float(pipeSide), vect.Float(pipeSide))
	pipeBox.SetElasticity(0.6)

	body := chipmunk.NewBody(chipmunk.Inf, chipmunk.Inf)
	body.SetPosition(pos)
	body.SetVelocity(pipeVelX, pipeVelY)
	body.IgnoreGravity = true

	body.AddShape(pipeBox)
	space.AddBody(body)
	pipe = append(pipe, pipeBox)
}
开发者ID:himanshushekhar,项目名称:golang-flappybirdclone,代码行数:14,代码来源:main.go

示例12: getRandomPointInCircle

func getRandomPointInCircle(radius float64) vect.Vect {
	t := 2 * math.Pi * rand.Float64()
	u := rand.Float64() + rand.Float64()
	r := .0
	if u > 1 {
		r = 2 - u
	} else {
		r = u
	}
	return vect.Vect{
		X: vect.Float(roundm(radius*r*math.Cos(t), 4.0)) + 300,
		Y: vect.Float(roundm(radius*r*math.Sin(t), 4.0)) + 300,
	}
}
开发者ID:hatajoe,项目名称:go-procedural-dungeon-generation,代码行数:14,代码来源:main.go

示例13: Explosion

// Explosion produce an explosion at the given coordinates.
func (w *World) Explosion(x, y float32) {
	w.explosionPlayer.Play(w.explosionBuffer, nil)
	y = float32(w.height) - y
	for _, box := range w.boxes {
		cx, cy := box.openglShape.Center()
		force := vect.Sub(
			vect.Vect{vect.Float(cx / float32(w.width)), vect.Float(cy / float32(w.height))},
			vect.Vect{vect.Float(x / float32(w.width)), vect.Float(y / float32(w.height))},
		)
		force.Normalize()
		force.Mult(vect.Float(1 / force.Length() * 1e5))
		box.physicsBody.SetForce(float32(force.X), float32(force.Y))
	}
}
开发者ID:remogatto,项目名称:mandala-examples,代码行数:15,代码来源:world.go

示例14: Remove

// Remove removes the box at the given coordinates.
func (w *World) Remove(x, y float32) int {
	y = float32(w.height) - y
	for id, box := range w.boxes {
		cx, cy := box.openglShape.Center()
		distance := vect.Sub(
			vect.Vect{vect.Float(cx), vect.Float(cy)},
			vect.Vect{vect.Float(x), vect.Float(y)},
		)
		if distance.LengthSqr() < vect.Float(BoxSize) {
			w.removeBox(box, id)
			return id
		}
	}
	return -1
}
开发者ID:remogatto,项目名称:mandala-examples,代码行数:16,代码来源:world.go

示例15: addFlappy

func addFlappy() {
	flappyBird := chipmunk.NewBox(vect.Vector_Zero, vect.Float(pipeSide), vect.Float(pipeSide))
	flappyBird.SetElasticity(0.95)

	body := chipmunk.NewBody(vect.Float(flappyMass), vect.Float(flappyMoment))
	body.SetPosition(vect.Vect{100, vect.Float(winHeight)})
	body.SetAngularVelocity(float32(10 * deg2rad))

	// hook collision events
	handlers := collisionHandlers{}
	body.CallbackHandler = handlers

	body.AddShape(flappyBird)
	space.AddBody(body)
	flappyBirds = append(flappyBirds, flappyBird)
}
开发者ID:himanshushekhar,项目名称:golang-flappybirdclone,代码行数:16,代码来源:main.go


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