import Blender
from Blender import *


scn = Scene.GetCurrent()
ob = Object.GetSelected()[0]
me = ob.getData(mesh=1)
mat = ob.matrix
print mat
mat_inv = Mathutils.Matrix(mat).invert()
#point = Mathutils.Vector(0,-2,2)
point= Mathutils.Vector(Window.GetCursorPos())
print point
if me.pointInside(point*mat_inv):
	print 'hello'
	
outfile = open('MonkeyCoords.txt','w')


# Coordinates of bounding box
xmin = -2.0
xmax = 2.0
ymin = -2.0
ymax = 2.0
zmin = -2.0
zmax = 2.0


step = 0.05
xlist = []
ylist = []
zlist = []
val = xmin

while 1:
	xlist.append(val)
	ylist.append(val)
	zlist.append(val)
	val = val+step
	if val>=xmax:
		break

for x in xlist:
	print x
	for y in ylist:
		for z in zlist:
			x = float(x)
			y = float(y)
			z = float(z)
			pt=Mathutils.Vector(x,y,z)
			inside= me.pointInside(pt*mat_inv)
			if inside==False:
				status=0
			if inside==True:
				status=1
							
			outfile.write(str(x)+' '+str(y)+' '+str(z)+' '+str(status)+'\n')



outfile.close()