Exemplo n.º 1
0
        public static ManualObject CreateRectangle(SceneManager sceneMgr, Vector3 pos, Vector3 size, string material = ColoredMaterials.BLUE)
        {
            Vector3[,] points = new Vector3[2, 4];
            for (int y = 0; y < 2; y++)
            {
                points[y, 0] = pos + y * Vector3.UNIT_Y * size.y;
                points[y, 1] = pos + new Vector3(1, y, 0) * size;
                points[y, 2] = pos + new Vector3(1, y, 1) * size;
                points[y, 3] = pos + new Vector3(0, y, 1) * size;
            }

            ManualObject manOb = sceneMgr.CreateManualObject();

            manOb.Begin(material, RenderOperation.OperationTypes.OT_LINE_LIST);
            for (int y = 0; y < 2; y++)
            {
                for (int i = 0; i < 4; i++)
                {
                    manOb.Position(points[y, i]);
                    manOb.Position(points[y, (i + 1) % 4]);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                manOb.Position(points[0, i]);
                manOb.Position(points[1, i]);
            }

            manOb.End();
            return(manOb);
        }
Exemplo n.º 2
0
        protected void drawLine(SceneNode p_Node, string lineName, Vector3 p_Point1, Vector3 p_Point2)
        {
            // create material (colour)
            MaterialPtr moMaterial = MaterialManager.Singleton.Create(lineName, "debugger");

            moMaterial.ReceiveShadows = false;
            moMaterial.GetTechnique(0).SetLightingEnabled(true);
            moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0);
            moMaterial.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1);
            moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1);
            moMaterial.Dispose();  // dispose pointer, not the material


            // create line object
            ManualObject manOb = mSceneManager.CreateManualObject(lineName);

            manOb.Begin(lineName, RenderOperation.OperationTypes.OT_LINE_LIST);
            manOb.Position(p_Point1.x, p_Point1.y, p_Point1.z);
            manOb.Position(p_Point2.x, p_Point2.y, p_Point2.z);
            // ... maybe more points
            manOb.End();

            // create SceneNode and attach the line
            //            p_Node.Position = Vector3.ZERO;
            p_Node.AttachObject(manOb);
        }
Exemplo n.º 3
0
        /* Apply an inefficient but simple-to-implement subdivision scheme for a triangle. */
        static void TriangleDivide(ManualObject obj, int depth,
            float[] a, float[] b, float[] c,
            float[] ca, float[] cb, float[] cc)
        {
            if (depth == 0)
            {
                obj.Position(c[0], c[1], 0);
                obj.Colour(cc[0], cc[1], cc[2]);
                obj.Position(b[0], b[1], 0);
                obj.Colour(cb[0], cb[1], cb[2]);
                obj.Position(a[0], a[1], 0);
                obj.Colour(ca[0], ca[1], ca[2]);
            }
            else
            {
                float[] d = new float[2] { (a[0] + b[0]) / 2, (a[1] + b[1]) / 2 };
                float[] e = new float[2] { (b[0] + c[0]) / 2, (b[1] + c[1]) / 2 };
                float[] f = new float[2] { (c[0] + a[0]) / 2, (c[1] + a[1]) / 2 };
                float[] cd = new float[3] { (ca[0] + cb[0]) / 2, (ca[1] + cb[1]) / 2, (ca[2] + cb[2]) / 2 };
                float[] ce = new float[3] { (cb[0] + cc[0]) / 2, (cb[1] + cc[1]) / 2, (cb[2] + cc[2]) / 2 };
                float[] cf = new float[3] { (cc[0] + ca[0]) / 2, (cc[1] + ca[1]) / 2, (cc[2] + ca[2]) / 2 };

                depth -= 1;
                TriangleDivide(obj, depth, a, d, f, ca, cd, cf);
                TriangleDivide(obj, depth, d, b, e, cd, cb, ce);
                TriangleDivide(obj, depth, f, e, c, cf, ce, cc);
                TriangleDivide(obj, depth, d, e, f, cd, ce, cf);
            }
        }
Exemplo n.º 4
0
        public MeshPtr getCube(string cubeName)
        {
            manualObj = mSceneMgr.CreateManualObject("maualObjQuad");
            manualObj.Begin("void", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); // Starts filling the manual object as a triangle list

            // ---- Vertex Buffer ----
            manualObj.Position(new Vector3(-1000, 0, 1000));        // --- Vertex 0 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Position(new Vector3(1000, 0, 1000));         // --- Vertex 1 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Position(new Vector3(1000, 0, -1000));        // --- Vertex 2 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Position(new Vector3(-1000, 0, -1000 0));     // --- Vertex 3 ---
            manualObj.TextureCoord(new Vector2(1, 1));

            // ---- Index Buffer ----
            // --- Triangle 0 ---
            manualObj.Index(0);
            manualObj.Index(1);
            manualObj.Index(2);

            // --- Triangle 1 ---
            manualObj.Index(1);
            manualObj.Index(3);
            manualObj.Index(2);


            manualObj.End();                                    // Closes the manual objet

            return(manualObj.ConvertToMesh("Floor"));           // Prepares the data to be sent to the GPU
        }
Exemplo n.º 5
0
        void CreateGrassMesh()
        {
            const float  width  = 25;
            const float  height = 30;
            Vector3      vec    = new Vector3(width / 2, 0, 0);
            ManualObject obj    = _sceneManager.CreateManualObject("GrassObject");

            Quaternion quat = new Quaternion(new Degree(60), Vector3.UNIT_Y);

            obj.Begin("Examples/GrassBlades", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            for (uint i = 0; i < 3; ++i)
            {
                obj.Position(-vec.x, height, -vec.z);
                obj.TextureCoord(0, 0);
                obj.Position(vec.x, height, vec.z);
                obj.TextureCoord(1, 0);
                obj.Position(-vec.x, 0, -vec.z);
                obj.TextureCoord(0, 1);
                obj.Position(vec.x, 0, vec.z);
                obj.TextureCoord(1, 1);

                uint offset = 4 * i;
                obj.Triangle(offset, offset + 3, offset + 1);
                obj.Triangle(offset, offset + 2, offset + 3);

                vec = quat * vec;
            }

            obj.End();
            obj.ConvertToMesh("grass");
            _sceneManager.DestroyManualObject(obj);
        }
Exemplo n.º 6
0
        private void CreateLine(ManualObject mo, Vector3 origin, Vector3 final, int useMaterial, Vector4 color)
        {
            float lineWidth = 0.1f;

            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN;
            switch (useMaterial)
            {
            case 1:
                mo.Begin("SharpMap/Line3D_v1", operation);
                break;

            default:
                MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/ColourLines3d",
                                                                                  ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first;
                material.GetTechnique(0).GetPass(0).VertexColourTracking =
                    (int)TrackVertexColourEnum.TVC_AMBIENT;
                mo.Begin("Test/ColourLines3d", operation);

                break;
            }

            Vector3 delta = final - origin;

            delta = new Vector3(-delta.y, delta.x, delta.z).NormalisedCopy *lineWidth;
            mo.Position(origin);
            mo.Position(final);
            mo.Position(final + delta);
            mo.Position(origin + delta);
            //lines3d.TextureCoord((float)i / (float)pointsList.Count);

            ManualObject.ManualObjectSection section = lines3d.End();
            section.SetCustomParameter(constantColor, color);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This private method defines the vertex and index buffers of a quad as a triangle list.
        /// </summary>
        private MeshPtr Quad()
        {
            manualObj = mSceneMgr.CreateManualObject("maualObjQuad");
            manualObj.Begin("void", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);    // Starts filling the manual object as a triangle list

            // ---- Vertex Buffer ----
            manualObj.Position(new Vector3(5, 5, 0));               // --- Vertex 0 ---
            manualObj.Position(new Vector3(-5, 5, 0));              // --- Vertex 1 ---
            manualObj.Position(new Vector3(5, -5, 0));              // --- Vertex 2 ---
            manualObj.Position(new Vector3(-5, -5, 0));             // --- Vertex 3 ---

            // ---- Index Buffer ----
            // --- Triangle 0 ---
            manualObj.Index(0);
            manualObj.Index(1);
            manualObj.Index(2);

            // --- Triangle 1 ---
            manualObj.Index(1);
            manualObj.Index(3);
            manualObj.Index(2);

            manualObj.End();                                        // Closes the manual objet

            return(manualObj.ConvertToMesh("Quad"));                // Prepares the data to be sent to the GPU
        }
Exemplo n.º 8
0
        public static ManualObject CreateLine(SceneManager sceneMgr, Vector3 p1, Vector3 p2, string material = ColoredMaterials.BLUE)
        {
            ManualObject manOb = sceneMgr.CreateManualObject();

            manOb.Begin(material, RenderOperation.OperationTypes.OT_LINE_LIST);
            manOb.Position(p1);
            manOb.Position(p2);
            manOb.End();

            return(manOb);
        }
Exemplo n.º 9
0
        public BulletDebugDrawer()
        {
            sceneMgr = LKernel.GetG<SceneManager>();

            lines = new ManualObject("physics lines");
            triangles = new ManualObject("physics triangles");
            lines.Dynamic = true;
            triangles.Dynamic = true;

            sceneMgr.RootSceneNode.AttachObject(lines);
            sceneMgr.RootSceneNode.AttachObject(triangles);

            string matName = "BulletDebugDrawerMaterial";
            MaterialPtr mtl = MaterialManager.Singleton.GetDefaultSettings().Clone(matName);
            mtl.ReceiveShadows = false;
            mtl.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
            mtl.SetDepthBias(0.1f, 0);

            TextureUnitState tu = mtl.GetTechnique(0).GetPass(0).CreateTextureUnitState();
            tu.SetColourOperationEx(LayerBlendOperationEx.LBX_SOURCE1, LayerBlendSource.LBS_DIFFUSE);
            mtl.GetTechnique(0).SetLightingEnabled(false);

            lines.Begin(matName, RenderOperation.OperationTypes.OT_LINE_LIST);
            begin = true;
            lines.Position(Vector3.ZERO);
            lines.Colour(ColourValue.Blue);
            lines.Position(Vector3.ZERO);
            lines.Colour(ColourValue.Blue);
            lines.End();

            triangles.Begin(matName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            triangles.Position(Vector3.ZERO);
            triangles.Colour(ColourValue.Blue);
            triangles.Position(Vector3.ZERO);
            triangles.Colour(ColourValue.Blue);
            triangles.Position(Vector3.ZERO);
            triangles.Colour(ColourValue.Blue);
            triangles.End();
            begin = false;

            DebugMode = DebugDrawModes.DrawWireframe | /*DebugDrawModes.DrawAabb |*/ DebugDrawModes.FastWireframe
                | DebugDrawModes.EnableCCD | DebugDrawModes.DrawNormals;

            levelMgr = LKernel.GetG<LevelManager>();
            mainPlayerKartNode = LKernel.GetG<PlayerManager>().MainPlayer.Kart.RootNode;

            PhysicsMain.PreSimulate += PreSimulate;
            PhysicsMain.PostSimulate += PostSimulate;

            LKernel.GetG<PhysicsMain>().World.DebugDrawer = this;
        }
        /// Builds the normals representation as a manual object
        /// \exception Ogre::InvalidStateException The input triangle buffer must not be null
        /// \exception Ogre::InvalidStateException Scene Manager is not set in OGRE root object
        //
        //ORIGINAL LINE: ManualObject* buildManualObject() const
        public ManualObject buildManualObject()
        {
            if (mTriangleBuffer == null)
            {
                OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "The input triangle buffer must not be null", "Procedural::ShowNormalsGenerator::buildManualObject()");
            }
            ;
            //SceneManager sceneMgr = Root.Singleton.GetSceneManagerIterator().Current;
            Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator();
            item.MoveNext();
            Mogre.SceneManager sceneMgr = item.Current;
            item.Dispose();
            if (sceneMgr == null)
            {
                OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "Scene Manager must be set in Root", "Procedural::ShowNormalsGenerator::buildManualObject()");
            }
            ;
            ManualObject manual = sceneMgr.CreateManualObject("debug_procedural_" + Guid.NewGuid().ToString("N"));

            manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_LIST);
            std_vector <TriangleBuffer.Vertex> vertices = mTriangleBuffer.getVertices();

            //for (List<TriangleBuffer.Vertex>.Enumerator it = vertices.GetEnumerator(); it.MoveNext(); ++it)
            foreach (var it in vertices)
            {
                manual.Position(it.mPosition);
                manual.Position(it.mPosition + it.mNormal * mSize);

                if (mVisualStyle == VisualStyle.VS_ARROW)
                {
                    Vector3 axis2 = it.mNormal.Perpendicular;
                    Vector3 axis3 = it.mNormal.CrossProduct(axis2);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + (.8f * it.mNormal + .1f * axis2) * mSize);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + .8f * (it.mNormal - .1f * axis2) * mSize);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + .8f * (it.mNormal + .1f * axis3) * mSize);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + .8f * (it.mNormal - .1f * axis3) * mSize);
                }
            }
            manual.End();

            return(manual);
        }
Exemplo n.º 11
0
        private void DrawLine(ManualObject manualObject, int index0, int index1, ColourValue colour)
        {
            Vector3 p0     = corners[index0];
            Vector3 p1     = corners[index1];
            float   length = (p1 - p0).Length;

            manualObject.Position(p0);
            manualObject.Colour(colour);
            manualObject.TextureCoord(0);

            manualObject.Position(p1);
            manualObject.Colour(colour);
            manualObject.TextureCoord(length);
        }
Exemplo n.º 12
0
        // creates a wireframe octahedron as a dummy model
        public static MovableObject MakeDummy(SceneManager mgr, String name, String materialName, float size)
        {
            ManualObject dummy = mgr.CreateManualObject(name);

            dummy.Begin(materialName, RenderOperation.OperationTypes.OT_LINE_LIST);

            // octahedron wire shape
            Vector3[] points =
            {
                new Vector3(0,     size,      0), new Vector3(0,     0, size),
                new Vector3(0,     size,      0), new Vector3(0,     0, -size),
                new Vector3(0,     size,      0), new Vector3(-size, 0,     0),
                new Vector3(0,     size,      0), new Vector3(size,  0,     0),

                new Vector3(0,     -size,     0), new Vector3(0,     0, size),
                new Vector3(0,     -size,     0), new Vector3(0,     0, -size),
                new Vector3(0,     -size,     0), new Vector3(-size, 0,     0),
                new Vector3(0,     -size,     0), new Vector3(size,  0,     0),

                new Vector3(-size,     0,     0), new Vector3(0,     0, size),
                new Vector3(0,         0, size),  new Vector3(size,  0,     0),
                new Vector3(size,      0,     0), new Vector3(0,     0, -size),
                new Vector3(0,         0, -size), new Vector3(-size, 0,     0),
            };

            foreach (Vector3 v in points)
            {
                dummy.Position(v);
            }

            dummy.End();

            return(dummy);
        }
Exemplo n.º 13
0
        public MeshPtr LoadStaticBrfMeshIntoOgre(SceneManager sceneManager, MBBrfMesh brfMesh, int frame = 0)
        {
            //Convert Vertex and Faces to Ogre Mesh Format
            if (brfMesh == null)
            {
                return(null);
            }
            if (meshes.ContainsKey(brfMesh.Name))
            {
                return(meshes[brfMesh.Name]);
            }
            ManualObject mo = sceneManager.CreateManualObject(brfMesh.Name + "-" + Guid.NewGuid().ToString());

            mo.Begin(brfMesh.Material);

            int np = 0, nv = 0;

            for (int i = 0; i < brfMesh.Frames[frame].pos.Count; i++)
            {
                mo.Position(
                    brfMesh.Frames[frame].pos[i].x,
                    brfMesh.Frames[frame].pos[i].y,
                    brfMesh.Frames[frame].pos[i].z
                    );
                np++;
            }

            for (int i = 0; i < brfMesh.Frames[frame].norm.Count; i++)
            {
                mo.Normal(
                    -brfMesh.Frames[frame].norm[i].x,
                    brfMesh.Frames[frame].norm[i].y,
                    brfMesh.Frames[frame].norm[i].z
                    );
                mo.TextureCoord(
                    brfMesh.Vertex[i].ta.X,
                    brfMesh.Vertex[i].ta.Y
                    );
                nv++;
            }

            for (int i = 0; i < brfMesh.Faces.Count; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    mo.Triangle(
                        (uint)(brfMesh.Vertex[brfMesh.Faces[i].index[j]].index + 1 + cp),
                        (uint)(brfMesh.Faces[i].index[j] + 1 + cv),
                        (uint)(brfMesh.Faces[i].index[j] + 1 + cv)
                        );
                }
            }

            mo.End();

            cp += np;
            cv += nv;

            return(mo.ConvertToMesh(brfMesh.Name + "-" + Guid.NewGuid().ToString()));
        }
Exemplo n.º 14
0
        private void UpdateCloudPoints(List <Point3D> PointsList, Decimal d_threshold_meters)
        {
            if (manual == null)
            {
                return;
            }
            if (PointsList == null)
            {
                return;
            }

            double threshold = (double)d_threshold_meters * 1000d; // convert to mm

            try
            {
                manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_POINT_LIST);

                // Real data
                foreach (Point3D sp in PointsList)
                {
                    ColourValue cv = sp.color;
                    Vector3     v  = new Vector3((float)sp.x, (float)sp.y, (float)sp.z);

                    manual.Position(v);
                    manual.Colour(cv);
                }
                manual.End();
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception when plotting points: " + e.Message);
                // ignore throw e;
            }
        }
Exemplo n.º 15
0
        static ManualObject DrawTriangle(ManualObject obj)
        {
            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST;

            obj.Begin("CgTutorials/C3E5_Material", operation);
            obj.Position(0.0f, -0.8f, 0.0f);
            obj.TextureCoord(0, 0);

            obj.Position(0.8f, 0.8f, 0.0f);
            obj.TextureCoord(1, 0);

            obj.Position(-0.8f, 0.8f, 0.0f);
            obj.TextureCoord(0.5f, 1);

            obj.End();

            return(obj);
        }
Exemplo n.º 16
0
        static ManualObject DrawTriangle(ManualObject obj)
        {
            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST;

            obj.Begin("CgTutorials/C3E5_Material", operation);
            obj.Position(0.0f, -0.8f, 0.0f);
            obj.TextureCoord(0, 0);

            obj.Position(0.8f, 0.8f, 0.0f);
            obj.TextureCoord(1, 0);

            obj.Position(-0.8f, 0.8f, 0.0f);
            obj.TextureCoord(0.5f, 1);

            obj.End();

            return obj;
        }
Exemplo n.º 17
0
        static ManualObject DrawTriangle(ManualObject obj)
        {
            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST;

            obj.Begin("CgTutorials/C3E2_Material", operation);
            obj.Position(0.0f, -0.8f, 0.0f);
            obj.Colour(0, 0, 1);  /* Blue */

            obj.Position(0.8f, 0.8f, 0.0f);
            obj.Colour(0, 1, 0);  /* Green */

            obj.Position(-0.8f, 0.8f, 0.0f);
            obj.Colour(1, 0, 0);  /* Red */

            obj.End();

            return obj;
        }
Exemplo n.º 18
0
        public int AddVertex(float x, float y)
        {
            Console.WriteLine("AddVertex: (" + x.ToString(nfi) + "; " + y.ToString(nfi) + ")");
            Point p = TransformVertex(x, y);

            rendererObj.Position(new Vector3(p.X, p.Y, 0));
            pointsList.Add(p);
            return(pointsList.Count - 1);
        }
Exemplo n.º 19
0
        static ManualObject DrawTriangle(ManualObject obj)
        {
            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST;

            obj.Begin("CgTutorials/C3E2_Material", operation);
            obj.Position(0.0f, -0.8f, 0.0f);
            obj.Colour(0, 0, 1);  /* Blue */

            obj.Position(0.8f, 0.8f, 0.0f);
            obj.Colour(0, 1, 0);  /* Green */

            obj.Position(-0.8f, 0.8f, 0.0f);
            obj.Colour(1, 0, 0);  /* Red */

            obj.End();

            return(obj);
        }
Exemplo n.º 20
0
    public void Initialise(SceneManager aSceneManager, float aFillAlpha)
    {
        if (isInitialised)
        {
            // Initialization multiple call guard
            return;
        }

        if (aSceneManager == null)
        {
            return;
        }

        m_sceneManager = aSceneManager;
        fillAlpha      = aFillAlpha;
        m_manualObject = null;
        linesIndex     = 0;
        trianglesIndex = 0;

        m_manualObject             = m_sceneManager.CreateManualObject("debugDrawer_object");
        m_manualObject.CastShadows = false;

        m_sceneManager.RootSceneNode.CreateChildSceneNode("debugDrawer_object").AttachObject(m_manualObject);
        m_manualObject.Dynamic = (true);

        icoSphere.Create(this.DEFAULT_ICOSPHERE_RECURSION_LEVEL);

        m_manualObject.Begin("debug_draw", RenderOperation.OperationTypes.OT_LINE_LIST);
        m_manualObject.Position(Vector3.ZERO);
        m_manualObject.Colour(ColourValue.ZERO);
        m_manualObject.Index(0);
        m_manualObject.End();
        m_manualObject.Begin("debug_draw", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
        m_manualObject.Position(Vector3.ZERO);
        m_manualObject.Colour(ColourValue.ZERO);
        m_manualObject.Index(0);
        m_manualObject.End();

        trianglesIndex = 0;
        linesIndex     = trianglesIndex;

        isInitialised = true;
        // Initialization multiple call guard
    }
Exemplo n.º 21
0
    public void Build()
    {
        if (Initialized == false)
        {
            throw new Exception("You forgot to call 'Initialise(...)'");
        }
        m_manualObject.BeginUpdate(0);
        if (lineVertices.Count > 0 && isEnabled)
        {
            m_manualObject.EstimateVertexCount(System.Convert.ToUInt32(lineVertices.Count));
            m_manualObject.EstimateIndexCount(System.Convert.ToUInt32(lineIndices.Count));
            LinkedList <KeyValuePair <Vector3, ColourValue> > .Enumerator i = lineVertices.GetEnumerator();
            while (i.MoveNext())
            {
                m_manualObject.Position(i.Current.Key);
                m_manualObject.Colour(i.Current.Value);
            }
            LinkedList <int> .Enumerator i2 = lineIndices.GetEnumerator();
            while (i2.MoveNext())
            {
                m_manualObject.Index(System.Convert.ToUInt16(i2.Current));
            }
        }
        m_manualObject.End();

        m_manualObject.BeginUpdate(1);
        if (triangleVertices.Count > 0 && isEnabled)
        {
            m_manualObject.EstimateVertexCount(System.Convert.ToUInt16((triangleVertices.Count)));
            m_manualObject.EstimateIndexCount(System.Convert.ToUInt16(triangleIndices.Count));
            LinkedList <KeyValuePair <Vector3, ColourValue> > .Enumerator i = triangleVertices.GetEnumerator();
            while (i.MoveNext())
            {
                m_manualObject.Position(i.Current.Key);
                m_manualObject.Colour(i.Current.Value.r, i.Current.Value.g, i.Current.Value.b, fillAlpha);
            }
            LinkedList <int> .Enumerator i2 = triangleIndices.GetEnumerator();
            while (i2.MoveNext())
            {
                m_manualObject.Index(System.Convert.ToUInt16(i2.Current));
            }
        }
        m_manualObject.End();
    }
Exemplo n.º 22
0
        // create a 2D hud element: pos = [-1;1] & size = (pixels)
        public static MovableObject MakeHud(SceneManager mgr, Viewport vp, String materialName, Vector2 pos, Vector2 size)
        {
            // Create a manual object for 2D
            ManualObject manual = mgr.CreateManualObject();

            // Use identity view/projection matrices
            manual.UseIdentityProjection = true;
            manual.UseIdentityView       = true;

            // convert from pixels to screen coords
            float s = size.x / vp.ActualWidth;
            float t = size.y / vp.ActualHeight;

            manual.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);

            manual.Position(pos.x - s, pos.y - t, 0.0f); manual.TextureCoord(0, 1);
            manual.Position(pos.x + s, pos.y - t, 0.0f); manual.TextureCoord(1, 1);
            manual.Position(pos.x + s, pos.y + t, 0.0f); manual.TextureCoord(1, 0);
            manual.Position(pos.x - s, pos.y + t, 0.0f); manual.TextureCoord(0, 0);

            manual.Index(0);
            manual.Index(1);
            manual.Index(2);
            manual.Index(3);
            manual.Index(0);

            manual.End();

            // Use infinite AAB to always stay visible
            AxisAlignedBox aabInf = new AxisAlignedBox();

            aabInf.SetInfinite();
            manual.BoundingBox = aabInf;

            // Render just before overlays
            manual.RenderQueueGroup = (byte)(RenderQueueGroupID.RENDER_QUEUE_OVERLAY - 1);
            manual.CastShadows      = false;

            // Attach to scene
            mgr.RootSceneNode.CreateChildSceneNode().AttachObject(manual);
            return(manual);
        }
Exemplo n.º 23
0
        public static SceneNode block(Vector3 loc, SceneManager sceneMgr)
        {
            ManualObject block = new ManualObject("block-" + Guid.NewGuid().ToString());

            block.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_LIST);

            for (int i = 0; i < blockPointCoords.Length; i++) {
                block.Position(loc + blockPointCoords[i]);
                if(i != 0) {
                    block.Position(loc + blockPointCoords[i]);
                }
            }

            block.End();

            SceneNode returnNode = sceneMgr.RootSceneNode.CreateChildSceneNode("cubeBorders", new Vector3(0, 0, 0));

            returnNode.AttachObject(block);
            return returnNode;
        }
Exemplo n.º 24
0
        private void createSphere(string strName, float r, SceneManager sceneMgr, int nRings = 16, int nSegments = 16)
        {
            ManualObject manual = sceneMgr.CreateManualObject(strName);

            manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            float  fDeltaRingAngle = (Mogre.Math.PI / nRings);
            float  fDeltaSegAngle  = (2 * Mogre.Math.PI / nSegments);
            ushort wVerticeIndex   = 0;

            // Generate the group of rings for the sphere
            for (int ring = 0; ring <= nRings; ring++)
            {
                float r0 = r * Mogre.Math.Sin(ring * fDeltaRingAngle);
                float y0 = r * Mogre.Math.Cos(ring * fDeltaRingAngle);

                // Generate the group of segments for the current ring
                for (int seg = 0; seg <= nSegments; seg++)
                {
                    float x0 = r0 * Mogre.Math.Sin(seg * fDeltaSegAngle);
                    float z0 = r0 * Mogre.Math.Cos(seg * fDeltaSegAngle);

                    // Add one vertex to the strip which makes up the sphere
                    manual.Position(x0, y0, z0);
                    manual.Normal(new Mogre.Vector3(x0, y0, z0).NormalisedCopy);
                    manual.TextureCoord((float)seg / (float)nSegments, (float)ring / (float)nRings);

                    if (ring != nRings)
                    {
                        // each vertex (except the last) has six indicies pointing to it
                        manual.Index((uint)(wVerticeIndex + nSegments + 1));
                        manual.Index(wVerticeIndex);
                        manual.Index((uint)(wVerticeIndex + nSegments));
                        manual.Index((uint)(wVerticeIndex + nSegments + 1));
                        manual.Index((uint)(wVerticeIndex + 1));
                        manual.Index(wVerticeIndex);
                        wVerticeIndex++;
                    }
                }
                ;  // end for seg
            } // end for ring
            manual.End();
            MeshPtr mesh = manual.ConvertToMesh(strName);

            mesh._setBounds(new AxisAlignedBox(new Mogre.Vector3(-r, -r, -r), new Mogre.Vector3(r, r, r)), false);

            mesh._setBoundingSphereRadius(r);
            ushort src, dest;

            if (!mesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest))
            {
                mesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest);
            }
        }
Exemplo n.º 25
0
        /* Apply an inefficient but simple-to-implement subdivision scheme for a triangle. */
        static void TriangleDivide(ManualObject obj, int depth,
                                   float[] a, float[] b, float[] c,
                                   float[] ca, float[] cb, float[] cc)
        {
            if (depth == 0)
            {
                obj.Position(c[0], c[1], 0);
                obj.Colour(cc[0], cc[1], cc[2]);
                obj.Position(b[0], b[1], 0);
                obj.Colour(cb[0], cb[1], cb[2]);
                obj.Position(a[0], a[1], 0);
                obj.Colour(ca[0], ca[1], ca[2]);
            }
            else
            {
                float[] d = new float[2] {
                    (a[0] + b[0]) / 2, (a[1] + b[1]) / 2
                };
                float[] e = new float[2] {
                    (b[0] + c[0]) / 2, (b[1] + c[1]) / 2
                };
                float[] f = new float[2] {
                    (c[0] + a[0]) / 2, (c[1] + a[1]) / 2
                };
                float[] cd = new float[3] {
                    (ca[0] + cb[0]) / 2, (ca[1] + cb[1]) / 2, (ca[2] + cb[2]) / 2
                };
                float[] ce = new float[3] {
                    (cb[0] + cc[0]) / 2, (cb[1] + cc[1]) / 2, (cb[2] + cc[2]) / 2
                };
                float[] cf = new float[3] {
                    (cc[0] + ca[0]) / 2, (cc[1] + ca[1]) / 2, (cc[2] + ca[2]) / 2
                };

                depth -= 1;
                TriangleDivide(obj, depth, a, d, f, ca, cd, cf);
                TriangleDivide(obj, depth, d, b, e, cd, cb, ce);
                TriangleDivide(obj, depth, f, e, c, cf, ce, cc);
                TriangleDivide(obj, depth, d, e, f, cd, ce, cf);
            }
        }
Exemplo n.º 26
0
        public ManualObject CreateNode(string name, SceneManager sceneMgr)
        {
            ManualObject manualObj = sceneMgr.CreateManualObject(name);

            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST;
            MaterialPtr material = MaterialManager.Singleton.Create("Test/Tutorial00",
                                                                    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            material.GetTechnique(0).GetPass(0).VertexColourTracking =
                (int)TrackVertexColourEnum.TVC_AMBIENT;

            manualObj.Begin("Test/Tutorial00", operation);

            manualObj.Position(-5.0f, 0.0f, 0.0f);
            manualObj.Position(5.0f, 0.0f, 0.0f);
            manualObj.Position(0.0f, 5.0f, 0.0f);

            manualObj.End();

            return(manualObj);
        }
Exemplo n.º 27
0
        public void AddPt(Vector3 pt)
        {
            this.ptlist.Add(pt);
            ManualLineObject.Begin(ColorMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            foreach (Vector3 ptt in this.ptlist)
            {
                ManualLineObject.Position(ptt);
                ManualLineObject.TextureCoord(ptt.x / 100, ptt.y / 100);
            }

            ManualLineObject.End();
        }
Exemplo n.º 28
0
        public static SceneNode block(Vector3 loc, SceneManager sceneMgr)
        {
            ManualObject block = new ManualObject("block-" + Guid.NewGuid().ToString());

            block.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_LIST);

            for (int i = 0; i < blockPointCoords.Length; i++)
            {
                block.Position(loc + blockPointCoords[i]);
                if (i != 0)
                {
                    block.Position(loc + blockPointCoords[i]);
                }
            }

            block.End();

            SceneNode returnNode = sceneMgr.RootSceneNode.CreateChildSceneNode("cubeBorders", new Vector3(0, 0, 0));

            returnNode.AttachObject(block);
            return(returnNode);
        }
Exemplo n.º 29
0
        public static void AttachLine(SceneManager sceneMgr, Vector3 from, Vector3 to)
        {
            if (sceneMgr.HasManualObject("line" + from + "_" + to))
            {
                return;
            }

            // create line object
            ManualObject manOb = sceneMgr.CreateManualObject("line" + from + "_" + to);

            manOb.Begin("line_material" + from + "_" + to, RenderOperation.OperationTypes.OT_LINE_LIST);
            manOb.Position(from);
            manOb.Position(to);
            // ... maybe more points
            manOb.End();

            // create SceneNode and attach the line
            SceneNode moNode = sceneMgr.RootSceneNode.CreateChildSceneNode("line_node" + from + "_" + to);

            //moNode.SetPosition(Vector3.ZERO);
            moNode.AttachObject(manOb);
        }
Exemplo n.º 30
0
        /*
         * @param the block's location
         */
        public void addBlock(Vector3 loc, BlockFace face)
        {
            Vector3 displayCoord = this.mWorld.getDisplayCoords(this.mIsland.getPosition(), loc);

            for (int i = 0; i < 4; i++)
            {
                block.Position(displayCoord + getBlockPointsCoord((int)face * 4 + i));
                block.TextureCoord(getTextureCoord((int)face * 4 + i));
                block.Normal(this.getNormals((int)face));
                this.faceNumber++;
            }
            block.Quad((uint)this.faceNumber - 4, (uint)this.faceNumber - 3, (uint)this.faceNumber - 2, (uint)this.faceNumber - 1);
        }
Exemplo n.º 31
0
        static void DrawStar(ManualObject obj, float x, float y, int starPoints, float R, float r)
        {
            int   i;
            float piOverStarPoints = 3.14159f / starPoints,
                  angle            = 0.0f;

            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN;
            obj.Begin("CgTutorials/C2E2_green_Material", operation);
            obj.Position(x, y, 0.0f);  /* Center of star */
            /* Emit exterior vertices for star's points. */
            for (i = 0; i < starPoints; i++)
            {
                obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f);
                angle += piOverStarPoints;
                obj.Position(x + r * Math.Cos(angle), y + r * Math.Sin(angle), 0.0f);
                angle += piOverStarPoints;
            }
            /* End by repeating first exterior vertex of star. */
            angle = 0;
            obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f);
            obj.End();
        }
Exemplo n.º 32
0
        ManualObject CreateGrid(SceneManager theSceneMng, float theWidth, float theStep, string theName)
        {
            float halfW = theWidth / 2f;

            // create material (colour)
            MaterialPtr moMaterial = MaterialManager.Singleton.Create("line_material", "General");

            moMaterial.ReceiveShadows = false;
            moMaterial.GetTechnique(0).SetLightingEnabled(true);
            moMaterial.GetTechnique(0).GetPass(0).SetDiffuse(0.1f, 0.1f, 0.1f, 0);
            moMaterial.GetTechnique(0).GetPass(0).SetAmbient(0.1f, 0.1f, 0.1f);
            moMaterial.GetTechnique(0).GetPass(0).SetSelfIllumination(0.1f, 0.1f, 0.1f);
            moMaterial.Dispose();  // dispose pointer, not the material

            // create line object
            ManualObject manOb = theSceneMng.CreateManualObject("line_" + theName);

            // X lines
            for (float x = -halfW; x <= halfW; x += theStep)
            {
                // draw line
                manOb.Begin("line_material", RenderOperation.OperationTypes.OT_LINE_LIST);
                manOb.Position(x, 0, -halfW);
                manOb.Position(x, 0, halfW);
                manOb.End();
            }

            // Z lines
            for (float z = -halfW; z <= halfW; z += theStep)
            {
                // draw line
                manOb.Begin("line_material", RenderOperation.OperationTypes.OT_LINE_LIST);
                manOb.Position(-halfW, 0, z);
                manOb.Position(halfW, 0, z);
                manOb.End();
            }

            return(manOb);
        }
Exemplo n.º 33
0
        static void DrawStar(ManualObject obj, float x, float y, int starPoints, float R, float r)
        {
            int i;
            float piOverStarPoints = 3.14159f / starPoints,
                   angle = 0.0f;

            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN;
            obj.Begin("CgTutorials/C2E2_green_Material", operation);
            obj.Position(x, y, 0.0f);  /* Center of star */
            /* Emit exterior vertices for star's points. */
            for (i = 0; i < starPoints; i++)
            {
                obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f);
                angle += piOverStarPoints;
                obj.Position(x + r * Math.Cos(angle), y + r * Math.Sin(angle), 0.0f);
                angle += piOverStarPoints;
            }
            /* End by repeating first exterior vertex of star. */
            angle = 0;
            obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f);
            obj.End();
        }
Exemplo n.º 34
0
        public static SceneNode DrawLine(SceneManager mSceneMgr, Vector3 start, Vector3 end)
        {
            ManualObject line     = mSceneMgr.CreateManualObject("line" + numLines);
            SceneNode    lineNode = mSceneMgr.RootSceneNode.CreateChildSceneNode("line" + numLines + "_node");

            MaterialPtr lineMaterial = MaterialManager.Singleton.Create("line" + numLines + "_material", "Default");

            lineMaterial.ReceiveShadows = false;
            lineMaterial.SetLightingEnabled(true);
            lineMaterial.SetDiffuse(LineColour.r, LineColour.g, LineColour.b, 0);
            lineMaterial.SetAmbient(LineColour.r, LineColour.g, LineColour.b);
            lineMaterial.SetSelfIllumination(LineColour.r, LineColour.g, LineColour.b);

            line.Begin("line" + numLines + "_material", RenderOperation.OperationTypes.OT_LINE_LIST);
            line.Position(start);
            line.Position(end);
            line.End();

            lineNode.AttachObject(line);
            ++numLines;
            return(lineNode);
        }
Exemplo n.º 35
0
        public ManualObject CreateNode(string name, SceneManager sceneMgr, bool useScreenPos)
        {
            ManualObject manualObj = sceneMgr.CreateManualObject(name);

            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_LIST;

            if (useScreenPos)
            {
                manualObj.Begin("CgTutorials/C2E1v_green_Material", operation);
            }
            else
            {
                manualObj.Begin("CgTutorials/C2E1v_green_Material_2", operation);
            }

            manualObj.Position(-0.5f, 0.0f, 0.0f);
            manualObj.Position(0.5f, 0.0f, 0.0f);
            manualObj.Position(0.0f, 0.5f, 0.0f);

            manualObj.End();

            return(manualObj);
        }
Exemplo n.º 36
0
        public void BuildPlane(string materialName, ref SceneManager mSceneMgr)
        {
            float z = planeWidth / 2;
            float y = planeHeight / 2;
            float x = -40f;

            ManualObject cube = mSceneMgr.CreateManualObject(planeName);

            cube.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(x, -y, -z);
            cube.TextureCoord(1, 1);
            cube.Position(x, y, -z);
            cube.TextureCoord(1, 0);
            cube.Position(x, y, z);
            cube.TextureCoord(0, 0);
            cube.Position(x, -y, z);
            cube.TextureCoord(0, 1);

//
//             cube.Triangle(0, 2, 1);
//             cube.Triangle(0, 2, 3);
            cube.End();
        }
Exemplo n.º 37
0
        /// <summary>
        /// Helper method to render a composite map.
        /// </summary>
        /// <param name="size"> The requested composite map size</param>
        /// <param name="rect"> The region of the composite map to update, in image space</param>
        /// <param name="mat">The material to use to render the map</param>
        /// <param name="destCompositeMap"></param>
        public virtual void RenderCompositeMap(int size, Rectangle rect,
            Material mat, Texture destCompositeMap)
        {
            //return;
            if (mCompositeMapSM == null)
            {
                //dedicated SceneManager

                mCompositeMapSM = Root.Instance.CreateSceneManager(SceneType.ExteriorClose, "TerrainMaterialGenerator_SceneManager");
                float camDist = 100;
                float halfCamDist = camDist * 0.5f;
                mCompositeMapCam = mCompositeMapSM.CreateCamera("TerrainMaterialGenerator_Camera");
                mCompositeMapCam.Position = new Vector3(0, 0, camDist);
                //mCompositeMapCam.LookAt(Vector3.Zero);
                mCompositeMapCam.ProjectionType = Projection.Orthographic;
                mCompositeMapCam.Near = 10;
                mCompositeMapCam.Far = 999999* 3;
                //mCompositeMapCam.AspectRatio = camDist / camDist;
                mCompositeMapCam.SetOrthoWindow(camDist, camDist);
                // Just in case material relies on light auto params
                mCompositeMapLight = mCompositeMapSM.CreateLight("TerrainMaterialGenerator_Light");
                mCompositeMapLight.Type = LightType.Directional;

                RenderSystem rSys = Root.Instance.RenderSystem;
                float hOffset = rSys.HorizontalTexelOffset / (float)size;
                float vOffset = rSys.VerticalTexelOffset / (float)size;

                //setup scene
                mCompositeMapPlane = mCompositeMapSM.CreateManualObject("TerrainMaterialGenerator_ManualObject");
                mCompositeMapPlane.Begin(mat.Name, OperationType.TriangleList);
                mCompositeMapPlane.Position(-halfCamDist, halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(0 - hOffset, 0 - vOffset);
                mCompositeMapPlane.Position(-halfCamDist, -halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(0 - hOffset, 1 - vOffset);
                mCompositeMapPlane.Position(halfCamDist, -halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(1 - hOffset, 1 - vOffset);
                mCompositeMapPlane.Position(halfCamDist, halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(1 - hOffset, 0 - vOffset);
                mCompositeMapPlane.Quad(0, 1, 2, 3);
                mCompositeMapPlane.End();
                mCompositeMapSM.RootSceneNode.AttachObject(mCompositeMapPlane);
            }//end if

            // update
            mCompositeMapPlane.SetMaterialName(0, mat.Name);
            mCompositeMapLight.Direction = TerrainGlobalOptions.LightMapDirection;
            mCompositeMapLight.Diffuse = TerrainGlobalOptions.CompositeMapDiffuse;
            mCompositeMapSM.AmbientLight =TerrainGlobalOptions.CompositeMapAmbient;
            

            //check for size change (allow smaller to be reused)
            if (mCompositeMapRTT != null && size != mCompositeMapRTT.Width)
            {
                TextureManager.Instance.Remove(mCompositeMapRTT);
                mCompositeMapRTT = null;
            }
            if (mCompositeMapRTT == null)
            {
                mCompositeMapRTT = TextureManager.Instance.CreateManual(
                    mCompositeMapSM.Name + "/compRTT",
                    ResourceGroupManager.DefaultResourceGroupName,
                    TextureType.TwoD,
                    size,
                    size,
                    0,
                    PixelFormat.BYTE_RGBA,
                    TextureUsage.RenderTarget);

                RenderTarget rtt = mCompositeMapRTT.GetBuffer().GetRenderTarget();
                // don't render all the time, only on demand
                rtt.IsAutoUpdated = false;
                Viewport vp = rtt.AddViewport(mCompositeMapCam);
                // don't render overlays
                vp.ShowOverlays = false;
            }

            // calculate the area we need to update
            float vpleft = (float)rect.Left / (float)size;
            float vptop = (float)rect.Top / (float)size;
            float vpright = (float)rect.Right / (float)size;
            float vpbottom = (float)rect.Bottom / (float)size;
            float vpwidth = (float)rect.Width / (float)size;
            float vpheight = (float)rect.Height / (float)size;

            RenderTarget rtt2 = mCompositeMapRTT.GetBuffer().GetRenderTarget();
            Viewport vp2 = rtt2.GetViewport(0);
            mCompositeMapCam.SetWindow(vpleft, vptop, vpright, vpbottom);
            rtt2.Update();
            vp2.Update();
            // We have an RTT, we want to copy the results into a regular texture
            // That's because in non-update scenarios we don't want to keep an RTT
            // around. We use a single RTT to serve all terrain pages which is more
            // efficient.
            BasicBox box = new BasicBox((int)rect.Left, (int)rect.Top, (int)rect.Right, (int)rect.Bottom);
            destCompositeMap.GetBuffer().Blit(mCompositeMapRTT.GetBuffer(), box, box);
        }
Exemplo n.º 38
0
        private void DrawLine(ManualObject manualObject, int index0, int index1, ColourValue colour)
        {
            Vector3 p0 = corners[index0];
            Vector3 p1 = corners[index1];
            float length = (p1 - p0).Length;

            manualObject.Position(p0);
            manualObject.Colour(colour);
            manualObject.TextureCoord(0);

            manualObject.Position(p1);
            manualObject.Colour(colour);
            manualObject.TextureCoord(length);
        }
Exemplo n.º 39
0
			public DebugRenderable( Node parent )
			{
				_parent = parent;

				string materialName = "Axiom/Debug/AxesMat";
				_material = (Material)MaterialManager.Instance[ materialName ];
				if ( _material == null )
				{
					_material = (Material)MaterialManager.Instance.Create( materialName, ResourceGroupManager.InternalResourceGroupName );
					Pass p = _material.GetTechnique( 0 ).GetPass( 0 );
					p.LightingEnabled = false;
					//TODO: p.PolygonModeOverrideable = false;
					p.VertexColorTracking = TrackVertexColor.Ambient;
					p.SetSceneBlending( SceneBlendType.TransparentAlpha );
					p.CullingMode = CullingMode.None;
					p.DepthWrite = false;
				}

				string meshName = "Axiom/Debug/AxesMesh";
				_mesh = MeshManager.Instance[ meshName ];
				if ( _mesh == null )
				{
					ManualObject mo = new ManualObject( "tmp" );
					mo.Begin( Material.Name, OperationType.TriangleList );
					/* 3 axes, each made up of 2 of these (base plane = XY)
					 *   .------------|\
					 *   '------------|/
					 */
					mo.EstimateVertexCount( 7 * 2 * 3 );
					mo.EstimateIndexCount( 3 * 2 * 3 );
					Quaternion[] quat = new Quaternion[ 6 ];
					ColorEx[] col = new ColorEx[ 3 ];

					// x-axis
					quat[ 0 ] = Quaternion.Identity;
					quat[ 1 ] = Quaternion.FromAxes( Vector3.UnitX, Vector3.NegativeUnitZ, Vector3.UnitY );
					col[ 0 ] = ColorEx.Red;
					col[ 0 ].a = 0.8f;
					// y-axis
					quat[ 2 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.NegativeUnitX, Vector3.UnitZ );
					quat[ 3 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.UnitZ, Vector3.UnitX );
					col[ 1 ] = ColorEx.Green;
					col[ 1 ].a = 0.8f;
					// z-axis
					quat[ 4 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitY, Vector3.NegativeUnitX );
					quat[ 5 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitX, Vector3.UnitY );
					col[ 2 ] = ColorEx.Blue;
					col[ 2 ].a = 0.8f;

					Vector3[] basepos = new Vector3[ 7 ]  
										{
											// stalk
											new Vector3(0f, 0.05f, 0f), 
											new Vector3(0f, -0.05f, 0f),
											new Vector3(0.7f, -0.05f, 0f),
											new Vector3(0.7f, 0.05f, 0f),
											// head
											new Vector3(0.7f, -0.15f, 0f),
											new Vector3(1f, 0f, 0f),
											new Vector3(0.7f, 0.15f, 0f)
										};


					// vertices
					// 6 arrows
					for ( int i = 0; i < 6; ++i )
					{
						// 7 points
						for ( int p = 0; p < 7; ++p )
						{
							Vector3 pos = quat[ i ] * basepos[ p ];
							mo.Position( pos );
							mo.Color( col[ i / 2 ] );
						}
					}

					// indices
					// 6 arrows
					for ( int i = 0; i < 6; ++i )
					{
						ushort baseIndex = (ushort)( i * 7 );
						mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 1 ), (ushort)( baseIndex + 2 ) );
						mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 2 ), (ushort)( baseIndex + 3 ) );
						mo.Triangle( (ushort)( baseIndex + 4 ), (ushort)( baseIndex + 5 ), (ushort)( baseIndex + 6 ) );
					}

					mo.End();

					_mesh = mo.ConvertToMesh( meshName, ResourceGroupManager.InternalResourceGroupName );
				}
			}
Exemplo n.º 40
0
 //    *
 //	 * Appends the shape vertices to a manual object being edited
 //	 
 //-----------------------------------------------------------------------
 //
 //ORIGINAL LINE: void _appendToManualObject(ManualObject* manual) const
 public void _appendToManualObject(ManualObject manual) {
     //for (List<Vector2>.Enumerator itPos = mPoints.GetEnumerator(); itPos.MoveNext(); itPos++)
     foreach (var itPos in mPoints) {
         manual.Position(new Vector3(itPos.x, itPos.y, 0.0f));
     }
     if (mClosed) {
         //manual.Position(new Vector3(mPoints.GetEnumerator().x, mPoints.GetEnumerator().y, 0.0f));
         manual.Position(new Vector3(mPoints[0].x, mPoints[0].y, 0f));
     }
 }
Exemplo n.º 41
0
        /// <summary>
        /// This private method defines the vertex and index buffers of a quad as a triangle list.
        /// </summary>
        private MeshPtr Quad()
        {
            manualObj = mSceneMgr.CreateManualObject("maualObjQuad");
            manualObj.Begin("void", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);    // Starts filling the manual object as a triangle list

            // ---- Vertex Buffer ----
            manualObj.Position(new Vector3(5, 5, 0));               // --- Vertex 0 ---
            manualObj.Position(new Vector3(-5, 5, 0));              // --- Vertex 1 ---
            manualObj.Position(new Vector3(5, -5, 0));              // --- Vertex 2 ---
            manualObj.Position(new Vector3(-5, -5, 0));             // --- Vertex 3 ---

            // ---- Index Buffer ----
            // --- Triangle 0 ---
            manualObj.Index(0);
            manualObj.Index(1);
            manualObj.Index(2);

            // --- Triangle 1 ---
            manualObj.Index(1);
            manualObj.Index(3);
            manualObj.Index(2);

            manualObj.End();                                        // Closes the manual objet

            return manualObj.ConvertToMesh("Quad");                 // Prepares the data to be sent to the GPU
        }
    public void Initialise(SceneManager aSceneManager, float aFillAlpha)
    {
        if (isInitialised) {
            // Initialization multiple call guard
            return;
        }

        if (aSceneManager == null) {
            return;
        }

        m_sceneManager = aSceneManager;
        fillAlpha = aFillAlpha;
        m_manualObject = null;
        linesIndex = 0;
        trianglesIndex = 0;

        m_manualObject = m_sceneManager.CreateManualObject("debugDrawer_object");
        m_manualObject.CastShadows = false;

        m_sceneManager.RootSceneNode.CreateChildSceneNode("debugDrawer_object").AttachObject(m_manualObject);
        m_manualObject.Dynamic = (true);

        icoSphere.Create(this.DEFAULT_ICOSPHERE_RECURSION_LEVEL);

        m_manualObject.Begin("debug_draw", RenderOperation.OperationTypes.OT_LINE_LIST);
        m_manualObject.Position(Vector3.ZERO);
        m_manualObject.Colour(ColourValue.ZERO);
        m_manualObject.Index(0);
        m_manualObject.End();
        m_manualObject.Begin("debug_draw", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
        m_manualObject.Position(Vector3.ZERO);
        m_manualObject.Colour(ColourValue.ZERO);
        m_manualObject.Index(0);
        m_manualObject.End();

        trianglesIndex = 0;
        linesIndex = trianglesIndex;

        isInitialised = true;
        // Initialization multiple call guard
    }
Exemplo n.º 43
0
        static ManualObject.ManualObjectSection BuildTerrainBlock(ManualObject obj, ushort pointsX, ushort pointsY,
            Vector4 translationScale, Vector4 color)
        {
            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_STRIP;

            obj.Begin("Terrain/Terrain_Material", operation);
            /*
             * This function uses one big zigzag triangle strip for the whole grid.
             * And insert degenerated (invisible) triangles to join 2 rows. For instance:
             * 0  1  2  3
             * 4  5  6  7
             * 8  9  10 11
             * 12 13 14 15
             *
             * The index buffer would look like :
             * 0, 4, 1, 5, 2, 6, 3, 7, 7, 7, 11, 6, 10, 5, 9, 4, 8, 8, 8, 12, 9, 13, 10, 14, 11, 15
             */
            for (int y = pointsY - 1; y >= 0; y--)
            {
                for (int x = 0; x <= pointsX - 1; x++)
                {
                    obj.Position(x, y, 0.0f);
                    obj.TextureCoord((float)x / (float)(pointsX), (float)y / (float)(pointsY));
                }
            }
            //Console.Write("\n Index:");
            // We have pointsX -1 lines
            for (ushort y = 0; y < pointsY - 1; y++)
            {
                if (y % 2 == 0)
                {
                    for (int x = 0; x < pointsX; x++)
                    {
                        obj.Index((ushort)(y * pointsX + x));            //(x, y + 1, 0.0f);
                        //Console.Write("," + (y * pointsX + x));
                        obj.Index((ushort)(y * pointsX + x + pointsX));  //(x, y, 0.0f);
                        //Console.Write("," + (y * pointsX + x + pointsX));

                    }

                    if (y != pointsY - 2)
                    {
                        obj.Index((ushort)(y * pointsX + pointsX - 1));         //(0, y+1, 0.0f);
                        //Console.Write("," + (y * pointsX + 2 * pointsX - 1));
                    }
                }
                else
                {
                    for (int x = pointsX - 1; x >= 0; x--)
                    {
                        obj.Index((ushort)(y * pointsX + x));           //(x, y + 1, 0.0f);
                        //Console.Write(", " + (y * pointsX + x));
                        obj.Index((ushort)(y * pointsX + x + pointsX));  //(x, y, 0.0f);
                        //Console.Write(", " + (y * pointsX + x + pointsX));
                    }
                    if (y != pointsY - 2)
                    {
                        obj.Index((ushort)(y * pointsX + pointsX));         //(0, y+1, 0.0f);
                        //Console.Write(", " + (y * pointsX + pointsX));
                    }

                }
            }
            //Console.WriteLine(";");
            ManualObject.ManualObjectSection manualObjSec1 = obj.End();
            obj.BoundingBox = new AxisAlignedBox(translationScale.x,
                                                 translationScale.y, -1,
                                                (pointsX * translationScale.z + translationScale.x),
                                                (pointsY * translationScale.w + translationScale.y), 1);
            manualObjSec1.SetCustomParameter(TransXYscaleXY, translationScale);
            manualObjSec1.SetCustomParameter(ColorAndHeightScale, color);
            return manualObjSec1;
        }
Exemplo n.º 44
0
        private void CreateLine(ManualObject mo, Vector3 origin, Vector3 final, int useMaterial, Vector4 color)
        {
            float lineWidth = 0.1f;

            RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN;
            switch (useMaterial)
            {
                case 1:
                    mo.Begin("SharpMap/Line3D_v1", operation);
                    break;
                default:
                    MaterialPtr material = MaterialManager.Singleton.CreateOrRetrieve("Test/ColourLines3d",
                                                                            ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).first;
                    material.GetTechnique(0).GetPass(0).VertexColourTracking =
                                   (int)TrackVertexColourEnum.TVC_AMBIENT;
                    mo.Begin("Test/ColourLines3d", operation);

                    break;
            }

            Vector3 delta = final - origin;
            delta = new Vector3(-delta.y, delta.x, delta.z).NormalisedCopy * lineWidth;
            mo.Position(origin);
            mo.Position(final);
            mo.Position(final + delta);
            mo.Position(origin + delta);
            //lines3d.TextureCoord((float)i / (float)pointsList.Count);

            ManualObject.ManualObjectSection section = lines3d.End();
            section.SetCustomParameter(constantColor, color);
        }
Exemplo n.º 45
0
        public static ManualObject CreateTetrahedron3(String name, Mogre.Vector3 position, Single scale, String materialName)
        {
            ManualObject manObTetra = new ManualObject(name);
            manObTetra.CastShadows = false;

            // render just before overlays (so all objects behind the transparent tetrahedron are visible)
            manObTetra.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_OVERLAY - 1; // = 99

            Mogre.Vector3[] c = new Mogre.Vector3[4]; // corners

            // calculate corners of tetrahedron (with point of origin in middle of volume)
            Single mbot = scale * 0.2f;      // distance middle to bottom
            Single mtop = scale * 0.62f;     // distance middle to top    
            Single mf = scale * 0.289f;    // distance middle to front
            Single mb = scale * 0.577f;    // distance middle to back
            Single mlr = scale * 0.5f;      // distance middle to left right 
            //               width / height / depth
            c[0] = new Mogre.Vector3(-mlr, -mbot, mf);  // left bottom front
            c[1] = new Mogre.Vector3(mlr, -mbot, mf);  // right bottom front
            c[2] = new Mogre.Vector3(0, -mbot, -mb);  // (middle) bottom back
            c[3] = new Mogre.Vector3(0, mtop, 0);  // (middle) top (middle)

            // add position offset for all corners (move tetrahedron)
            for (Int16 i = 0; i <= 3; i++)
                c[i] += position;

            // create bottom
            manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manObTetra.Position(c[2]);
            manObTetra.Position(c[1]);
            manObTetra.Position(c[0]);
            manObTetra.Triangle(0, 1, 2);
            manObTetra.End();
            // create right back side
            manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manObTetra.Position(c[1]);
            manObTetra.Position(c[2]);
            manObTetra.Position(c[3]);
            manObTetra.Triangle(0, 1, 2);
            manObTetra.End();
            // create left back side
            manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manObTetra.Position(c[3]);
            manObTetra.Position(c[2]);
            manObTetra.Position(c[0]);
            manObTetra.Triangle(0, 1, 2);
            manObTetra.End();
            // create front side
            manObTetra.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manObTetra.Position(c[0]);
            manObTetra.Position(c[1]);
            manObTetra.Position(c[3]);
            manObTetra.Triangle(0, 1, 2);
            manObTetra.End();
            return manObTetra;

        } // CreateTetrahedron
Exemplo n.º 46
0
        public void Initialise() {
            manualObject = sceneManager.CreateManualObject("debug_object");
            sceneManager.RootSceneNode.CreateChildSceneNode("debug_object").AttachObject(manualObject);
            manualObject.Dynamic = true;

            _icoSphere.create(DEFAULT_ICOSPHERE_RECURSION_LEVEL);

            manualObject.Begin("debug_draw", RenderOperation.OperationTypes.OT_LINE_LIST);
            manualObject.Position(Vector3.ZERO);
            manualObject.Colour(ColourValue.ZERO);
            manualObject.Index(0);
            manualObject.End();
            manualObject.Begin("debug_draw", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manualObject.Position(Vector3.ZERO);
            manualObject.Colour(ColourValue.ZERO);
            manualObject.Index(0);
            manualObject.End();

            trianglesIndex = 0;
            linesIndex = trianglesIndex;
        }
Exemplo n.º 47
0
        public static void generateFace()
        {
            string defaultMaterial = "Default";

            ManualObject block = new ManualObject("frontFace");
            block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            block.Position(new Vector3(0, 0, 0));                                     block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[0]);
            block.Position(new Vector3(0, Cst.CUBE_SIDE, 0));                   block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[0]);
            block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[0]);
            block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0)); block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[0]);

            block.Quad(3, 2, 1, 0);
            block.End();
            block.ConvertToMesh("frontFace");

            block = new ManualObject("underFace");
            block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            block.Position(new Vector3(0, 0, 0));                                      block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[1]);
            block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE));                   block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[1]);
            block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[1]);
            block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0));                    block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[1]);

            block.Quad(0, 1, 2, 3);
            block.End();
            block.ConvertToMesh("underFace");

            block = new ManualObject("rightFace");
            block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            block.Position(new Vector3(Cst.CUBE_SIDE, 0, 0));                                      block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[2]);
            block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE));                   block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[2]);
            block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[2]);
            block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0));                    block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[2]);

            block.Quad(0, 1, 2, 3);
            block.End();
            block.ConvertToMesh("rightFace");

            block = new ManualObject("upperFace");
            block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, 0));                    block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[3]);
            block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[3]);
            block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE));                   block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[3]);
            block.Position(new Vector3(0, Cst.CUBE_SIDE, 0));                                      block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[3]);

            block.Quad(0, 1, 2, 3);
            block.End();
            block.ConvertToMesh("upperFace");

            block = new ManualObject("leftFace");
            block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            block.Position(new Vector3(0, 0, 0));                                      block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[4]);
            block.Position(new Vector3(0, Cst.CUBE_SIDE, 0));                    block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[4]);
            block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[4]);
            block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE));                   block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[4]);

            block.Quad(0, 1, 2, 3);
            block.End();
            block.ConvertToMesh("leftFace");

            block = new ManualObject("backFace");
            block.Begin(defaultMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            block.Position(new Vector3(0, 0, -Cst.CUBE_SIDE));                                     block.TextureCoord(1, 1); block.Normal(VanillaMultiBlock.normals[5]);
            block.Position(new Vector3(0, Cst.CUBE_SIDE, -Cst.CUBE_SIDE));                   block.TextureCoord(1, 0); block.Normal(VanillaMultiBlock.normals[5]);
            block.Position(new Vector3(Cst.CUBE_SIDE, Cst.CUBE_SIDE, -Cst.CUBE_SIDE)); block.TextureCoord(0, 0); block.Normal(VanillaMultiBlock.normals[5]);
            block.Position(new Vector3(Cst.CUBE_SIDE, 0, -Cst.CUBE_SIDE));                   block.TextureCoord(0, 1); block.Normal(VanillaMultiBlock.normals[5]);

            block.Quad(0, 1, 2, 3);
            block.End();
            block.ConvertToMesh("backFace");
        }
Exemplo n.º 48
0
        static void DisplayRectangle(Vector3 origin, int height, int width, int depth, SceneNode node)
        {
            ManualObject block = new ManualObject(Guid.NewGuid().ToString());
            block.Begin("cube/Sand", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            Vector2[] textureCoord =
                new Vector2[] {
                    new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0),
                    new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 1),
                    new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0),
                    new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0),
                    new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 1),
                    new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 0)
                };

            Vector3[] blockPointCoords =
            new Vector3[] {
                new Vector3(0, height, 0),            new Vector3(0, 0, 0),                       new Vector3(width, 0, 0),                new Vector3(width, height, 0),
                new Vector3(0, 0, -depth),            new Vector3(0, height, -depth),             new Vector3(width, height, -depth),      new Vector3(width, 0, -depth),
                new Vector3(width, height, 0),        new Vector3(width, height, -depth),         new Vector3(0, height, -depth),          new Vector3(0, height, 0),
                new Vector3(0, 0, 0),                 new Vector3(0, 0, -depth),                  new Vector3(width, 0, -depth),           new Vector3(width, 0, 0),
                new Vector3(0, 0, 0),                 new Vector3(0, height, 0),                  new Vector3(0, height, -depth),          new Vector3(0, 0, -depth),
                new Vector3(width, 0, 0),             new Vector3(width, 0, -depth),              new Vector3(width, height, -depth),      new Vector3(width, height, 0),
            };
            int a = 0;
            for(int i = 0; i < 6; i++) {
                for(int j = 0; j < 4; j++) {
                    block.Position(origin + blockPointCoords[j * 4 + i]); block.TextureCoord(textureCoord[j * 4 + i]);
                    a++;
                }
                block.Quad((uint)a-4, (uint)a-3, (uint)a-2, (uint)a-1);
            }

            block.End();
            node.AttachObject(block);
        }