Exemplo n.º 1
0
        protected Matrix4 straightMissileSpawnTxfm(ISSpaceMissileTarget target,
                                                   Vector3 launcherPos, Vector3 launcherVel,
                                                   int id, int clusterSize)
        {
            const float sideDispersal = 2f;
            float       angle         = (float)Math.PI * 2f / (float)clusterSize * id;
            Vector3     toTarget      = (target.position - launcherPos);
            float       length        = toTarget.Length;

            if (length < 0.0001f)
            {
                toTarget = -Vector3.UnitZ;
            }
            else
            {
                // normalize
                toTarget /= length;
            }
            Quaternion orientQuat  = OpenTKHelper.neededRotation(Vector3.UnitZ, toTarget);
            Matrix4    orientMat   = Matrix4.CreateFromQuaternion(orientQuat);
            Matrix4    disperalMat = Matrix4.CreateTranslation(sideDispersal * (float)Math.Cos(angle),
                                                               sideDispersal * (float)Math.Sin(angle), 0f);

            return(disperalMat * orientMat * Matrix4.CreateTranslation(launcherPos) * Matrix4.CreateTranslation(toTarget * 7f));
        }
        public SSpaceMissileClusterData(
            Vector3 launcherPos, Vector3 launcherVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileParameters mParams)
        {
            _target = target;
            _timeToHit = timeToHit;
            _parameters = mParams;
            _missiles = new SSpaceMissileData[numMissiles];

            if (_parameters.spawnGenerator != null) {
                _parameters.spawnGenerator.Generate(numMissiles,
                    (i, scale, pos, orient) => {
                        Matrix4 spawnTxfm = _parameters.spawnTxfm(_target,
                            launcherPos, launcherVel, i, numMissiles);
                        Vector3 missilePos = pos * _parameters.spawnGeneratorScale;
                        missilePos = Vector3.Transform(missilePos, spawnTxfm);
                        _missiles [i] = new SSpaceMissileData (
                            this, i, launcherPos, launcherVel, missilePos, timeToHit);
                        return true; // accept new missile from the generator
                    }
                );
            } else {
                for (int i = 0; i < numMissiles; ++i) {
                    Matrix4 spawnTxfm = _parameters.spawnTxfm(_target,
                        launcherPos, launcherVel, i, numMissiles);
                    var missilePos = Vector3.Transform(Vector3.Zero, spawnTxfm);
                    _missiles [i] = new SSpaceMissileData (
                        this, i, launcherPos, launcherVel, missilePos, timeToHit);
                }
            }
        }
Exemplo n.º 3
0
        public SSpaceMissileClusterVisualData(
            Matrix4 launcherWorldMat, Vector3 launcherVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileVisualParameters mParams,
            Vector3[] meshPositioningOffsets                  = null,
            Vector3[] meshPositioningDirections               = null,
            BodiesFieldGenerator meshPositioningGenerator     = null,
            SSpaceMissileVisualData.AtTargetFunc atTargetFunc = null)
        {
            _target           = target;
            _timeToHit        = timeToHit;
            _parameters       = mParams;
            _missiles         = new SSpaceMissileVisualData[numMissiles];
            this.atTargetFunc = atTargetFunc;

            Vector3[]    localSpawnPts     = new Vector3[numMissiles];
            Quaternion[] localSpawnOrients = new Quaternion[numMissiles];
            if (meshPositioningGenerator != null)
            {
                meshPositioningGenerator.Generate(numMissiles,
                                                  (id, scale, pos, orient) => {
                    localSpawnPts [id]     = pos;
                    localSpawnOrients [id] = orient;
                    return(true);
                }
                                                  );
            }

            Quaternion launcherOrientation = launcherWorldMat.ExtractRotation();

            for (int i = 0; i < numMissiles; ++i)
            {
                if (meshPositioningOffsets != null && meshPositioningOffsets.Length > 0)
                {
                    localSpawnPts [i] += meshPositioningOffsets [i % meshPositioningOffsets.Length];
                }
                if (meshPositioningDirections != null && meshPositioningDirections.Length > 0)
                {
                    int idx = i % meshPositioningDirections.Length;
                    localSpawnOrients [i] *= OpenTKHelper.getRotationTo(
                        Vector3.UnitZ, meshPositioningDirections [idx], Vector3.UnitZ);
                }
                Vector3 missileWorldPos = Vector3.Transform(localSpawnPts [i], launcherWorldMat);
                Vector3 missileLocalDir = Vector3.Transform(Vector3.UnitZ, localSpawnOrients [i]);
                Vector3 missileWorldDir = Vector3.Transform(missileLocalDir, launcherOrientation);
                Vector3 missileWorldVel = launcherVel + missileWorldDir * mParams.ejectionVelocity;

                _missiles [i] = mParams.createMissile(
                    missileWorldPos, missileWorldDir, missileWorldVel, this, i);

                #if false
                _missiles [i] = new SSpaceMissileVisualData(
                    missileWorldPos, missileWorldDir, missileWorldVel,
                    this, clusterId: i);
                #endif
            }
        }
        public SSpaceMissileClusterData launchCluster(
            Vector3 launchPos, Vector3 launchVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileParameters clusterParams)
        {
            var cluster = new SSpaceMissileClusterData(
                launchPos, launchVel, numMissiles, target, timeToHit, clusterParams);

            _clusters.Add(cluster);
            _targets.Add(target);
            return(cluster);
        }
        public SSpaceMissileClusterVisualData(
            Matrix4 launcherWorldMat, Vector3 launcherVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileVisualParameters mParams,
            Vector3[] meshPositioningOffsets = null,
            Vector3[] meshPositioningDirections = null,
            BodiesFieldGenerator meshPositioningGenerator = null,
            SSpaceMissileVisualData.AtTargetFunc atTargetFunc = null)
        {
            _target = target;
            _timeToHit = timeToHit;
            _parameters = mParams;
            _missiles = new SSpaceMissileVisualData[numMissiles];
            this.atTargetFunc = atTargetFunc;

            Vector3[] localSpawnPts = new Vector3[numMissiles];
            Quaternion[] localSpawnOrients = new Quaternion[numMissiles];
            if (meshPositioningGenerator != null) {
                meshPositioningGenerator.Generate(numMissiles,
                    (id, scale, pos, orient) => {
                        localSpawnPts [id] = pos;
                        localSpawnOrients [id] = orient;
                        return true;
                    }
                );
            }

            Quaternion launcherOrientation = launcherWorldMat.ExtractRotation();
            for (int i = 0; i < numMissiles; ++i) {
                if (meshPositioningOffsets != null && meshPositioningOffsets.Length > 0) {
                    localSpawnPts [i] += meshPositioningOffsets [i % meshPositioningOffsets.Length];
                }
                if (meshPositioningDirections != null && meshPositioningDirections.Length > 0) {
                    int idx = i % meshPositioningDirections.Length;
                    localSpawnOrients [i] *= OpenTKHelper.getRotationTo(
                        Vector3.UnitZ, meshPositioningDirections [idx], Vector3.UnitZ);
                }
                Vector3 missileWorldPos = Vector3.Transform(localSpawnPts [i], launcherWorldMat);
                Vector3 missileLocalDir = Vector3.Transform(Vector3.UnitZ, localSpawnOrients [i]);
                Vector3 missileWorldDir = Vector3.Transform(missileLocalDir, launcherOrientation);
                Vector3 missileWorldVel = launcherVel + missileWorldDir * mParams.ejectionVelocity;

                _missiles [i] = mParams.createMissile(
                    missileWorldPos, missileWorldDir, missileWorldVel, this, i);

                #if false
                _missiles [i] = new SSpaceMissileVisualData (
                    missileWorldPos, missileWorldDir, missileWorldVel,
                    this, clusterId: i);
                #endif
            }
        }
Exemplo n.º 6
0
        public SSpaceMissileClusterData launchCluster(
            Vector3 launchPos, Vector3 launchVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileParameters clusterParams)
        {
            _initParamsSpecific(clusterParams);
            var cluster = _simulation.launchCluster(launchPos, launchVel, numMissiles,
                                                    target, timeToHit, clusterParams);

            foreach (var missile in cluster.missiles)
            {
                _addMissileRender(missile);
            }
            return(cluster);
        }
Exemplo n.º 7
0
        public SSpaceMissileVisualData(
            Vector3 missileWorldPos, Vector3 missileWorldVel,
            SSpaceMissileParameters parameters = null, ISSpaceMissileTarget target      = null, AtTargetFunc atf = null,
            float ejectionYawVelocity          = float.NaN, float ejectionPitchVelocity = float.NaN)
            : base(missileWorldPos, missileWorldVel, parameters, target)
        {
            var ejectionAsVisual = _driver as SMissileEjectionVisualDriver;

            if (!float.IsNaN(ejectionYawVelocity))
            {
                ejectionAsVisual.yawVelocity = ejectionYawVelocity;
            }
            if (!float.IsNaN(ejectionPitchVelocity))
            {
                ejectionAsVisual.pitchVelocity = ejectionPitchVelocity;
            }
        }
Exemplo n.º 8
0
        public SSpaceMissileData(
            Vector3 missileWorldPos, Vector3 missileWorldVel,
            SSpaceMissileParameters parameters = null, ISSpaceMissileTarget target = null,
            float timeToHitTarget = 0f, ISharableData sharableData = null, AtTargetFunc atf = null)
        {
            _sharableData = sharableData ?? new SingleInstanceData()
            {
                target          = target,
                parameters      = parameters,
                timeSinceLaunch = 0f,
                timeToHit       = timeToHitTarget,
                atTargetFunc    = atf,
            };

            this.position = missileWorldPos;
            this.velocity = missileWorldVel;
        }
Exemplo n.º 9
0
        public SSpaceMissileClusterVisualData launchCluster(
            Matrix4 launcherWorldMat, Vector3 launchVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileVisualParameters clusterParams,
            Vector3[] localPositioningOffsets                 = null,
            Vector3[] localDirectionPresets                   = null,
            BodiesFieldGenerator meshPositioningGenerator     = null,
            SSpaceMissileVisualData.AtTargetFunc atTargetFunc = null
            )
        {
            var cluster = new SSpaceMissileClusterVisualData(
                launcherWorldMat, launchVel, numMissiles, target, timeToHit, clusterParams,
                localPositioningOffsets, localDirectionPresets, meshPositioningGenerator,
                atTargetFunc
                );

            _clusters.Add(cluster);
            _targets.Add(target);
            return(cluster);
        }
Exemplo n.º 10
0
        public SSpaceMissileClusterVisualData launchCluster(
            Matrix4 launcherWorldMat, Vector3 launchVel, int numMissiles,
            ISSpaceMissileTarget target,
            SSpaceMissileVisualParameters clusterParams,
            Vector3[] localPositioningOffsets = null,
            Vector3[] localDirections         = null,
            BodiesFieldGenerator localPositioningGenerator           = null,
            SSpaceMissileVisualData.AtTargetFunc missileAtTargetFunc = null,
            float timeToHit = float.NaN
            )
        {
            _initParamsSpecific(clusterParams);
            var cluster = _simulation.launchCluster(
                launcherWorldMat, launchVel, numMissiles,
                target, timeToHit, clusterParams,
                localPositioningOffsets, localDirections, localPositioningGenerator,
                missileAtTargetFunc);

            foreach (var missile in cluster.missiles)
            {
                _addMissileRender(missile);
            }
            return(cluster);
        }
Exemplo n.º 11
0
        public SSpaceMissileClusterData(
            Vector3 launcherPos, Vector3 launcherVel, int numMissiles,
            ISSpaceMissileTarget target, float timeToHit,
            SSpaceMissileParameters mParams)
        {
            _target     = target;
            _timeToHit  = timeToHit;
            _parameters = mParams;
            _missiles   = new SSpaceMissileData[numMissiles];

            if (_parameters.spawnGenerator != null)
            {
                _parameters.spawnGenerator.Generate(numMissiles,
                                                    (i, scale, pos, orient) => {
                    Matrix4 spawnTxfm = _parameters.spawnTxfm(_target,
                                                              launcherPos, launcherVel, i, numMissiles);
                    Vector3 missilePos = pos * _parameters.spawnGeneratorScale;
                    missilePos         = Vector3.Transform(missilePos, spawnTxfm);
                    _missiles [i]      = new SSpaceMissileData(
                        this, i, launcherPos, launcherVel, missilePos, timeToHit);
                    return(true);    // accept new missile from the generator
                }
                                                    );
            }
            else
            {
                for (int i = 0; i < numMissiles; ++i)
                {
                    Matrix4 spawnTxfm = _parameters.spawnTxfm(_target,
                                                              launcherPos, launcherVel, i, numMissiles);
                    var missilePos = Vector3.Transform(Vector3.Zero, spawnTxfm);
                    _missiles [i] = new SSpaceMissileData(
                        this, i, launcherPos, launcherVel, missilePos, timeToHit);
                }
            }
        }
 public SSpaceMissileClusterVisualData launchCluster(
     Matrix4 launcherWorldMat, Vector3 launchVel, int numMissiles,
     ISSpaceMissileTarget target, float timeToHit,
     SSpaceMissileVisualParameters clusterParams,
     Vector3[] localPositioningOffsets = null,
     Vector3[] localDirectionPresets = null,
     BodiesFieldGenerator meshPositioningGenerator = null,
     SSpaceMissileVisualData.AtTargetFunc atTargetFunc = null
 )
 {
     var cluster = new SSpaceMissileClusterVisualData (
         launcherWorldMat, launchVel, numMissiles, target, timeToHit, clusterParams,
         localPositioningOffsets, localDirectionPresets, meshPositioningGenerator,
         atTargetFunc
     );
     _clusters.Add(cluster);
     _targets.Add(target);
     return cluster;
 }
 public SSpaceMissileClusterData launchCluster(
     Vector3 launchPos, Vector3 launchVel, int numMissiles,
     ISSpaceMissileTarget target, float timeToHit,
     SSpaceMissileParameters clusterParams)
 {
     _initParamsSpecific(clusterParams);
     var cluster = _simulation.launchCluster(launchPos, launchVel, numMissiles,
                                             target, timeToHit, clusterParams);
     foreach (var missile in cluster.missiles) {
         _addMissileRender(missile);
     }
     return cluster;
 }
Exemplo n.º 14
0
 public SSpaceMissileClusterData launchCluster(
     Vector3 launchPos, Vector3 launchVel, int numMissiles,
     ISSpaceMissileTarget target, float timeToHit,
     SSpaceMissileParameters clusterParams)
 {
     var cluster = new SSpaceMissileClusterData (
       launchPos, launchVel, numMissiles, target, timeToHit, clusterParams);
     _clusters.Add(cluster);
     _targets.Add(target);
     return cluster;
 }
Exemplo n.º 15
0
 protected Matrix4 straightMissileSpawnTxfm(ISSpaceMissileTarget target, 
                                            Vector3 launcherPos, Vector3 launcherVel,
                                            int id, int clusterSize)
 {
     const float sideDispersal = 2f;
     float angle = (float)Math.PI * 2f / (float)clusterSize * id;
     Vector3 toTarget = (target.position - launcherPos);
     float length = toTarget.Length;
     if (length < 0.0001f) {
         toTarget = -Vector3.UnitZ;
     } else {
         // normalize
         toTarget /= length;
     }
     Quaternion orientQuat = OpenTKHelper.neededRotation(Vector3.UnitZ, toTarget);
     Matrix4 orientMat = Matrix4.CreateFromQuaternion(orientQuat);
     Matrix4 disperalMat = Matrix4.CreateTranslation(sideDispersal * (float)Math.Cos(angle),
                               sideDispersal * (float)Math.Sin(angle), 0f);
     return disperalMat * orientMat * Matrix4.CreateTranslation(launcherPos) * Matrix4.CreateTranslation(toTarget * 7f);
 }