Beispiel #1
0
// Draw draws this to the target region.
func (m *Model) Draw(r Region, delta float64) {
	if m.isNew || m.isDirty() || forceDirty {
		m.isNew = false
		data := m.data[:0]

		for _, v := range m.verts {
			vec := mgl32.Vec3{v.X - 0.5, v.Y - 0.5, v.Z - 0.5}
			vec = m.mat.Mul4x1(vec.Vec4(1)).Vec3().
				Add(mgl32.Vec3{0.5, 0.5, 0.5})
			vX, vY, vZ := vec[0], 1.0-vec[1], vec[2]

			dx := r.X + r.W*float64(vX)
			dy := r.Y + r.H*float64(vY)
			dx /= scaledWidth
			dy /= scaledHeight
			data = appendShort(data, int16(math.Floor((dx*float64(lastWidth))+0.5)))
			data = appendShort(data, int16(math.Floor((dy*float64(lastHeight))+0.5)))
			data = appendShort(data, 256*int16(m.Layer())+int16(256*vZ))
			data = appendShort(data, 0)
			data = appendUnsignedShort(data, v.TX)
			data = appendUnsignedShort(data, v.TY)
			data = appendUnsignedShort(data, v.TW)
			data = appendUnsignedShort(data, v.TH)
			data = appendShort(data, v.TOffsetX)
			data = appendShort(data, v.TOffsetY)
			data = appendShort(data, v.TAtlas)
			data = appendShort(data, 0)
			data = appendUnsignedByte(data, v.R)
			data = appendUnsignedByte(data, v.G)
			data = appendUnsignedByte(data, v.B)
			data = appendUnsignedByte(data, v.A)
		}
		m.data = data
	}
	render.UIAddBytes(m.data)
}