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


Golang mgl32.Vec3类代码示例

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


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

示例1: RotateTo

// RotateTo adjusts the yaw and pitch to face a point.
func (c *QuatCamera) RotateTo(center mgl.Vec3) {
	direction := center.Sub(c.position).Normalize()
	right := direction.Cross(AxisUp)
	up := right.Cross(direction)

	c.rotation = mgl.QuatLookAtV(c.position, center, up)
}
开发者ID:shazow,项目名称:go-gameblocks,代码行数:8,代码来源:camera.go

示例2: safeNormalize

func safeNormalize(v mgl32.Vec3) mgl32.Vec3 {
	v = v.Normalize()
	if math.IsInf(float64(v[0]), 0) || math.IsNaN(float64(v[0])) {
		return mgl32.Vec3{}
	}
	return v
}
开发者ID:num5,项目名称:steven,代码行数:7,代码来源:frustum.go

示例3: MoveSelectedNodeModel

func (e *Editor) MoveSelectedNodeModel(x, y float32, axisLock mgl32.Vec3) {
	selectedModel, _ := e.overviewMenu.getSelectedNode(e.currentMap.Root)
	if selectedModel != nil {
		selectedModel.Translation = selectedModel.Translation.Add(axisLock.Mul(x * mouseSpeed))
	}
	updateMap(e.currentMap.Root)
}
开发者ID:walesey,项目名称:go-engine,代码行数:7,代码来源:editorController.go

示例4: PointToLineDist

//PointToLineDist distance from line (a,b) to point
func PointToLineDist(a, b, point mgl32.Vec3) float32 {
	ab := b.Sub(a)
	ap := point.Sub(a)
	prj := ap.Dot(ab)
	lenSq := ab.Dot(ab)
	t := prj / lenSq
	return ab.Mul(t).Add(a).Sub(point).Len()
}
开发者ID:walesey,项目名称:go-engine,代码行数:9,代码来源:math.go

示例5: setPoints

func (f *fPlane) setPoints(v1, v2, v3 mgl32.Vec3) {
	aux1 := v1.Sub(v2)
	aux2 := v3.Sub(v2)

	f.N = aux2.Cross(aux1)
	f.N = safeNormalize(f.N)
	f.P = v2
	f.D = -(f.N.Dot(f.P))
}
开发者ID:num5,项目名称:steven,代码行数:9,代码来源:frustum.go

示例6: Lerp

// Lerp will interpolate between the desired position/center by amount.
func (c *QuatCamera) Lerp(position mgl.Vec3, center mgl.Vec3, amount float32) {
	direction := center.Sub(position).Normalize()
	right := direction.Cross(AxisUp)
	up := right.Cross(direction)

	targetRot := mgl.QuatLookAtV(position, center, up)
	c.rotation = mgl.QuatNlerp(c.rotation, targetRot, amount)
	c.position = c.position.Add(position.Sub(c.position).Mul(amount))
}
开发者ID:shazow,项目名称:go-gameblocks,代码行数:10,代码来源:camera.go

示例7: pix2Vec

func (self *pane) pix2Vec(evnt *js.Object) mgl32.Vec2 {
	v := mgl32.Vec3{ // generate vector from current pixel coords
		float32(evnt.Get("clientX").Float()),
		float32(evnt.Get("clientY").Float()),
		1.0, // apply translations from transform matrix
	}
	v = self.untransform.Mul3x1(v) // apply pan & zoom untransform matrix

	return v.Vec2() // return vec2
}
开发者ID:philetus,项目名称:flyspek,代码行数:10,代码来源:event.go

示例8: getIntersection

func getIntersection(fDst1, fDst2 float32, P1, P2 mgl32.Vec3, Hit *mgl32.Vec3) bool {
	if (fDst1 * fDst2) >= 0.0 {
		return false
	}
	if fDst1 == fDst2 {
		return false
	}
	*Hit = P1.Add((P2.Sub(P1)).Mul(-fDst1 / (fDst2 - fDst1)))
	return true
}
开发者ID:xnattack,项目名称:GCSolutions,代码行数:10,代码来源:piano.go

示例9: Rotate

// Rotate adjusts the direction vectors by a delta vector of {pitch, yaw, roll}.
// Roll is ignored for now.
func (c *EulerCamera) Rotate(delta mgl.Vec3) {
	c.yaw += float64(delta.Y())
	c.pitch += float64(delta.X())

	// Limit vertical rotation to avoid gimbal lock
	if c.pitch > halfPi {
		c.pitch = halfPi
	} else if c.pitch < -halfPi {
		c.pitch = -halfPi
	}

	c.updateVectors()
}
开发者ID:shazow,项目名称:go-gameblocks,代码行数:15,代码来源:camera.go

示例10: CreateBeam

// CreateBeam - creates a square prism oriented along the vector
func CreateBeam(width float32, vector mgl32.Vec3) *Geometry {
	direction := vector.Normalize()
	geo := CreateBoxWithOffset(width, width, -width*0.5, -width*0.5)
	geo2 := CreateBoxWithOffset(width, width, -width*0.5, -width*0.5)
	facingTx := util.Mat4From(mgl32.Vec3{1, 1, 1}, mgl32.Vec3{}, util.FacingOrientation(0, direction, mgl32.Vec3{0, 0, 1}, mgl32.Vec3{1, 0, 0}))
	geo.Transform(facingTx)
	facingTx = util.Mat4From(mgl32.Vec3{1, 1, 1}, vector, util.FacingOrientation(0, direction, mgl32.Vec3{0, 0, -1}, mgl32.Vec3{1, 0, 0}))
	geo2.Optimize(geo, facingTx)
	geo.Indicies = append(geo.Indicies, 0, 1, 4, 4, 5, 0) //top
	geo.Indicies = append(geo.Indicies, 1, 2, 7, 7, 4, 1) //side
	geo.Indicies = append(geo.Indicies, 2, 3, 6, 6, 7, 2) //bottom
	geo.Indicies = append(geo.Indicies, 3, 0, 5, 5, 6, 3) //side
	return geo
}
开发者ID:walesey,项目名称:go-engine,代码行数:15,代码来源:geometry.go

示例11: Upvote

func Upvote(tip mgl.Vec3, size float32) []float32 {
	a := tip.Add(mgl.Vec3{-size / 2, -size * 2, 0})
	b := tip.Add(mgl.Vec3{size / 2, -size, 0})
	return []float32{
		tip[0], tip[1], tip[2], // Top
		tip[0] - size, tip[1] - size, tip[2], // Bottom left
		tip[0] + size, tip[1] - size, tip[2], // Bottom right

		// Arrow handle
		b[0], b[1], b[2], // Top Right
		a[0], b[1], a[2], // Top Left
		a[0], a[1], a[2], // Bottom Left
		a[0], a[1], a[2], // Bottom Left
		b[0], b[1], b[2], // Top Right
		b[0], a[1], b[2], // Bottom Right
	}
}
开发者ID:shazow,项目名称:go-gameblocks,代码行数:17,代码来源:util.go

示例12: GetKeyFromRay

func (p *fullPiano) GetKeyFromRay(rayStart, rayEnd mgl32.Vec3) *PianoKey {
	minDist := float32(10000)
	minDistIdx := -1

	for i, k := range p.Keys {
		hit, pos := k.Hit(rayStart, rayEnd)
		if hit {
			dist := rayStart.Sub(pos).Len()
			if dist < minDist {
				minDistIdx = i
				minDist = dist
			}
		}
	}

	if minDistIdx != -1 {
		return &p.Keys[minDistIdx]
	}

	return nil
}
开发者ID:xnattack,项目名称:GCSolutions,代码行数:21,代码来源:piano.go

示例13: PointToPlaneDist

//PointToPlaneDist distance from plane (a,b,c) to point
func PointToPlaneDist(a, b, c, point mgl32.Vec3) float32 {
	ab := b.Sub(a)
	ac := c.Sub(a)
	ap := point.Sub(a)
	normal := ac.Cross(ab).Normalize()
	return float32(math.Abs(float64(ap.Dot(normal))))
}
开发者ID:walesey,项目名称:go-engine,代码行数:8,代码来源:math.go

示例14: NewPianoKey

// NewPianoKey returns a key for our piano.
func NewPianoKey(pos mgl32.Vec3, lightColor mgl32.Vec3, white bool, freq float32) PianoKey {
	var color mgl32.Vec4
	var keySize float32
	if white {
		color = mgl32.Vec4{0.98, 0.97, 0.94}
		keySize = 2
	} else {
		color = mgl32.Vec4{0.1, 0.1, 0.1, 1.0}
		keySize = 1

	}
	pk := PianoKey{Pos: pos, Angle: 0, Color: color, Frequency: freq, Finger: -1, white: white, LightColor: lightColor}
	pk.BBox[0] = pos.Sub(mgl32.Vec3{0.5, 0.6, keySize})
	pk.BBox[1] = pos.Add(mgl32.Vec3{0.5, 0.6, keySize})
	pk.source = al.GenSources(1)[0]
	pk.source.SetGain(1.0)
	pk.source.SetPosition(al.Vector{pos.X(), pos.Y(), pos.Z()})
	pk.source.SetVelocity(al.Vector{})
	pk.buffers = al.GenBuffers(3)

	var samples [1024 * 16]int16

	sampleRate := 44100
	amplitude := float32(0.8 * 0x7FFF)

	for i := 0; i < len(samples); i++ {
		val := f32.Sin((2.0 * math.Pi * freq) / float32(sampleRate) * float32(i))
		samples[i] = int16(amplitude * val)
	}

	buf := &bytes.Buffer{}
	binary.Write(buf, binary.LittleEndian, &samples)
	pk.buffers[0].BufferData(al.FormatMono16, buf.Bytes(), 44100)

	f, _ := os.Create("audio.raw")
	binary.Write(f, binary.LittleEndian, &samples)
	f.Close()

	return pk
}
开发者ID:xnattack,项目名称:GCSolutions,代码行数:41,代码来源:piano.go

示例15: esLightModel

// updates the Colors of the model to fake lighting
func esLightModel(p PositionComponent, s SizeComponent, m interface {
	Model() *render.StaticModel
}) {
	if m.Model() == nil {
		return
	}
	xx, yy, zz := p.Position()
	bounds := s.Bounds()
	bounds = bounds.Shift(float32(xx), float32(yy), float32(zz))

	c := mgl32.Vec3{float32(xx), float32(yy), float32(zz)}
	c[1] += bounds.Max.Sub(bounds.Min).Mul(0.5).Y()

	var light, skyLight float32
	var count float32
	for y := bounds.Min.Y(); y <= bounds.Max.Y(); y++ {
		for z := bounds.Min.Z() - 1; z <= bounds.Max.Z()+1; z++ {
			for x := bounds.Min.X() - 1; x <= bounds.Max.X()+1; x++ {
				bx, by, bz := int(math.Floor(float64(x))), int(math.Floor(float64(y))), int(math.Floor(float64(z)))
				bl := float32(chunkMap.BlockLight(bx, by, bz))
				sl := float32(chunkMap.SkyLight(bx, by, bz))

				dist := 1.0 - c.Sub(mgl32.Vec3{float32(bx) + 0.5, float32(by) + 0.5, float32(bz) + 0.5}).Len()
				if dist < 0 {
					continue
				}

				light += bl * dist
				skyLight += sl * dist
				count += dist
			}
		}
	}
	light /= count
	skyLight /= count
	model := m.Model()
	model.BlockLight, model.SkyLight = light, skyLight
}
开发者ID:suedadam,项目名称:steven,代码行数:39,代码来源:entitysystems.go


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