protected override void CreateScene()
        {
            viewport.BackgroundColor = ColorEx.White;

            scene.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f);

            Light light = scene.CreateLight("MainLight");
            light.Position = new Vector3(20, 80, 50);
            light.Diffuse = ColorEx.Blue;

            scene.LoadWorldGeometry("Terrain.xml");

            scene.SetFog(FogMode.Exp2, ColorEx.White, .008f, 0, 250);

            // water plane setup
            Plane waterPlane = new Plane(Vector3.UnitY, 1.5f);

            MeshManager.Instance.CreatePlane(
                "WaterPlane",
                waterPlane,
                2800, 2800,
                20, 20,
                true, 1,
                10, 10,
                Vector3.UnitZ);

            Entity waterEntity  = scene.CreateEntity("Water", "WaterPlane");
            waterEntity.MaterialName = "Terrain/WaterPlane";

            waterNode = scene.RootSceneNode.CreateChildSceneNode("WaterNode");
            waterNode.AttachObject(waterEntity);
            waterNode.Translate(new Vector3(1000, 0, 1000));
        }
        protected override void CreateScene()
        {
            // set ambient light
            scene.AmbientLight = new ColorEx(1.0f, 0.5f, 0.5f, 0.5f);

            // create a skydome
            scene.SetSkyDome(true, "Examples/CloudySky", 5, 8);

            // create a light
            Light light = scene.CreateLight("MainLight");
            light.Position = new Vector3(20, 80, 50);

            // add a floor plane
            Plane p = new Plane();
            p.Normal = Vector3.UnitY;
            p.D = 200;
            MeshManager.Instance.CreatePlane("FloorPlane", p, 2000, 2000, 1, 1, true, 1, 5, 5, Vector3.UnitZ);

            // add the floor entity
            Entity floor = scene.CreateEntity("Floor", "FloorPlane");
            floor.MaterialName = "Examples/RustySteel";
            scene.RootSceneNode.CreateChildSceneNode().AttachObject(floor);

            ogre = scene.CreateEntity("Ogre", "ogrehead.mesh");
            scene.RootSceneNode.CreateChildSceneNode().AttachObject(ogre);
        }
        protected override void CreateScene()
        {
            // set some ambient light
            scene.AmbientLight = new ColorEx(1.0f, 0.5f, 0.5f, 0.5f);

            Plane plane = new Plane();
            // 5000 units from the camera
            plane.D = 5000;
            // above the camera, facing down
            plane.Normal = -Vector3.UnitY;

            // create the skyplace 10000 units wide, tile the texture 3 times
            scene.SetSkyPlane(true, plane, "Skyplane/Space", 10000, 3, true, 0);

            // create a default point light
            Light light = scene.CreateLight("MainLight");
            light.Position = new Vector3(20, 80, 50);

            // stuff a dragon into the scene
            Entity entity = scene.CreateEntity("dragon", "dragon.mesh");
            scene.RootSceneNode.AttachObject(entity);
        }
        public bool CalculateTexCoordsAndColors(Plane plane, Vector3[] vertices, out Vector2[] texCoors, out ColorEx[] colors)
        {
            switch (this.Type)
            {
                case LightType.Directional:
                    return CalculateForDirectionalLight(plane, vertices, out texCoors, out colors);

                case LightType.Point:
                    return CalculateForPointLight(plane, vertices, out texCoors, out colors);

                case LightType.Spotlight:
                    return CalculateForSpotLight(plane, vertices, out texCoors, out colors);
            }

            texCoors = null;
            colors = null;
            return false;
        }
        protected bool CalculateForDirectionalLight(Plane plane, Vector3[] vertices, out Vector2[] texCoors, out ColorEx[] colors)
        {
            texCoors = new Vector2[vertices.Length];
            colors = new ColorEx[vertices.Length];

            float angle = MathUtil.Abs(plane.Normal.Dot(this.DerivedDirection));

            ColorEx lightCol = new ColorEx(textureColor.a * angle,
                textureColor.r, textureColor.g, textureColor.b);

            for (int i = 0; i < vertices.Length; i++)
            {
                colors[i] = lightCol;
            }

            return true;
        }
        private void CreateBrushes(Quake3Level q3lvl)
        {
            // Reserve enough memory for all brushes, solid or not (need to maintain indexes)
            brushes = new BspBrush[q3lvl.NumBrushes];

            for(int i = 0; i < q3lvl.NumBrushes; i++)
            {
                InternalBspBrush q3brush = q3lvl.Brushes[i];

                // Create a new OGRE brush
                BspBrush brush = new BspBrush();
                int numBrushSides = q3brush.numSides;
                int brushSideIdx = q3brush.firstSide;

                // Iterate over the sides and create plane for each
                while(numBrushSides-- > 0)
                {
                    InternalBspPlane side = q3lvl.Planes[q3lvl.BrushSides[brushSideIdx].planeNum];

                    // Notice how we normally invert Q3A plane distances, but here we do not
                    // Because we want plane normals pointing out of solid brushes, not in.
                    Plane brushSide = new Plane(
                        new Vector3(
                            q3lvl.Planes[q3lvl.BrushSides[brushSideIdx].planeNum].normal[0],
                            q3lvl.Planes[q3lvl.BrushSides[brushSideIdx].planeNum].normal[1],
                            q3lvl.Planes[q3lvl.BrushSides[brushSideIdx].planeNum].normal[2]
                            ), q3lvl.Planes[q3lvl.BrushSides[brushSideIdx].planeNum].distance);

                    brush.Planes.Add(brushSide);
                    brushSideIdx++;
                }

                // Build world fragment
                brush.Fragment.FragmentType = WorldFragmentType.PlaneBoundedRegion;
                brush.Fragment.Planes = brush.Planes;

                brushes[i] = brush;
            }
        }
        protected override void CreateScene()
        {
            // set ambient light
            scene.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f);

            scene.SetSkyBox(true, "Skybox/Morning", 5000);

            // create a default point light
            Light light = scene.CreateLight("MainLight");
            light.Type = LightType.Directional;
            Vector3 dir = new Vector3(0.5f, -1, 0);
            dir.Normalize();
            light.Direction = dir;
            light.Diffuse = new ColorEx(1.0f, 1.0f, 0.8f);
            light.Specular = ColorEx.White;

            // create a plane
            plane = new MovablePlane("ReflectPlane");
            plane.D = 0;
            plane.Normal = Vector3.UnitY;

            // create another plane to create the mesh.  Ogre's MovablePlane uses multiple inheritance, bah!
            Plane tmpPlane = new Plane();
            tmpPlane.D = 0;
            tmpPlane.Normal = Vector3.UnitY;

            MeshManager.Instance.CreatePlane("ReflectionPlane", tmpPlane, 2000, 2000, 1, 1, true, 1, 1, 1, Vector3.UnitZ);
            planeEntity = scene.CreateEntity("Plane", "ReflectionPlane");

            // create an entity from a model
            Entity knot = scene.CreateEntity("Knot", "knot.mesh");
            knot.MaterialName = "TextureFX/Knot";

            // create an entity from a model
            Entity head = scene.CreateEntity("Head", "ogrehead.mesh");

            // attach the render to texture entity to the root of the scene
            SceneNode rootNode = scene.RootSceneNode;
            planeNode = rootNode.CreateChildSceneNode();

            planeNode.AttachObject(planeEntity);
            planeNode.AttachObject(plane);
            planeNode.Translate(new Vector3(0, -10, 0));

            // tilt it a little to make it interesting
            planeNode.Roll(5);

            rootNode.CreateChildSceneNode("Head").AttachObject(head);

            // create a render texture
            RenderTexture rttTex = Root.Instance.RenderSystem.CreateRenderTexture("RttTex", 512, 512);
            reflectCam = scene.CreateCamera("ReflectCam");
            reflectCam.Near = camera.Near;
            reflectCam.Far = camera.Far;
            reflectCam.AspectRatio = (float)window.GetViewport(0).ActualWidth / (float)window.GetViewport(0).ActualHeight;

            Viewport viewport = rttTex.AddViewport(reflectCam);
            viewport.ClearEveryFrame = true;
            viewport.OverlaysEnabled = false;
            viewport.BackgroundColor = ColorEx.Black;

            Material mat = scene.CreateMaterial("RttMat");
            TextureUnitState t = mat.GetTechnique(0).GetPass(0).CreateTextureUnitState("RustedMetal.jpg");
            t = mat.GetTechnique(0).GetPass(0).CreateTextureUnitState("RttTex");

            // blend with base texture
            t.SetColorOperationEx(LayerBlendOperationEx.BlendManual, LayerBlendSource.Texture, LayerBlendSource.Current,
                ColorEx.White, ColorEx.White, 0.25f);

            t.SetProjectiveTexturing(true, reflectCam);

            // register events for viewport before/after update
            rttTex.AfterUpdate += new RenderTargetUpdateEventHandler(rttTex_AfterUpdate);
            rttTex.BeforeUpdate += new RenderTargetUpdateEventHandler(rttTex_BeforeUpdate);

            // set up linked reflection
            reflectCam.EnableReflection(plane);

            // also clip
            reflectCam.EnableCustomNearClipPlane(plane);

            planeEntity.MaterialName = "RttMat";

            Entity clone = null;

            for(int i = 0; i < 10; i++) {
                // create a new node under the root
                SceneNode node = scene.CreateSceneNode();

                // calculate a random position
                Vector3 nodePosition = new Vector3();
                nodePosition.x = MathUtil.SymmetricRandom() * 750.0f;
                nodePosition.y = MathUtil.SymmetricRandom() * 100.0f + 25;
                nodePosition.z = MathUtil.SymmetricRandom() * 750.0f;

                // set the new position
                node.Position = nodePosition;

                // attach this node to the root node
                rootNode.AddChild(node);

                // clone the knot
                string cloneName = string.Format("Knot{0}", i);
                clone = knot.Clone(cloneName);

                // add the cloned knot to the scene
                node.AttachObject(clone);
            }

            camera.Position = new Vector3(-50, 100, 500);
            camera.LookAt(new Vector3(0, 0, 0));
        }
        /// <summary>
        ///		Transforms a plane using the specified transform.
        /// </summary>
        /// <param name="result"></param>
        /// <param name="matrix">Transformation matrix.</param>
        /// <param name="plane">Plane to transform.</param>
        /// <returns></returns>
        public static void MultiplyRef(ref Plane result, ref Matrix4 left, ref Plane plane)
        {
            Vector3 planeNormal = plane.Normal;

            result.Normal = new Vector3(
                left.m00 * planeNormal.x + left.m01 * planeNormal.y + left.m02 * planeNormal.z,
                left.m10 * planeNormal.x + left.m11 * planeNormal.y + left.m12 * planeNormal.z,
                left.m20 * planeNormal.x + left.m21 * planeNormal.y + left.m22 * planeNormal.z);

            Vector3 pt = planeNormal * -plane.D;
            pt = left * pt;

            result.D = -pt.Dot(result.Normal);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">Name of the plane mesh.</param>
        /// <param name="plane">Plane to use for distance and orientation of the mesh.</param>
        /// <param name="width">Width in world coordinates.</param>
        /// <param name="height">Height in world coordinates.</param>
        /// <param name="xSegments">Number of x segments for tesselation.</param>
        /// <param name="ySegments">Number of y segments for tesselation.</param>
        /// <param name="normals">If true, plane normals are created.</param>
        /// <param name="numTexCoordSets">Number of 2d texture coord sets to use.</param>
        /// <param name="uTile">Number of times the texture should be repeated in the u direction.</param>
        /// <param name="vTile">Number of times the texture should be repeated in the v direction.</param>
        /// <param name="upVec">The up direction of the plane.</param>
        /// <returns></returns>
        public Mesh CreatePlane(string name, Plane plane, float width, float height, int xSegments, int ySegments, bool normals, int numTexCoordSets, float uTile, float vTile, Vector3 upVec,
            BufferUsage vertexBufferUsage, BufferUsage indexBufferUsage, bool vertexShadowBuffer, bool indexShadowBuffer )
        {
            Mesh mesh = CreateManual(name);
            SubMesh subMesh = mesh.CreateSubMesh(name + "SubMesh");

            mesh.SharedVertexData = new VertexData();
            VertexData vertexData = mesh.SharedVertexData;

            VertexDeclaration decl = vertexData.vertexDeclaration;
            int currOffset = 0;

            // add position data
            decl.AddElement(0, currOffset, VertexElementType.Float3, VertexElementSemantic.Position);
            currOffset += VertexElement.GetTypeSize(VertexElementType.Float3);

            // normals are optional
            if(normals) {
                decl.AddElement(0, currOffset, VertexElementType.Float3, VertexElementSemantic.Normal);
                currOffset += VertexElement.GetTypeSize(VertexElementType.Float3);
            }

            // add texture coords
            for(ushort i = 0; i < numTexCoordSets; i++) {
                decl.AddElement(0, currOffset, VertexElementType.Float2, VertexElementSemantic.TexCoords, i);
                currOffset += VertexElement.GetTypeSize(VertexElementType.Float2);
            }

            vertexData.vertexCount = (xSegments + 1) * (ySegments + 1);

            // create a new vertex buffer (based on current API)
            HardwareVertexBuffer vbuf =
                HardwareBufferManager.Instance.CreateVertexBuffer(decl.GetVertexSize(0), vertexData.vertexCount, vertexBufferUsage, vertexShadowBuffer);

            // get a reference to the vertex buffer binding
            VertexBufferBinding binding = vertexData.vertexBufferBinding;

            // bind the first vertex buffer
            binding.SetBinding(0, vbuf);

            // transform the plane based on its plane def
            Matrix4 translate = Matrix4.Identity;
            Matrix4 transform = Matrix4.Zero;
            Matrix4 rotation = Matrix4.Identity;
            Matrix3 rot3x3 = Matrix3.Zero;

            Vector3 xAxis, yAxis, zAxis;
            zAxis = plane.Normal;
            zAxis.Normalize();
            yAxis = upVec;
            yAxis.Normalize();
            xAxis = yAxis.Cross(zAxis);

            if (xAxis.Length == 0) {
                throw new AxiomException("The up vector for a plane cannot be parallel to the planes normal.");
            }

            rot3x3.FromAxes(xAxis, yAxis, zAxis);
            rotation = rot3x3;

            // set up transform from origin
            translate.Translation = plane.Normal * -plane.D;

            transform = translate * rotation;

            float xSpace = width / xSegments;
            float ySpace = height / ySegments;
            float halfWidth = width / 2;
            float halfHeight = height / 2;
            float xTexCoord = (1.0f * uTile) / xSegments;
            float yTexCoord = (1.0f * vTile) / ySegments;
            Vector3 vec = Vector3.Zero;
            Vector3 min = Vector3.Zero;
            Vector3 max = Vector3.Zero;
            float maxSquaredLength = 0;
            bool firstTime = true;

            // generate vertex data
            GeneratePlaneVertexData(vbuf, ySegments, xSegments, xSpace, halfWidth, ySpace, halfHeight, transform, firstTime, normals, rotation, numTexCoordSets, xTexCoord, yTexCoord, subMesh, ref min, ref max, ref maxSquaredLength);

            // generate face list
            Tesselate2DMesh(subMesh, xSegments + 1, ySegments + 1, false, indexBufferUsage, indexShadowBuffer);

            // generate bounds for the mesh
            mesh.BoundingBox = new AxisAlignedBox(min, max);
            mesh.BoundingSphereRadius = MathUtil.Sqrt(maxSquaredLength);

            mesh.Load();
            mesh.Touch();

            return mesh;
        }
 /// <summary>
 ///		Overload.
 /// </summary>
 /// <param name="enable"></param>
 /// <param name="plane"></param>
 public virtual void SetSkyPlane(bool enable, Plane plane, string materialName)
 {
     // call the overloaded method
     SetSkyPlane(enable, plane, materialName, 1000.0f, 10.0f, true, 0);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="plane"></param>
 /// <returns>True if the plane intersects, false otherwise.</returns>
 public bool Intersects(Plane plane)
 {
     return MathUtil.Intersects(plane, this);
 }
Esempio n. 12
0
        protected override void CreateScene()
        {
            // initialise the SoundManager by setting the RenderWindow
            SoundManager.Instance.SetRenderWindow(this.window, this.camera);
               	int back_id = SoundManager.Instance.PreLoadSound("background.wav", Sound.SIMPLE_SOUND);

               	// set some ambient light
            scene.AmbientLight = new ColorEx(1.0f, 0.2f, 0.2f, 0.2f);

            // create a skydome
            scene.SetSkyDome(true, "Examples/CloudySky", 5, 8);

            // create a simple default point light
            Light light = scene.CreateLight("MainLight");
            light.Position = new Vector3(20, 80, 50);

            // create a plane for the plane mesh
            Plane plane = new Plane();
            plane.Normal = Vector3.UnitY;
            plane.D = 200;

            // create a plane mesh
            MeshManager.Instance.CreatePlane("FloorPlane", plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ);

            // create an entity to reference this mesh
            Entity planeEntity = scene.CreateEntity("Floor", "FloorPlane");
            planeEntity.MaterialName = "Examples/RustySteel";
            scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity);

            // create an entity to have follow the path
            Entity ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh");

            // create a scene node for the entity and attach the entity
            headNode = scene.RootSceneNode.CreateChildSceneNode("OgreHeadNode", Vector3.Zero, Quaternion.Identity);
            headNode.AttachObject(ogreHead);

            // make sure the camera tracks this node
            //camera.SetAutoTracking(true, headNode, Vector3.Zero);

            // create a scene node to attach the camera to
            SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode("CameraNode");
            cameraNode.AttachObject(camera);

            /////////////////////////- AGE Sound Library Settings -//////////////////////////
            SoundManager.Instance.RolloffFactor = 0.01f; // we're working on a large scale
               	growl = SoundManager.Instance.LoadSound("growl.ogg", Sound.THREED_SOUND);

            Sound back = SoundManager.Instance.GetSound( back_id );

            // load a simple sound
            //Sound back = SoundManager.Instance.LoadSound("background.wav", Sound.SIMPLE_SOUND);
            // set the volume low
            back.Volume = -2000;
            // play the simple sound in a loop
            back.Play(true);

            // load a 3D sound
             // attach the sound to the head
               	headNode.AttachObject(growl);
            // set the sound's properties
            growl.ConeAngles = new int[]{120, 120};
            growl.ConeDirection = Vector3.UnitZ;
              		//growl.MaxDistance = 5000;
            growl.OutsideVolume = -10000;
            // play the 3D sound in a loop
            growl.Play(true);

            ////////////////////////////////////////////////////////////////////////////////

            // create new animation
            Animation animation = scene.CreateAnimation("OgreHeadAnimation", 10.0f);

            // nice smooth animation
            animation.InterpolationMode = InterpolationMode.Spline;

            // create the main animation track
            AnimationTrack track = animation.CreateTrack(0, cameraNode);

            // create a few keyframes to move the camera around
            KeyFrame frame = track.CreateKeyFrame(0.0f);

            frame = track.CreateKeyFrame(2.5f);
            frame.Translate = new Vector3(500, 500, -1000);

            frame = track.CreateKeyFrame(5.0f);
            frame.Translate = new Vector3(-1500, 1000, -600);

            frame = track.CreateKeyFrame(7.5f);
            frame.Translate = new Vector3(0, -100, 0);

            frame = track.CreateKeyFrame(10.0f);
            frame.Translate = Vector3.Zero;

            // create a new animation state to control the animation
            animationState = scene.CreateAnimationState("OgreHeadAnimation");

            // enable the animation
            animationState.IsEnabled = true;

            // turn on some fog
            scene.SetFog(FogMode.Exp, ColorEx.White, 0.0002f);
        }
        /// <summary>
        ///		Enables / disables a 'sky plane' i.e. a plane at constant
        ///		distance from the camera representing the sky.
        /// </summary>
        /// <param name="enable">True to enable the plane, false to disable it.</param>
        /// <param name="plane">Details of the plane, i.e. it's normal and it's distance from the camera.</param>
        /// <param name="materialName">The name of the material the plane will use.</param>
        /// <param name="scale">The scaling applied to the sky plane - higher values mean a bigger sky plane.</param>
        /// <param name="tiling">How many times to tile the texture across the sky.</param>
        /// <param name="drawFirst">
        ///		If true, the plane is drawn before all other geometry in the scene, without updating the depth buffer.
        ///		This is the safest rendering method since all other objects
        ///		will always appear in front of the sky. However this is not
        ///		the most efficient way if most of the sky is often occluded
        ///		by other objects. If this is the case, you can set this
        ///		parameter to false meaning it draws <em>after</em> all other
        ///		geometry which can be an optimisation - however you must
        ///		ensure that the plane.d value is large enough that no objects
        ///		will 'poke through' the sky plane when it is rendered.
        ///	 </param>
        /// <param name="bow">
        ///		If above zero, the plane will be curved, allowing
        ///		the sky to appear below camera level.  Curved sky planes are 
        ///		simular to skydomes, but are more compatable with fog.
        /// </param>
        public virtual void SetSkyPlane(bool enable, Plane plane, string materialName, float scale, float tiling, bool drawFirst, float bow)
        {
            isSkyPlaneEnabled = enable;

            if(enable) {
                string meshName = "SkyPlane";
                skyPlane = plane;

                Material m = MaterialManager.Instance.GetByName(materialName);

                if(m == null)
                    throw new AxiomException(string.Format("Skyplane material '{0}' not found.", materialName));

                // make sure the material doesn't update the depth buffer
                m.DepthWrite = false;
                m.Load();

                isSkyPlaneDrawnFirst = drawFirst;

                // set up the place
                Mesh planeMesh = MeshManager.Instance.GetByName(meshName);

                // unload the old one if it exists
                if(planeMesh != null)
                    MeshManager.Instance.Unload(planeMesh);

                // create up vector
                Vector3 up = plane.Normal.Cross(Vector3.UnitX);
                if(up == Vector3.Zero)
                    up = plane.Normal.Cross(-Vector3.UnitZ);

                if(bow > 0) {
                    planeMesh = MeshManager.Instance.CreateCurvedIllusionPlane(
                        meshName,
                        plane,
                        scale * 100,
                        scale * 100,
                        scale * bow * 100,
                        6, 6, false, 1, tiling, tiling, up);
                }
                else {
                    planeMesh = MeshManager.Instance.CreatePlane(meshName, plane, scale * 100, scale * 100, 1, 1, false, 1, tiling, tiling, up);
                }

                if(skyPlaneEntity != null) {
                    ExtractMovableObject(skyPlaneEntity);
                }

                // create entity for the plane, using the mesh name
                skyPlaneEntity = CreateEntity(meshName, meshName);
                skyPlaneEntity.MaterialName = materialName;
                // sky entities need not cast shadows
                skyPlaneEntity.CastShadows = false;

                if(skyPlaneNode == null)
                    skyPlaneNode = CreateSceneNode(meshName + "Node");
                else
                    skyPlaneNode.DetachAllObjects();

                // attach the skyplane to the new node
                skyPlaneNode.AttachObject(skyPlaneEntity);
            }
        }
Esempio n. 14
0
        /// <summary>
        ///		Used to multiply a transformation to a Plane.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="plane"></param>
        /// <returns></returns>
        public static Plane operator *(Matrix4 left, Plane plane)
        {
            Plane result = new Plane();

            Vector3 planeNormal = plane.Normal;

            result.Normal = new Vector3(
                left.m00 * planeNormal.x + left.m01 * planeNormal.y + left.m02 * planeNormal.z,
                left.m10 * planeNormal.x + left.m11 * planeNormal.y + left.m12 * planeNormal.z,
                left.m20 * planeNormal.x + left.m21 * planeNormal.y + left.m22 * planeNormal.z);

            Vector3 pt = planeNormal * -plane.D;
            pt = left * pt;

            result.D = -pt.Dot(result.Normal);

            return result;
        }
        protected override void CreateScene()
        {
            // set some ambient light
            scene.AmbientLight = new ColorEx(1.0f, 0.2f, 0.2f, 0.2f);

            // create a skydome
            scene.SetSkyDome(true, "Examples/CloudySky", 5, 8);

            // create a simple default point light
            Light light = scene.CreateLight("MainLight");
            light.Position = new Vector3(20, 80, 50);

            // create a plane for the plane mesh
            Plane plane = new Plane();
            plane.Normal = Vector3.UnitY;
            plane.D = 200;

            // create a plane mesh
            MeshManager.Instance.CreatePlane("FloorPlane", plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ);

            // create an entity to reference this mesh
            Entity planeEntity = scene.CreateEntity("Floor", "FloorPlane");
            planeEntity.MaterialName = "Examples/RustySteel";
            scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity);

            // create an entity to have follow the path
            Entity ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh");

            // create a scene node for the entity and attach the entity
            headNode = scene.RootSceneNode.CreateChildSceneNode("OgreHeadNode", Vector3.Zero, Quaternion.Identity);
            headNode.AttachObject(ogreHead);

            // make sure the camera tracks this node
            camera.SetAutoTracking(true, headNode, Vector3.Zero);

            // create a scene node to attach the camera to
            SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode("CameraNode");
            cameraNode.AttachObject(camera);

            // create new animation
            Animation animation = scene.CreateAnimation("OgreHeadAnimation", 10.0f);

            // nice smooth animation
            animation.InterpolationMode = InterpolationMode.Spline;

            // create the main animation track
            NodeAnimationTrack track = animation.CreateNodeTrack(0, cameraNode);

            // create a few keyframes to move the camera around
            AddKey(track, 0.0f, Vector3.Zero);
            AddKey(track, 2.5f, new Vector3(500, 500, -1000));
            AddKey(track, 5.0f, new Vector3(-1500, 1000, -600));
            AddKey(track, 7.5f, new Vector3(0, -100, 0));
            AddKey(track, 10.0f, Vector3.Zero);

            // create a new animation state to control the animation
            animationState = scene.CreateAnimationState("OgreHeadAnimation");

            // enable the animation
            animationState.IsEnabled = true;

            // turn on some fog
            scene.SetFog(FogMode.Exp, ColorEx.White, 0.0002f);
        }
Esempio n. 16
0
 /// <summary>
 ///		Tests whether this ray intersects the given plane. 
 /// </summary>
 /// <param name="plane"></param>
 /// <returns>
 ///		Struct containing info on whether there was a hit, and the distance from the 
 ///		origin of this ray where the intersect happened.
 ///	</returns>
 public IntersectResult Intersects(Plane plane)
 {
     return MathUtil.Intersects(this, plane);
 }
        protected bool CalculateForPointLight(Plane plane, Vector3[] vertices, out Vector2[] texCoors, out ColorEx[] colors)
        {
            texCoors = new Vector2[vertices.Length];
            colors = new ColorEx[vertices.Length];

            Vector3 lightPos, faceLightPos;

            lightPos = this.DerivedPosition;

            float dist = plane.GetDistance(lightPos);
            if (MathUtil.Abs(dist) < range)
            {
                // light is visible

                //light pos on face
                faceLightPos = lightPos - plane.Normal * dist;

                Vector3 verAxis = plane.Normal.Perpendicular();
                Vector3 horAxis = verAxis.Cross(plane.Normal);
                Plane verPlane = new Plane(verAxis, faceLightPos);
                Plane horPlane = new Plane(horAxis, faceLightPos);

                float lightRadiusSqr = range * range;
                float relRadiusSqr = lightRadiusSqr - dist * dist;
                float relRadius = MathUtil.Sqrt(relRadiusSqr);
                float scale = 0.5f / relRadius;

                float brightness = relRadiusSqr / lightRadiusSqr;
                ColorEx lightCol = new ColorEx(brightness * textureColor.a,
                    textureColor.r, textureColor.g, textureColor.b);

                for (int i = 0; i < vertices.Length; i++)
                {
                    texCoors[i].x = horPlane.GetDistance(vertices[i]) * scale + 0.5f;
                    texCoors[i].y = verPlane.GetDistance(vertices[i]) * scale + 0.5f;
                    colors[i] = lightCol;
                }

                return true;
            }

            return false;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="plane"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="curvature"></param>
 /// <param name="xSegments"></param>
 /// <param name="ySegments"></param>
 /// <param name="normals"></param>
 /// <param name="numberOfTexCoordSets"></param>
 /// <param name="uTiles"></param>
 /// <param name="vTiles"></param>
 /// <param name="upVector"></param>
 /// <returns></returns>
 public Mesh CreateCurvedIllusionPlane(string name, Plane plane, float width, float height, float curvature, int xSegments, int ySegments, bool normals, int numberOfTexCoordSets, float uTiles, float vTiles, Vector3 upVector)
 {
     return CreateCurvedIllusionPlane(name, plane, width, height, curvature, xSegments, ySegments, normals, numberOfTexCoordSets, uTiles, vTiles, upVector, Quaternion.Identity, BufferUsage.StaticWriteOnly, BufferUsage.StaticWriteOnly, true, true);
 }
        protected bool CalculateForSpotLight(Plane plane, Vector3[] vertices, out Vector2[] texCoors, out ColorEx[] colors)
        {
            texCoors = new Vector2[vertices.Length];
            colors = new ColorEx[vertices.Length];

            ColorEx lightCol = new ColorEx(textureColor.a,
                textureColor.r, textureColor.g, textureColor.b);

            for (int i = 0; i < vertices.Length; i++)
            {
                colors[i] = lightCol;
            }

            return true;
        }
 /// <summary>
 ///		Overloaded method.
 /// </summary>
 /// <param name="name">Name of the plane mesh.</param>
 /// <param name="plane">Plane to use for distance and orientation of the mesh.</param>
 /// <param name="width">Width in world coordinates.</param>
 /// <param name="height">Height in world coordinates.</param>
 /// <returns></returns>
 public Mesh CreatePlane(string name, Plane plane, int width, int height)
 {
     return CreatePlane(name, plane, width, height, 1, 1, true, 1, 1.0f, 1.0f, Vector3.UnitY, BufferUsage.StaticWriteOnly, BufferUsage.StaticWriteOnly, true, true);
 }
        /// <summary>
        ///		Utility method for creating the planes of a skybox.
        /// </summary>
        /// <param name="plane"></param>
        /// <param name="distance"></param>
        /// <param name="orientation"></param>
        /// <returns></returns>
        protected Mesh CreateSkyboxPlane(BoxPlane plane, float distance, Quaternion orientation)
        {
            Plane p = new Plane();
            string meshName = "SkyboxPlane_";
            Vector3 up = Vector3.Zero;

            // set the distance of the plane
            p.D = distance;

            switch(plane) {
                case BoxPlane.Front:
                    p.Normal = Vector3.UnitZ;
                    up = Vector3.UnitY;
                    meshName += "Front";
                    break;
                case BoxPlane.Back:
                    p.Normal = -Vector3.UnitZ;
                    up = Vector3.UnitY;
                    meshName += "Back";
                    break;
                case BoxPlane.Left:
                    p.Normal = Vector3.UnitX;
                    up = Vector3.UnitY;
                    meshName += "Left";
                    break;
                case BoxPlane.Right:
                    p.Normal = -Vector3.UnitX;
                    up = Vector3.UnitY;
                    meshName += "Right";
                    break;
                case BoxPlane.Up:
                    p.Normal = -Vector3.UnitY;
                    up = Vector3.UnitZ;
                    meshName += "Up";
                    break;
                case BoxPlane.Down:
                    p.Normal = Vector3.UnitY;
                    up = -Vector3.UnitZ;
                    meshName += "Down";
                    break;
            }

            // modify by orientation
            p.Normal = orientation * p.Normal;
            up = orientation * up;

            MeshManager modelMgr = MeshManager.Instance;

            // see if this mesh exists
            Mesh planeModel = modelMgr.GetByName(meshName);

            // trash it if it already exists
            if(planeModel != null)
                modelMgr.Unload(planeModel);

            float planeSize = distance * 2;

            // create and return the plane mesh
            return modelMgr.CreatePlane(meshName, p, planeSize, planeSize, 1, 1, false, 1, 1, 1, up);
        }
Esempio n. 22
0
 /// <summary>
 ///		Transforms a plane using the specified transform.
 /// </summary>
 /// <param name="matrix">Transformation matrix.</param>
 /// <param name="plane">Plane to transform.</param>
 /// <returns>A transformed plane.</returns>
 public static Plane Multiply(Matrix4 matrix, Plane plane)
 {
     return matrix * plane;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="plane"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="curvature"></param>
        /// <param name="xSegments"></param>
        /// <param name="ySegments"></param>
        /// <param name="normals"></param>
        /// <param name="numberOfTexCoordSets"></param>
        /// <param name="uTiles"></param>
        /// <param name="vTiles"></param>
        /// <param name="upVector"></param>
        /// <param name="orientation"></param>
        /// <param name="vertexBufferUsage"></param>
        /// <param name="indexBufferUsage"></param>
        /// <param name="vertexShadowBuffer"></param>
        /// <param name="indexShadowBuffer"></param>
        /// <returns></returns>
        public Mesh CreateCurvedIllusionPlane(string name, Plane plane, float width, float height, float curvature, int xSegments, int ySegments, bool normals, int numberOfTexCoordSets, float uTiles, float vTiles, Vector3 upVector, Quaternion orientation, BufferUsage vertexBufferUsage, BufferUsage indexBufferUsage, bool vertexShadowBuffer, bool indexShadowBuffer)
        {
            Mesh mesh = CreateManual(name);
            SubMesh subMesh = mesh.CreateSubMesh(name + "SubMesh");

            // set up vertex data, use a single shared buffer
            mesh.SharedVertexData = new VertexData();
            VertexData vertexData = mesh.SharedVertexData;

            // set up vertex declaration
            VertexDeclaration vertexDeclaration = vertexData.vertexDeclaration;
            int currentOffset = 0;

            // always need positions
            vertexDeclaration.AddElement(0, currentOffset, VertexElementType.Float3, VertexElementSemantic.Position);
            currentOffset += VertexElement.GetTypeSize(VertexElementType.Float3);

            // optional normals
            if(normals) {
                vertexDeclaration.AddElement(0, currentOffset, VertexElementType.Float3, VertexElementSemantic.Normal);
                currentOffset += VertexElement.GetTypeSize(VertexElementType.Float3);
            }

            for(ushort i = 0; i < numberOfTexCoordSets; i++) {
                // assumes 2d texture coordinates
                vertexDeclaration.AddElement(0, currentOffset, VertexElementType.Float2, VertexElementSemantic.TexCoords, i);
                currentOffset += VertexElement.GetTypeSize(VertexElementType.Float2);
            }

            vertexData.vertexCount = (xSegments + 1) * (ySegments + 1);

            // allocate vertex buffer
            HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer(vertexDeclaration.GetVertexSize(0), vertexData.vertexCount, vertexBufferUsage, vertexShadowBuffer);

            // set up the binding, one source only
            VertexBufferBinding binding = vertexData.vertexBufferBinding;
            binding.SetBinding(0, vertexBuffer);

            // work out the transform required, default orientation of plane is normal along +z, distance 0
            Matrix4 xlate, xform, rot;
            Matrix3 rot3 = Matrix3.Identity;
            xlate = rot = Matrix4.Identity;

            // determine axes
            Vector3 zAxis, yAxis, xAxis;
            zAxis = plane.Normal;
            zAxis.Normalize();
            yAxis = upVector;
            yAxis.Normalize();
            xAxis = yAxis.Cross(zAxis);
            if(xAxis.Length == 0) {
                throw new AxiomException("The up vector for a plane cannot be parallel to the planes normal.");
            }

            rot3.FromAxes(xAxis, yAxis, zAxis);
            rot = rot3;

            // set up standard xform from origin
            xlate.Translation = plane.Normal * -plane.D;

            // concatenate
            xform = xlate * rot;

            // generate vertex data, imagine a large sphere with the camera located near the top,
            // the lower the curvature, the larger the sphere.  use the angle from the viewer to the
            // points on the plane
            float cameraPosition;      // camera position relative to the sphere center

            // derive sphere radius (unused)
            //float sphereDistance;      // distance from the camera to the sphere along box vertex vector
            float sphereRadius;

            // actual values irrelevant, it's the relation between the sphere's radius and the camera's position which is important
            float SPHERE_RADIUS = 100;
            float CAMERA_DISTANCE = 5;
            sphereRadius = SPHERE_RADIUS - curvature;
            cameraPosition = sphereRadius - CAMERA_DISTANCE;

            // lock the whole buffer
            float xSpace = width / xSegments;
            float ySpace = height / ySegments;
            float halfWidth = width / 2;
            float halfHeight = height / 2;
            Vector3 vec = Vector3.Zero;
            Vector3 norm = Vector3.Zero;
            Vector3 min = Vector3.Zero;
            Vector3 max = Vector3.Zero;
            float maxSquaredLength = 0;
            bool firstTime = true;

            // generate vertex data
            GenerateCurvedIllusionPlaneVertexData(vertexBuffer, ySegments, xSegments, xSpace, halfWidth, ySpace, halfHeight, xform, firstTime, normals, orientation, cameraPosition, sphereRadius, uTiles, vTiles, numberOfTexCoordSets, ref min, ref max, ref maxSquaredLength);

            // generate face list
            subMesh.useSharedVertices = true;
            Tesselate2DMesh(subMesh, xSegments + 1, ySegments + 1, false, indexBufferUsage, indexShadowBuffer);

            // generate bounds for the mesh
            mesh.BoundingBox = new AxisAlignedBox(min, max);
            mesh.BoundingSphereRadius = MathUtil.Sqrt(maxSquaredLength);

            mesh.Load();
            mesh.Touch();

            return mesh;
        }
        /// <summary>
        ///    
        /// </summary>
        /// <param name="plane"></param>
        /// <param name="curvature"></param>
        /// <param name="tiling"></param>
        /// <param name="distance"></param>
        /// <param name="orientation"></param>
        /// <returns></returns>
        protected Mesh CreateSkyDomePlane(BoxPlane plane, float curvature, float tiling, float distance, Quaternion orientation)
        {
            Plane p = new Plane();
            Vector3 up = Vector3.Zero;
            string meshName = "SkyDomePlane_";

            // set up plane equation
            p.D = distance;

            switch(plane) {
                case BoxPlane.Front:
                    p.Normal = Vector3.UnitZ;
                    up = Vector3.UnitY;
                    meshName += "Front";
                    break;
                case BoxPlane.Back:
                    p.Normal = -Vector3.UnitZ;
                    up = Vector3.UnitY;
                    meshName += "Back";
                    break;
                case BoxPlane.Left:
                    p.Normal = Vector3.UnitX;
                    up = Vector3.UnitY;
                    meshName += "Left";
                    break;
                case BoxPlane.Right:
                    p.Normal = -Vector3.UnitX;
                    up = Vector3.UnitY;
                    meshName += "Right";
                    break;
                case BoxPlane.Up:
                    p.Normal = -Vector3.UnitY;
                    up = Vector3.UnitZ;
                    meshName += "Up";
                    break;
                case BoxPlane.Down:
                    return null;
            }

            // modify orientation
            p.Normal = orientation * p.Normal;
            up = orientation * up;

            // check to see if mesh exists
            MeshManager meshManager = MeshManager.Instance;
            Mesh planeMesh = meshManager.GetByName(meshName);

            // destroy existing
            if(planeMesh != null) {
                meshManager.Unload(planeMesh);
                planeMesh.Dispose();
            }

            // create new
            float planeSize = distance * 2;
            int segments = 16;
            planeMesh =
                meshManager.CreateCurvedIllusionPlane(
                meshName, p, planeSize, planeSize, curvature, segments, segments,
                false, 1, tiling, tiling, up, orientation,
                BufferUsage.DynamicWriteOnly, BufferUsage.StaticWriteOnly, true, true);

            return planeMesh;
        }
 public Mesh CreatePlane(string name, Plane plane, float width, float height, int xSegments, int ySegments, bool normals, int numTexCoordSets, float uTile, float vTile, Vector3 upVec)
 {
     return CreatePlane(name, plane, width, height, xSegments, ySegments, normals, numTexCoordSets, uTile, vTile, upVec, BufferUsage.StaticWriteOnly, BufferUsage.StaticWriteOnly, true, true);
 }
Esempio n. 26
0
 /// <summary>
 ///		Returns whether or not this sphere interects a plane.
 /// </summary>
 /// <param name="plane"></param>
 /// <returns>True if the plane intersects, false otherwise.</returns>
 public bool Intersects(Plane plane)
 {
     return MathUtil.Intersects(this, plane);
 }
Esempio n. 27
0
        protected override void CreateScene()
        {
            viewport.BackgroundColor = ColorEx.White;
            viewport.OverlaysEnabled = false;

            gen = new Multiverse.Generator.Generator();
            gen.Algorithm = GeneratorAlgorithm.HybridMultifractalWithSeedMap;
            gen.LoadSeedMap("map.csv");
            gen.OutsideMapSeedHeight = 0;
            gen.SeedMapOrigin = new Vector3(-3200, 0, -5120);
            gen.SeedMapMetersPerSample = 128;
            gen.XOff = -0.4f;
            gen.YOff = -0.3f;
            gen.HeightFloor = 0;
            gen.FractalOffset = 0.1f;
            gen.HeightOffset = -0.15f;
            gen.HeightScale = 300;
            gen.MetersPerPerlinUnit = 800;

            lodSpec = new LODSpec();
            lodSpecPrev = new LODSpecPrev();

            // water plane setup
            Plane waterPlane = new Plane(Vector3.UnitY, 10f * oneMeter);

            waterMesh = MeshManager.Instance.CreatePlane(
                "WaterPlane",
                waterPlane,
                60 * 128 * oneMeter, 90 * 128 * oneMeter,
                20, 20,
                true, 1,
                10, 10,
                Vector3.UnitZ);

            Debug.Assert(waterMesh != null);

            SetupScene();
        }
Esempio n. 28
0
 public Plane(Plane plane)
 {
     this.Normal = plane.Normal;
     this.D = plane.D;
 }
Esempio n. 29
0
        private void CreateNodes(Quake3Level q3lvl)
        {
            // Allocate memory for all nodes (leaves and splitters)
            nodes = new BspNode[q3lvl.NumNodes + q3lvl.NumLeaves];
            numLeaves = q3lvl.NumLeaves;
            leafStart = q3lvl.NumNodes;

            // Run through and initialize the array so front/back node pointers
            // aren't null.
            for(int i = 0; i < nodes.Length; i++)
                nodes[i] = new BspNode();

            // Convert nodes
            // In our array, first q3lvl.NumNodes are non-leaf, others are leaves
            for(int i = 0; i < q3lvl.NumNodes; i++)
            {
                BspNode node = nodes[i];
                InternalBspNode q3node = q3lvl.Nodes[i];

                node.IsLeaf = false;
                node.Owner = this;

                Plane splitPlane = new Plane();

                // Set plane
                splitPlane.Normal = new Vector3(
                    q3lvl.Planes[q3node.plane].normal[0],
                    q3lvl.Planes[q3node.plane].normal[1],
                    q3lvl.Planes[q3node.plane].normal[2]
                    );
                splitPlane.D = -q3lvl.Planes[q3node.plane].distance;

                node.SplittingPlane = splitPlane;

                // Set bounding box
                node.BoundingBox = new AxisAlignedBox(
                    new Vector3(
                        q3node.bbox[0],
                        q3node.bbox[1],
                        q3node.bbox[2]
                        ),
                    new Vector3(
                        q3node.bbox[3],
                        q3node.bbox[4],
                        q3node.bbox[5]
                        )
                    );

                // Set back pointer
                // Negative indexes in Quake3 mean leaves.
                if(q3node.back < 0)
                    node.BackNode = nodes[leafStart + (~(q3node.back))];
                else
                    node.BackNode = nodes[q3node.back];

                // Set front pointer
                // Negative indexes in Quake3 mean leaves
                if(q3node.front < 0)
                    node.FrontNode = nodes[leafStart + (~(q3node.front))];
                else
                    node.FrontNode = nodes[q3node.front];
            }
        }
 /// <summary>
 ///		Update a perspective projection matrix to use 'oblique depth projection'.
 /// </summary>
 /// <remarks>
 ///		This method can be used to change the nature of a perspective 
 ///		transform in order to make the near plane not perpendicular to the 
 ///		camera view direction, but to be at some different orientation. 
 ///		This can be useful for performing arbitrary clipping (e.g. to a 
 ///		reflection plane) which could otherwise only be done using user
 ///		clip planes, which are more expensive, and not necessarily supported
 ///		on all cards.
 /// </remarks>
 /// <param name="projMatrix">
 ///		The existing projection matrix. Note that this must be a
 ///		perspective transform (not orthographic), and must not have already
 ///		been altered by this method. The matrix will be altered in-place.
 /// </param>
 /// <param name="plane">
 ///		The plane which is to be used as the clipping plane. This
 ///		plane must be in CAMERA (view) space.
 ///	</param>
 /// <param name="forGpuProgram">Is this for use with a Gpu program or fixed-function transforms?</param>
 public abstract void ApplyObliqueDepthProjection(ref Matrix4 projMatrix, Plane plane, bool forGpuProgram);