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

Golang vect.Float函数代码示例

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

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



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


示例16: Start

func (p *Physics) Start() {
	//p.Interpolate = true
	pos := p.GameObject().Transform().WorldPosition()
	p.Body.SetAngle(vect.Float(p.GameObject().Transform().WorldRotation().Z) * RadianConst)
	p.Body.SetPosition(vect.Vect{vect.Float(pos.X), vect.Float(pos.Y)})
	p.lastPosition = p.Body.Position()
	p.lastAngle = p.Body.Angle()

	if p.GameObject().Sprite != nil {
		p.GameObject().Sprite.UpdateShape()
		p.Body.UpdateShapes()
	}

	//p.Body.UpdateShapes()
	Space.AddBody(p.Body)
}
开发者ID:gulinfang,项目名称:GarageEngine,代码行数:16,代码来源:Physics.go


示例17: NewPhysics

func NewPhysics(static bool) *Physics {
	var body *chipmunk.Body

	box := chipmunk.NewBox(vect.Vect{0, 0}, vect.Float(1), vect.Float(1))

	if static {
		body = chipmunk.NewBodyStatic()
	} else {
		body = chipmunk.NewBody(1, box.Moment(1))
	}

	p := &Physics{BaseComponent: NewComponent(), Body: body, Box: box.GetAsBox(), Shape: box}

	body.AddShape(box)
	return p
}
开发者ID:gulinfang,项目名称:GarageEngine,代码行数:16,代码来源:Physics.go


示例18: Update

func (cSpace *ChipmonkSpace) Update(dt float64) {
	cSpace.Space.Step(vect.Float(dt))
	if cSpace.OnCollision != nil {
		for _, a := range cSpace.Space.Arbiters {
			cSpace.OnCollision(a.ShapeA, a.ShapeB)
		}
	}
}
开发者ID:walesey,项目名称:go-engine,代码行数:8,代码来源:world.go


示例19: NewEnemy

func NewEnemy(ballRadius, ballMass int32, game *Game) *Enemy {
	x := rand.Intn(1280)
	ball := chipmunk.NewCircle(vect.Vector_Zero, float32(ballRadius))
	ball.SetElasticity(0.95)
	ball.SetFriction(1.5)

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

	body.AddShape(ball)

	game.Space.AddBody(body)

	return &Enemy{Body: ball.Body, ball: ball, alive: true, Radius: ballRadius, Mass: ballMass}
}
开发者ID:jhautefeuille,项目名称:hellochipmunk,代码行数:17,代码来源:enemy.go


示例20: NewPlayer

func NewPlayer(ballRadius, ballMass int32, game *Game) *Player {
	x := rand.Intn(350-115) + 115
	ball := chipmunk.NewCircle(vect.Vector_Zero, float32(ballRadius))
	ball.SetElasticity(0.95)
	ball.SetFriction(1.5)

	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)

	game.Space.AddBody(body)

	return &Player{Body: ball.Body, ball: ball,
		Radius: ballRadius, Mass: ballMass,
		jumpTickStop: 2, jumpTick: 0, jumping: false, speed: 5}
}
开发者ID:jhautefeuille,项目名称:hellochipmunk,代码行数:18,代码来源:player.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang vect.Mult函数代码示例发布时间:2022-05-28
下一篇:
Golang vm.VirtualMachine类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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