public static void DuplicateKeyFrame(NodeAnimationTrack track, TransformKeyFrame orig)
        {
            TransformKeyFrame newKeyFrame = (TransformKeyFrame)track.CreateKeyFrame(orig.Time);

            newKeyFrame.Scale     = orig.Scale;
            newKeyFrame.Rotation  = orig.Rotation;
            newKeyFrame.Translate = orig.Translate;
        }
Exemplo n.º 2
0
        void setupLighting()
        {
            /****/
            // Set ambient light
            mSceneManager.SetAmbientLight(Converter.GetColor(0.2f, 0.2f, 0.2f));
            // Point light, movable, reddish
            mLight = mSceneManager.CreateLight("Light2");
            mLight.SetDiffuseColour(mMinLightColour);
            mLight.SetSpecularColour(1.0f, 1.0f, 1.0f);
            mLight.SetAttenuation(8000.0f, 1.0f, 0.0005f, 0.0f);

            // Create light node
            mLightNode = mSceneManager.GetRootSceneNode().CreateChildSceneNode("MovingLightNode");
            mLightNode.AttachObject(mLight);
            // create billboard set
            BillboardSet bbs = mSceneManager.CreateBillboardSet("lightbbs", 1);

            bbs.SetMaterialName("Examples/Flare");
            Billboard bb = bbs.CreateBillboard(0, 0, 0, mMinLightColour);

            // attach
            mLightNode.AttachObject(bbs);



            // create controller, after this is will get updated on its own
            mWFCF   = new WaveformControllerFunction(WaveformType.Sine, 0.0f, 0.5f);
            mCFFPtr = new ControllerFunctionFloatPtr(mWFCF);

            mLightWibbler = new LightWibbler(mLight, bb, mMinLightColour, mMaxLightColour, mMinFlareSize, mMaxFlareSize);
            mCVFPtr       = new ControllerValueFloatPtr(mLightWibbler.mCVFH);

            ControllerManager contMgr = ControllerManager.GetSingleton();

            mLightCtlFlt = contMgr.CreateController(contMgr.GetFrameTimeSource(), mCVFPtr, mCFFPtr);

            mLightNode.SetPosition(new Vector3(300, 250, -300));


            // Create a track for the light
            Animation anim = mSceneManager.CreateAnimation("LightTrack", 20.0f);

            // Spline it for nice curves
            anim.SetInterpolationMode(Animation.InterpolationMode.Spline);
            // Create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, mLightNode);
            // Setup keyframes
            TransformKeyFrame key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(0.0f)).Handle, false);              // A startposition

            key.SetTranslate(new Vector3(300.0f, 550.0f, -300.0f));

            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(2.0f)).Handle, false);             //B
            key.SetTranslate(new Vector3(150.0f, 600.0f, -250.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(4.0f)).Handle, false);             //C
            key.SetTranslate(new Vector3(-150.0f, 650.0f, -100.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(6.0f)).Handle, false);             //D
            key.SetTranslate(new Vector3(-400.0f, 500.0f, -200.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(8.0f)).Handle, false);             //E
            key.SetTranslate(new Vector3(-200.0f, 500.0f, -400.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(10.0f)).Handle, false);            //F
            key.SetTranslate(new Vector3(-100.0f, 450.0f, -200.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(12.0f)).Handle, false);            //G
            key.SetTranslate(new Vector3(-100.0f, 400.0f, 180.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(14.0f)).Handle, false);            //H
            key.SetTranslate(new Vector3(0.0f, 250.0f, 600.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(16.0f)).Handle, false);            //I
            key.SetTranslate(new Vector3(100.0f, 650.0f, 100.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(18.0f)).Handle, false);            //J
            key.SetTranslate(new Vector3(250.0f, 600.0f, 0.0f));
            key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(20.0f)).Handle, false);            //K == A
            key.SetTranslate(new Vector3(300.0f, 550.0f, -300.0f));
            // Create a new animation state to track this
            mAnimState = mSceneManager.CreateAnimationState("LightTrack");
            mAnimState.SetEnabled(true);
            /****/
        }
Exemplo n.º 3
0
        // Just override the mandatory create scene method
        protected override void CreateScene()
        {
            RAND               = new Random(0);                    // najak: use a time-based seed
            GuiMgr             = OverlayElementManager.Instance;
            scene.AmbientLight = new ColorEx(0.75f, 0.75f, 0.75f); // default Ambient Light

            // Customize Controls - speed up camera and slow down the input update rate
            this.camSpeed = 5.0f;
            inputInterval = inputTimer = 0.02f;

            // Create water mesh and entity, and attach to sceneNode
            waterMesh   = new WaterMesh("WaterMesh", PLANE_SIZE, CMPLX);
            waterEntity = scene.CreateEntity("WaterEntity", "WaterMesh");
            SceneNode waterNode = scene.RootSceneNode.CreateChildSceneNode();

            waterNode.AttachObject(waterEntity);

            // Add Ogre head, give it it's own node
            headNode = waterNode.CreateChildSceneNode();
            Entity ent = scene.CreateEntity("head", "ogrehead.mesh");

            headNode.AttachObject(ent);

            // Create the camera node, set its position & attach camera
            camera.Yaw(-45f);
            camera.Move(new Vector3(1500f, 700f, PLANE_SIZE + 700f));
            camera.LookAt(new Vector3(PLANE_SIZE / 2f, 300f, PLANE_SIZE / 2f));
            camera.SetAutoTracking(false, headNode);             // Autotrack the head, but it isn't working right

            //scene.SetFog(FogMode.Exp, ColorEx.White, 0.000020f); // add Fog for fun, cuz we can

            // show overlay
            waterOverlay = (Overlay)OverlayManager.Instance.GetByName("Example/WaterOverlay");
            waterOverlay.Show();

            // Create Rain Emitter, but default Rain to OFF
            particleSystem  = ParticleSystemManager.Instance.CreateSystem("rain", "Examples/Water/Rain");
            particleEmitter = particleSystem.GetEmitter(0);
            particleEmitter.EmissionRate = 0f;

            // Attach Rain Emitter to SceneNode, and place it 3000f above the water surface
            SceneNode rNode = scene.RootSceneNode.CreateChildSceneNode();

            rNode.Translate(new Vector3(PLANE_SIZE / 2.0f, 3000, PLANE_SIZE / 2.0f));
            rNode.AttachObject(particleSystem);
            particleSystem.FastForward(20);             // Fastforward rain to make it look natural

            // It can't be set in .particle file, and we need it ;)
            particleSystem.BillboardOrigin = BillboardOrigin.BottomCenter;

            // Set Lighting
            lightNode             = scene.RootSceneNode.CreateChildSceneNode();
            lightSet              = scene.CreateBillboardSet("Lights", 20);
            lightSet.MaterialName = "Particles/Flare";
            lightNode.AttachObject(lightSet);
            SetLighting("Ambient");             // Add Lights - added by Najak to show lighted Water conditions - cool!

            #region STUBBED LIGHT ANIMATION
            // Create a new animation state to track this
            // TODO: Light Animation not working.
            //this.animState = scene.CreateAnimationState("WaterLight");
            //this.animState.Time = 0f;
            //this.animState.IsEnabled = false;

            // set up spline animation of light node.  Create random Spline
            Animation          anim  = scene.CreateAnimation("WaterLight", 20);
            NodeAnimationTrack track = anim.CreateNodeTrack(0, this.lightNode);
            TransformKeyFrame  key   = (TransformKeyFrame)track.CreateKeyFrame(0);
            for (int ff = 1; ff <= 19; ff++)
            {
                key = (TransformKeyFrame)track.CreateKeyFrame(ff);
                Random  rand = new Random(0);
                Vector3 lpos = new Vector3(
                    (float)rand.NextDouble() % (int)PLANE_SIZE,                    //- PLANE_SIZE/2,
                    (float)rand.NextDouble() % 300 + 100,
                    (float)rand.NextDouble() % (int)PLANE_SIZE);                   //- PLANE_SIZE/2
                key.Translate = lpos;
            }
            key = (TransformKeyFrame)track.CreateKeyFrame(20);
            #endregion STUBBED LIGHT ANIMATION

            // Initialize the Materials/Demo
            UpdateMaterial();  UpdateInfoParamC();  UpdateInfoParamD();  UpdateInfoParamU();
            UpdateInfoParamT();  UpdateInfoNormals();  UpdateInfoHeadDepth();  UpdateInfoSkyBox();
            UpdateInfoHeadSpeed(); UpdateInfoLights(); UpdateInfoTracking();

            // Init Head Animation:  Load adds[] elements - Ogre head animation
            adds[0]  = 0.3f; adds[1] = -1.6f; adds[2] = 1.1f; adds[3] = 0.5f;
            sines[0] = 0; sines[1] = 100; sines[2] = 200; sines[3] = 300;
        }         // end CreateScene()