[Bf-python] New Mathutils and old Math - Letter rip.
Gilbert, Joseph
jgilbert at tigr.ORG
Fri Sep 30 18:12:59 CEST 2005
I'll take a look at what's going on here. I'm thinking something might
be at issue with Window.GetPerspMatrix() or matrix instance assignment.
I'll try running this script here. I think we can submit a bug report to
see what's going on. If there is a better script or a .blend which more
clearly illustrates what's going on let me know or submit it to the
tracker.
-----Original Message-----
From: bf-python-bounces at projects.blender.org
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Campbell
Barton
Sent: Tuesday, September 27, 2005 8:30 PM
To: bf-python at blender.org
Subject: [Bf-python] New Mathutils and old Math - Letter rip.
Hi, quick message.
I was using LetterRips function to get the worldspace coords for the
mouse in the 3d view. as used by the sculpt mesh script.
Recently I found that it stopped working in perspective mode, is awyone
aware of why this might happen?
Im not sure exactly when this happened but it was definetly working
after the Mathutils update that deprecated a lot of things, because I
modified it to work with the new mathutils.
Somehow its broken, I tested sculpt_mesh_tablet25.zip and thats also
broken in perspective mode, so thaught I post.
- Cam
______________ LetterRips Very usefull function for getting mouse
coords/vector in 3d space.
def getMouseLocalCoordinates(screen_x, screen_y, useMid = False):
def sub_v3v3 (vector1, vector2):
return [vector1[0]-vector2[0], vector1[1]-vector2[1],
vector1[2]-vector2[2]]
def dot_v3v3 (vector1, vector2):
return vector1[0]*vector2[0] + vector1[1]*vector2[1] +
vector1[2]*vector2[2]
def scale_v3s (vector, scalar):
return [vector[0]*scalar, vector[1]*scalar, vector[2]*scalar]
def normalize_v3 (vector):
length = math.sqrt (dot_v3v3 (vector, vector))
if length != 0.0: return scale_v3s (vector, 1.0/length)
return [0.0, 0.0, 0.0]
for win3d in Window.GetScreenInfo(Window.Types.VIEW3D):
win_min_x, win_min_y, win_max_x, win_max_y =
win3d.get('vertices')
win_mid_x = (win_max_x + win_min_x + 1.0) * 0.5
win_mid_y = (win_max_y + win_min_y + 1.0) * 0.5
win_size_x = (win_max_x - win_min_x + 1.0) * 0.5
win_size_y = (win_max_y - win_min_y + 1.0) * 0.5
if useMid == True:
screen_x = win_mid_x
screen_y = win_mid_y
if (win_max_x > screen_x > win_min_x) and ( win_max_y >
screen_y > win_min_y):
Window.QHandle(win3d.get('id'))
vmi = Window.GetViewMatrix(); vmi.invert() #should be done
outside of the loop
pm = Window.GetPerspMatrix() #also outside of loop
pmi = Window.GetPerspMatrix(); pmi.invert() #also outside
of loop
epsilon = 1e-3
if (1.0 - epsilon < pmi[3][3] < 1.0 + epsilon):
hms = Vector([(screen_x-win_mid_x) / win_size_x,
(screen_y-win_mid_y) / win_size_y, 0.0,1.0])
#p=VecMultMat(hms,pmi)
p = hms * pmi
d=Vector(list(Window.GetViewVector())+[0.0])
else:
dxy=[pm[3][3]*(((screen_x-win_min_x)/win_size_x)-1.0) -
pm[3][0],
pm[3][3]*(((screen_y-win_min_y)/win_size_y)-1.0) - pm[3][1]]
fp=Vector([pmi[0][0]*dxy[0]+pmi[1][0]*dxy[1],
pmi[0][1]*dxy[0]+pmi[1][1]*dxy[1],
pmi[0][2]*dxy[0]+pmi[1][2]*dxy[1]])
p=Vector([vmi[3][0],vmi[3][1],vmi[3][2],vmi[3][3]])
d=Vector(normalize_v3(sub_v3v3(p, fp))+[0.0])
return True,p,d
else:
return False,Vector(),Vector()
--
Campbell J Barton
133 Hope Street
Geelong West, Victoria 3218 Australia
URL: http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241
_______________________________________________
Bf-python mailing list
Bf-python at projects.blender.org
http://projects.blender.org/mailman/listinfo/bf-python
More information about the Bf-python
mailing list