예제 #1
0
 def Pan(self, dx = 0, dy = 0, dz = 0):
     """ Pan along current camera xyz coordinates """
     if self.panTarget is None:
         self.panTarget = geo2.Vector(0, 0, 0)
     if dx:
         self.panTarget += geo2.Scale(self.GetXAxis(), dx)
     if dy:
         self.panTarget += geo2.Scale(self.GetYAxis(), dy)
     if dz:
         self.panTarget += geo2.Scale(self.GetZAxis(), dz)
     if not self.panUpdateThread:
         self.panUpdateThread = uthread.new(self.PanUpdateThread)
예제 #2
0
 def PanMouseDelta(self, dx, dy):
     unit = geo2.Vec3Length(self._eyePositionCurrent) / math.atan(self.fieldOfView / 2)
     if self.viewport:
         viewUnit = unit / self.viewport.height / 2.0
     else:
         viewUnit = 2.0
     if self._panSpeed is None:
         self._panSpeed = geo2.Vector(0, 0, 0)
     if dx:
         self._panSpeed += geo2.Scale(self.GetXAxis(), -dx * viewUnit)
     if dy:
         self._panSpeed += geo2.Scale(self.GetYAxis(), dy * viewUnit)
예제 #3
0
 def _EnforceMinMaxZoom(self, eyePos):
     vEye = geo2.Subtract(eyePos, self.atPosition)
     vMaxZoom = geo2.Scale(self.GetZAxis(), self.maxZoom)
     vEyeToMaxZoom = geo2.Subtract(vEye, vMaxZoom)
     if geo2.Vec3Dot(vEyeToMaxZoom, vMaxZoom) < 0:
         eyePos = geo2.Add(self.atPosition, vMaxZoom)
         self.zoomTarget = None
     vMinZoom = geo2.Scale(self.GetZAxis(), self.minZoom)
     vEyeToMinZoom = geo2.Subtract(vEye, vMinZoom)
     if geo2.Vec3Dot(vEyeToMinZoom, vMinZoom) > 0:
         eyePos = geo2.Add(self.atPosition, vMinZoom)
         self.zoomTarget = None
     return eyePos
예제 #4
0
 def PanAxis(self, axis, amount):
     """ Pan along a given axis """
     if self.panTarget is None:
         self.panTarget = geo2.Vector(0, 0, 0)
     self.panTarget += geo2.Scale(axis, amount)
     if not self.panUpdateThread:
         self.panUpdateThread = uthread.new(self.PanUpdateThread)
예제 #5
0
파일: mathUtil.py 프로젝트: R4M80MrX/eve-1
def RayToPlaneIntersection(P, d, Q, n):
    denom = geo2.Vec3Dot(n, d)
    if abs(denom) < 1e-05:
        return P
    else:
        distance = -geo2.Vec3Dot(Q, n)
        t = -(geo2.Vec3Dot(n, P) + distance) / denom
        S = geo2.Add(geo2.Scale(d, t), P)
        return S
예제 #6
0
def RayToPlaneIntersection(P, d, Q, n, returnSign = False):
    position = P
    sign = 1
    denom = geo2.Vec3Dot(n, d)
    if abs(denom) >= 1e-05:
        distance = -geo2.Vec3Dot(Q, n)
        t = -(geo2.Vec3Dot(n, P) + distance) / denom
        if t < 0:
            sign = -1
        S = geo2.Add(geo2.Scale(d, t), P)
        position = S
    if returnSign:
        return (position, sign)
    return position
예제 #7
0
 def Update(self, *args):
     t = blue.os.GetSimTime()
     if t == self.lastUpdateTime:
         return
     if sm.GetService('michelle').GetBall(self.itemID) is None:
         self.Close()
         return
     self.UpdateBoxPosition()
     bracketPos = self.GetContainerPosition(self.bracket)
     boxPos = self.GetContainerPosition(self.floatingBox)
     lineTo = self.GetLineConnectionPointOnBox(bracketPos, self.floatingBox)
     cornerPos = geo2.Vec2Add(boxPos, lineTo)
     vec = geo2.Vec2Subtract(bracketPos, cornerPos)
     length = geo2.Vec2Length(vec)
     vec = geo2.Scale(vec, (length - uicore.ScaleDpi(ICON_SIZE / 2)) / length)
     self.line.translationTo = geo2.Vec2Add(vec, lineTo)
     self.line.translationFrom = lineTo
예제 #8
0
def RayToPlaneIntersection(P, d, Q, n):
    """
    Computes the intersection of the ray defined by point P and direction d with the plane
    defined by the point Q and the normal n.
    
    If the P lies on the plane defined by n and Q, there are infinite number of 
    intersection points, so the function returns P.
    
    d' = - Q.Dot(n)
    t = -(n.Dot(P) + d' )/n.Dot(d)
    S = P + t*d
    """
    denom = geo2.Vec3Dot(n, d)
    if abs(denom) < 1e-05:
        return P
    else:
        distance = -geo2.Vec3Dot(Q, n)
        t = -(geo2.Vec3Dot(n, P) + distance) / denom
        S = geo2.Add(geo2.Scale(d, t), P)
        return S
예제 #9
0
def RayToPlaneIntersection(P, d, Q, n):
    """
        The intersection point(S) on a plane where d shot from P would intersect
        the plane defined by Q and n.
    
        If the P lies on the plane defined by n and Q, there are infinite number of 
        intersection points so the function returns P.
    
        d' = - Q.Dot(n)
        t = -(n.Dot(P) + d' )/n.Dot(d)
        S = P + t*d
    """
    denom = geo2.Vec3Dot(n, d)
    if abs(denom) < 1e-05:
        return P
    else:
        distance = -geo2.Vec3Dot(Q, n)
        t = -(geo2.Vec3Dot(n, P) + distance) / denom
        scaledRay = geo2.Scale(d, t)
        ret = geo2.Add(scaledRay, P)
        return geo2.Vector(*ret)
예제 #10
0
    def RotateSelected(self, yaw, pitch, roll):
        slimItems = self.GetSelObjects()
        if len(slimItems) == 0:
            return
        yawRad = yaw / 180.0 * math.pi
        pitchRad = pitch / 180.0 * math.pi
        rollRad = roll / 180.0 * math.pi
        rotationToAdd = geo2.QuaternionRotationSetYawPitchRoll(
            yawRad, pitchRad, rollRad)
        posCtr = geo2.VectorD(0, 0, 0)
        for slimItem in slimItems:
            posCtr += geo2.VectorD(slimItem.dunX, slimItem.dunY, slimItem.dunZ)

        geo2.Scale(posCtr, 1.0 / len(slimItems))
        for slimItem in slimItems:
            rot = getattr(slimItem, 'dunRotation', None)
            slimItemRotation = geo2.QuaternionIdentity()
            if rot is not None:
                yaw, pitch, roll = rot
                slimItemRotation = geo2.QuaternionRotationSetYawPitchRoll(
                    yaw / 180.0 * math.pi, pitch / 180.0 * math.pi,
                    roll / 180.0 * math.pi)
            y, p, r = geo2.QuaternionRotationGetYawPitchRoll(slimItemRotation)
            slimItemRotation = geo2.QuaternionMultiply(rotationToAdd,
                                                       slimItemRotation)
            y, p, r = geo2.QuaternionRotationGetYawPitchRoll(slimItemRotation)
            y = y / math.pi * 180.0
            p = p / math.pi * 180.0
            r = r / math.pi * 180.0
            translation = geo2.VectorD(slimItem.dunX, slimItem.dunY,
                                       slimItem.dunZ)
            translation -= posCtr
            geo2.QuaternionTransformVector(rotationToAdd, translation)
            translation += posCtr
            dungeonHelper.SetObjectPosition(slimItem.dunObjectID,
                                            translation.x, translation.y,
                                            translation.z)
            dungeonHelper.SetObjectRotation(slimItem.dunObjectID, y, p, r)
예제 #11
0
 def _AddToPanTarget(self, dx, axis):
     self.panTarget = geo2.Vec3Add(self.panTarget, geo2.Scale(axis, dx))