def SetModel(self, scale): graphic = cfg.invtypes.Get(self.pinKv.typeID).Graphic() self.model = None if graphic and graphic.graphicFile: graphicFile = str(graphic.graphicFile) graphicFile = graphicFile.replace(':/model', ':/dx9/model').replace( '.blue', '.red') self.model = trinity.Load(graphicFile) if not self.model or self.model.__bluetype__ != 'trinity.EveTransform': self.model = trinity.Load( 'res:/dx9/model/worldobject/Orbital/UI/Terrestrial/Command/CommT_T1/CommT_T1.red' ) if not self.model: return EXT = 1.026 self.model.scaling = (scale, scale, scale) self.model.sortValueMultiplier = 0.5 self.model.translation = (EXT * self.surfacePoint.x, EXT * self.surfacePoint.y, EXT * self.surfacePoint.z) plnSurfRotMat = geo2.MatrixRotationAxis( geo2.Vec3Cross( geo2.Vec3Normalize(self.surfacePoint.GetAsXYZTuple()), (0.0, 1.0, 0.0)), -math.acos( geo2.Vec3Dot( geo2.Vec3Normalize(self.surfacePoint.GetAsXYZTuple()), (0.0, 1.0, 0.0)))) rotQuat = geo2.QuaternionRotationMatrix(plnSurfRotMat) self.model.rotation = rotQuat self.model.name = '%s,%s' % (planetCommon.PINTYPE_NORMAL, self.pinKv.id) self.transform.children.append(self.model)
def update_line_position(posInfo): lineData = posInfo[2] lineID = lineData.lineID fromPosition = posInfo[0] if fromPosition is None: fromMapNode = GetNodeBySolarSystemID(lineData.fromSolarSystemID) fromPosition = fromMapNode.position posInfo[0] = fromPosition toPosition = posInfo[1] if toPosition is None: toMapNode = GetNodeBySolarSystemID(lineData.toSolarSystemID) toPosition = toMapNode.position posInfo[1] = toPosition if lineID in adjustLines: fromPosition = geo2.Vec3Add(fromPosition, adjustLines[lineID][0]) toPosition = geo2.Vec3Add(toPosition, adjustLines[lineID][2]) lineSet.ChangeLinePositionCrt(lineID, fromPosition, toPosition) if lineData.jumpType == JUMPBRIDGE_TYPE: linkVec = geo2.Vec3Subtract(toPosition, fromPosition) normLinkVec = geo2.Vec3Normalize(linkVec) rightVec = geo2.Vec3Cross(worldUp, normLinkVec) upVec = geo2.Vec3Cross(rightVec, normLinkVec) offsetVec = geo2.Vec3Scale(geo2.Vec3Normalize(upVec), geo2.Vec3Length(linkVec) * 1.0) midPos = geo2.Vec3Scale(geo2.Vec3Add(toPosition, fromPosition), 0.5) splinePos = geo2.Vec3Add(midPos, offsetVec) lineSet.ChangeLineIntermediateCrt(lineID, splinePos)
def AddExplosion(self, uniqueName, explosionGfxID, spreadOut): if uniqueName not in self.districts: self.logger.error('Could not find district %s for planet with id %s', str(uniqueName), str(self.itemID)) graphics = GetGraphic(explosionGfxID) if graphics is None: self.logger.error("Explosion graphicsID %s doesn't exist!", str(explosionGfxID)) return fx = trinity.Load(graphics.graphicFile) if fx is None: self.logger.error("Explosion %s doesn't exist!", str(graphics.graphicFile)) return if len(fx.curveSets) == 0: self.logger.error('Explosion %s has no curveSets! This is useless...', str(graphics.graphicFile)) return direction = self.districts[uniqueName].centerNormal rotMatrix1 = geo2.MatrixRotationAxis((direction[1], direction[2], direction[0]), random.random() * spreadOut * self.districts[uniqueName].pinRadius) rotMatrix2 = geo2.MatrixRotationAxis(direction, random.uniform(0, 2.0 * math.pi)) direction = geo2.Vec3TransformNormal(direction, rotMatrix1) direction = geo2.Vec3TransformNormal(direction, rotMatrix2) fx.translation = direction fx.scaling = (5000.0 / PLANET_SIZE_SCALE, 5000.0 / PLANET_SIZE_SCALE, 5000.0 / PLANET_SIZE_SCALE) v1 = geo2.Vec3Cross(geo2.Vec3Normalize(direction), (0.0, 1.0, 0.0)) alpha = -math.acos(geo2.Vec3Dot(geo2.Vec3Normalize(direction), (0.0, 1.0, 0.0))) fx.rotation = geo2.QuaternionRotationAxis(v1, alpha) duration = fx.curveSets[0].GetMaxCurveDuration() self.districtExplosions.children.append(fx) uthread.new(self._RemoveExplosionFromDistrict, fx, duration)
def _TransformAxis(self, v): viewMat = trinity.GetViewTransform() viewVec = geo2.Vector(viewMat[0][2], viewMat[1][2], viewMat[2][2]) pos = self.GetTranslation() start = self.startPlanePos - pos start = geo2.Vec3Normalize(start) end = self.endPlanePos - pos end = geo2.Vec3Normalize(end) q = geo2.QuaternionIdentity() dot = geo2.Vec3Dot(start, end) if 1.0 - dot < 1e-05: return q dnormal = geo2.Vec3Cross(start, end) if self.activeManipAxis == 'w': worldInv = geo2.MatrixInverse(self.worldTranslation) axis = geo2.Vec3TransformNormal(viewVec, worldInv) axis = geo2.Vector(*axis) rdot = geo2.Vec3Dot(axis, viewVec) ddot = geo2.Vec3Dot(dnormal, axis) if ddot < 0.0 and rdot > 0.0: axis = -axis elif ddot > 0.0 and rdot < 0.0: axis = -axis elif self.activeManipAxis == 'ww': curP = self._Hemisphere(self.curX, self.curY) preP = self._Hemisphere(self.preX, self.preY) viewInverse = geo2.MatrixInverse(viewMat) norm = geo2.Vec3Cross(preP, curP) worldInv = geo2.MatrixInverse(self.worldTranslation) axis = geo2.Vec3TransformNormal(norm, worldInv) axis = geo2.Vec3TransformNormal(axis, viewInverse) dot = geo2.Vec3Dot(curP, preP) else: axis = self.axis[self.activeManipAxis] if geo2.Vec3Dot(dnormal, axis) < 0.0: axis = -axis if self.activeManipAxis == 'x' and self.worldTranslation[0][ 0] < 0.0 or self.activeManipAxis == 'y' and self.worldTranslation[ 1][1] < 0.0 or self.activeManipAxis == 'z' and self.worldTranslation[ 2][2] < 0.0: axis = -axis self.startPlanePos = self.endPlanePos if dot < -1: dot = -1 elif dot > 1: dot = 1 q = geo2.QuaternionRotationAxis(axis, math.acos(dot)) q = geo2.QuaternionNormalize(q) return q
def CreateImpact(self, targetBall, source): blue.synchro.Sleep(100) damageDuration = 3000 targetPos = targetBall.GetVectorAt(blue.os.GetSimTime()) target = geo2.Vector(targetPos.x, targetPos.y, targetPos.z) direction = geo2.Vec3Normalize(geo2.Vec3Subtract(source, target)) targetBall.model.CreateImpact(self.gfx.dest.damageLocatorIndex, direction, damageDuration * 0.001, 2.0)
def PickObject(self, x, y): if self.sceneManager.GetActiveScene() != self.renderScene: return rescale = 1.0 / 10000.0 projection = trinity.TriProjection() projection.PerspectiveFov(trinity.GetFieldOfView(), trinity.GetAspectRatio(), trinity.GetFrontClip(), trinity.GetBackClip()) view = trinity.TriView() view.transform = trinity.GetViewTransform() scaling, rotation, translation = geo2.MatrixDecompose( self.transform.worldTransform) direction = geo2.Vector(*translation) - geo2.Vector( view.transform[0][0], view.transform[1][0], view.transform[2][0]) if geo2.Vec3Dot( geo2.Vec3Normalize(direction), geo2.Vector(-view.transform[0][2], -view.transform[1][2], -view.transform[2][2])) < 0: return self.renderObject.translation = geo2.Vec3Scale(translation, rescale) self.renderObject.rotation = rotation self.renderObject.scaling = geo2.Vec3Scale(scaling, rescale) scaling, rotation, translation = geo2.MatrixDecompose(view.transform) translation = geo2.Vec3Scale(translation, rescale) view.transform = geo2.MatrixTransformation(None, None, scaling, None, rotation, translation) return self.renderObject.PickObject(x, y, projection, view, trinity.device.viewport)
def TryPickSphereBorder(self): matches = [] scannerWnd = Scanner.GetIfOpen() if scannerWnd: x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) ray, start = GetRayAndPointFromScreen(x, y) pickRadiusRay, pickRadiusStart = GetRayAndPointFromScreen(x - 30, y) camera = sm.GetService('sceneManager').GetRegisteredCamera('systemmap') if camera is None: return viewDir = geo2.QuaternionTransformVector(camera.rotationAroundParent, (0.0, 0.0, 1.0)) viewDir = geo2.Vec3Normalize(viewDir) targetPlaneNormal = geo2.Vector(*viewDir) scanSvc = sm.StartService('scanSvc') probeData = scanSvc.GetProbeData() probes = scannerWnd.GetProbeSpheres() for probeID, probeControl in probes.iteritems(): if probeID not in probeData or probeData[probeID].state != const.probeStateIdle: continue targetPlanePos = geo2.Vector(probeControl.locator.worldTransform[3][0], probeControl.locator.worldTransform[3][1], probeControl.locator.worldTransform[3][2]) rad = list(probeControl.sphere.scaling)[0] * SYSTEMMAP_SCALE pos = RayToPlaneIntersection(start, ray, targetPlanePos, targetPlaneNormal) picRadiusPos = RayToPlaneIntersection(pickRadiusStart, pickRadiusRay, targetPlanePos, targetPlaneNormal) pickRad = (trinity.TriVector(*picRadiusPos) - trinity.TriVector(*pos)).Length() diffFromPickToSphereBorder = (trinity.TriVector(*targetPlanePos) - trinity.TriVector(*pos)).Length() if rad + pickRad > diffFromPickToSphereBorder > rad - pickRad: matches.append((abs(rad - diffFromPickToSphereBorder), probeControl)) if matches: matches = uiutil.SortListOfTuples(matches) return matches[0]
def UpdatePosition(self, localPosition=None): if not self.model: self._LoadModel() if not len(self.model.children): return if not localPosition: localSystem = sm.StartService('map').GetItem(session.solarsystemid) localPosition = (localSystem.x, localSystem.y, localSystem.z) if not self.effectPosition: effectSystem = sm.StartService('map').GetItem(SUPERNOVA_SYSTEM_ID) self.effectPosition = (effectSystem.x, effectSystem.y, effectSystem.z) effect = self.model.children[0] direction = geo2.Vec3SubtractD(localPosition, self.effectPosition) direction = (direction[0], direction[1], -direction[2]) distance = geo2.Vec3LengthD(direction) / 1e+16 direction = geo2.Vec3Normalize(direction) if distance < self.nearDistance: scale = self.nearSize else: shift = (self.farSize * self.farDistance - self.nearSize * self.nearDistance) / (self.nearSize - self.farSize) baseSize = self.nearSize * (self.nearDistance + shift) scale = baseSize / (distance + shift) effect.scaling = (scale, scale, scale) effect.translation = geo2.Vec3Scale(direction, 15.0)
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)
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
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)
def __init__(self, orbitID, position, parentPosition, parentTransform): self.orbitID = orbitID dirVec = geo2.Vec3Subtract(position, parentPosition) radius = geo2.Vec3Length(dirVec) dirVec = geo2.Vec3Normalize(dirVec) fwdVec = (-1.0, 0.0, 0.0) rotation = geo2.QuaternionRotationArc(fwdVec, dirVec) radius = radius / self.lineSetScaling lineSet = mapViewUtil.CreateLineSet() lineSet.scaling = (self.lineSetScaling, self.lineSetScaling, self.lineSetScaling) lineSet.translation = parentPosition lineSet.rotation = rotation parentTransform.children.append(lineSet) self.pixelLineSet = lineSet mapViewUtil.DrawCircle(lineSet, (0, 0, 0), radius, startColor=(1, 1, 1, 0.25), endColor=(1, 1, 1, 0.25), lineWidth=2.5) lineSet.SubmitChanges() lineSet = mapViewUtil.CreatePlanarLineSet() lineSet.scaling = (self.lineSetScaling, self.lineSetScaling, self.lineSetScaling) lineSet.translation = parentPosition lineSet.rotation = rotation parentTransform.children.append(lineSet) self.planarLineSet = lineSet orbitLineColor = (1, 1, 1, 0.25) self.planarLineIDs = mapViewUtil.DrawCircle(lineSet, (0, 0, 0), radius, startColor=orbitLineColor, endColor=orbitLineColor, lineWidth=radius / 150.0) lineSet.SubmitChanges()
def Orbit(self, yaw, pitch): dev = trinity.device self.Focus(self.pointOfInterest) up = geo2.Vector(0.0, 1.0, 0.0) t = geo2.Vector(self.localViewMatrix[1][0], self.localViewMatrix[1][1], self.localViewMatrix[1][2]) if geo2.Vec3Dot(t, up) <= 0.0: pitch = -pitch yaw = -yaw pos = self.GetPosition() target = self.pointOfInterest view = geo2.Subtract(pos, target) view = geo2.Vec3Normalize(view) right = geo2.Vec3Cross(view, up) mat = self.localViewMatrix ipmat = geo2.MatrixTranslation(-target[0], -target[1], -target[2]) pmat = geo2.MatrixTranslation(target[0], target[1], target[2]) mat = geo2.MatrixInverse(mat) yrotMat = geo2.MatrixRotationAxis(up, yaw) rrotMat = geo2.MatrixRotationAxis(right, pitch) yrotMat = geo2.MatrixMultiply(yrotMat, rrotMat) mat = geo2.MatrixMultiply(mat, ipmat) mat = geo2.MatrixMultiply(mat, yrotMat) mat = geo2.MatrixMultiply(mat, pmat) self._position = geo2.MatrixDecompose(mat)[2] mat = geo2.MatrixInverse(mat) self.localViewMatrix = mat
def GetSolidAroundLine(line, radius): rad = math.pi * 2.0 / 3.0 triangle1 = [] triangle1.append((math.cos(0) * radius, math.sin(0) * radius, 0.0)) triangle1.append((math.cos(rad) * radius, math.sin(rad) * radius, 0.0)) triangle1.append( (math.cos(2 * rad) * radius, math.sin(2 * rad) * radius, 0.0)) dirOfLine = geo2.Vec3Normalize(geo2.Vec3Subtract(line[1], line[0])) if abs(geo2.Vec3Dot((0.0, 0.0, 1.0), dirOfLine)) != 1.0: rot = geo2.QuaternionRotationArc((0.0, 0.0, 1.0), dirOfLine) else: rot = geo2.QuaternionIdentity() rot = geo2.MatrixRotationQuaternion(rot) t1 = geo2.MatrixTranslation(*line[0]) t2 = geo2.MatrixTranslation(*line[1]) compA = geo2.MatrixMultiply(rot, t1) compB = geo2.MatrixMultiply(rot, t2) startTri = geo2.Vec3TransformCoordArray(triangle1, compA) endTri = geo2.Vec3TransformCoordArray(triangle1, compB) triangles = [ startTri[1], endTri[0], startTri[0], endTri[1], endTri[0], startTri[1], startTri[2], endTri[1], startTri[1], endTri[2], endTri[1], startTri[2], startTri[0], endTri[2], startTri[2], endTri[0], endTri[2], startTri[0] ] return triangles
def Update(self): sourcePoint = self.sourceFunction.GetValue() destPoint = self.destinationFunction.GetValue() d = geo2.Vec3Subtract(destPoint, sourcePoint) length = geo2.Vec3Length(d) self.model.scaling = (self.radius, length, self.radius) self.model.rotation = geo2.QuaternionRotationArc((0, 1, 0), geo2.Vec3Normalize(d))
def UpdatePosition(self, localPosition=None): """ Updates the position and scale of the supernova. localPosition: An optional 3 tuple for the local position. If not passed in the session.solarsystemid is used to determine the position. """ if not self.model: self._LoadModel() if not localPosition: localSystem = sm.StartService('map').GetItem(session.solarsystemid) localPosition = (localSystem.x, localSystem.y, localSystem.z) if not self.effectPosition: effectSystem = sm.StartService('map').GetItem(SUPERNOVA_SYSTEM_ID) self.effectPosition = (effectSystem.x, effectSystem.y, effectSystem.z) effect = self.model.children[0] direction = geo2.Vec3SubtractD(localPosition, self.effectPosition) direction = (direction[0], direction[1], -direction[2]) distance = geo2.Vec3LengthD(direction) / 1e+16 direction = geo2.Vec3Normalize(direction) if distance < self.nearDistance: scale = self.nearSize else: shift = (self.farSize * self.farDistance - self.nearSize * self.nearDistance) / (self.nearSize - self.farSize) baseSize = self.nearSize * (self.nearDistance + shift) scale = baseSize / (distance + shift) effect.scaling = (scale, scale, scale) effect.translation = geo2.Vec3Scale(direction, 15.0)
def _EnforceMaximumDistanceDetached(self): dist = geo2.Vec3Length(self.eyePosition) if dist > evecamera.LOOKATRANGE_MAX_NEW and not self.IsInTransit(): direction = geo2.Vec3Normalize(self.eyePosition) newEye = geo2.Vec3Scale(direction, evecamera.LOOKATRANGE_MAX_NEW) diff = geo2.Vec3Subtract(self.eyePosition, newEye) self.SetEyePosition(newEye) self.SetAtPosition(geo2.Vec3Subtract(self._atPosition, diff))
def ProjectPointTowardsFrontPlane(point, dist=7.0): ppos = point viewMat = trinity.GetViewTransform() cpos = geo2.Vector(*trinity.GetViewPosition()) dir = geo2.Vec3Normalize(geo2.Subtract(cpos, ppos)) lookat = geo2.Vector(viewMat[0][2], viewMat[1][2], viewMat[2][2]) point = cpos + lookat * dist return RayToPlaneIntersection(ppos, dir, point, lookat)
def GetMaxLookAtWeight_Facing(ent, targetPos): sourcePos = ent.GetComponent('position').position sourceRot = ent.GetComponent('position').rotation source2Target = geo2.Vec3Subtract(targetPos, sourcePos) source2Target = geo2.Vec3Normalize(source2Target) facingDir = mathCommon.CreateDirectionVectorFromYawAngle(geo2.QuaternionRotationGetYawPitchRoll(sourceRot)[0]) dot = geo2.Vec3Dot(source2Target, facingDir) return max(dot, 0)
def SetAxis(self, xaxis, zaxis): self.xaxis = xaxis self.zaxis = zaxis yaxis = geo2.Vec3Normalize(geo2.Vec3Cross(zaxis, xaxis)) self.rotation = geo2.QuaternionRotationMatrix((xaxis + (0,), yaxis + (0,), zaxis + (0,), (0, 0, 0, 1)))
def GetPitchAngleFromDirectionVector(vec3): testVec = list(geo2.Vec3Normalize(vec3)) if testVec[1] >= 1.0: testVec[1] = 1.0 elif testVec[1] <= -1.0: testVec[1] = -1.0 pitch = math.asin(testVec[1]) return pitch
def GetTrackingAtPosition(self): ballPos = GetBallPosition(self.trackBall) if geo2.Vec3Length(ballPos) > evecamera.LOOKATRANGE_MAX_NEW: direction = geo2.Vec3Normalize( geo2.Vec3Subtract(ballPos, self.eyePosition)) ballPos = geo2.Vec3Add( self.eyePosition, geo2.Vec3Scale(direction, evecamera.LOOKATRANGE_MAX_NEW)) return self.trackBallMorpher.GetValue(self.atPosition, ballPos)
def GetDotInCameraAlignedPlaneFromPosition(self, targetPlanePos): x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) ray, start = GetRayAndPointFromScreen(x, y) camera = sm.GetService('sceneManager').GetRegisteredCamera('systemmap') viewDir = geo2.QuaternionTransformVector(camera.rotationAroundParent, (0.0, 0.0, 1.0)) viewDir = geo2.Vec3Normalize(viewDir) targetPlaneNormal = geo2.Vector(*viewDir) pos = RayToPlaneIntersection(start, ray, targetPlanePos, targetPlaneNormal) return pos
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()
def CreateViewMatrix(self): upVector = (0, 1, 0) xaxis = geo2.Vec3Normalize(geo2.Vec3Cross(upVector, self.direction)) yaxis = geo2.Vec3Cross(self.direction, xaxis) return ((xaxis[0], yaxis[0], self.direction[0], 0.0), (xaxis[1], yaxis[1], self.direction[1], 0.0), (xaxis[2], yaxis[2], self.direction[2], 0.0), (-geo2.Vec3Dot(xaxis, self.cameraPosition), -geo2.Vec3Dot(yaxis, self.cameraPosition), -geo2.Vec3Dot(self.direction, self.cameraPosition), 1.0))
def PlerpVec3(self, start, end, timeLeft): doneSoFar = LERP_TIME - timeLeft percDone = doneSoFar / LERP_TIME if percDone > 1.0: return end percToEnd = math.sin(percDone * math.pi - math.pi / 2.0) / 2.0 + 0.5 distance = geo2.Vec3Length(geo2.Vec3Subtract(end, start)) * percToEnd vector = geo2.Vec3Normalize(geo2.Vec3Subtract(end, start)) currPoint = geo2.Vec3Add(start, (val * distance for val in vector)) return currPoint
def _RenderCallback(self): if self.oldCameraPos is None or self.oldCameraPos != self.camera.pos: self.oldCameraPos = self.camera.pos rightMat = geo2.MatrixRotationAxis(self.camera.rightVec, math.radians(-225)) upMat = geo2.MatrixRotationAxis(self.camera.upVec, math.radians(-45)) self.scene.sunDirection = geo2.Vec3Normalize( geo2.Vec3TransformNormal( geo2.Vec3TransformNormal(self.camera.viewVec, rightMat), upMat))
def UpdatePosition(self, cameraController): if not self.point1Path.IsComplete(): self.point1Path.UpdatePosition(cameraController) return if not self.IsComplete(): ray_dir, start = cameraController.GetPickVector() plane_position = self.point1Path.GetEndPosition() pick_position = RayToPlaneIntersection(start, ray_dir, plane_position, self.pickPlaneDirection) plane_offset = geo2.Vec3Subtract(pick_position, plane_position) plane_offset = geo2.Vec3Normalize(plane_offset) z_axis = plane_offset plane_offset = geo2.Vec3Scale(plane_offset, self.arcScale * self.pickLength) destination1_offset = geo2.Vec3Add(plane_position, plane_offset) destination2_offset = geo2.Vec3Subtract(plane_position, plane_offset) self.destinationFunction1.SetOffsetWorldspace(destination1_offset) self.destinationFunction2.SetOffsetWorldspace(destination2_offset) x_axis = geo2.Vec3Normalize(geo2.Vec3Subtract(plane_position, self.point1Path.offsetAnchorFunction.GetValue())) if self.areaIndication is not None: self.areaIndication.SetAxis(x_axis, z_axis) self.areaIndication.Update()
def GetPitchAngleFromDirectionVector(vec3): """ Calculates the pitch angle represented by a vector """ testVec = list(geo2.Vec3Normalize(vec3)) if testVec[1] >= 1.0: testVec[1] = 1.0 elif testVec[1] <= -1.0: testVec[1] = -1.0 pitch = math.asin(testVec[1]) return pitch
def GetCorrectCameraXandYFactors(self, position, poi): cameraZ = geo2.Vec3Normalize(geo2.Subtract(position, poi)) cameraX = geo2.Vec3Cross(cameraZ, (0.0, 1.0, 0.0)) cameraY = geo2.Vec3Cross(cameraZ, cameraX) cameraMatrix = ((cameraX[0], cameraY[0], cameraZ[0], 0.0), (cameraX[1], cameraY[1], cameraZ[1], 0.0), (cameraX[2], cameraY[2], cameraZ[2], 0.0), (0.0, 0.0, 0.0, 1.0)) offset = geo2.Subtract(self.focus, poi) res = geo2.Vec3Transform(offset, cameraMatrix) return (res[0], res[1])