Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        protected override void SetupContent()
        {
            this.ptex = TextureManager.Instance.CreateManual("DynaTex", ResourceGroupManager.DefaultResourceGroupName,
                                                             TextureType.ThreeD, 64, 64, 64, 0, Media.PixelFormat.A8R8G8B8,
                                                             TextureUsage.Default, null);

            SceneManager.AmbientLight = new ColorEx(0.6f, 0.6f, 0.6f);
            SceneManager.SetSkyBox(true, "Examples/MorningSkyBox", 50);

            Light light = SceneManager.CreateLight("VolumeTextureSampleLight");

            light.Diffuse  = new ColorEx(0.75f, 0.75f, 0.80f);
            light.Specular = new ColorEx(0.9f, 0.9f, 1);
            light.Position = new Vector3(-100, 80, 50);
            SceneManager.RootSceneNode.AttachObject(light);

            // Create volume renderable
            this.snode = SceneManager.RootSceneNode.CreateChildSceneNode(Vector3.Zero);

            this.vrend = new VolumeRendable(32, 750, "DynaTex");
            this.snode.AttachObject(this.vrend);

            this.trend          = new ThingRendable(90, 32, 7.5f);
            this.trend.Material = (Material)MaterialManager.Instance.GetByName("Examples/VTDarkStuff");
            this.trend.Material.Load();
            this.snode.AttachObject(this.trend);

            this.fnode = SceneManager.RootSceneNode.CreateChildSceneNode();
            Entity head = SceneManager.CreateEntity("head", "ogrehead.mesh");

            this.fnode.AttachObject(head);

            Animation anim = SceneManager.CreateAnimation("OgreTrack", 10);

            anim.InterpolationMode = InterpolationMode.Spline;

            NodeAnimationTrack track = anim.CreateNodeTrack(0, this.fnode);
            TransformKeyFrame  key   = track.CreateNodeKeyFrame(0);

            key.Translate            = new Vector3(0, -15, 0);
            key                      = track.CreateNodeKeyFrame(5);
            key.Translate            = new Vector3(0, 15, 0);
            key                      = track.CreateNodeKeyFrame(10);
            key.Translate            = new Vector3(0, -15, 0);
            this.animState           = SceneManager.CreateAnimationState("OgreTrack");
            this.animState.IsEnabled = true;

            this.globalReal  = 0.4f;
            this.globalImag  = 0.6f;
            this.globalTheta = 0.0f;

            CreateControls();

            DragLook = true;

            Generate();
        }
Exemplo n.º 2
0
        public override void CreateScene()
        {
            SceneNode node1 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Tutorial10Node");

            // Create a point light
            Light l = base.sceneMgr.CreateLight("MainLight");
            // Accept default settings: point light, white diffuse, just set position
            // Add light to the scene node
            SceneNode lightNode = base.sceneMgr.RootSceneNode.CreateChildSceneNode();

            lightNode.CreateChildSceneNode(new Vector3(10, 10, 10)).AttachObject(l);

            MeshPtr pMesh = MeshManager.Singleton.Load("knot.mesh",
                                                       ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                                                       HardwareBuffer.Usage.HBU_DYNAMIC_WRITE_ONLY,
                                                       HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY,
                                                       true,
                                                       true);//can still read it
            //ushort src, dest;
            //if (!pMesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest))
            //    pMesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest);

            //create entity
            Entity entity = sceneMgr.CreateEntity("Tutorial10Entity", "knot.mesh");

            entity.SetMaterialName("CgTutorials/C5E2_Material");
            //attach to main node
            node1.AttachObject(entity);

            // set up spline animation of node
            Animation anim = sceneMgr.CreateAnimation("LightTrack", 10F);

            // Spline it for nice curves

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
            // Create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, lightNode);

            // Setup keyframes
            TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition

            key           = track.CreateNodeKeyFrame(2.5F);
            key.Translate = new Vector3(500F, 500F, -1000F);
            key           = track.CreateNodeKeyFrame(5F);
            key.Translate = new Vector3(-1500F, 1000F, -600F);
            key           = track.CreateNodeKeyFrame(7.5F);
            key.Translate = new Vector3(0F, 100F, 0F);
            key           = track.CreateNodeKeyFrame(10F);
            key.Translate = new Vector3(0F, 0F, 0F);

            // Create a new animation state to track this
            animState         = sceneMgr.CreateAnimationState("LightTrack");
            animState.Enabled = true;
        }
Exemplo n.º 3
0
        /// <summary>
        ///    Reads an animation track section.
        /// </summary>
        protected void ReadKeyFrame(BinaryReader reader, NodeAnimationTrack track)
        {
            var time = ReadFloat(reader);

            // create a new keyframe with the specified length
            var keyFrame = track.CreateNodeKeyFrame(time);

            // read orientation
            var rotate = ReadQuat(reader);

            keyFrame.Rotation = rotate;

            // read translation
            var translate = ReadVector3(reader);

            keyFrame.Translate = translate;

            // read scale if it is in there
            if (currentChunkLength >= 50)
            {
                var scale = ReadVector3(reader);
                keyFrame.Scale = scale;
            }
            else
            {
                keyFrame.Scale = Vector3.UnitScale;
            }
        }
        protected void TransformTrack(Matrix4 exportTransform,
                                      NodeAnimationTrack newTrack,
                                      NodeAnimationTrack track,
                                      Bone bone)
        {
            Matrix4 invExportTransform = exportTransform.Inverse();
            Bone    oldNode            = (Bone)track.TargetNode;
            Bone    newNode            = (Bone)newTrack.TargetNode;

            for (int i = 0; i < track.KeyFrames.Count; ++i)
            {
                TransformKeyFrame keyFrame       = track.GetTransformKeyFrame(i);
                TransformKeyFrame newKeyFrame    = newTrack.CreateNodeKeyFrame(keyFrame.Time);
                Quaternion        oldOrientation = oldNode.Orientation * keyFrame.Rotation;
                Vector3           oldTranslation = oldNode.Position + keyFrame.Translate;
                Matrix4           oldTransform   = Multiverse.MathLib.MathUtil.GetTransform(oldOrientation, oldTranslation);
                Matrix4           newTransform   = exportTransform * oldTransform * invExportTransform;
                Quaternion        newOrientation = GetRotation(newTransform);
                Vector3           newTranslation = newTransform.Translation;
                newKeyFrame.Rotation  = newNode.Orientation.Inverse() * newOrientation;
                newKeyFrame.Translate = newTranslation - newNode.Position;
                //if (oldNode.Name == "Lower_Torso_BIND_jjj") {
                //    log.DebugFormat("New translation: {0}; New Position: {1}", newTranslation, newNode.Position);
                //}
            }
        }
Exemplo n.º 5
0
        public override void CreateScene()
        {
            SceneNode node1  = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Tutorial08Node");
            Entity    entity = base.sceneMgr.CreateEntity("Tutorial08Entity", SceneManager.PrefabType.PT_SPHERE);

            entity.SetMaterialName("CgTutorials/C4E1_Material");
            node1.AttachObject(entity);

            // Make sure the camera track this node
            camera.SetAutoTracking(true, node1);

            // Create the camera node & attach camera
            SceneNode camNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

            camNode.AttachObject(camera);

            // set up spline animation of node
            Animation anim = sceneMgr.CreateAnimation("CameraTrack", 10F);

            // Spline it for nice curves

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
            // Create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode);

            // Setup keyframes
            TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition

            key           = track.CreateNodeKeyFrame(2.5F);
            key.Translate = new Vector3(500F, 500F, -1000F);
            key           = track.CreateNodeKeyFrame(5F);
            key.Translate = new Vector3(-1500F, 1000F, -600F);
            key           = track.CreateNodeKeyFrame(7.5F);
            key.Translate = new Vector3(0F, 100F, 0F);
            key           = track.CreateNodeKeyFrame(10F);
            key.Translate = new Vector3(0F, 0F, 0F);

            // Create a new animation state to track this
            animState         = sceneMgr.CreateAnimationState("CameraTrack");
            animState.Enabled = true;

            camera.PolygonMode = PolygonMode.PM_WIREFRAME;
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        protected override void SetupContent()
        {
            // setup some basic lighting for our scene
            SceneManager.AmbientLight = new ColorEx(0.3f, 0.3f, 0.3f);
            SceneManager.CreateLight("CameraTrackLight").Position = new Vector3(20, 80, 50);

            SceneManager.SetSkyBox(true, "Examples/MorningSkyBox", 5000);
            // create an ogre head entity and attach it to a node
            Entity    head     = SceneManager.CreateEntity("Head", "ogrehead.mesh");
            SceneNode headNode = SceneManager.RootSceneNode.CreateChildSceneNode();

            headNode.AttachObject(head);
            CameraManager.setStyle(CameraStyle.Manual);
            // we will be controlling the camera ourselves, so disable the camera man
            Camera.SetAutoTracking(true, headNode); // make the camera face the head


            // create a camera node and attach camera to it
            SceneNode camNode = SceneManager.RootSceneNode.CreateChildSceneNode();

            camNode.AttachObject(Camera);

            // set up a 10 second animation for our camera, using spline interpolation for nice curves
            Animation anim = SceneManager.CreateAnimation("CameraTrack", 10);

            anim.InterpolationMode = InterpolationMode.Spline;
            // create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode);

            // create keyframes for our track
            track.CreateNodeKeyFrame(0).Translate    = new Vector3(200, 0, 0);
            track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100);
            track.CreateNodeKeyFrame(5).Translate    = new Vector3(-500, 100, 0);
            track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300);
            track.CreateNodeKeyFrame(10).Translate   = new Vector3(200, 0, 0);

            // create a new animation state to track this
            this.animState           = SceneManager.CreateAnimationState("CameraTrack");
            this.animState.IsEnabled = true;
            base.SetupContent();
        }
Exemplo n.º 7
0
        protected void buildFloatAnimation(SceneNode animationNode, float duration, bool sidewaysOnly)
        {
            Animation animation = framework.SceneMgr.CreateAnimation(animationNode.Name + "_FloatAnimation", duration);

            animation.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
            NodeAnimationTrack track = animation.CreateNodeTrack(0, animationNode);
            TransformKeyFrame  key;

            Radian depth;

            depth = sidewaysOnly ? new Radian(new Degree(0)) : new Radian(new Degree(-2));


            Quaternion baseQ = Quaternion.IDENTITY;

            key          = track.CreateNodeKeyFrame(0.0f);
            key.Rotation = Quaternion.IDENTITY * baseQ;


            key          = track.CreateNodeKeyFrame(2.0f);
            key.Rotation = new Quaternion(new Radian(new Degree(-5)), Vector3.UNIT_Z) * baseQ; // bok



            key          = track.CreateNodeKeyFrame(5.0f);
            key.Rotation = new Quaternion(new Radian(new Degree(0)), Vector3.UNIT_Z) * new Quaternion(depth, Vector3.UNIT_X) * baseQ; // gora / dol


            key          = track.CreateNodeKeyFrame(7.0f);
            key.Rotation = new Quaternion(new Radian(new Degree(4)), Vector3.UNIT_Z) * new Quaternion(new Radian(new Degree(-0)), Vector3.UNIT_X) * baseQ; // bok


            key          = track.CreateNodeKeyFrame(10.0f);
            key.Rotation = Quaternion.IDENTITY * baseQ;


            shipAnimationState         = framework.SceneMgr.CreateAnimationState(animationNode.Name + "_FloatAnimation");
            shipAnimationState.Enabled = true;
            shipAnimationState.Loop    = true;
        }
Exemplo n.º 8
0
        protected override void CreateScene()
        {
            // Set ambient light
            sceneMgr.AmbientLight = new ColourValue(0.75f, 0.75f, 0.75f);

            // Create a light
            Light l = sceneMgr.CreateLight("MainLight");

            // Accept default settings: point light, white diffuse, just set position
            // NB I could attach the light to a SceneNode if I wanted it to move automatically with
            //  other objects, but I don't
            l.Position = new Vector3(200, 700, 100);

            sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;

            // Create a skydome
            sceneMgr.SetSkyDome(true, "Examples/CloudySky", 30, 5);

            // Put in a bit of fog for the hell of it
            sceneMgr.SetFog(FogMode.FOG_EXP, ColourValue.White, 0.0001f, 0.5f);

            // Define a floor plane mesh
            Plane p = new Plane();

            p.normal = Vector3.UNIT_Y;
            p.d      = 180;
            MeshManager.Singleton.CreatePlane("FloorPlane",
                                              ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                                              p, PLANE_SIZE * 1000, PLANE_SIZE * 1000, 20, 20, true, 1, 50, 50, Vector3.UNIT_Z);

            Entity ent = sceneMgr.CreateEntity("floorEntity", "FloorPlane");

            ent.SetMaterialName("Examples/RustySteel");
            ent.CastShadows = false;
            SceneNode floorNode = sceneMgr.RootSceneNode.CreateChildSceneNode("floorSceneNode");

            floorNode.AttachObject(ent);

            // Add a head, give it it's own node
            // The Ogre head faces to Z
            headNode        = sceneMgr.RootSceneNode.CreateChildSceneNode("headSceneNode");
            ent             = sceneMgr.CreateEntity("head", "ogrehead.mesh");
            ent.CastShadows = true;
            headNode.AttachObject(ent);

            atheneNode = sceneMgr.RootSceneNode.CreateChildSceneNode("atheneSceneNode");
            //Entity *Athene = mSceneMgr->createEntity( "Razor", "razor.mesh" );
            Entity Athene = sceneMgr.CreateEntity("Athene", "athene.mesh");

            Athene.SetMaterialName("Examples/Athene/NormalMapped");
            Athene.CastShadows = true;
            atheneNode.AttachObject(Athene);
            atheneNode.SetPosition(500, -100, 500);

            // Obstacle for collisions detection
            SceneNode barrelNode = sceneMgr.RootSceneNode.CreateChildSceneNode("barrelSceneNode");
            Entity    barrel     = sceneMgr.CreateEntity("barrel", "barrel.mesh");

            barrel.CastShadows = true;
            barrelNode.AttachObject(barrel);
            barrelNode.SetPosition(1300, -100, 500);
            barrelNode.SetScale(40, 40, 40);

            // Create light node
            SceneNode lightNode = sceneMgr.RootSceneNode.CreateChildSceneNode("lightSceneNode");

            lightNode.AttachObject(l);
            goto cameraControl;

            // set up spline animation of node
            Animation anim = sceneMgr.CreateAnimation("HeadTrack", 20);

            // Spline it for nice curves

            anim.SetInterpolationMode(Mogre.Animation.InterpolationMode.IM_SPLINE);
            // Create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, headNode);
            // Setup keyframes
            TransformKeyFrame key = track.CreateNodeKeyFrame(0); // startposition

            key.Translate = new Vector3(0, 0, 0);
            key.Rotation  = Quaternion.IDENTITY;

            key           = track.CreateNodeKeyFrame(2.5f);
            key.Translate = new Vector3(0, 0, 1000);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, 0, 1000));

            key           = track.CreateNodeKeyFrame(5);
            key.Translate = new Vector3(1000, 0, 1000);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, 0, 0));

            key           = track.CreateNodeKeyFrame(7.5f);
            key.Translate = new Vector3(1000, 0, 0);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(Vector3.NEGATIVE_UNIT_X);

            key           = track.CreateNodeKeyFrame(10);
            key.Translate = new Vector3(0, 0, 0);

            // Second round
            key           = track.CreateNodeKeyFrame(11);
            key.Translate = new Vector3(0, 0, 400);
            key.Rotation  = new Quaternion(new Radian(3.14f / 4.0f), Vector3.UNIT_Z);

            key           = track.CreateNodeKeyFrame(11.5f);
            key.Translate = new Vector3(0, 0, 600);
            key.Rotation  = new Quaternion(new Radian(-3.14f / 4.0f), Vector3.UNIT_Z);

            key           = track.CreateNodeKeyFrame(12.5f);
            key.Translate = new Vector3(0, 0, 1000);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(new Vector3(500, 500, 1000));

            key           = track.CreateNodeKeyFrame(13.25f);
            key.Translate = new Vector3(500, 500, 1000);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, -500, 1000));

            key           = track.CreateNodeKeyFrame(15);
            key.Translate = new Vector3(1000, 0, 1000);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, 0, -500));

            key           = track.CreateNodeKeyFrame(16);
            key.Translate = new Vector3(1000, 0, 500);

            key           = track.CreateNodeKeyFrame(16.5f);
            key.Translate = new Vector3(1000, 0, 600);

            key           = track.CreateNodeKeyFrame(17.5f);
            key.Translate = new Vector3(1000, 0, 0);
            key.Rotation  = Vector3.UNIT_Z.GetRotationTo(new Vector3(-500, 500, 0));

            key           = track.CreateNodeKeyFrame(118.25f);
            key.Translate = new Vector3(500, 500, 0);
            key.Rotation  = new Quaternion(new Radian(3.14f), Vector3.UNIT_X) * Vector3.UNIT_Z.GetRotationTo(new Vector3(-500, -500, 0));

            key           = track.CreateNodeKeyFrame(20);
            key.Translate = new Vector3(0, 0, 0);

            key           = track.CreateNodeKeyFrame(2000);
            key.Translate = new Vector3(-20000000, 0, 0);

            // Create a new animation state to track this
            mAnimState         = sceneMgr.CreateAnimationState("HeadTrack");
            mAnimState.Enabled = true;

            cameraControl :;
            setupCameraControlSystem();
        }
Exemplo n.º 9
0
        protected override void CreateScene()
        {
            // setup some basic lighting for our scene
            _sceneManager.AmbientLight = new ColourValue(0.3f, 0.3f, 0.3f);
            var lightNode = _sceneManager.RootSceneNode.CreateChildSceneNode();

            lightNode.SetPosition(20, 80, 50);
            lightNode.AttachObject(_sceneManager.CreateLight());

            _sceneManager.SetSkyBox(true, "Examples/SpaceSkyBox");

            // create an ogre head entity and attach it to a node
            Entity head = _sceneManager.CreateEntity("ogrehead.mesh");

            head.Name = "Head";
            SceneNode headNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            headNode.Translate(0, 40, 0);
            headNode.AttachObject(head);

            // create a camera node and attach camera to it
            SceneNode camNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            _camera.DetachFromParent();
            camNode.AttachObject(_camera);

            // set up a 10 second animation for our camera, using spline interpolation for nice curves
            Animation anim = _sceneManager.CreateAnimation("CameraTrack", 10);

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);

            // create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(camNode);

            // create keyframes for our track
            track.CreateNodeKeyFrame(0).Translate    = new Vector3(200, 0, 0);
            track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100);
            track.CreateNodeKeyFrame(5).Translate    = new Vector3(-500, 100, 0);
            track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300);
            track.CreateNodeKeyFrame(10).Translate   = new Vector3(200, 0, 0);

            // create a new animation state to track this
            _animState         = _sceneManager.CreateAnimationState("CameraTrack");
            _animState.Enabled = true;

            // Now create another scene manager with only
            _rttSceneManager = CreateSceneManager();

            // Create the RenderTargetTexture
            _rttCamera          = _rttSceneManager.CreateCamera("RttCamera");
            _rttCamera.Position = new Vector3(0f, 10f, 500f);
            _rttCamera.LookAt(new Vector3(0f, 0f, -300f));
            _rttCamera.AutoAspectRatio  = true;
            _rttCamera.NearClipDistance = 5.0f;

            // Penguin
            Entity penguin = _rttSceneManager.CreateEntity("penguin.mesh");

            _penguinNode = _rttSceneManager.RootSceneNode.CreateChildSceneNode();
            _penguinNode.AttachObject(penguin);
            penguin.Name = "Penguin";

            MaterialPtr penguinMaterial = MaterialManager.Singleton.Create("PenguinMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            penguinMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false;
            penguinMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("penguin.jpg");
            penguin.SetMaterialName(penguinMaterial.Name);

            var screenTexture0 = TextureManager.Singleton.CreateManual(
                "screenTexture0",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                TextureType.TEX_TYPE_2D,
                640,
                480,
                0,
                PixelFormat.PF_R8G8B8,
                (int)TextureUsage.TU_RENDERTARGET
                );

            CompositorManager2 compositorManager = _root.CompositorManager2;
            string             workspaceName     = GetType().Name + "RttWorkspace";

            if (!compositorManager.HasWorkspaceDefinition(workspaceName))
            {
                compositorManager.CreateBasicWorkspaceDef(workspaceName, new ColourValue(1.0f, 0.0f, 0.0f, 1.0f));
            }

            _rttWorkspace = _root.CompositorManager2.AddWorkspace(
                _rttSceneManager,
                screenTexture0.GetBuffer().GetRenderTarget(),
                _rttCamera,
                workspaceName,
                true);

            MaterialPtr renderMat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            var         pass      = renderMat.GetTechnique(0).GetPass(0);

            pass.LightingEnabled = false;
            var textureUnit = pass.CreateTextureUnitState();

            textureUnit.SetContentType(TextureUnitState.ContentType.CONTENT_COMPOSITOR);
            textureUnit.SetTextureName("screenTexture0", TextureType.TEX_TYPE_2D);
            textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP);

            Plane plane = new Plane(Vector3.UNIT_Y, 0);

            MeshManager.Singleton.CreatePlane(
                "planeMesh",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                plane,
                700.0f, 1300.0f,
                10, 10, true, 1,
                4.0f, 4.0f,
                Vector3.UNIT_Z);

            Entity planeEntity = _sceneManager.CreateEntity("planeMesh");

            planeEntity.SetMaterialName("RttMat");
            planeEntity.CastShadows = false;
            _sceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity);
        }
Exemplo n.º 10
0
        void SetupTrailLights()
        {
            sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);
            Vector3 dir = new Vector3(-1, -1, 0.5f);

            dir.Normalise();
            Light l = sceneMgr.CreateLight("light1");

            l.Type      = Light.LightTypes.LT_DIRECTIONAL;
            l.Direction = dir;

            NameValuePairList pairList = new NameValuePairList();

            pairList["numberOfChains"] = "2";
            pairList["maxElements"]    = "80";
            RibbonTrail trail = (RibbonTrail)(
                sceneMgr.CreateMovableObject("1", "RibbonTrail", pairList));

            trail.MaterialName = "Examples/LightRibbonTrail";
            trail.TrailLength  = 400;

            sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(trail);

            // Create 3 nodes for trail to follow
            SceneNode animNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

            animNode.Position = new Vector3(50, 30, 0);
            Animation anim = sceneMgr.CreateAnimation("an1", 14);

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
            NodeAnimationTrack track = anim.CreateNodeTrack(1, animNode);
            TransformKeyFrame  kf    = track.CreateNodeKeyFrame(0);

            kf.Translate = new Vector3(50, 30, 0);
            kf           = track.CreateNodeKeyFrame(2);
            kf.Translate = new Vector3(100, -30, 0);
            kf           = track.CreateNodeKeyFrame(4);
            kf.Translate = new Vector3(120, -100, 150);
            kf           = track.CreateNodeKeyFrame(6);
            kf.Translate = new Vector3(30, -100, 50);
            kf           = track.CreateNodeKeyFrame(8);
            kf.Translate = new Vector3(-50, 30, -50);
            kf           = track.CreateNodeKeyFrame(10);
            kf.Translate = new Vector3(-150, -20, -100);
            kf           = track.CreateNodeKeyFrame(12);
            kf.Translate = new Vector3(-50, -30, 0);
            kf           = track.CreateNodeKeyFrame(14);
            kf.Translate = new Vector3(50, 30, 0);

            AnimationState animState = sceneMgr.CreateAnimationState("an1");

            animState.Enabled = true;
            mAnimStateList.Add(animState);

            trail.SetInitialColour(0, 1.0f, 0.8f, 0);
            trail.SetColourChange(0, 0.5f, 0.5f, 0.5f, 0.5f);
            trail.SetInitialWidth(0, 5);
            trail.AddNode(animNode);

            // Add light
            Light l2 = sceneMgr.CreateLight("l2");

            l2.DiffuseColour = (trail.GetInitialColour(0));
            animNode.AttachObject(l2);

            // Add billboard
            BillboardSet bbs = sceneMgr.CreateBillboardSet("bb", 1);

            bbs.CreateBillboard(Vector3.ZERO, trail.GetInitialColour(0));
            bbs.MaterialName = "Examples/Flare";
            animNode.AttachObject(bbs);

            animNode          = sceneMgr.RootSceneNode.CreateChildSceneNode();
            animNode.Position = new Vector3(-50, 100, 0);
            anim = sceneMgr.CreateAnimation("an2", 10);
            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
            track        = anim.CreateNodeTrack(1, animNode);
            kf           = track.CreateNodeKeyFrame(0);
            kf.Translate = new Vector3(-50, 100, 0);
            kf           = track.CreateNodeKeyFrame(2);
            kf.Translate = new Vector3(-100, 150, -30);
            kf           = track.CreateNodeKeyFrame(4);
            kf.Translate = new Vector3(-200, 0, 40);
            kf           = track.CreateNodeKeyFrame(6);
            kf.Translate = new Vector3(0, -150, 70);
            kf           = track.CreateNodeKeyFrame(8);
            kf.Translate = new Vector3(50, 0, 30);
            kf           = track.CreateNodeKeyFrame(10);
            kf.Translate = new Vector3(-50, 100, 0);

            animState         = sceneMgr.CreateAnimationState("an2");
            animState.Enabled = true;
            mAnimStateList.Add(animState);

            trail.SetInitialColour(1, 0.0f, 1.0f, 0.4f);
            trail.SetColourChange(1, 0.5f, 0.5f, 0.5f, 0.5f);
            trail.SetInitialWidth(1, 5);
            trail.AddNode(animNode);

            // Add light
            l2 = sceneMgr.CreateLight("l3");
            l2.DiffuseColour = trail.GetInitialColour(1);
            animNode.AttachObject(l2);

            // Add billboard
            bbs = sceneMgr.CreateBillboardSet("bb2", 1);
            bbs.CreateBillboard(Vector3.ZERO, trail.GetInitialColour(1));
            bbs.MaterialName = "Examples/Flare";
            animNode.AttachObject(bbs);
        }
Exemplo n.º 11
0
        // Scene creation
        public override void CreateScene()
        {
            // Set ambient light
            sceneMgr.AmbientLight = new ColourValue(0.2F, 0.2F, 0.2F);

            // Create a skydome
            sceneMgr.SetSkyDome(true, "Examples/CloudySky", 5, 8);

            // Create a light
            Light l = sceneMgr.CreateLight("MainLight");

            // Accept default settings: point light, white diffuse, just set position
            // NB I could attach the light to a SceneNode if I wanted it to move automatically with
            //  other objects, but I don't
            l.Position = new Vector3(20F, 80F, 50F);

            // Define a floor plane mesh
            Plane p;

            p.normal = Vector3.UNIT_Y;
            p.d      = 200;
            MeshManager.Singleton.CreatePlane("FloorPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, p, 200000F, 20000F, 20, 20, true, 1, 50F, 50F, Vector3.UNIT_Z);

            Entity ent;

            // Create an entity (the floor)
            ent = sceneMgr.CreateEntity("floor", "FloorPlane");
            ent.SetMaterialName("Examples/RustySteel");

            // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
            sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

            // Add a head, give it it's own node
            SceneNode headNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

            ent = sceneMgr.CreateEntity("head", "ogrehead.mesh");

            headNode.AttachObject(ent);

            // Make sure the camera track this node
            camera.SetAutoTracking(true, headNode);

            // Create the camera node & attach camera
            SceneNode camNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

            camNode.AttachObject(camera);

            // set up spline animation of node
            Animation anim = sceneMgr.CreateAnimation("CameraTrack", 10F);

            // Spline it for nice curves

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);
            // Create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode);

            // Setup keyframes
            TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition

            key           = track.CreateNodeKeyFrame(2.5F);
            key.Translate = new Vector3(500F, 500F, -1000F);
            key           = track.CreateNodeKeyFrame(5F);
            key.Translate = new Vector3(-1500F, 1000F, -600F);
            key           = track.CreateNodeKeyFrame(7.5F);
            key.Translate = new Vector3(0F, 100F, 0F);
            key           = track.CreateNodeKeyFrame(10F);
            key.Translate = new Vector3(0F, 0F, 0F);

            // Create a new animation state to track this
            animState         = sceneMgr.CreateAnimationState("CameraTrack");
            animState.Enabled = true;

            // Put in a bit of fog for the hell of it
            sceneMgr.SetFog(FogMode.FOG_EXP, ColourValue.White, 0.0002F);
        }
Exemplo n.º 12
0
        protected void CreateRibbons()
        {
            viewport.BackgroundColor = ColorEx.Black;
            float scale = 100f;

            scene.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f);
            //scene.SetSkyBox(true, "Examples/SpaceSkyBox", 20f * oneMeter);
            Vector3 dir = new Vector3(-1f, -1f, 0.5f);

            dir.Normalize();
            Light light1 = scene.CreateLight("light1");

            light1.Type      = LightType.Directional;
            light1.Direction = dir;

            // Create a barrel for the ribbons to fly through
            Entity    barrel     = scene.CreateEntity("barrel", "barrel.mesh");
            SceneNode barrelNode = scene.RootSceneNode.CreateChildSceneNode();

            barrelNode.ScaleFactor = 5f * Vector3.UnitScale;
            barrelNode.AttachObject(barrel);

            RibbonTrail trail = new RibbonTrail("DemoTrail", "numberOfChains", 2, "maxElementsPerChain", 80);

            trail.MaterialName = "Examples/LightRibbonTrail";
            trail.TrailLength  = scale * 400f;
            scene.RootSceneNode.CreateChildSceneNode().AttachObject(trail);

            // Create 3 nodes for trail to follow
            SceneNode animNode = scene.RootSceneNode.CreateChildSceneNode();

            animNode.Position = scale * new Vector3(50f, 30f, 0);
            Animation anim = scene.CreateAnimation("an1", 14);

            anim.InterpolationMode = InterpolationMode.Spline;
            NodeAnimationTrack track = anim.CreateNodeTrack(1, animNode);
            TransformKeyFrame  kf    = track.CreateNodeKeyFrame(0);

            kf.Translate = scale * new Vector3(50f, 30f, 0f);
            kf           = track.CreateNodeKeyFrame(2);
            kf.Translate = scale * new Vector3(100f, -30f, 0f);
            kf           = track.CreateNodeKeyFrame(4);
            kf.Translate = scale * new Vector3(120f, -100f, 150f);
            kf           = track.CreateNodeKeyFrame(6);
            kf.Translate = scale * new Vector3(30f, -100f, 50f);
            kf           = track.CreateNodeKeyFrame(8);
            kf.Translate = scale * new Vector3(-50f, 30f, -50f);
            kf           = track.CreateNodeKeyFrame(10);
            kf.Translate = scale * new Vector3(-150f, -20f, -100f);
            kf           = track.CreateNodeKeyFrame(12);
            kf.Translate = scale * new Vector3(-50f, -30f, 0f);
            kf           = track.CreateNodeKeyFrame(14);
            kf.Translate = scale * new Vector3(50f, 30f, 0f);

            AnimationState animState = scene.CreateAnimationState("an1");

            //animState.Enabled = true;
            animStateList = new List <AnimationState>();
            animStateList.Add(animState);

            trail.SetInitialColor(0, 1.0f, 0.8f, 0f, 1.0f);
            trail.SetColorChange(0, 0.5f, 0.5f, 0.5f, 0.5f);
            trail.SetInitialWidth(0, scale * 5f);
            trail.AddNode(animNode);

            // Add light
            Light light2 = scene.CreateLight("light2");

            light2.Diffuse = trail.GetInitialColor(0);
            animNode.AttachObject(light2);

            // Add billboard
            BillboardSet bbs = scene.CreateBillboardSet("bb", 1);

            bbs.CreateBillboard(Vector3.Zero, trail.GetInitialColor(0));
            bbs.MaterialName = "flare";
            animNode.AttachObject(bbs);

            animNode          = scene.RootSceneNode.CreateChildSceneNode();
            animNode.Position = scale * new Vector3(-50f, 100f, 0f);
            anim = scene.CreateAnimation("an2", 10);
            anim.InterpolationMode = InterpolationMode.Spline;
            track        = anim.CreateNodeTrack(1, animNode);
            kf           = track.CreateNodeKeyFrame(0);
            kf.Translate = scale * new Vector3(-50f, 100f, 0f);
            kf           = track.CreateNodeKeyFrame(2);
            kf.Translate = scale * new Vector3(-100f, 150f, -30f);
            kf           = track.CreateNodeKeyFrame(4);
            kf.Translate = scale * new Vector3(-200f, 0f, 40f);
            kf           = track.CreateNodeKeyFrame(6);
            kf.Translate = scale * new Vector3(0f, -150f, 70f);
            kf           = track.CreateNodeKeyFrame(8);
            kf.Translate = scale * new Vector3(50f, 0f, 30f);
            kf           = track.CreateNodeKeyFrame(10);
            kf.Translate = scale * new Vector3(-50f, 100f, 0f);

            animState = scene.CreateAnimationState("an2");
            //animState.setEnabled(true);
            animStateList.Add(animState);

            trail.SetInitialColor(1, 0.0f, 1.0f, 0.4f, 1.0f);
            trail.SetColorChange(1, 0.5f, 0.5f, 0.5f, 0.5f);
            trail.SetInitialWidth(1, scale * 5f);
            trail.AddNode(animNode);


            // Add light
            Light light3 = scene.CreateLight("l3");

            light3.Diffuse = trail.GetInitialColor(1);
            animNode.AttachObject(light3);

            // Add billboard
            bbs = scene.CreateBillboardSet("bb2", 1);
            bbs.CreateBillboard(Vector3.Zero, trail.GetInitialColor(1));
            bbs.MaterialName = "flare";
            animNode.AttachObject(bbs);
        }
Exemplo n.º 13
0
        protected override void CreateScene()
        {
            // setup some basic lighting for our scene
            _sceneManager.AmbientLight = new ColourValue(0.3f, 0.3f, 0.3f);
            var lightNode = _sceneManager.RootSceneNode.CreateChildSceneNode();

            lightNode.SetPosition(20, 80, 50);
            lightNode.AttachObject(_sceneManager.CreateLight());

            _sceneManager.SetSkyBox(true, "Examples/SpaceSkyBox");

            // create an ogre head entity and attach it to a node
            Entity head = _sceneManager.CreateEntity("ogrehead.mesh");

            head.Name = "Head";
            SceneNode headNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            headNode.Translate(0, 40, 0);
            headNode.AttachObject(head);

            // create a camera node and attach camera to it
            SceneNode camNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode();

            _camera.DetachFromParent();
            camNode.AttachObject(_camera);

            // set up a 10 second animation for our camera, using spline interpolation for nice curves
            Animation anim = _sceneManager.CreateAnimation("CameraTrack", 10);

            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);

            // create a track to animate the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(camNode);

            // create keyframes for our track
            track.CreateNodeKeyFrame(0).Translate    = new Vector3(200, 0, 0);
            track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100);
            track.CreateNodeKeyFrame(5).Translate    = new Vector3(-500, 100, 0);
            track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300);
            track.CreateNodeKeyFrame(10).Translate   = new Vector3(200, 0, 0);

            // create a new animation state to track this
            _animState         = _sceneManager.CreateAnimationState("CameraTrack");
            _animState.Enabled = true;

            // Now create another scene manager with only
            _rttSceneManager = CreateSceneManager();

            // Create the RenderTargetTexture
            _rttCamera          = _rttSceneManager.CreateCamera("RttCamera");
            _rttCamera.Position = new Vector3(0f, 10f, 500f);
            _rttCamera.LookAt(new Vector3(0f, 0f, -300f));
            _rttCamera.AutoAspectRatio  = true;
            _rttCamera.NearClipDistance = 5.0f;

            // Penguin
            Entity penguin = _rttSceneManager.CreateEntity("penguin.mesh");

            _penguinNode = _rttSceneManager.RootSceneNode.CreateChildSceneNode();
            _penguinNode.AttachObject(penguin);
            penguin.Name = "Penguin";

            MaterialPtr penguinMaterial = MaterialManager.Singleton.Create("PenguinMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            penguinMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false;
            penguinMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("penguin.jpg");
            penguin.SetMaterialName(penguinMaterial.Name);

            var screenTexture0 = TextureManager.Singleton.CreateManual(
                "screenTexture0",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                TextureType.TEX_TYPE_2D,
                640,
                480,
                0,
                PixelFormat.PF_R8G8B8,
                (int)TextureUsage.TU_RENDERTARGET
                );

            CompositorManager2 compositorManager = _root.CompositorManager2;
            string             workspaceName     = GetType().Name + "RttWorkspace";

            if (!compositorManager.HasWorkspaceDefinition(workspaceName))
            {
                compositorManager.CreateBasicWorkspaceDef(workspaceName, new ColourValue(1.0f, 0.0f, 0.0f, 1.0f));
            }

            _rttWorkspace = _root.CompositorManager2.AddWorkspace(
                _rttSceneManager,
                screenTexture0.GetBuffer().GetRenderTarget(),
                _rttCamera,
                workspaceName,
                true);

            MaterialPtr renderMat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
            var         pass      = renderMat.GetTechnique(0).GetPass(0);

            pass.LightingEnabled = false;
            var textureUnit = pass.CreateTextureUnitState();

            textureUnit.SetContentType(TextureUnitState.ContentType.CONTENT_COMPOSITOR);
            textureUnit.SetTextureName("screenTexture0", TextureType.TEX_TYPE_2D);
            textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP);

            Plane plane = new Plane(Vector3.UNIT_Y, 0);

            MeshManager.Singleton.CreatePlane(
                "planeMesh",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                plane,
                700.0f, 1300.0f,
                10, 10, true, 1,
                4.0f, 4.0f,
                Vector3.UNIT_Z);

            Entity planeEntity = _sceneManager.CreateEntity("planeMesh");

            planeEntity.SetMaterialName("RttMat");
            planeEntity.CastShadows = false;
            _sceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity);

            // Test Miyagi
            // Init MiyagiSystem
            _miyagiSystem = new MiyagiSystem("Mogre", (int)_window.Width, (int)_window.Height);
            //const string PluginPath = @"..\..\..\debug\Plugins";
            //this.miyagiSystem.PluginManager.LoadPlugin(Path.Combine(PluginPath, "Miyagi.Plugin.Input.Mois.dll"), this.inputKeyboard, this.inputMouse);

            Resources.Create(_miyagiSystem);
            //Utilities.CreateCursor(system.GUIManager);

            // create a default GUI
            var gui = new GUI();


            // A Button is a simple skinned control capable of changing its current texture automatically on certain mouse events
            // (MouseDown/MouseEnter/MouseLeave/MouseUp). Those subskins are optinal, if a subskin is not defined, Miyagi will fall
            // back to an appropriate alternative.
            // Since Button inherits from Label it provides the same TextStyle options.
            var button1 = new Miyagi.UI.Controls.Button
            {
                Text      = "HELLO WORLD",
                Location  = new Point(140, 140),
                Size      = new Size(200, 50),
                Skin      = Resources.Skins["ButtonSkin"],
                TextStyle =
                {
                    Alignment        = Alignment.MiddleCenter,
                    ForegroundColour = Colours.White
                }
            };

            // add the Buttons to the GUI
            gui.Controls.Add(button1);
            //gui.Controls.Add(button2);

            var pictureBox = new Miyagi.UI.Controls.PictureBox
            {
                Name     = "testingPictureBox",
                Location = new Point(380, 140),
                Size     = new Size(400, 100),
            };

            pictureBox.Bitmap = new System.Drawing.Bitmap(new System.Drawing.Bitmap(400, 100));

            // add the Buttons to the GUI
            gui.Controls.Add(pictureBox);

            // add the GUI to the GUIManager
            _miyagiSystem.GUIManager.GUIs.Add(gui);
            gui.SpriteRenderer.CacheToTexture = true;

            System.Windows.Forms.Timer dummyTimer = new System.Windows.Forms.Timer();
            dummyTimer.Interval = 2000;
            dummyTimer.Tick    += dummyTimer_Tick;
            dummyTimer.Start();
        }
Exemplo n.º 14
0
        private void SetupLighting()
        {
            scene.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f);
            Light = scene.CreateLight("Light2");
            Light.DiffuseColour = MinLightColour;
            Light.SetAttenuation(8000, 1, 0.0005f, 0);
            Light.SpecularColour = new ColorEx(1, 1, 1);

            LightNode = scene.RootSceneNode.CreateChildSceneNode("MovingLightNode");
            LightNode.AttachObject(Light);
            //create billboard set

            BillboardSet bbs = scene.CreateBillboardSet("lightbbs", 1);

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

            LightNode.AttachObject(bbs);

            mLightController = new LightGrassWibbler(Light, bb, MinLightColour, this.MaxLightColour, MinFlareSize, MaxFlareSize);

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

            //ControllerManager.Instance.CreateController(val, func);

            LightNode.Position = new Vector3(300, 250, -300);

            Animation anim = scene.CreateAnimation("LightTrack", 20);

            //Spline it for nce curves
            anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);// = Mogre.Animation.InterpolationMode.IM_SPLINE;
            //create a srtack to animte the camera's node
            NodeAnimationTrack track = anim.CreateNodeTrack(0, LightNode);
            //setup keyframes
            TransformKeyFrame key = track.CreateNodeKeyFrame(0);

            key.Translate = new Vector3(300, 550, -300);
            key           = track.CreateNodeKeyFrame(2);  //B
            key.Translate = new Vector3(150, 600, -250);
            key           = track.CreateNodeKeyFrame(4);  //C
            key.Translate = new Vector3(-150, 650, -100);
            key           = track.CreateNodeKeyFrame(6);  //D
            key.Translate = new Vector3(-400, 500, -200);
            key           = track.CreateNodeKeyFrame(8);  //E
            key.Translate = new Vector3(-200, 500, -400);
            key           = track.CreateNodeKeyFrame(10); //F
            key.Translate = new Vector3(-100, 450, -200);
            key           = track.CreateNodeKeyFrame(12); //G
            key.Translate = new Vector3(-100, 400, 180);
            key           = track.CreateNodeKeyFrame(14); //H
            key.Translate = new Vector3(0, 250, 600);
            key           = track.CreateNodeKeyFrame(16); //I
            key.Translate = new Vector3(100, 650, 100);
            key           = track.CreateNodeKeyFrame(18); //J
            key.Translate = new Vector3(250, 600, 0);
            key           = track.CreateNodeKeyFrame(20); //K == A
            key.Translate = new Vector3(300, 550, -300);
            // Create a new animation state to track this

            AnimState         = scene.CreateAnimationState("LightTrack");
            AnimState.Enabled = true;
        }