示例#1
0
 def DrawDebugAxis(self, pos = None, lineWidth = 5, len = 1000.0):
     """ Draw xyz axis for debugging purposes at a given position or (0,0,0) otherwise """
     import geo2, util
     self.ConstructDebugLineset()
     if not pos:
         pos = (0, 0, 0)
     self.debugLineSet.AddStraightLine(pos, util.Color.YELLOW, geo2.Add(pos, (len, 0, 0)), util.Color.YELLOW, lineWidth)
     self.debugLineSet.AddStraightLine(pos, util.Color.RED, geo2.Add(pos, (0, len, 0)), util.Color.RED, lineWidth)
     self.debugLineSet.AddStraightLine(pos, util.Color.GREEN, geo2.Add(pos, (0, 0, len)), util.Color.GREEN, lineWidth)
     self.debugLineSet.SubmitChanges()
示例#2
0
 def SetupComponent(self, entity, component):
     self.LogInfo('Setting up component', component)
     gw = GameWorld.Manager.GetGameWorld(long(entity.scene.sceneID))
     if hasattr(component, 'radius'):
         gw.CreateTriggerSphere(entity.entityID, geo2.Add(entity.position.position, component.relativePosition), entity.position.rotation, component.radius)
     elif hasattr(component, 'dimensions'):
         gw.CreateTriggerAABB(entity.entityID, geo2.Add(entity.position.position, component.relativePosition), entity.position.rotation, component.dimensions)
     else:
         raise RuntimeError('Unknown trigger shape')
     self.LogInfo('Creating trigger shape for component', component)
 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 DrawDebugAxis(self, pos=None, lineWidth=5, len=1000.0):
     import geo2, util
     self.ConstructDebugLineset()
     if not pos:
         pos = (0, 0, 0)
     self.debugLineSet.AddStraightLine(pos, util.Color.YELLOW,
                                       geo2.Add(pos, (len, 0, 0)),
                                       util.Color.YELLOW, lineWidth)
     self.debugLineSet.AddStraightLine(pos, util.Color.RED,
                                       geo2.Add(pos, (0, len, 0)),
                                       util.Color.RED, lineWidth)
     self.debugLineSet.AddStraightLine(pos, util.Color.GREEN,
                                       geo2.Add(pos, (0, 0, len)),
                                       util.Color.GREEN, lineWidth)
     self.debugLineSet.SubmitChanges()
 def __init__(self, position, *args, **kw):
     ShipTreeNodeBase.__init__(self, *args, **kw)
     self._skillLevel = None
     if self.parent:
         self.SetPosition(geo2.Add(self.parent.GetPosition(), position))
     else:
         self.SetPosition(position)
示例#6
0
    def GetProjectedPosition(self, bloodlineID, genderID, camera):
        """
        Method to get the position of the characters head into 2D space.
        If no genderID is given the a point 2 meters above the bloodline platform is returned.
        """
        if camera is None:
            return
        avatar = None
        camera.Update()
        for platform in self.lineUp:
            if platform.bloodlineID == bloodlineID:
                if genderID is None:
                    position = geo2.Add(platform.position, (0.0, 2.0, 0.0))
                    return camera.ProjectPoint(position)
                for i, each in enumerate(platform.pair):
                    if i == genderID:
                        avatar = each.avatar

        if avatar == None:
            log.LogError(
                'Could not get the projected head position for character with bloodlineID %s and genderID %s',
                (bloodlineID, genderID))
            return (0, 0)
        index = avatar.GetBoneIndex('Head')
        position = avatar.GetBonePosition(index)
        return camera.ProjectPoint(position)
 def UpdateViewProjForLight(self, stepView, stepProj, light, effectValue):
     """
     Renderstep callback to make sure the rendersteps that deal with view transform and
     projection, are still up to date with any changes to the lights.  Works out the values
     for this light and then delegates to the individual MeshData instances.
     """
     eye = light.position
     at = geo2.Add(eye, light.coneDirection)
     up = (0, 0, 1)
     if SkinSpotLightShadows.REUSE_ENGINE_MAPS:
         VP = light.GetViewProjMatrix()
     else:
         if effectValue:
             effectValue.value = (0,
              0,
              0,
              light.radius)
         viewmat = geo2.MatrixLookAtRH(eye, at, up)
         self.ComputeProjectionMatrix(stepProj.projection, light, viewmat)
         stepView.view.transform = viewmat
         VP1 = geo2.MatrixMultiply(viewmat, stepProj.projection.transform)
         VP = geo2.MatrixMultiply(VP1, self.uvAdjustMatrix)
     VPT = geo2.MatrixTranspose(VP)
     for meshData in self.meshes.itervalues():
         meshData.updateParams(light, VPT)
    def OrbitUpdateThread(self):
        try:
            while True:
                if self.orbitTarget is None:
                    break
                vLookAt = self.GetLookAtDirection()
                currPitch = self.GetAngleLookAtToUpDirection()
                self.eyePosition = geo2.Subtract(self.eyePosition, self.atPosition)
                yawLeft = self.orbitTarget[0]
                if yawLeft:
                    yaw = self.kOrbitSpeed * yawLeft / blue.os.fps
                    if math.fabs(yawLeft) < self.kOrbitStopAngle:
                        yaw = yawLeft
                    rotYaw = geo2.MatrixRotationAxis(self.upDirection, yaw)
                    self.eyePosition = geo2.Vec3Transform(self.eyePosition, rotYaw)
                    self.orbitTarget[0] -= yaw
                targetPitch = self.orbitTarget[1]
                pitchLeft = currPitch - targetPitch
                if pitchLeft:
                    pitch = self.kOrbitSpeed * pitchLeft / blue.os.fps
                    if math.fabs(pitchLeft) < self.kOrbitStopAngle:
                        pitch = pitchLeft
                    axis = geo2.Vec3Cross(vLookAt, self.upDirection)
                    rotPitch = geo2.MatrixRotationAxis(axis, pitch)
                    self.eyePosition = geo2.Vec3Transform(self.eyePosition, rotPitch)
                self.eyePosition = geo2.Add(self.eyePosition, self.atPosition)
                if not pitchLeft and not yawLeft:
                    break
                blue.synchro.Yield()

        finally:
            self.orbitUpdateThread = None
            self.orbitTarget = None
 def __init__(self, shipGroupID, factionID, position, *args, **kw):
     ShipTreeNodeBase.__init__(self, *args, **kw)
     self.shipGroupID = shipGroupID
     self.factionID = factionID
     if self.parent:
         self.SetPosition(geo2.Add(self.parent.GetPosition(), position))
     else:
         self.SetPosition(position)
示例#10
0
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
示例#11
0
 def Rotate(self, x = 0, y = 0):
     xAxis = self.GetXAxis()
     yAxis = self.GetYAxis()
     self.atPosition = geo2.Subtract(self.atPosition, self.eyePosition)
     rotY = geo2.MatrixRotationAxis(xAxis, y)
     self.atPosition = geo2.Vec3Transform(self.atPosition, rotY)
     rotX = geo2.MatrixRotationAxis(yAxis, x)
     self.atPosition = geo2.Vec3Transform(self.atPosition, rotX)
     self.atPosition = geo2.Add(self.atPosition, self.eyePosition)
示例#12
0
    def PanUpdateThread(self):
        while True:
            if self.panTarget is None:
                break
            distLeft = geo2.Vec3Length(self.panTarget)
            if distLeft == 0:
                break
            dist = self.kPanSpeed / blue.os.fps
            if distLeft < self.kPanStopDist:
                dist *= self.kPanStopDist / distLeft
            dist = min(dist, 1.0)
            toMove = geo2.Vec3Scale(self.panTarget, dist)
            self.eyePosition = geo2.Add(self.eyePosition, toMove)
            self.atPosition = geo2.Add(self.atPosition, toMove)
            self.panTarget -= toMove
            if dist == 1.0:
                break
            blue.synchro.Yield()

        self.panUpdateThread = None
        self.panTarget = None
示例#13
0
 def Update(self):
     if self.updateFocus:
         right = self.GetBonePosition('fj_eyeballRight')
         left = self.GetBonePosition('fj_eyeballLeft')
         self.focus = geo2.Add(right, left)
         self.focus = geo2.Vector(*self.focus) * 0.5
     if self.moveCallback:
         self.moveCallback(self.viewMatrix)
     if self.controlStyle == CONTROL_VERTICAL:
         length = geo2.Vec2Length(geo2.Vector(self.focus[0], self.focus[2]))
         self.focus = (0.0, self.focus[1], length)
         self.updateFocus = False
     cameras.PolarCamera.Update(self)
示例#14
0
 def PlacePortraitCamera(self, pos, poi):
     direction = geo2.Subtract(pos, poi)
     self.distance = geo2.Vec3Length(direction)
     direction = geo2.Vec3Normalize(direction)
     self.yaw = math.acos(direction[0])
     self.pitch = math.asin(direction[1]) + math.pi / 2.0
     right = self.GetBonePosition('fj_eyeballRight')
     left = self.GetBonePosition('fj_eyeballLeft')
     self.focus = geo2.Add(right, left)
     self.focus = geo2.Vector(*self.focus) * 0.5
     xFactor, yFactor = self.GetCorrectCameraXandYFactors(pos, poi)
     self.xFactor = xFactor
     self.yFactor = yFactor
示例#15
0
 def LookAt(self, position, duration = None, followWithEye = True, eyePos = None):
     if duration:
         uicore.animations.MorphVector3(self, 'atPosition', self.atPosition, position, duration=duration)
     else:
         self.atPosition = position
     if followWithEye:
         if not eyePos:
             eyePos = geo2.Subtract(self.eyePosition, self.atPosition)
             eyePos = geo2.Add(eyePos, position)
         if duration:
             uicore.animations.MorphVector3(self, 'eyePosition', self.eyePosition, eyePos, duration=duration)
         else:
             self.eyePosition = eyePos
示例#16
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
 def PlacePortraitCamera(self, pos, poi):
     """ This method takes in pos and poi and places the camera with correct 
     yaw and pitch, distance, xFactor, yFactor and focus."""
     direction = geo2.Subtract(pos, poi)
     self.distance = geo2.Vec3Length(direction)
     direction = geo2.Vec3Normalize(direction)
     self.yaw = math.acos(direction[0])
     self.pitch = math.asin(direction[1]) + math.pi / 2.0
     right = self.GetBonePosition('fj_eyeballRight')
     left = self.GetBonePosition('fj_eyeballLeft')
     self.focus = geo2.Add(right, left)
     self.focus = geo2.Vector(*self.focus) * 0.5
     xFactor, yFactor = self.GetCorrectCameraXandYFactors(pos, poi)
     self.xFactor = xFactor
     self.yFactor = yFactor
示例#18
0
 def UpdateViewProjForLight(self, stepView, stepProj, light, effectValue):
     eye = light.position
     at = geo2.Add(eye, light.coneDirection)
     up = (0, 0, 1)
     if SkinSpotLightShadows.REUSE_ENGINE_MAPS:
         VP = light.GetViewProjMatrix()
     else:
         if effectValue:
             effectValue.value = (0, 0, 0, light.radius)
         viewmat = geo2.MatrixLookAtRH(eye, at, up)
         self.ComputeProjectionMatrix(stepProj.projection, light, viewmat)
         stepView.view.transform = viewmat
         VP1 = geo2.MatrixMultiply(viewmat, stepProj.projection.transform)
         VP = geo2.MatrixMultiply(VP1, self.uvAdjustMatrix)
     VPT = geo2.MatrixTranspose(VP)
     for meshData in self.meshes.itervalues():
         meshData.updateParams(light, VPT)
示例#19
0
 def Update(self):
     speedFactor = 0.2
     diff = geo2.Vec3Subtract(self.pointOfInterest, self._pointOfInterestCurrent)
     diffLength = geo2.Vec3Length(diff)
     if diffLength > 0.001:
         self._pointOfInterestCurrent = geo2.Vec3Add(self._pointOfInterestCurrent, geo2.Vec3Scale(diff, speedFactor))
     else:
         self._pointOfInterestCurrent = self.pointOfInterest
     if abs(self._yawSpeed) > 0.0001:
         yawChange = self._yawSpeed * speedFactor
         rotYaw = geo2.MatrixRotationAxis(self.upVector, yawChange)
         self._eyePositionCurrent = geo2.Vec3Transform(self._eyePositionCurrent, rotYaw)
         self._yawSpeed -= yawChange
     else:
         self._yawSpeed = 0.0
     if abs(self._pitchSpeed) > 0.0001:
         pitchChange = self._pitchSpeed * speedFactor
         viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent)
         axis = geo2.Vec3Cross(viewVectorNormalized, self.upVector)
         rotPitch = geo2.MatrixRotationAxis(axis, pitchChange)
         self._eyePositionCurrent = geo2.Vec3Transform(self._eyePositionCurrent, rotPitch)
         self._pitchSpeed -= pitchChange
     else:
         self._pitchSpeed = 0.0
     if self._panSpeed:
         panDistance = geo2.Vec3Length(self._panSpeed)
         if panDistance > 0.001:
             toMove = geo2.Vec3Scale(self._panSpeed, 0.95)
             self.pointOfInterest = geo2.Add(self.pointOfInterest, toMove)
             self._panSpeed -= toMove
         else:
             self._panSpeed = None
     cameraDistance = self.GetZoomDistance()
     cameraDistanceDiff = self._translationFromPOI - cameraDistance
     if math.fabs(cameraDistanceDiff) > 0.001:
         usedDist = cameraDistanceDiff * 0.1
         viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent)
         newDistance = min(self.maxDistance, max(self.minDistance, cameraDistance + usedDist))
         self._eyePositionCurrent = geo2.Vec3Scale(viewVectorNormalized, newDistance)
         self.translationFromParent = newDistance
     self.UpdateProjection()
     self.UpdateView()
     if self.callback:
         self.callback()
示例#20
0
    def GetTransitAtCurve(self, posStart, posEnd, newDir, smoothing, numPoints):
        """ Returns control points for the lookAt transit curve spline. We travel along a straight line offset quadtratically according the the smoothing argument"""
        currDir = self.GetLookAtDirection()
        angle = math.acos(geo2.Vec3Dot((currDir[0], 0, currDir[2]), (newDir[1], 0, newDir[2])))
        if smoothing and angle:
            offset = geo2.Vec3Normalize(geo2.Vec3Negate(newDir))
            dist = geo2.Vec3Distance(posStart, posEnd)
            offset = geo2.Vec3Scale(offset, dist * angle * smoothing)
        else:
            offset = (0, 0, 0)
        points = []
        for i in xrange(numPoints + 1):
            t = self._GetHermiteValue(float(i) / numPoints)
            offsetDist = 2 * (t - t ** 2)
            point = geo2.Vec3Lerp(posStart, posEnd, t)
            point = geo2.Add(point, geo2.Vec3Scale(offset, offsetDist))
            points.append(point)

        return points
示例#21
0
    def OrbitUpdateThread(self):
        try:
            while True:
                if self.orbitTarget is None:
                    break
                vLookAt = self.GetLookAtDirectionWithOffset()
                currPitch = self.GetAngleLookAtToUpDirection()
                offset = self.GetOrbitPoint()
                self.eyePosition = geo2.Subtract(self._eyePosition, offset)
                yawRemaining = self._UpdateYaw()
                pitchRemaining = self._UpdatePitch(currPitch, vLookAt)
                self.SetEyePosition(geo2.Add(self._eyePosition, offset))
                if not pitchRemaining and not yawRemaining:
                    break
                blue.synchro.Yield()

        finally:
            self.orbitUpdateThread = None
            self.orbitTarget = None
示例#22
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
示例#23
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)
示例#24
0
    def ZoomUpdateThread(self):
        while True:
            if self.zoomTarget is None:
                break
            distLeft = self.zoomTarget - self.GetZoomDistance()
            if not distLeft:
                break
            moveProp = self.kZoomSpeed / blue.os.fps
            if math.fabs(distLeft) < self.kZoomStopDist:
                moveProp *= self.kZoomStopDist / math.fabs(distLeft)
            moveProp = min(moveProp, 1.0)
            toMove = geo2.Vec3Scale(self.GetLookAtDirection(), moveProp * distLeft)
            eyePos = geo2.Add(self.eyePosition, toMove)
            self.eyePosition = self._EnforceMinMaxZoom(eyePos)
            if moveProp == 1.0:
                break
            for listener in self.eventListeners['zoom']:
                listener.OnZoomChanged(self.GetZoomProportion())

            blue.synchro.Yield()

        self.zoomUpdateThread = None
        self.zoomTarget = None