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


Golang Rect3.Center方法代码示例

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


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

示例1: expand

// expand performs expansion of the root node, n, towards r's center. If a new
// root node is created then it is returned and n.parent is set to the new root
// node.
func (n *Node) expand(r math.Rect3) *Node {
	nb := n.bounds
	if nb.Empty() {
		// For starting bounds we will (squarely) encapsulate the rectangle.
		rsz := r.Size()
		s := rsz.X
		if rsz.Y > s {
			s = rsz.Y
		}
		if rsz.Z > s {
			s = rsz.Z
		}
		rcenter := r.Center()
		s /= 2
		s *= 32
		startSize := math.Vec3{s, s, s}
		n.bounds = math.Rect3{
			Min: rcenter.Sub(startSize),
			Max: rcenter.Add(startSize),
		}
		return nil
	}

	// Expansion occurs by growing the octree such that the root node becomes
	// a new node whose child is the old root node. Thus we can simply
	// determine in which direction the new root should be extended (by twice
	// the old root's size) by comparing the centres of the old root and the
	// rectangle in question.
	c := nb.Center()
	rc := r.Center()
	sz := nb.Size()

	// Expand by becoming the opposite octant of r's closest point to nb.
	var ci ChildIndex
	if rc.Z > c.Z {
		// Top
		if rc.Y > c.Y {
			// Top, Front
			if rc.X > c.X {
				ci = TopFrontRight
			} else {
				ci = TopFrontLeft
			}
		} else {
			// Top, Back
			if rc.X > c.X {
				ci = TopBackRight
			} else {
				ci = TopBackLeft
			}
		}
	} else {
		// Bottom
		if rc.Y > c.Y {
			// Bottom, Front
			if rc.X > c.X {
				ci = BottomFrontRight
			} else {
				ci = BottomFrontLeft
			}
		} else {
			// Bottom, Back
			if rc.X > c.X {
				ci = BottomBackRight
			} else {
				ci = BottomBackLeft
			}
		}
	}

	expDown := ci.Bottom()
	expBack := ci.Back()
	expLeft := ci.Left()

	fb := n.bounds
	if expDown {
		fb.Min.Z -= sz.Z
	} else {
		fb.Max.Z += sz.Z
	}

	if expBack {
		fb.Min.Y -= sz.Y
	} else {
		fb.Max.Y += sz.Y
	}

	if expLeft {
		fb.Min.X -= sz.X
	} else {
		fb.Max.X += sz.X
	}

	newRoot := &Node{
		access:  n.access,
		bounds:  fb,
		level:   n.level + 1,
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:rand,代码行数:101,代码来源:node.go


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