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 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 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 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); }
protected override void setupScene() { base.setupScene(); var droneMesh = SSAssetManager.GetInstance <SSMesh_wfOBJ> ("./drone2/Drone2.obj"); //var droneMesh = SSAssetManager.GetInstance<SSMesh_wfOBJ> ("missiles", "missile.obj"); var vandalMesh = SSAssetManager.GetInstance <SSMesh_wfOBJ> ("missiles/vandal_assembled.obj"); // add drones attackerDrone = new SSObjectMesh(droneMesh); attackerDrone.Pos = new OpenTK.Vector3(-20f, 0f, 0f); attackerDrone.Orient(Vector3.UnitX, Vector3.UnitY); attackerDrone.AmbientMatColor = new Color4(0.1f, 0.1f, 0.1f, 0.1f); attackerDrone.DiffuseMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); attackerDrone.SpecularMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); attackerDrone.EmissionMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); attackerDrone.Name = "attacker drone"; main3dScene.AddObject(attackerDrone); targetDrone = new SSObjectMesh(droneMesh); targetDrone.Pos = new OpenTK.Vector3(200f, 0f, 0f); targetDrone.Orient(-Vector3.UnitX, Vector3.UnitY); targetDrone.AmbientMatColor = new Color4(0.1f, 0.1f, 0.1f, 0.1f); targetDrone.DiffuseMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); targetDrone.SpecularMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); targetDrone.EmissionMatColor = new Color4(0.3f, 0.3f, 0.3f, 0.3f); targetDrone.Name = "target drone"; targetDrone.MainColor = new Color4(1f, 0f, 0.7f, 1f); main3dScene.AddObject(targetDrone); vandalShip = new SSObjectMesh(vandalMesh); vandalShip.Pos = new OpenTK.Vector3(100f, 0f, 0f); vandalShip.Scale = new Vector3(0.05f); vandalShip.AmbientMatColor = new Color4(0.1f, 0.1f, 0.1f, 0.1f); vandalShip.DiffuseMatColor = new Color4(0.1f, 0.1f, 0.1f, 0.1f); vandalShip.SpecularMatColor = new Color4(0.1f, 0.1f, 0.1f, 0.1f); vandalShip.EmissionMatColor = new Color4(0.0f, 0.0f, 0.0f, 0.0f); vandalShip.Name = "Vandal ship"; vandalShip.MainColor = new Color4(0.6f, 0.6f, 0.6f, 1f); //vandalShip.MainColor = new Color4(1f, 0f, 0.7f, 1f); //droneObj2.renderState.visible = false; vandalShip.Orient((targetDrone.Pos - vandalShip.Pos).Normalized(), Vector3.UnitY); main3dScene.AddObject(vandalShip); // shows explosions explosionManager = new SExplosionRenderManager(); explosionManager.particleSystem.doShockwave = false; explosionManager.particleSystem.doDebris = false; explosionManager.particleSystem.timeScale = 3f; //explosionManager.renderState.visible = false; alpha3dScene.AddObject(explosionManager); // attacker drone missile parameters attackerDroneFieldGen = new BodiesFieldGenerator( new ParticlesSphereGenerator(Vector3.Zero, 1f)); attackerDroneMissileParams = new SSpaceMissileVisualParameters(); // vandal missile params vandalShipFieldGen = new BodiesRingGenerator( new ParticlesOvalGenerator(1f, 1f), ringCenter: new Vector3(0f, 0f, 0f), up: Vector3.UnitZ, ringRadius: 80f, oriPolicy: BodiesFieldGenerator.OrientPolicy.None ); vandalShipMissileParams = new SSpaceMissileVisualParameters(); vandalShipMissileParams.ejectionMaxRotationVel = 0.05f; vandalShipMissileParams.ejectionVelocity = 30f; vandalShipMissileParams.pursuitActivationTime = 0.1f; vandalShipMissileParams.ejectionSmokeDuration = 0.5f; vandalShipMissileParams.ejectionSmokeSizeMax = 5f; cameraMissileParams = new SSpaceMissileVisualParameters(); //cameraMissileParams.spawnGenerator = null; //cameraMissileParams.spawnTxfm = straightMissileSpawnTxfm; cameraMissileParams.ejectionMaxRotationVel = 0.05f; cameraMissileParams.ejectionVelocity = 10f; // missile manager missileManager = new SSpaceMissilesRenderManager(main3dScene, alpha3dScene, hud2dScene); // additional statistics text missileStatsText = new SSObjectGDISurface_Text(); missileStatsText.alphaBlendingEnabled = true; missileStatsText.Label = "stats placeholder..."; missileStatsText.Pos = new Vector3(100f, 100f, 0f); //missileStatsText.Size = 20f; hud2dScene.AddObject(missileStatsText); var targetsManager = new SHudTargetsManager(main3dScene, hud2dScene); targetHud = targetsManager.addTarget( (o) => Color4.Red, _showDistanceFunc, (o) => o != null ? o.Name : "none", getTargetObject() ); }
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; }