Esempio n. 1
0
// Move overrides the default movement behaviour so that motion is applied to
// any associated bodies as velocity instead of directly updating the location.
func (p *part) Move(x, y, z float64) {
	if p.body == nil {
		p.pov.Move(x, y, z)
	} else {

		// apply push in the current direction.
		dx, dy, dz := lin.MultSQ(x, y, z, p.dir)
		p.body.Push(dx, dy, dz)
	}
}
Esempio n. 2
0
// Implements Shape.Aabb
// The axis aligned bounding box must be big enough to surround a box
// that has been transformed.
func (b *box) Aabb(t *lin.T, ab *Abox, margin float64) *Abox {

	// transform the basis vectors, keeping them positive for extents.
	xx, xy, xz := lin.MultSQ(1, 0, 0, t.Rot)
	yx, yy, yz := lin.MultSQ(0, 1, 0, t.Rot)
	zx, zy, zz := lin.MultSQ(0, 0, 1, t.Rot)
	xx, xy, xz = math.Abs(xx), math.Abs(xy), math.Abs(xz)
	yx, yy, yz = math.Abs(yx), math.Abs(yy), math.Abs(yz)
	zx, zy, zz = math.Abs(zx), math.Abs(zy), math.Abs(zz)

	// Dot the half-extents, plus margin, with the transformed basis vectors.
	// to get the furthest extent in each direction.
	hmx, hmy, hmz := b.Hx+margin, b.Hy+margin, b.Hz+margin
	ex := hmx*xx + hmy*xy + hmz*xz
	ey := hmx*yx + hmy*yy + hmz*yz
	ez := hmx*zx + hmy*zy + hmz*zz

	ab.Sx, ab.Sy, ab.Sz = t.Loc.X-ex, t.Loc.Y-ey, t.Loc.Z-ez
	ab.Lx, ab.Ly, ab.Lz = t.Loc.X+ex, t.Loc.Y+ey, t.Loc.Z+ez
	return ab
}
Esempio n. 3
0
// Move increments the current position with respect to the current
// orientation, i.e. adds the distance travelled in the current direction
// to the current location.
func (p *pov) Move(x, y, z float64) {
	dx, dy, dz := lin.MultSQ(x, y, z, p.dir)
	p.loc.X += dx
	p.loc.Y += dy
	p.loc.Z += dz
}