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 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 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 __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 SetFormationCenter(self, centerPosition): self.formationCenter = centerPosition q = geo2.QuaternionRotationArc( (0.0, 0.0, 1.0), geo2.Vec3Normalize( geo2.Vec3Subtract(self.formationCenter, self.locator.translation))) if self.spreadCursor: self.spreadCursor.rotation = q if self.rangeCursor: self.rangeCursor.rotation = q
def AlignSpaceCameraToViewVector(self, viewVector, duration = None, callback = None, sleep = False): rotation = geo2.QuaternionRotationArc((0, 0, 1), viewVector) y, p, r = geo2.QuaternionRotationGetYawPitchRoll(rotation) if duration: currentYaw, currentPitch = self.spaceCameraOrbit yawDiff = GetLesserAngleBetweenYaws(currentYaw, y) pitchDiff = GetLesserAngleBetweenYaws(currentPitch, p) endVal = (currentYaw + yawDiff, currentPitch + pitchDiff) uicore.animations.MorphVector2(self, 'spaceCameraOrbit', startVal=(currentYaw, currentPitch), endVal=endVal, duration=duration, callback=callback, sleep=sleep) else: uicore.animations.StopAnimation(self, 'spaceCameraOrbit') self.spaceCameraOrbit = (y, p)
def Start(self, duration): sourceBall = self.GetEffectShipBall() targetBall = self.GetEffectTargetBall() sourcePos = sourceBall.GetVectorAt(blue.os.GetSimTime()) sourcePos = (sourcePos.x, sourcePos.y, sourcePos.z) targetPos = targetBall.GetVectorAt(blue.os.GetSimTime()) targetPos = (targetPos.x, targetPos.y, targetPos.z) direction = geo2.Vec3Direction(sourcePos, targetPos) rotation = geo2.QuaternionRotationArc((0, 0, 1), direction) direction = geo2.Vec3Scale(direction, -1.0) for x in range(self.projectileCount): uthread.new(self.StartIndividual, duration, sourceBall, targetBall, rotation, direction)
def AddRangeLabel(self, text, radius): for x, z in [(0.0, radius), (radius, 0.0), (0.0, -radius), (-radius, 0.0)]: label = TransformableLabel(text, self.rootTransform, size=64, shadow=0, hspace=0) label.transform.translation = (x, 0.0, z) sx, sy, sz = label.transform.scaling label.transform.scaling = (sx / sy, 1.0, 0.0) label.SetDiffuseColor(self.labelColor) label.transform.useDistanceBasedScale = False label.transform.modifier = 0 label.transform.rotation = geo2.QuaternionRotationArc((0, -1, 0), (0, 0, 1))
def PlayFX(self, targetObject, fx, spewCone): """ Playes the spew effect on the target object, using the information supplied in the spewCone """ position, direction = spewCone targetObject.children.append(fx) fx.scaling = (2000.0, 3000.0, 2000.0) rotation = geo2.QuaternionRotationArc((0.0, 1.0, 0.0), direction) fx.translation = position fx.rotation = rotation for curveSet in fx.curveSets: curveSet.scale = 0.15 curveSet.PlayFrom(0.2)
def SetViewVector(self, viewVector, duration=None, callback=None, sleep=False): endRotation = geo2.QuaternionRotationArc((1.0, 0.0, 0.0), viewVector) if duration: curveSet = uicore.animations.MorphQuaternion( self, 'rotationAroundInterest', startVal=self.rotationAroundInterest, endVal=endRotation, duration=duration, callback=callback, sleep=sleep) else: uicore.animations.StopAnimation(self, 'rotationAroundInterest') self.rotationAroundInterest = endRotation
def SetUpChildExplosion(explosionModel, explosionLocatorSets): explosionChildren = explosionModel.Find('trinity.EveChildExplosion', 2) if explosionLocatorSets is not None: transforms = [] locators = [(each[0], each[1]) for each in ( explosionLocatorSets.locators if explosionLocatorSets else [])] random.shuffle(locators) for position, direction in locators: rotation = geo2.QuaternionRotationArc((0, 1, 0), direction) transform = geo2.MatrixTransformation( (0, 0, 0), (0, 0, 0, 1), (1, 1, 1), (0, 0, 0), rotation, position) transforms.append(transform) for each in explosionChildren: each.SetLocalExplosionTransforms(transforms) for each in explosionChildren: each.Play()
def _RunEffect(self): shipBall = self.GetEffectShipBall() if self.abort or shipBall is None: self._Cleanup() return speed = self._WaitForAcceleration(310000.0) if self.abort or self._IsWarpingWithClient(speed): self._Cleanup() return blue.synchro.SleepSim(random.random() * 250.0) direction = geo2.Vec3Normalize(self.direction) rotation = geo2.QuaternionRotationArc((0, 0, 1), direction) if self.abort: return posNow = shipBall.GetVectorAt(blue.os.GetSimTime()) posNow = (posNow.x, posNow.y, posNow.z) self.gfxBall = self._SpawnClientBall(posNow) if self.gfxModel_trace is not None: soundEvent = 'warp_out_%s1_play' % (self.soundInsert, ) self.observer.observer.SendEvent(soundEvent) self.gfxModel_trace.translationCurve = self.gfxBall self.gfxModel_trace.rotation = rotation self.AddToScene(self.gfxModel_trace) for each in self.gfx_trace.curveSets: each.Play() self.gfxModel_ship.translationCurve = shipBall self.gfxModel_ship.rotation = rotation self.AddToScene(self.gfxModel_ship) for each in self.gfx_ship.curveSets: each.Play() if shipBall.model is not None: shipBall.model.display = False blue.synchro.SleepSim(1500.0) self._Cleanup()
def fget(self): spaceCamera = self.GetSpaceCamera() viewVector = spaceCamera.GetViewVector() rotation = geo2.QuaternionRotationArc((0, 0, 1), viewVector) yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(rotation) return (yaw, pitch)
def SetArrowDirection(self, direction): impactDir = geo2.Vec3Normalize(direction) self.arrowRotation = geo2.QuaternionRotationArc((0, 1, 0), impactDir) if impactDir == (0, -1, 0): self.arrowRotation = geo2.QuaternionRotationSetYawPitchRoll( 0.0, math.pi, 0.0)
def GetYawAndPitchAnglesRad(position0, position1): direction = geo2.Vec3Subtract(position1, position0) direction = geo2.Vec3Normalize(direction) angle = geo2.QuaternionRotationArc(direction, (0.0, 0.0, 1.0)) rot = geo2.QuaternionRotationGetYawPitchRoll(angle) return (rot[0], rot[1])
def GetYawAndPitchQuaternion(position0, position1): direction = geo2.Vec3Subtract(position1, position0) direction = geo2.Vec3Normalize(direction) quat = geo2.QuaternionRotationArc(direction, (0.0, 0.0, 1.0)) return quat
def fget(self): viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent) rotation = geo2.QuaternionRotationArc((1.0, 0.0, 0.0), viewVectorNormalized) return rotation