def GetPickIntersectionPoint(x=None, y=None):
    """
    Returns the point on the planet at (x, y) screen coordinates. This is done
    by casting a ray based on the screen coordinates (x, y) and the viewport
    and then finally calculating the intersection of that ray and a sphere (the planet).
    Method defaults to the current mouse coordinates if x and y arguments are None
    Returns None if the planet was not clicked.
    Arguments:
    x - the x coordinates in screen space
    y - the y coordinares in screen space
    """
    if None in (x, y):
        x, y = int(uicore.uilib.x * uicore.desktop.dpiScaling), int(
            uicore.uilib.y * uicore.desktop.dpiScaling)
    device = trinity.device
    proj, view, vp = uix.GetFullscreenProjectionViewAndViewport()
    ray, start = device.GetPickRayFromViewport(x, y, vp, view.transform,
                                               proj.transform)
    lineVec = trinity.TriVector(*ray)
    lineP0 = trinity.TriVector(*start)
    sphereP0 = trinity.TriVector(0.0, 0.0, 0.0)
    sphereRad = 1000.0
    pInt = GetSphereLineIntersectionPoint(lineP0, lineVec, sphereP0, sphereRad)
    if not pInt:
        return
    ret = SurfacePoint(pInt.x, pInt.y, pInt.z)
    ret.SetRadius(1.0)
    return ret
Example #2
0
 def _GetLineCenterPoint(self, sp1, sp2):
     x = sp1.x / 2.0 + sp2.x / 2.0
     y = sp1.y / 2.0 + sp2.y / 2.0
     z = sp1.z / 2.0 + sp2.z / 2.0
     sp = SurfacePoint(x, y, z)
     sp.SetRadius(1.0)
     return sp
Example #3
0
 def _GetTriangleCenterPoint(self, sp1, sp2, sp3):
     x = sp1.x / 3.0 + sp2.x / 3.0 + sp3.x / 3.0
     y = sp1.y / 3.0 + sp2.y / 3.0 + sp3.y / 3.0
     z = sp1.z / 3.0 + sp2.z / 3.0 + sp3.z / 3.0
     sp = SurfacePoint(x, y, z)
     sp.SetRadius(1.0)
     return sp
Example #4
0
def GetPickIntersectionPoint(x=None, y=None):
    if None in (x, y):
        x, y = int(uicore.uilib.x * uicore.desktop.dpiScaling), int(
            uicore.uilib.y * uicore.desktop.dpiScaling)
    device = trinity.device
    proj, view, vp = uix.GetFullscreenProjectionViewAndViewport()
    ray, start = device.GetPickRayFromViewport(x, y, vp, view.transform,
                                               proj.transform)
    lineVec = trinity.TriVector(*ray)
    lineP0 = trinity.TriVector(*start)
    sphereP0 = trinity.TriVector(0.0, 0.0, 0.0)
    sphereRad = 1000.0
    pInt = GetSphereLineIntersectionPoint(lineP0, lineVec, sphereP0, sphereRad)
    if not pInt:
        return
    ret = SurfacePoint(pInt.x, pInt.y, pInt.z)
    ret.SetRadius(1.0)
    return ret
Example #5
0
 def _SplitTriangle(self, v0, v1, v2, lines, cLines, hLines, sps, level):
     level -= 1
     lc0 = self._GetLineCenterPoint(v0, v1)
     lc1 = self._GetLineCenterPoint(v1, v2)
     lc2 = self._GetLineCenterPoint(v2, v0)
     tc = self._GetTriangleCenterPoint(v0, v1, v2)
     if level > 0:
         self._SplitTriangle(v0, lc0, lc2, lines, cLines, hLines, sps,
                             level)
         self._SplitTriangle(v1, lc1, lc0, lines, cLines, hLines, sps,
                             level)
         self._SplitTriangle(v2, lc2, lc1, lines, cLines, hLines, sps,
                             level)
         self._SplitTriangle(lc0, lc1, lc2, lines, cLines, hLines, sps,
                             level)
     else:
         v = geo2.Vector
         vecC = v(*tc.GetAsXYZTuple())
         vec0 = v(*v0.GetAsXYZTuple())
         vec1 = v(*v0.GetAsXYZTuple())
         vec2 = v(*v0.GetAsXYZTuple())
         vec01 = v(*(v1.x - v0.x, v1.y - v0.y, v1.z - v0.z))
         n0 = v(*geo2.Vec3Cross(vecC, vec01))
         vec12 = v(*(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z))
         n1 = v(*geo2.Vec3Cross(vecC, vec12))
         vec20 = v(*(v0.x - v2.x, v0.y - v2.y, v0.z - v2.z))
         n2 = v(*geo2.Vec3Cross(vecC, vec20))
         s = 0.16
         sGap = 0.1
         n0 = v(*(s * n0))
         n1 = v(*(s * n1))
         n2 = v(*(s * n2))
         lp0 = SurfacePoint(*(vecC - n0))
         lp1 = SurfacePoint(*(vecC - n1))
         lp2 = SurfacePoint(*(vecC - n2))
         lr0 = SurfacePoint(*(vecC - v(*(sGap * n0))))
         lr1 = SurfacePoint(*(vecC - v(*(sGap * n1))))
         lr2 = SurfacePoint(*(vecC - v(*(sGap * n2))))
         lp0.SetRadius(1.0)
         lp1.SetRadius(1.0)
         lp2.SetRadius(1.0)
         lr0.SetRadius(1.0)
         lr1.SetRadius(1.0)
         lr2.SetRadius(1.0)
         lines.add((lr0, lp0))
         lines.add((lr1, lp1))
         lines.add((lr2, lp2))