コード例 #1
0
ファイル: RocketFactory.cs プロジェクト: thomai-d/Orbiter
        public override void OnAttachedToNode(Node node)
        {
            base.OnAttachedToNode(node);

            if (this.Node != this.Scene)
            {
                throw new InvalidOperationException("RocketFactory should be attached to the scene");
            }

            this.cameraNode = this.Scene.GetChild("MainCamera", false)
                              ?? throw new InvalidOperationException("'MainCamera' not found");

            this.planetFactory = this.Scene.GetComponent <PlanetFactory>()
                                 ?? throw new InvalidOperationException("'PlanetFactory' not found");

            this.focusManager = this.Scene.GetComponent <FocusManager>()
                                ?? throw new InvalidOperationException("'FocusManager' not found");

            this.rocketsNode = this.Node.CreateChild("Rockets");
            this.soundSource = this.Node.CreateComponent <SoundSource>();
        }
コード例 #2
0
        public override void OnAttachedToNode(Node node)
        {
            base.OnAttachedToNode(node);

            this.planetFactory = this.Scene.GetComponent <PlanetFactory>()
                                 ?? throw new InvalidOperationException("'PlanetFactory' not found");

            this.joystickServer = this.Scene.GetComponent <JoystickServer>()
                                  ?? throw new InvalidOperationException("'JoystickServer' not found");

            this.focusManager = this.Scene.GetComponent <FocusManager>()
                                ?? throw new InvalidOperationException("'FocusManager' not found");

            this.cameraNode = this.Scene.GetChild("MainCamera", false)
                              ?? throw new InvalidOperationException("'MainCamera' not found");

            // Geometry.
            this.geometryNode = this.Node.CreateChild("Geometry");
            var planeModel = this.geometryNode.CreateComponent <StaticModel>();

            planeModel.Model    = this.Application.ResourceCache.GetModel("Models\\Rocket.mdl");
            planeModel.Material = this.Application.ResourceCache.GetMaterial("Materials\\RocketMaterial.xml");

            // Gravity.
            this.rigidBody      = this.Node.CreateComponent <RigidBody>();
            this.rigidBody.Mass = Constants.RocketDefaultMass;
            this.rigidBody.LinearRestThreshold = 0.0003f;
            this.rigidBody.AngularDamping      = 0;
            this.rigidBody.SetAngularFactor(Vector3.Zero);
            rigidBody.SetLinearVelocity(this.cameraNode.Rotation * Constants.RocketLaunchVelocity);

            // Engine particle emitter.
            var engineParticleNode = this.Node.CreateChild("RocketEngine");

            this.engineParticleEmitter         = engineParticleNode.CreateComponent <ParticleEmitter>();
            this.engineParticleEmitter.Enabled = false;
            this.engineParticleEmitter.Effect  = this.Application.ResourceCache.GetParticleEffect("Particles\\RocketEngine.xml");
            engineParticleNode.Translate(new Vector3(0, 0, -0.03f));

            // Collision particles.
            var collisionParticleNode = this.Node.CreateChild("CollisionParticle");

            this.collisionParticleEmitter         = collisionParticleNode.CreateComponent <ParticleEmitter>();
            this.collisionParticleEmitter.Enabled = false;
            this.collisionParticleEmitter.Effect  = this.Application.ResourceCache.GetParticleEffect("Particles\\Explosion.xml");

            // Collision detection.
            this.collisionShape = this.Node.CreateComponent <CollisionShape>();
            this.collisionShape.SetCylinder(0.07f, 0.015f, Vector3.Zero, Quaternion.Identity);

            // Background sound.
            this.rocketSoundSource = this.Node.CreateComponent <SoundSource3D>();
            this.rocketSoundSource.SetDistanceAttenuation(0.0f, 2.0f, 1.0f);
            var sound = this.Application.ResourceCache.GetSound("Sounds\\Rocket.wav");

            sound.Looped = true;
            this.rocketSoundSource.Play(sound);
            this.rocketSoundSource.Gain = 0.1f;
            this.soundBaseFrequency     = this.rocketSoundSource.Frequency;

            // Collision sound.
            this.collisionSoundSource = this.Node.CreateComponent <SoundSource3D>();
            this.collisionSound       = this.Application.ResourceCache.GetSound("Sounds\\Collision.wav");
            this.collisionSoundSource.SetDistanceAttenuation(0.0f, 5.0f, 3.0f);

            // Engine sound.
            this.engineSoundSource = this.Node.CreateComponent <SoundSource3D>();
            this.engineSound       = this.Application.ResourceCache.GetSound("Sounds\\RocketEngine.wav");
            this.engineSoundSource.SetDistanceAttenuation(0.0f, 5.0f, 1.0f);
            this.engineSound.Looped = true;
        }