def do_highlight_C(highlight_cursor, faces, points): global self_model, self_proj, self_view # the gluProject helper retrieve those for us # but calling this once is a good time save speedup model = glGetDoublev( GL_MODELVIEW_MATRIX ) proj = glGetDoublev( GL_PROJECTION_MATRIX ) view = glGetIntegerv( GL_VIEWPORT ) # same camera ? def same_float_array(X, Y): Z = X - Y for i in Z: for j in i: if abs(j) > 0.00001: return False return True V = view == self_view if not isinstance(V, bool): V = V.all() same_camera = V and \ same_float_array(model, self_model) and \ same_float_array(proj, self_proj) self_model = model self_proj = proj self_view = view cursor = Point2D(*highlight_cursor) if not same_camera: with benchmark('glu'): model_as_list = model[0].tolist() + \ model[1].tolist() + \ model[2].tolist() + \ model[3].tolist() proj_as_list = proj[0].tolist() + \ proj[1].tolist() + \ proj[2].tolist() + \ proj[3].tolist() view_as_list = view.tolist() projall(model_as_list, proj_as_list, view_as_list) with benchmark('python'): hits = gethits(cursor.x, cursor.y) display_hits(hits, points) return True
from scene import ArgsOptions, load from cobj import setup, projall, gethits def scene2c(): ao = ArgsOptions() options = [ao.options.fn, ao.options.verbose, ao.options.procedural] return load(*options) sc = scene2c() print sc setup([p.pos for p in sc.objets[0].g.points], sc.objets[0].g.faces) model = [ -0.62869209, 0.77656037, -0.04123428, 0., 0.22454762, 0.13051406, -0.9656834, 0., -0.74452978, -0.61637658, -0.25642794, 0. - 0.03640071, -0.0022433, -0.45071667, 1. ] proj = [ 3.02691031, 0., 0., 0., 0., 3.4874146, 0., 0., 0., 0., -1.01390326, -1., -0., -0., -0.01119764, -0. ] view = [0, 0, 674, 585] projall(model, proj, view) gethits(50, 50)
from scene import ArgsOptions, load from cobj import setup, projall, gethits def scene2c(): ao = ArgsOptions() options = [ao.options.fn, ao.options.verbose, ao.options.procedural] return load(*options) sc = scene2c() print sc setup([p.pos for p in sc.objets[0].g.points], sc.objets[0].g.faces) model = [-0.62869209, 0.77656037 , -0.04123428 , 0. , 0.22454762, 0.13051406 , -0.9656834 , 0. , -0.74452978, -0.61637658 , -0.25642794 , 0. -0.03640071, -0.0022433 , -0.45071667 , 1. ] proj = [ 3.02691031, 0. , 0. , 0. , 0. , 3.4874146 , 0. , 0. , 0. , 0. , -1.01390326, -1. , -0. , -0. , -0.01119764, -0. ] view = [ 0, 0, 674, 585] projall(model, proj, view) gethits(50, 50)