Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
        // creates a simple box with specified material
        public static MovableObject MakeBox(SceneManager mgr, String materialName, Vector3 dims, Vector2 coord)
        {
            ManualObject mo = mgr.CreateManualObject();

            mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            float w = dims.x * 0.5f;
            float h = dims.y * 0.5f;
            float d = dims.z * 0.5f;

            Vector3[] norm =
            {
                new Vector3(1.0f,   0.0f, 0.0f),
                new Vector3(0.0f,   1.0f, 0.0f),
                new Vector3(0.0f,   0.0f, 1.0f),
                new Vector3(-1.0f,  0.0f, 0.0f),
                new Vector3(0.0f,  -1.0f, 0.0f),
                new Vector3(0.0f,   0.0f, -1.0f)
            };

            Vector3[] geom =   // 6 faces x 4 vertexes
            {
                new Vector3(+w, -h, +d), new Vector3(+w, -h, -d), new Vector3(+w, +h, -d), new Vector3(+w, +h, +d),
                new Vector3(+w, +h, +d), new Vector3(+w, +h, -d), new Vector3(-w, +h, -d), new Vector3(-w, +h, +d),
                new Vector3(+w, +h, +d), new Vector3(-w, +h, +d), new Vector3(-w, -h, +d), new Vector3(+w, -h, +d),
                new Vector3(-w, -h, +d), new Vector3(-w, +h, +d), new Vector3(-w, +h, -d), new Vector3(-w, -h, -d),
                new Vector3(-w, -h, +d), new Vector3(-w, -h, -d), new Vector3(+w, -h, -d), new Vector3(+w, -h, +d),
                new Vector3(-w, -h, -d), new Vector3(-w, +h, -d), new Vector3(+w, +h, -d), new Vector3(+w, -h, -d)
            };

            // texcoords
            Vector2[] uvs = { new Vector2(0, 0), new Vector2(0, coord.y), coord, new Vector2(coord.x, 0) };

            for (int i = 0; i < 6; i++) // 6 faces
            {
                uint k = (uint)(i * 4);
                for (int j = 0; j < 4; j++) // 4 verts
                {
                    mo.Position(geom[k + j]);
                    mo.Normal(norm[i]);
                    mo.TextureCoord(uvs[j]);
                }
                mo.Quad(k, k + 1, k + 2, k + 3);
            }

            mo.End();

            return(mo);
        }
Exemplo n.º 13
0
        public VideoTexture(SceneManager scm, float width, float height, string aviFileName)
        {
            AviManager aviMgr = new AviManager(aviFileName, true);

            Stream = aviMgr.GetVideoStream();

            TexturePtr VideoTexture = TextureManager.Singleton.CreateManual(
                "Video",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                TextureType.TEX_TYPE_2D, Convert.ToUInt32(Stream.Width), Convert.ToUInt32(Stream.Height), 0, PixelFormat.PF_R8G8B8A8, (int)TextureUsage.TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
            MaterialPtr VideoMat = MaterialManager.Singleton.Create(
                "VideoMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);

            VideoMat.GetTechnique(0).GetPass(0).LightingEnabled = false;
            VideoMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("Video");

            PixelBuffer = VideoTexture.GetBuffer();

            screen         = scm.CreateManualObject("Screen");
            screen.Dynamic = true;
            screen.Begin("VideoMat", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            screen.Position(0, 0, 0);
            screen.TextureCoord(0, 0);

            screen.Position(width, 0, 0);
            screen.TextureCoord(1, 0);

            screen.Position(width, height, 0);
            screen.TextureCoord(1, 1);

            screen.Triangle(0, 1, 2);

            screen.Position(0, 0, 0);
            screen.TextureCoord(0, 0);

            screen.Position(width, height, 0);
            screen.TextureCoord(1, 1);

            screen.Position(0, height, 0);
            screen.TextureCoord(0, 1);

            screen.Triangle(3, 4, 5);

            screen.End();

            SceneNode node = scm.RootSceneNode.CreateChildSceneNode();

            node.Position = new Vector3(0, 0, 0);
            node.AttachObject(screen);

            Stream.GetFrameOpen();
            FrameNum = 0;
        }
Exemplo n.º 14
0
            public void vertex(object vertexData)
            {
#if TESSELLATION_TRACE
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod() + " vertex=" + vertexData);
#endif
                manualObj.Position((Vector3)vertexData);
                manualObj.TextureCoord(((Vector3)vertexData).x * materialScale.x, ((Vector3)vertexData).z * materialScale.y);
                if (vec3 != null)
                {
                    Vector3 v = Registry.instance().GetEngine("Python").run(vec3, feature, null).asVec3();
                    manualObj.Colour(v.x, v.y, v.z);
                }
                //if (Material != null)
                //{
                //    manualObj.TextureCoord(0);
                //}
            }
Exemplo n.º 15
0
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="PtList"></param>
        public DrawLine3DClass(List <Vector3> PtList, string ColorMaterial, string name)
        {
            ogreimage = EsdSceneManager.Singleton.OgreImage;
            esmanager = EsdSceneManager.Singleton;

            this.ColorMaterial = ColorMaterial;
            this.ptlist        = PtList;
            ManualLineObject   = ogreimage.SceneManager.CreateManualObject(name);

            ManualLineObject.Begin(ColorMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_FAN);

            foreach (Vector3 pt in PtList)
            {
                ManualLineObject.Position(pt);
                ManualLineObject.TextureCoord(pt.x / 100, pt.y / 100);
            }

            ManualLineObject.End();
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        ///private MeshPtr Quad()
        public MeshPtr Quad()
        {
            cube = mSceneMgr.CreateManualObject("fieldQuad");
            cube.Begin("void", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            cube.Position(new Vector3(20f, 20f, 20f)); // Vector 0
            cube.TextureCoord(new Vector2(0, 0));

            cube.Position(new Vector3(20f, -20f, 20f)); // Vector 1
            cube.TextureCoord(new Vector2(1, 0));

            cube.Position(new Vector3(20f, 20f, -20f)); // Vector 2
            cube.TextureCoord(new Vector2(0, 1));

            cube.Position(new Vector3(20f, -20f, -20f)); // Vector 3
            cube.TextureCoord(new Vector2(1, 1));

            cube.Position(new Vector3(-20f, 20f, 20f)); // Vector 4
            cube.TextureCoord(new Vector2(0, 0));

            cube.Position(new Vector3(-20f, -20f, 20f)); // Vector 5
            cube.TextureCoord(new Vector2(0, 1));

            cube.Position(new Vector3(-20f, 20f, -20f)); // Vector 6
            cube.TextureCoord(new Vector2(1, 0));

            cube.Position(new Vector3(-20f, -20f, -20f)); // Vector 7
            cube.TextureCoord(new Vector2(1, 1));

            // Index Buffer

            // Triangle 0
            cube.Index(0);
            cube.Index(1);
            cube.Index(2);

            // Triangle 1
            cube.Index(2);
            cube.Index(1);
            cube.Index(3);

            // Triangle 2
            cube.Index(4);
            cube.Index(6);
            cube.Index(5);

            // Triangle 3
            cube.Index(6);
            cube.Index(7);
            cube.Index(5);

            // Triangle 4
            cube.Index(0);
            cube.Index(4);
            cube.Index(1);

            // Triangle 5
            cube.Index(1);
            cube.Index(4);
            cube.Index(5);

            // Triangle 6
            cube.Index(0);
            cube.Index(6);
            cube.Index(4);

            // Triangle 7
            cube.Index(0);
            cube.Index(2);
            cube.Index(6);

            // Triangle 8
            cube.Index(6);
            cube.Index(2);
            cube.Index(3);

            // Triangle 9
            cube.Index(6);
            cube.Index(3);
            cube.Index(7);

            // Triangle 9
            cube.Index(3);
            cube.Index(1);
            cube.Index(7);

            cube.Index(1);
            cube.Index(5);
            cube.Index(7);

            cube.End();

            return(cube.ConvertToMesh("Quad"));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Buduje quada o wymaganych parametrach. Quad bedzie mogl byc wyswietlony w przestrzeni 3D. Ma nakladn¹ teksture wg textureName
        /// </summary>
        /// <param name="quadrangle"></param>
        /// <param name="origin"></param>
        /// <param name="textureName"></param>
        public void SetCorners3D(Quadrangle quadrangle, Vector3 origin, String textureName)
        {
            this.quadrangle = quadrangle;
            Vector2 leftBottom  = quadrangle.Peaks[0].ToVector2();
            Vector2 leftTop     = quadrangle.Peaks[1].ToVector2();
            Vector2 rightTop    = quadrangle.Peaks[2].ToVector2();
            Vector2 rightBottom = quadrangle.Peaks[3].ToVector2();

            float extend = 1.25f;


            corners       = new float[4][];
            corners[0]    = new float[3];
            corners[0][0] = extend * rightBottom.x + origin.x;
            corners[0][1] = extend * rightBottom.y + origin.y;
            corners[0][2] = origin.z;


            corners[1]    = new float[3];
            corners[1][0] = extend * rightTop.x + origin.x;
            corners[1][1] = extend * rightTop.y + origin.y;
            corners[1][2] = origin.z;


            corners[2]    = new float[3];
            corners[2][0] = extend * leftTop.x + origin.x;
            corners[2][1] = extend * leftTop.y + origin.y;
            corners[2][2] = origin.z;


            corners[3]    = new float[3];
            corners[3][0] = extend * leftBottom.x + origin.x;
            corners[3][1] = extend * leftBottom.y + origin.y;
            corners[3][2] = origin.z;


            float textureTop    = 0;
            float textureLeft   = 0;
            float textureBottom = 1;
            float textureRight  = 1;

            //      manualObject.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_MAIN - 1;

            manualObject.Clear();
            manualObject.Begin("Misc/BoundingQuadrangle", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manualObject.Position(origin.x + leftBottom.x, origin.y + leftBottom.y, origin.z);
            manualObject.TextureCoord(textureLeft, textureBottom);
            manualObject.Position(origin.x + leftTop.x, origin.y + leftTop.y, origin.z);
            manualObject.TextureCoord(textureLeft, textureTop);
            manualObject.Position(origin.x + rightTop.x, origin.y + rightTop.y, origin.z);
            manualObject.TextureCoord(textureRight, textureTop);
            manualObject.Position(origin.x + rightBottom.x, origin.y + rightBottom.y, origin.z);
            manualObject.TextureCoord(textureRight, textureBottom);

            /*    manualObject.Position( origin.x + leftBottom.x, origin.y + leftBottom.y,  origin.z);
             *  manualObject.TextureCoord(0, 0);*/
            manualObject.Quad(3, 2, 1, 0);
            manualObject.End();


/*
 *          AxisAlignedBox box = new AxisAlignedBox();
 *          float hwidth = 1.4f * (quadrangle.RightMostX - quadrangle.LeftMostX) * 0.5f;
 *          float hheight = 1.4f * (quadrangle.HighestY - quadrangle.LowestY) * 0.5f;
 *          box.SetMinimum(origin.x - hwidth, origin.y - hheight, origin.z - 10);
 *          box.SetMaximum(origin.x + hwidth, origin.y + hheight, origin.z + 10);
 *
 *          manualObject.BoundingBox = box;
 */
            MaterialPtr mat  = ViewHelper.CloneMaterial("AdMaterial", manualObject.Name + "AdMaterial");
            Pass        pass = mat.GetBestTechnique().GetPass(0);

            pass.DepthWriteEnabled = true;
            pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);

            TextureUnitState state = pass.GetTextureUnitState(0);

            state.SetTextureName(textureName);

            manualObject.SetMaterialName(0, mat.Name);
            manualObject.CastShadows = false;
            OnSetCorners();
            //  manualObject.SetMaterialName(0, "Concrete");
        }
Exemplo n.º 19
0
        public void BuildCube(string materialName, ref SceneManager mSceneMgr)
        {
            ManualObject cube = mSceneMgr.CreateManualObject(cubeName);
            int          x    = cubeHeight / 2;
            int          y    = cubeWidth / 2;
            int          z    = cubeLength / 2;

            cube.Begin("other", RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(-x, -y, -z);  //0
            cube.TextureCoord(1, 0);
            cube.Position(x, -y, -z);   //1
            cube.TextureCoord(0, 0);
            cube.Position(x, -y, z);    //2
            cube.TextureCoord(0, 1);
            cube.Position(-x, -y, z);   //3
            cube.TextureCoord(1, 1);
            cube.End();

            /// 左面
            cube.Begin("other", RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(-x, -y, z);   //3
            cube.TextureCoord(1, 0);
            cube.Position(-x, y, z);    //7
            cube.TextureCoord(0, 0);
            cube.Position(-x, y, -z);   //4
            cube.TextureCoord(0, 1);
            cube.Position(-x, -y, -z);  //0
            cube.TextureCoord(1, 1);
            cube.End();

            /// 上面
            cube.Begin("other", RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(-x, y, -z);  //4
            cube.TextureCoord(1, 0);
            cube.Position(-x, y, z);   //7
            cube.TextureCoord(0, 0);
            cube.Position(x, y, z);    //6
            cube.TextureCoord(0, 1);
            cube.Position(x, y, -z);   //5
            cube.TextureCoord(1, 1);
            cube.End();

            /// 右面
            cube.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(x, -y, -z);  //1
            cube.TextureCoord(1, 1);
            cube.Position(x, y, -z);   //5
            cube.TextureCoord(1, 0);
            cube.Position(x, y, z);    //6
            cube.TextureCoord(0, 0);
            cube.Position(x, -y, z);   //2
            cube.TextureCoord(0, 1);
            cube.End();

            /// 前面
            cube.Begin("other", RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(x, -y, -z);   //1
            cube.TextureCoord(1, 0);
            cube.Position(-x, -y, -z);  //0
            cube.TextureCoord(0, 0);
            cube.Position(-x, y, -z);   //4
            cube.TextureCoord(0, 1);
            cube.Position(x, y, -z);    //5
            cube.TextureCoord(1, 1);
            cube.End();

            /// 后面
            cube.Begin("other", RenderOperation.OperationTypes.OT_TRIANGLE_FAN);
            cube.Position(x, -y, z);   //2
            cube.TextureCoord(1, 0);
            cube.Position(x, y, z);    //6
            cube.TextureCoord(0, 0);
            cube.Position(-x, y, z);   //7
            cube.TextureCoord(0, 1);
            cube.Position(-x, -y, z);  //3
            cube.TextureCoord(1, 1);
            cube.End();
        }
Exemplo n.º 20
0
        public MeshPtr getCube(string cubeName, string materialName, float width, float height, float depth)
        {
            cube = mSceneMgr.CreateManualObject(cubeName + "_ManObj");
            cube.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            // --- Fills the Vertex buffer and define the texture coordinates for each vertex ---

            //--- Vertex 0 ---
            cube.Position(new Vector3(.5f * width, .5f * height, .5f * depth));
            cube.TextureCoord(new Vector2(0, 0));
            //--- Vertex 1 ---
            cube.Position(new Vector3(.5f * width, -.5f * height, .5f * depth));
            cube.TextureCoord(new Vector2(1, 0));
            //--- Vertex 2 ---
            cube.Position(new Vector3(.5f * width, .5f * height, -.5f * depth));
            cube.TextureCoord(new Vector2(0, 1));
            //--- Vertex 3 ---
            cube.Position(new Vector3(.5f * width, -.5f * height, -.5f * depth));
            cube.TextureCoord(new Vector2(1, 1));

            //--- Vertex 4 ---
            cube.Position(new Vector3(-.5f * width, .5f * height, .5f * depth));
            cube.TextureCoord(new Vector2(0, 0));
            //--- Vertex 5 ---
            cube.Position(new Vector3(-.5f * width, -.5f * height, .5f * depth));
            cube.TextureCoord(new Vector2(1, 0));
            //--- Vertex 6 ---
            cube.Position(new Vector3(-.5f * width, .5f * height, -.5f * depth));
            cube.TextureCoord(new Vector2(0, 1));
            //--- Vertex 7 ---
            cube.Position(new Vector3(-.5f * width, -.5f * height, -.5f * depth));
            cube.TextureCoord(new Vector2(1, 1));

            // --- Fills the Index Buffer ---
            //--------Face 1----------
            cube.Index(0);
            cube.Index(1);
            cube.Index(2);

            cube.Index(2);
            cube.Index(1);
            cube.Index(3);

            //--------Face 2----------
            cube.Index(4);
            cube.Index(6);
            cube.Index(5);

            cube.Index(6);
            cube.Index(7);
            cube.Index(5);

            //--------Face 3----------
            cube.Index(0);
            cube.Index(4);
            cube.Index(1);

            cube.Index(1);
            cube.Index(4);
            cube.Index(5);

            //--------Face 4----------
            cube.Index(0);
            cube.Index(6);
            cube.Index(4);

            cube.Index(0);
            cube.Index(2);
            cube.Index(6);

            //--------Face 5----------
            cube.Index(6);
            cube.Index(2);
            cube.Index(3);

            cube.Index(6);
            cube.Index(3);
            cube.Index(7);

            //--------Face 5----------
            cube.Index(3);
            cube.Index(1);
            cube.Index(7);

            cube.Index(1);
            cube.Index(5);
            cube.Index(7);

            cube.End();
            return(cube.ConvertToMesh(cubeName));
        }
Exemplo n.º 21
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.º 22
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.º 23
0
        private SceneNode buildElement(DPOW.Reader.Element elem, string name)
        {
            if (mgr.HasSceneNode(name + "_node"))
            {
                return(mgr.GetSceneNode(name + "_node"));
            }

            SceneNode node = mgr.CreateSceneNode(name + "_node");

            node.SetPosition(elem.Position.X * 200, -elem.Position.Y * 200, -elem.Position.Z * 10);

            for (int i = 0; i < elem.Images.Length; i++)
            {
                string imgname = name + "_text" + i.ToString();

                SceneNode    textnode = node.CreateChildSceneNode(name + "_text" + i.ToString() + "_node", new Vector3(elem.Images[i].Position.X * 200, -elem.Images[i].Position.Y * 200, -elem.Images[i].Position.Z * 10));
                ManualObject manual   = mgr.CreateManualObject(name + "_text" + i.ToString());
                string       matname;
                matname = dpow.Textures[elem.Images[i].TextureId];
                // Build new material, if it's selected
                if (imgname == SelectedItem)
                {
                    matname = "Selected";
                }

                /*else
                 * {
                 *  MaterialPtr newmat = ((MaterialPtr)MaterialManager.Singleton.GetByName(matname, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)).Clone(imgname + "_mat");
                 *  matname = imgname + "_mat";
                 * }*/
                manual.Begin(matname, RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);

                for (int j = 0; j < elem.Images[i].Points.Length; j++)
                {
                    manual.Position(elem.Images[i].Points[j].X * 200, -elem.Images[i].Points[j].Y * 200, -elem.Images[i].Points[j].Z * 10);
                    manual.TextureCoord(elem.Images[i].Points[j].U, elem.Images[i].Points[j].V);
                    if (elem.Images[i].isGradient)
                    {
                        manual.Colour((float)elem.Images[i].Points[j].Color.R / 255, (float)elem.Images[i].Points[j].Color.G / 255, (float)elem.Images[i].Points[j].Color.B / 255, (float)elem.Images[i].Points[j].Color.A / 255);
                    }
                }

                manual.End();

                textnode.AttachObject(manual);
            }

            for (int i = 0; i < elem.Texts.Length; i++)
            {
                SceneNode strnode = node.CreateChildSceneNode(name + "_str" + i.ToString() + "_node", new Vector3(elem.Texts[i].Position.X * 200, -elem.Texts[i].Position.Y * 200, -elem.Texts[i].Position.Z * 10));

                ManualObject manual = mgr.CreateManualObject(name + "_str" + i.ToString());
                manual.Begin("String", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);

                float left   = 0;
                float right  = elem.Texts[i].Size.X * 200;
                float bottom = -elem.Texts[i].Size.Y * 200.0f;
                float top    = 0;
                manual.Position(left, bottom, 0);
                manual.Position(right, bottom, 0);
                manual.Position(left, top, 0);
                manual.Position(right, top, 0);

                manual.End();

                strnode.AttachObject(manual);
            }

            for (int i = 0; i < elem.Icons.Length; i++)
            {
                SceneNode flagnode = node.CreateChildSceneNode(name + "_flag" + i.ToString() + "_node", new Vector3(elem.Icons[i].Position.X * 200, -elem.Icons[i].Position.Y * 200, -elem.Icons[i].Position.Z * 10));

                ManualObject manual = mgr.CreateManualObject(name + "_flag" + i.ToString());
                manual.Begin("Flag", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);

                float left   = 0;
                float right  = elem.Icons[i].Size.X * 200;
                float bottom = -elem.Icons[i].Size.Y * 200.0f;
                float top    = 0;
                if (elem.Icons[i].WTF == 0)
                {
                    left   = -elem.Icons[i].Size.X / 2 * 200;
                    right  = elem.Icons[i].Size.X / 2 * 200;
                    bottom = -elem.Icons[i].Size.Y / 2 * 200.0f;
                    top    = elem.Icons[i].Size.Y / 2 * 200.0f;
                }
                manual.Position(left, bottom, 0);
                manual.Position(right, bottom, 0);
                manual.Position(left, top, 0);
                manual.Position(right, top, 0);

                manual.End();

                flagnode.AttachObject(manual);
            }

            return(node);
        }
Exemplo n.º 24
0
        /// <summary>
        /// This method contructs the mesh for the cube
        /// </summary>
        /// <param name="cubeName"></param>
        /// <returns>cubeMesh object</returns>
        public MeshPtr getCube(string cubeName)
        {
            // Console.Write("getCube: "+count);
            manualObj = mSceneMgr.CreateManualObject("manualObjQuad" + count);
            manualObj.Begin("void", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); // Starts filling the manual object as a triangle list

            // ---- Vertex Buffer ----
            manualObj.Position(new Vector3(30, 30, 0));           // --- Vertex 0 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, 30, 0));              // --- Vertex 1 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, -30, 0));              // --- Vertex 2 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, -30, 0));             // --- Vertex 3 ---
            manualObj.TextureCoord(new Vector2(1, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, 30, -60));             // --- Vertex 4 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, -30, -60));            // --- Vertex 5 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, 30, -60));             // --- Vertex 6 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, -30, -60));            // --- Vertex 7 ---
            manualObj.TextureCoord(new Vector2(1, 1));
            manualObj.Normal(1, 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);


            // --- Triangle 8 ---
            manualObj.Index(4);
            manualObj.Index(5);
            manualObj.Index(6);

            // --- Triangle 9 ---
            manualObj.Index(5);
            manualObj.Index(7);
            manualObj.Index(6);


            manualObj.Position(new Vector3(30, 30, -60));          // --- Vertex 8 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, 30, 0));              // --- Vertex 9 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, -30, -60));              // --- Vertex 10 ---
            manualObj.TextureCoord(new Vector2(1, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, -30, 0));             // --- Vertex 11 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, 30, 0));             // --- Vertex 12 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, 30, -60));            // --- Vertex 13 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, -30, 0));             // ---Vertex 14 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, -30, -60));            // ---Vertex 15 ---
            manualObj.TextureCoord(new Vector2(1, 1));
            manualObj.Normal(1, 1, 1);

            // ---Triangle 12-- -
            manualObj.Index(8);
            manualObj.Index(9);
            manualObj.Index(10);

            //  ---Triangle 13-- -
            manualObj.Index(9);
            manualObj.Index(11);
            manualObj.Index(10);

            // ---Triangle 14-- -
            manualObj.Index(12);
            manualObj.Index(13);
            manualObj.Index(14);

            //  ---Triangle 15-- -
            manualObj.Index(13);
            manualObj.Index(15);
            manualObj.Index(14);

            manualObj.Position(new Vector3(30, 30, -60));               // --- Vertex 16 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, 30, -60));              // --- Vertex 17 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, 30, 0));              // --- Vertex 18 ---
            manualObj.TextureCoord(new Vector2(1, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, 30, 0));             // --- Vertex 19 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, -30, 0));             // --- Vertex 20 ---
            manualObj.TextureCoord(new Vector2(0, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, -30, 0));            // --- Vertex 21 ---
            manualObj.TextureCoord(new Vector2(0, 1));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(30, -30, -60));             // ---Vertex 22 ---
            manualObj.TextureCoord(new Vector2(1, 0));
            manualObj.Normal(1, 1, 1);
            manualObj.Position(new Vector3(-30, -30, -60));           // ---Vertex 23 ---
            manualObj.TextureCoord(new Vector2(1, 1));
            manualObj.Normal(1, 1, 1);

            // ---Triangle 12-- -
            manualObj.Index(16);
            manualObj.Index(17);
            manualObj.Index(18);

            //  ---Triangle 13-- -
            manualObj.Index(17);
            manualObj.Index(19);
            manualObj.Index(18);

            // ---Triangle 14-- -
            manualObj.Index(20);
            manualObj.Index(21);
            manualObj.Index(22);

            //  ---Triangle 15-- -
            manualObj.Index(21);
            manualObj.Index(23);
            manualObj.Index(22);


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

            return(manualObj.ConvertToMesh(cubeName));            // Prepares the data to be sent to the GPU
        }
Exemplo n.º 25
0
        public MeshPtr getCube(string cubeName, string materialName, float width, float height, float depth)
        {
            manual = mSceneMgr.CreateManualObject(cubeName + "_ManObj");
            manual.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            // --- Fills the Vertex buffer and define the texture coordinates for each vertex ---

            //--- Vertex 0 ---
            v0 = new Vector3(.5f * width, .5f * height, .5f * depth);
            manual.Position(v0);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(0, 0));

            //--- Vertex 1 ---
            v1 = new Vector3(.5f * width, -.5f * height, .5f * depth);
            manual.Position(v1);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(1, 0));

            //--- Vertex 2 ---
            v2 = new Vector3(.5f * width, .5f * height, -.5f * depth);
            manual.Position(v2);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(0, 1));

            //--- Vertex 3 ---
            v3 = new Vector3(.5f * width, -.5f * height, -.5f * depth);
            manual.Position(v3);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(1, 1));


            //--- Vertex 4 ---
            v4 = new Vector3(-.5f * width, .5f * height, .5f * depth);
            manual.Position(v4);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(0, 0));

            //--- Vertex 5 ---
            v5 = new Vector3(-.5f * width, -.5f * height, .5f * depth);
            manual.Position(v5);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(-1, 0));

            //--- Vertex 6 ---
            v6 = new Vector3(-.5f * width, .5f * height, -.5f * depth);
            manual.Position(v6);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(0, -1));

            //--- Vertex 7 ---
            v7 = new Vector3(-.5f * width, -.5f * height, -.5f * depth);
            manual.Position(v7);
            //Texture coordinates here!
            manual.TextureCoord(new Vector2(-1, -1));


            // --- Fills the Index Buffer ---
            //--------Face 1----------
            manual.Index(2);
            manual.Index(1);
            manual.Index(0);

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

            //--------Face 2----------
            manual.Index(5);
            manual.Index(6);
            manual.Index(4);

            manual.Index(5);
            manual.Index(7);
            manual.Index(6);

            //--------Face 3----------
            manual.Index(1);
            manual.Index(4);
            manual.Index(0);

            manual.Index(5);
            manual.Index(4);
            manual.Index(1);

            ////--------Face 4----------
            //manual.Index(0);
            //manual.Index(6);
            //manual.Index(4);

            //manual.Index(0);
            //manual.Index(2);
            //manual.Index(6);

            //--------Face 5----------
            manual.Index(3);
            manual.Index(2);
            manual.Index(6);

            manual.Index(7);
            manual.Index(3);
            manual.Index(6);

            //--------Face 6----------
            //manual.Index(3);
            //manual.Index(1);
            //manual.Index(7);

            //manual.Index(1);
            //manual.Index(5);
            //manual.Index(7);

            manual.End();
            return(manual.ConvertToMesh(cubeName));
        }
Exemplo n.º 26
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.º 27
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.º 28
0
        private static ManualObject GenerateCubeHelper(float x, float y, float z, String name, Material frontFace, Material backFace, Material leftFace, Material rightFace, Material topFace, Material bottomFace, Vector3 positionOffset)
        {
            float xOffset = positionOffset.x;
            float yOffset = positionOffset.y;
            float zOffset = positionOffset.z;

            x /= 2;
            y /= 2;
            z /= 2;

            ManualObject cube = Engine.Renderer.Scene.CreateManualObject(name);

            cube.Dynamic = true;

            //START GENERATION

            cube.Begin(bottomFace.Name);

            cube.Position(x + xOffset, -y + yOffset, z + zOffset);
            cube.Normal(0.408248f, -0.816497f, 0.408248f);
            cube.TextureCoord(1, 0);

            //1
            cube.Position(-x + xOffset, -y + yOffset, -z + zOffset);
            cube.Normal(-0.408248f, -0.816497f, -0.408248f);
            cube.TextureCoord(0, 1);

            //2
            cube.Position(x + xOffset, -y + yOffset, -z + zOffset);
            cube.Normal(0.666667f, -0.333333f, -0.666667f);
            cube.TextureCoord(1, 1);

            //3
            cube.Position(-x + xOffset, -y + yOffset, z + zOffset);
            cube.Normal(-0.666667f, -0.333333f, 0.666667f);
            cube.TextureCoord(0, 0);

            cube.Triangle(0, 1, 2);
            cube.Triangle(3, 1, 0);

            cube.End();
            cube.Begin(backFace.Name);

            //4
            cube.Position(x + xOffset, y + yOffset, z + zOffset);
            cube.Normal(0.666667f, 0.333333f, 0.666667f);
            cube.TextureCoord(1, 0);

            //5
            cube.Position(-x + xOffset, -y + yOffset, z + zOffset);
            cube.Normal(-0.666667f, -0.333333f, 0.666667f);
            cube.TextureCoord(0, 1);

            //6
            cube.Position(x + xOffset, -y + yOffset, z + zOffset);
            cube.Normal(0.408248f, -0.816497f, 0.408248f);
            cube.TextureCoord(1, 1);

            //7
            cube.Position(-x + xOffset, y + yOffset, z + zOffset);
            cube.Normal(-0.408248f, 0.816497f, 0.408248f);
            cube.TextureCoord(0, 0);

            cube.Triangle(0, 1, 2);
            cube.Triangle(0, 3, 1);

            cube.End();
            cube.Begin(leftFace.Name);

            //7
            cube.Position(-x + xOffset, y + yOffset, z + zOffset);
            cube.Normal(-0.408248f, 0.816497f, 0.408248f);
            cube.TextureCoord(0, 0);

            //8
            cube.Position(-x + xOffset, y + yOffset, -z + zOffset);
            cube.Normal(-0.666667f, 0.333333f, -0.666667f);
            cube.TextureCoord(0, 1);

            //9
            cube.Position(-x + xOffset, -y + yOffset, -z + zOffset);
            cube.Normal(-0.408248f, -0.816497f, -0.408248f);
            cube.TextureCoord(1, 1);

            //10
            cube.Position(-x + xOffset, -y + yOffset, z + zOffset);
            cube.Normal(-0.666667f, -0.333333f, 0.666667f);
            cube.TextureCoord(1, 0);

            cube.Triangle(1, 2, 3);
            cube.Triangle(3, 0, 1);

            cube.End();
            cube.Begin(rightFace.Name);

            //4
            cube.Position(x + xOffset, y + yOffset, z + zOffset);
            cube.Normal(0.666667f, 0.333333f, 0.666667f);
            cube.TextureCoord(1, 0);

            //11
            cube.Position(x + xOffset, -y + yOffset, -z + zOffset);
            cube.Normal(0.666667f, -0.333333f, -0.666667f);
            cube.TextureCoord(0, 1);

            //12
            cube.Position(x + xOffset, y + yOffset, -z + zOffset);
            cube.Normal(0.408248f, 0.816497f, -0.408248f);
            cube.TextureCoord(1, 1);

            //13
            cube.Position(x + xOffset, -y + yOffset, z + zOffset);
            cube.Normal(0.408248f, -0.816497f, 0.408248f);
            cube.TextureCoord(0, 0);

            cube.Triangle(0, 1, 2);
            cube.Triangle(0, 3, 1);

            cube.End();
            cube.Begin(frontFace.Name);

            //8
            cube.Position(-x + xOffset, y + yOffset, -z + zOffset);
            cube.Normal(-0.666667f, 0.333333f, -0.666667f);
            cube.TextureCoord(0, 1);

            //12
            cube.Position(x + xOffset, y + yOffset, -z + zOffset);
            cube.Normal(0.408248f, 0.816497f, -0.408248f);
            cube.TextureCoord(1, 1);

            //14
            cube.Position(x + xOffset, -y + yOffset, -z + zOffset);
            cube.Normal(0.666667f, -0.333333f, -0.666667f);
            cube.TextureCoord(1, 0);

            //15
            cube.Position(-x + xOffset, -y + yOffset, -z + zOffset);
            cube.Normal(-0.408248f, -0.816497f, -0.408248f);
            cube.TextureCoord(0, 0);

            cube.Triangle(2, 0, 1);
            cube.Triangle(2, 3, 0);

            cube.End();
            cube.Begin(topFace.Name);

            //16
            cube.Position(-x + xOffset, y + yOffset, z + zOffset);
            cube.Normal(-0.408248f, 0.816497f, 0.408248f);
            cube.TextureCoord(1, 0);

            //17
            cube.Position(x + xOffset, y + yOffset, -z + zOffset);
            cube.Normal(0.408248f, 0.816497f, -0.408248f);
            cube.TextureCoord(0, 1);

            //18
            cube.Position(-x + xOffset, y + yOffset, -z + zOffset);
            cube.Normal(-0.666667f, 0.333333f, -0.666667f);
            cube.TextureCoord(1, 1);

            //19
            cube.Position(x + xOffset, y + yOffset, z + zOffset);
            cube.Normal(0.666667f, 0.333333f, 0.666667f);
            cube.TextureCoord(0, 0);

            cube.Triangle(0, 1, 2);
            cube.Triangle(0, 3, 1);

            cube.End();

            return(cube);
        }
Exemplo n.º 29
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.º 30
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);
        }
Exemplo n.º 31
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.º 32
0
        private static ManualObject UpdateCubeHelper(ManualObject updating, float x, float y, float z, Material frontFace, Material backFace, Material leftFace, Material rightFace, Material topFace, Material bottomFace, Face updatedFaces, Vector3 positionOffset)
        {
            float xOffset = positionOffset.x;
            float yOffset = positionOffset.y;
            float zOffset = positionOffset.z;

            x /= 2;
            y /= 2;
            z /= 2;

            //START GENERATION

            updating.BeginUpdate(0);

            updating.Position(x + xOffset, -y + yOffset, z + zOffset);
            updating.Normal(0.408248f, -0.816497f, 0.408248f);
            updating.TextureCoord(1, 0);

            //1
            updating.Position(-x + xOffset, -y + yOffset, -z + zOffset);
            updating.Normal(-0.408248f, -0.816497f, -0.408248f);
            updating.TextureCoord(0, 1);

            //2
            updating.Position(x + xOffset, -y + yOffset, -z + zOffset);
            updating.Normal(0.666667f, -0.333333f, -0.666667f);
            updating.TextureCoord(1, 1);

            //3
            updating.Position(-x + xOffset, -y + yOffset, z + zOffset);
            updating.Normal(-0.666667f, -0.333333f, 0.666667f);
            updating.TextureCoord(0, 0);

            updating.Triangle(0, 1, 2);
            updating.Triangle(3, 1, 0);

            updating.End();
            updating.BeginUpdate(1);

            //4
            updating.Position(x + xOffset, y + yOffset, z + zOffset);
            updating.Normal(0.666667f, 0.333333f, 0.666667f);
            updating.TextureCoord(1, 0);

            //5
            updating.Position(-x + xOffset, -y + yOffset, z + zOffset);
            updating.Normal(-0.666667f, -0.333333f, 0.666667f);
            updating.TextureCoord(0, 1);

            //6
            updating.Position(x + xOffset, -y + yOffset, z + zOffset);
            updating.Normal(0.408248f, -0.816497f, 0.408248f);
            updating.TextureCoord(1, 1);

            //7
            updating.Position(-x + xOffset, y + yOffset, z + zOffset);
            updating.Normal(-0.408248f, 0.816497f, 0.408248f);
            updating.TextureCoord(0, 0);

            updating.Triangle(0, 1, 2);
            updating.Triangle(0, 3, 1);

            updating.End();
            updating.BeginUpdate(2);

            //7
            updating.Position(-x + xOffset, y + yOffset, z + zOffset);
            updating.Normal(-0.408248f, 0.816497f, 0.408248f);
            updating.TextureCoord(0, 0);

            //8
            updating.Position(-x + xOffset, y + yOffset, -z + zOffset);
            updating.Normal(-0.666667f, 0.333333f, -0.666667f);
            updating.TextureCoord(0, 1);

            //9
            updating.Position(-x + xOffset, -y + yOffset, -z + zOffset);
            updating.Normal(-0.408248f, -0.816497f, -0.408248f);
            updating.TextureCoord(1, 1);

            //10
            updating.Position(-x + xOffset, -y + yOffset, z + zOffset);
            updating.Normal(-0.666667f, -0.333333f, 0.666667f);
            updating.TextureCoord(1, 0);

            updating.Triangle(1, 2, 3);
            updating.Triangle(3, 0, 1);

            updating.End();
            updating.BeginUpdate(3);

            //4
            updating.Position(x + xOffset, y + yOffset, z + zOffset);
            updating.Normal(0.666667f, 0.333333f, 0.666667f);
            updating.TextureCoord(1, 0);

            //11
            updating.Position(x + xOffset, -y + yOffset, -z + zOffset);
            updating.Normal(0.666667f, -0.333333f, -0.666667f);
            updating.TextureCoord(0, 1);

            //12
            updating.Position(x + xOffset, y + yOffset, -z + zOffset);
            updating.Normal(0.408248f, 0.816497f, -0.408248f);
            updating.TextureCoord(1, 1);

            //13
            updating.Position(x + xOffset, -y + yOffset, z + zOffset);
            updating.Normal(0.408248f, -0.816497f, 0.408248f);
            updating.TextureCoord(0, 0);

            updating.Triangle(0, 1, 2);
            updating.Triangle(0, 3, 1);

            updating.End();
            updating.BeginUpdate(4);

            //8
            updating.Position(-x + xOffset, y + yOffset, -z + zOffset);
            updating.Normal(-0.666667f, 0.333333f, -0.666667f);
            updating.TextureCoord(0, 1);

            //12
            updating.Position(x + xOffset, y + yOffset, -z + zOffset);
            updating.Normal(0.408248f, 0.816497f, -0.408248f);
            updating.TextureCoord(1, 1);

            //14
            updating.Position(x + xOffset, -y + yOffset, -z + zOffset);
            updating.Normal(0.666667f, -0.333333f, -0.666667f);
            updating.TextureCoord(1, 0);

            //15
            updating.Position(-x + xOffset, -y + yOffset, -z + zOffset);
            updating.Normal(-0.408248f, -0.816497f, -0.408248f);
            updating.TextureCoord(0, 0);

            updating.Triangle(2, 0, 1);
            updating.Triangle(2, 3, 0);

            updating.End();
            updating.BeginUpdate(5);

            //16
            updating.Position(-x + xOffset, y + yOffset, z + zOffset);
            updating.Normal(-0.408248f, 0.816497f, 0.408248f);
            updating.TextureCoord(1, 0);

            //17
            updating.Position(x + xOffset, y + yOffset, -z + zOffset);
            updating.Normal(0.408248f, 0.816497f, -0.408248f);
            updating.TextureCoord(0, 1);

            //18
            updating.Position(-x + xOffset, y + yOffset, -z + zOffset);
            updating.Normal(-0.666667f, 0.333333f, -0.666667f);
            updating.TextureCoord(1, 1);

            //19
            updating.Position(x + xOffset, y + yOffset, z + zOffset);
            updating.Normal(0.666667f, 0.333333f, 0.666667f);
            updating.TextureCoord(0, 0);

            updating.Triangle(0, 1, 2);
            updating.Triangle(0, 3, 1);

            updating.End();

            updating.BoundingBox = new AxisAlignedBox(
                new Vector3(
                    -x + xOffset,
                    -y + yOffset,
                    -z + zOffset),
                new Vector3(
                    x + xOffset,
                    y + yOffset,
                    z + zOffset));

            return(updating);
        }