/// <summary> /// Disposes /// </summary> public override void Dispose() { mLightNode = null; mLight = null; mpObjsNode = null; mStaticGeom = null; mAnimState = null; mSceneManager.ClearScene(); mLightWibbler.Dispose(); mLightWibbler = null; //ControllerManager contMgr = ControllerManager.GetSingleton(); //contMgr.DestroyController( mLightCtlFlt ); mLightCtlFlt = null; mWFCF = null; mCFFPtr = null; mCVFPtr = null; mLog.Dispose(); mLog = null; //GC.Collect(); base.Dispose(); }
/// <summary> /// Creates a very flexible time-based texture transformation which can alter the scale, position or /// rotation of a texture based on a wave function. /// </summary> /// <param name="layer">The texture unit to effect.</param> /// <param name="type">The type of transform, either translate (scroll), scale (stretch) or rotate (spin).</param> /// <param name="waveType">The shape of the wave, see WaveformType enum for details.</param> /// <param name="baseVal">The base value of the output.</param> /// <param name="frequency">The speed of the wave in cycles per second.</param> /// <param name="phase">The offset of the start of the wave, e.g. 0.5 to start half-way through the wave.</param> /// <param name="amplitude">Scales the output so that instead of lying within 0..1 it lies within 0..(1 * amplitude) for exaggerated effects</param> /// <returns>A newly created controller object that will be updated during the main render loop.</returns> public Controller <Real> CreateTextureWaveTransformer(TextureUnitState layer, TextureTransform type, WaveformType waveType, Real baseVal, Real frequency, Real phase, Real amplitude) { IControllerValue <Real> val = null; IControllerFunction <Real> function = null; // determine which type of controller value this layer needs switch (type) { case TextureTransform.TranslateU: val = new TexCoordModifierControllerValue(layer, true, false); break; case TextureTransform.TranslateV: val = new TexCoordModifierControllerValue(layer, false, true); break; case TextureTransform.ScaleU: val = new TexCoordModifierControllerValue(layer, false, false, true, false, false); break; case TextureTransform.ScaleV: val = new TexCoordModifierControllerValue(layer, false, false, false, true, false); break; case TextureTransform.Rotate: val = new TexCoordModifierControllerValue(layer, false, false, false, false, true); break; } // switch // create a new waveform controller function function = new WaveformControllerFunction(waveType, baseVal, frequency, phase, amplitude, true); // finally, create the controller using frame time as the source value return(CreateController(this.frameTimeController, val, function)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WaveformControllerFunction obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
protected override void CreateScene() { // set ambient light off // scene.AmbientLight = new ColorEx(.5f, .5f, .5f); scene.AmbientLight = ColorEx.Black; // TODO: Check based on caps int currentAtheneMaterial = 0; // fixed light, dim if (showSunlight) { sunLight = scene.CreateLight("SunLight"); sunLight.Type = LightType.Directional; sunLight.Position = new Vector3(1000, 1250, 500); sunLight.SetSpotlightRange(30, 50); Vector3 dir = -sunLight.Position; dir.Normalize(); sunLight.Direction = dir; sunLight.Diffuse = new ColorEx(0.65f, 0.65f, 0.68f); sunLight.Specular = new ColorEx(0.9f, 0.9f, 1); } // point light, movable, reddish light = scene.CreateLight("Light2"); light.Diffuse = minLightColor; light.Specular = ColorEx.White; light.SetAttenuation(8000, 1, .0005f, 0); // create light node lightNode = scene.RootSceneNode.CreateChildSceneNode("MovingLightNode"); lightNode.AttachObject(light); // create billboard set BillboardSet bbs = scene.CreateBillboardSet("LightBBS", 1); bbs.MaterialName = "Examples/Flare"; Billboard bb = bbs.CreateBillboard(Vector3.Zero, minLightColor); // attach to the scene lightNode.AttachObject(bbs); // create controller, after this is will get updated on its own WaveformControllerFunction func = new WaveformControllerFunction(WaveformType.Sine, 0.75f, 0.5f); LightWibbler val = new LightWibbler(light, bb, minLightColor, maxLightColor, minFlareSize, maxFlareSize); ControllerManager.Instance.CreateController(val, func); lightNode.Position = new Vector3(300, 250, -300); // create a track for the light Animation anim = scene.CreateAnimation("LightTrack", 20); // spline it for nice curves anim.InterpolationMode = InterpolationMode.Spline; // create a track to animate the camera's node AnimationTrack track = anim.CreateNodeTrack(0, lightNode); // setup keyframes AddKey(track, 0, new Vector3(300, 250, -300)); AddKey(track, 2, new Vector3(150, 300, -250)); AddKey(track, 4, new Vector3(-150, 350, -100)); AddKey(track, 6, new Vector3(-400, 200, -200)); AddKey(track, 8, new Vector3(-200, 200, -400)); AddKey(track, 10, new Vector3(-100, 150, -200)); AddKey(track, 12, new Vector3(-100, 75, 180)); AddKey(track, 14, new Vector3(0, 250, 300)); AddKey(track, 16, new Vector3(100, 350, 100)); AddKey(track, 18, new Vector3(250, 300, 0)); AddKey(track, 20, new Vector3(300, 250, -300)); // create a new animation state to track this animState = scene.CreateAnimationState("LightTrack"); animState.IsEnabled = true; // Make light node look at origin, this is for when we // change the moving light to a spotlight lightNode.SetAutoTracking(true, scene.RootSceneNode); // lightSphereNode = scene.RootSceneNode.CreateChildSceneNode(); // lightSphere = scene.CreateEntity("LightSphere", "tiny_cube.mesh"); // lightSphereNode.AttachObject(lightSphere); // lightSphereNode.Position = new Vector3(300, 260, -300); // // create a track for the light sphere // Animation animSphere = scene.CreateAnimation("LightSphereTrack", 20); // // spline it for nice curves // animSphere.InterpolationMode = InterpolationMode.Spline; // // create a track to animate the camera's node // AnimationTrack trackSphere = animSphere.CreateTrack(0, lightSphereNode); // // setup keyframes // for (int i = 0; i <= 10; i++) { // Vector3 v = track.KeyFrames[i].Translate; // v.y += 10; // key = trackSphere.CreateKeyFrame(i * 2); // key.Translate = v; // } // // create a new animation state to track this // animSphereState = scene.CreateAnimationState("LightSphereTrack"); // animSphereState.IsEnabled = true; // // Make light node look at origin, this is for when we // // change the moving light to a spotlight // lightSphereNode.SetAutoTracking(true, scene.RootSceneNode); Mesh mesh = MeshManager.Instance.Load("athene.mesh"); short srcIdx, destIdx; // the athene mesh requires tangent vectors if (!mesh.SuggestTangentVectorBuildParams(out srcIdx, out destIdx)) { mesh.BuildTangentVectors(srcIdx, destIdx); } SceneNode node; //= scene.RootSceneNode.CreateChildSceneNode(); // athene = scene.CreateEntity("Athene", "athene.mesh"); // athene.MaterialName = atheneMaterials[currentAtheneMaterial]; // node.AttachObject(athene); // node.Translate(new Vector3(0, -20, 0)); // node.Yaw(90); Entity ent = null; node = scene.RootSceneNode.CreateChildSceneNode(); ent = scene.CreateEntity("Column1", "column.mesh"); ent.MaterialName = "Examples/Rockwall"; node.AttachObject(ent); node.Translate(new Vector3(200, 0, -200)); node = scene.RootSceneNode.CreateChildSceneNode(); ent = scene.CreateEntity("Column2", "column.mesh"); ent.MaterialName = "Examples/Rockwall"; node.AttachObject(ent); node.Translate(new Vector3(200, 0, 200)); node = scene.RootSceneNode.CreateChildSceneNode(); ent = scene.CreateEntity("Column3", "column.mesh"); ent.MaterialName = "Examples/Rockwall"; node.AttachObject(ent); node.Translate(new Vector3(-200, 0, -200)); node = scene.RootSceneNode.CreateChildSceneNode(); ent = scene.CreateEntity("Column4", "column.mesh"); ent.MaterialName = "Examples/Rockwall"; node.AttachObject(ent); node.Translate(new Vector3(-200, 0, 200)); scene.SetSkyBox(true, "Skybox/Stormy", 3000); Plane plane = new Plane(Vector3.UnitY, -100); MeshManager.Instance.CreatePlane( "MyPlane", plane, 1500, 1500, 20, 20, true, 1, 5, 5, Vector3.UnitZ); Entity planeEnt = scene.CreateEntity("Plane", "MyPlane"); planeEnt.MaterialName = "Examples/Rockwall"; planeEnt.CastShadows = false; scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEnt); if (Root.Instance.RenderSystem.Name.StartsWith("Axiom Direct")) { // In D3D, use a 1024x1024 shadow texture scene.SetShadowTextureSettings(1024, 2, PixelFormat.L16); } else { // Use 512x512 texture in GL since we can't go higher than the window res scene.SetShadowTextureSettings(512, 2, PixelFormat.L16); } // scene.ShadowColor = new ColorEx(0.5f, 0.5f, 0.5f); scene.ShadowColor = ColorEx.Black; scene.ShadowFarDistance = 1000f; // in case infinite far distance is not supported camera.Far = 100000; debugTextDelay = int.MaxValue; scene.ShadowTechnique = shadowTechniques[currentShadowTechnique]; ApplyShadowTechnique(); }
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); /****/ }