Esempio n. 1
0
 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)
Esempio n. 2
0
 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))
Esempio n. 3
0
 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
Esempio n. 4
0
 def _GetModelStartTransformAndSpeed(self, muzzleID, moduleIdx):
     if not self.model:
         self.LogError('Missile::_GetModelStart with no model')
         return (None, None)
     now = blue.os.GetSimTime()
     q = self.model.rotationCurve.GetQuaternionAt(now)
     v = self.model.translationCurve.GetVectorAt(now)
     missileBallWorldTransform = geo2.MatrixAffineTransformation(1.0, (0.0, 0.0, 0.0), (q.x,
      q.y,
      q.z,
      q.w), (v.x, v.y, v.z))
     sourceShipBallWorldTransform = missileBallWorldTransform
     firingPosWorldTransform = missileBallWorldTransform
     sourceShipBallSpeed = (0.0, 0.0, 0.0)
     sourceTurretSet = self._GetModelTurret(moduleIdx)
     sourceShipBall = self.globalsGlob.GetTargetBall(self.sourceShipID)
     if sourceShipBall is not None:
         q = sourceShipBall.GetQuaternionAt(now)
         v = sourceShipBall.GetVectorAt(now)
         sourceShipBallWorldTransform = geo2.MatrixAffineTransformation(1.0, (0.0, 0.0, 0.0), (q.x,
          q.y,
          q.z,
          q.w), (v.x, v.y, v.z))
         s = sourceShipBall.GetVectorDotAt(now)
         sourceShipBallSpeed = (s.x, s.y, s.z)
         if sourceTurretSet is not None and len(sourceTurretSet.turretSets) > 0:
             gfxTS = sourceTurretSet.turretSets[0]
             firingPosWorldTransform = gfxTS.GetFiringBoneWorldTransform(gfxTS.currentCyclingFiresPos + muzzleID)
     invMissileBallWorldTransform = geo2.MatrixInverse(missileBallWorldTransform)
     startTransform = geo2.MatrixMultiply(firingPosWorldTransform, invMissileBallWorldTransform)
     startSpeed = geo2.Vec3TransformNormal(sourceShipBallSpeed, invMissileBallWorldTransform)
     return (startTransform, startSpeed)
Esempio n. 5
0
 def _TransformAxis(self, v):
     if self.activeManipAxis != 'w':
         ret = geo2.Vector(*v)
         worldTransInv = geo2.MatrixInverse(self.worldTranslation)
         v = geo2.Vec3TransformNormal(v, worldTransInv)
         t = self.GetTranslation()
         self.Translate(t + v)
         return ret
     return v
Esempio n. 6
0
    def PickObject(self, obj, rayOrigin, rayDirection, areaName = None):
        if obj.placeableRes is None:
            return
        model = obj.placeableRes.visualModel
        if model is None:
            return
        pickingGeometry = None
        pickingMesh = None
        pickingArea = None
        pickingCount = None
        for mesh in model.meshes:
            for area in mesh.transparentAreas:
                if areaName is None or area.name == areaName:
                    pickingGeometry = mesh.geometry
                    pickingMesh = mesh.meshIndex
                    pickingArea = area.index
                    pickingCount = area.count
                    break

            for area in mesh.opaquePrepassAreas:
                if areaName is None or area.name == areaName:
                    pickingGeometry = mesh.geometry
                    pickingMesh = mesh.meshIndex
                    pickingArea = area.index
                    pickingCount = area.count
                    break

        if pickingGeometry is not None:
            world = ((obj.transform._11,
              obj.transform._12,
              obj.transform._13,
              obj.transform._14),
             (obj.transform._21,
              obj.transform._22,
              obj.transform._23,
              obj.transform._24),
             (obj.transform._31,
              obj.transform._32,
              obj.transform._33,
              obj.transform._34),
             (obj.transform._41,
              obj.transform._42,
              obj.transform._43,
              obj.transform._44))
            worldInv = geo2.MatrixInverse(world)
            origin = geo2.Vec3Transform(rayOrigin, worldInv)
            direction = geo2.Vec3TransformNormal(rayDirection, worldInv)
            for area in range(pickingCount):
                result = pickingGeometry.GetRayAreaIntersection(origin, direction, pickingMesh, pickingArea + area, trinity.TriGeometryCollisionResultFlags.ANY)
                if result is not None:
                    return result
Esempio n. 7
0
 def _GetModelStartTransformAndSpeed(self, muzzleID, moduleIdx):
     """Returns a tuple of the missile model's start transform and the
     starting speed. Does a lot of complex logic that only works in a full
     client environment. Override it to provide a constant transform and speed.
     
     :returns: transform, speed. Use an identity matrix for transform
       to start the missile at the destinyball's origin. Returns None, None
       if the values cannot be calculated (because self.model is None).
     """
     if not self.model:
         self.LogError('Missile::_GetModelStart with no model')
         return (None, None)
     now = blue.os.GetSimTime()
     q = self.model.rotationCurve.GetQuaternionAt(now)
     v = self.model.translationCurve.GetVectorAt(now)
     missileBallWorldTransform = geo2.MatrixAffineTransformation(
         1.0, (0.0, 0.0, 0.0), (q.x, q.y, q.z, q.w), (v.x, v.y, v.z))
     sourceShipBallWorldTransform = missileBallWorldTransform
     firingPosWorldTransform = missileBallWorldTransform
     sourceShipBallSpeed = (0.0, 0.0, 0.0)
     sourceTurretSet = self._GetModelTurret(moduleIdx)
     sourceShipBall = self.globalsGlob.GetTargetBall(self.sourceShipID)
     if sourceShipBall is not None:
         q = sourceShipBall.GetQuaternionAt(now)
         v = sourceShipBall.GetVectorAt(now)
         sourceShipBallWorldTransform = geo2.MatrixAffineTransformation(
             1.0, (0.0, 0.0, 0.0), (q.x, q.y, q.z, q.w), (v.x, v.y, v.z))
         s = sourceShipBall.GetVectorDotAt(now)
         sourceShipBallSpeed = (s.x, s.y, s.z)
         if sourceTurretSet is not None and len(
                 sourceTurretSet.turretSets) > 0:
             gfxTS = sourceTurretSet.turretSets[0]
             firingPosWorldTransform = gfxTS.GetFiringBoneWorldTransform(
                 gfxTS.currentCyclingFiresPos + muzzleID)
     invMissileBallWorldTransform = geo2.MatrixInverse(
         missileBallWorldTransform)
     startTransform = geo2.MatrixMultiply(firingPosWorldTransform,
                                          invMissileBallWorldTransform)
     startSpeed = geo2.Vec3TransformNormal(sourceShipBallSpeed,
                                           invMissileBallWorldTransform)
     return (startTransform, startSpeed)