Beispiel #1
0
 def GetRayAndPointFromUI(self,
                          x,
                          y,
                          projection2view=None,
                          view2world=None):
     viewport = self.viewport
     mx = x - viewport.x
     my = y - viewport.y
     w = viewport.width
     h = viewport.height
     fx = float(mx * 2) / w - 1.0
     fy = float(my * 2) / h - 1.0
     fy *= -1
     projection2view = projection2view or geo2.MatrixInverse(
         self.projectionMatrix.transform)
     view2world = view2world or geo2.MatrixInverse(
         self.viewMatrix.transform)
     rayStart = (fx, fy, 0.0)
     rayStart = geo2.Vec3TransformCoord(rayStart, projection2view)
     rayStart = geo2.Vec3TransformCoord(rayStart, view2world)
     rayEnd = (fx, fy, 1.0)
     rayEnd = geo2.Vec3TransformCoord(rayEnd, projection2view)
     rayEnd = geo2.Vec3TransformCoord(rayEnd, view2world)
     rayDir = geo2.Vec3SubtractD(rayEnd, rayStart)
     return (geo2.Vec3NormalizeD(rayDir), rayStart)
Beispiel #2
0
 def _Hemisphere(self, x, y):
     dev = trinity.device
     center = geo2.Vector(self.frontPlaneTranslation[3][0],
                          self.frontPlaneTranslation[3][1],
                          self.frontPlaneTranslation[3][2])
     view = trinity.GetViewTransform()
     proj = trinity.GetProjectionTransform()
     side = center - geo2.Vector(view[0][0], view[1][0], view[2][0])
     center = geo2.Vec3TransformCoord(center, view)
     center = geo2.Vec3TransformCoord(center, proj)
     center = geo2.Vector(*center)
     side = geo2.Vec3TransformCoord(side, view)
     side = geo2.Vec3TransformCoord(side, proj)
     side = geo2.Vector(*side)
     side.x += 1.0
     side.y += 1.0
     center.x += 1.0
     center.y += 1.0
     dim = abs(dev.width * (side.x - center.x)) * 0.5
     screenx = int((dev.width - 1) * 0.5 * center.x)
     screeny = dev.height - int((dev.height - 1) * 0.5 * center.y)
     px = float(x - screenx) / float(dim)
     py = float(screeny - y) / float(dim)
     d = math.sqrt(px * px + py * py)
     if d > 1.0:
         a = 1.0 / d
         vec = geo2.Vector(px * a, py * a, 0.0)
     else:
         vec = geo2.Vector(px, py, -(1.0 - d))
     return geo2.Vec3Normalize(vec)
Beispiel #3
0
 def GetUIPositionFromWorldPosition(self, worldPosition):
     worldPosition = geo2.Vec3TransformCoord(worldPosition,
                                             self.viewMatrix.transform)
     worldPosition = geo2.Vec3TransformCoord(
         worldPosition, self.projectionMatrix.transform)
     worldPosition = geo2.Vector(*worldPosition)
     x = 0.5 + worldPosition.x * 0.5
     y = 1.0 - (0.5 + worldPosition.y * 0.5)
     return (x * self.viewport.width, y * self.viewport.height)
 def Update(self):
     normalCamera = self._GetNonDebugCamera()
     if not self.IsUpdatingDebugCamera() and normalCamera:
         if normalCamera:
             normalCamera.Update()
     if self.IsShowingNormalCamera() and normalCamera:
         camPos = normalCamera.GetPosition()
         poi = normalCamera.GetPointOfInterest()
         vec = geo2.Vec3Subtract(poi, camPos)
         vec = geo2.Vec3Normalize(vec)
         vec = geo2.Vec3Scale(vec, 0.5)
         self.debugRenderClient.RenderCone(camPos,
                                           geo2.Vec3Add(camPos, vec),
                                           0.25,
                                           4278190335L,
                                           time=1)
         if self.lastCamPos is not None and camPos != self.lastCamPos:
             self.debugRenderClient.RenderRay(self.lastCamPos,
                                              camPos,
                                              4278190335L,
                                              4278255360L,
                                              time=1000,
                                              pulse=True)
         self.lastCamPos = camPos
     if self.translationVector != [0.0, 0.0, 0.0]:
         now = blue.os.GetWallclockTime()
         frameTime = float(now - self.lastUpdateTime) / const.SEC
         poi = cameras.PolarCamera.GetPointOfInterest(self)
         rotMatrix = geo2.MatrixRotationYawPitchRoll(
             math.pi / 2.0 - self.yaw, math.pi / 2.0 - self.pitch, 0.0)
         scaledVector = geo2.Vec3Scale(self.translationVector, frameTime)
         relativeVector = geo2.Vec3TransformCoord(scaledVector, rotMatrix)
         newPos = geo2.Vec3Add(poi, relativeVector)
         cameras.PolarCamera.SetPointOfInterest(self, newPos)
     cameras.PolarCamera.Update(self)
Beispiel #5
0
def DrawLineSetCircle(lineSet, centerPosition, outerPosition, segmentSize, lineColor = (0.3, 0.3, 0.3, 0.5), lineWeight = 2.0, animationSpeed = 0.0, dashSegments = 0, dashColor = None):
    orbitPos = geo2.Vector(*outerPosition)
    parentPos = geo2.Vector(*centerPosition)
    dirVec = orbitPos - parentPos
    radius = geo2.Vec3Length(dirVec)
    fwdVec = (1.0, 0.0, 0.0)
    dirVec = geo2.Vec3Normalize(dirVec)
    rotation = geo2.QuaternionRotationArc(fwdVec, dirVec)
    matrix = geo2.MatrixAffineTransformation(1.0, (0.0, 0.0, 0.0), rotation, centerPosition)
    circum = math.pi * 2 * radius
    steps = min(256, max(16, int(circum / segmentSize)))
    coordinates = []
    stepSize = math.pi * 2 / steps
    for step in range(steps):
        angle = step * stepSize
        x = math.cos(angle) * radius
        z = math.sin(angle) * radius
        pos = geo2.Vector(x, 0.0, z)
        pos = geo2.Vec3TransformCoord(pos, matrix)
        coordinates.append(pos)

    lineIDs = set()
    dashColor = dashColor or lineColor
    for start in xrange(steps):
        end = (start + 1) % steps
        lineID = lineSet.AddStraightLine(coordinates[start], lineColor, coordinates[end], lineColor, lineWeight)
        lineIDs.add(lineID)
        if dashSegments:
            lineSet.ChangeLineAnimation(lineID, dashColor, animationSpeed, dashSegments)

    return lineIDs
Beispiel #6
0
 def _GetViewMatrixFromAngle(self, cameraAngle, lookAt, cameraDistance):
     view_at = geo2.Vector(lookAt[0], lookAt[1], lookAt[2])
     view_eye = geo2.Vector(0.0, 0.0, 1.0)
     angleTransform = geo2.MatrixRotationYawPitchRoll(cameraAngle[0], cameraAngle[1], cameraAngle[2])
     view_eye = geo2.Vec3TransformCoord(view_eye, angleTransform)
     view_eye = geo2.Vector(*view_eye)
     view_eye = view_eye * cameraDistance + view_at
     return (view_eye, view_at, geo2.Vector(*GETPHOTO_VIEW_UP))
Beispiel #7
0
 def SetupFakeAudioTransformLocation(self, shipPosition):
     self.fakeAudioTransform.translationCurve = trinity.TriVectorCurve()
     viewTransformOffset = geo2.MatrixTransformation(
         (0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0), (1.0, 1.0, 1.0),
         (0.0, 0.0, 0.0), self.sceneRotation, self.sceneTranslation)
     viewTransformInverse = geo2.MatrixInverse(viewTransformOffset)
     newAudioEmitterPosition = geo2.Vec3TransformCoord(
         shipPosition, viewTransformInverse)
     self.fakeAudioTransform.translationCurve.value = newAudioEmitterPosition
     distance = geo2.Vec3Distance((0, 0, 0), newAudioEmitterPosition)
     gallenteHangarBaseline = 561.28692627
     audioScaleFactor = distance / gallenteHangarBaseline
     self.generalAudioEntity.SetAttenuationScalingFactor(audioScaleFactor)
def _GetViewMatrixFromAngle(cameraAngle, lookAt, cameraDistance):
    """
    Given a LookAt point, camera distance and direction (angle), return
    a (view_eye, view_at, view_up) tuple of geo2.Vectors
    """
    view_at = geo2.Vector(lookAt[0], lookAt[1], lookAt[2])
    view_eye = geo2.Vector(0.0, 0.0, 1.0)
    angleTransform = geo2.MatrixRotationYawPitchRoll(cameraAngle[0],
                                                     cameraAngle[1],
                                                     cameraAngle[2])
    view_eye = geo2.Vec3TransformCoord(view_eye, angleTransform)
    view_eye = geo2.Vector(*view_eye)
    view_eye = view_eye * cameraDistance + view_at
    return (view_eye, view_at, geo2.Vector(*GETPHOTO_VIEW_UP))
    def calculateProjectedBoundingBox(combinedTransform):
        """
        Project each vertex in the bounding box to screen space and calculate
        it's projected bounding box
        """
        edges = []
        edges.append(
            geo2.Vector(boundingBoxMin[0], boundingBoxMin[1],
                        boundingBoxMin[2]))
        edges.append(
            geo2.Vector(boundingBoxMin[0], boundingBoxMin[1],
                        boundingBoxMax[2]))
        edges.append(
            geo2.Vector(boundingBoxMin[0], boundingBoxMax[1],
                        boundingBoxMin[2]))
        edges.append(
            geo2.Vector(boundingBoxMin[0], boundingBoxMax[1],
                        boundingBoxMax[2]))
        edges.append(
            geo2.Vector(boundingBoxMax[0], boundingBoxMin[1],
                        boundingBoxMin[2]))
        edges.append(
            geo2.Vector(boundingBoxMax[0], boundingBoxMin[1],
                        boundingBoxMax[2]))
        edges.append(
            geo2.Vector(boundingBoxMax[0], boundingBoxMax[1],
                        boundingBoxMin[2]))
        edges.append(
            geo2.Vector(boundingBoxMax[0], boundingBoxMax[1],
                        boundingBoxMax[2]))
        for i, edge in enumerate(edges):
            edge = geo2.Vector(
                *geo2.Vec3TransformCoord(edge, combinedTransform))
            if i == 0:
                safeMin = geo2.Vector(*edge)
                safeMax = geo2.Vector(*edge)
            else:
                safeMin.x = min(safeMin.x, edge[0])
                safeMin.y = min(safeMin.y, edge[1])
                safeMin.z = min(safeMin.z, edge[2])
                safeMax.x = max(safeMax.x, edge[0])
                safeMax.y = max(safeMax.y, edge[1])
                safeMax.z = max(safeMax.z, edge[2])

        return (safeMin, safeMax)
Beispiel #10
0
        def CalculateProjectedBoundingBox(combinedTransform):
            edges = []
            edges.append(geo2.Vector(boundingBoxMin.x, boundingBoxMin.y, boundingBoxMin.z))
            edges.append(geo2.Vector(boundingBoxMin.x, boundingBoxMin.y, boundingBoxMax.z))
            edges.append(geo2.Vector(boundingBoxMin.x, boundingBoxMax.y, boundingBoxMin.z))
            edges.append(geo2.Vector(boundingBoxMin.x, boundingBoxMax.y, boundingBoxMax.z))
            edges.append(geo2.Vector(boundingBoxMax.x, boundingBoxMin.y, boundingBoxMin.z))
            edges.append(geo2.Vector(boundingBoxMax.x, boundingBoxMin.y, boundingBoxMax.z))
            edges.append(geo2.Vector(boundingBoxMax.x, boundingBoxMax.y, boundingBoxMin.z))
            edges.append(geo2.Vector(boundingBoxMax.x, boundingBoxMax.y, boundingBoxMax.z))
            for i, edge in enumerate(edges):
                edge = geo2.Vector(*geo2.Vec3TransformCoord(edge, combinedTransform))
                if i == 0:
                    safeMin = geo2.Vector(*edge)
                    safeMax = geo2.Vector(*edge)
                else:
                    safeMin.x = min(safeMin.x, edge[0])
                    safeMin.y = min(safeMin.y, edge[1])
                    safeMin.z = min(safeMin.z, edge[2])
                    safeMax.x = max(safeMax.x, edge[0])
                    safeMax.y = max(safeMax.y, edge[1])
                    safeMax.z = max(safeMax.z, edge[2])

            return (safeMin, safeMax)