def model_to_screen(x, y, z): m = get_model_matrix(c_double, pgl.glGetDoublev) p = get_projection_matrix(c_double, pgl.glGetDoublev) w = get_viewport() mx, my, mz = c_double(), c_double(), c_double() pgl.gluProject(x, y, z, m, p, w, mx, my, mz) return float(mx.value), float(my.value), float(mz.value)
def _worldobj_on_translate(control, target, x, y, dx, dy): from miru.context import context from miru import camera self = control if isinstance(context.camera, camera.MetaCamera): context.camera.focussed.render() viewport = (gl.GLint * 4)() mvmatrix = (gl.GLdouble * 16)() projmatrix = (gl.GLdouble * 16)() gl.glGetIntegerv(gl.GL_VIEWPORT, viewport) gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, mvmatrix) gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, projmatrix) wx = gl.GLdouble() wy = gl.GLdouble() wz = gl.GLdouble() sz = gl.GLdouble() ex = target.pos.x ey = target.pos.y ez = target.pos.z gl.gluProject(ex, ey, ez, mvmatrix, projmatrix, viewport, wx, wy, sz) gl.gluUnProject(x, y, sz, mvmatrix, projmatrix, viewport, wx, wy, wz) if self.axis == self.AXIS_X: target.pos = (wx.value, wz.value, target.pos.z) elif self.axis == self.AXIS_Y: target.pos = (target.pos.x, wy.value, wz.value) elif self.axis == self.AXIS_Z: tz = dy * 0.01 tz += (dx * 0.01) target.pos += (0, 0, tz) else: target.pos = (wx.value, wy.value, wz.value)
def model_to_screen(c): """ Returns the screen point of given 3D coordinate :param c: The 3D coordinates :type c: 3-tuple of float (x,y,z) :rtype: 3-tuple float (x,y,z) """ m = (c_double*16)() glGetDoublev(GL_MODELVIEW_MATRIX, m) p = (c_double*16)() glGetDoublev(GL_PROJECTION_MATRIX, p) v = (c_int*4)() glGetIntegerv(GL_VIEWPORT, v) x, y, z = c_double(), c_double(), c_double() gluProject(c[0], c[1], c[2], m, p, v, x, y, z) return x, y, z