当前位置: 首页>>代码示例>>C#>>正文


C# TgcBoundingBox.setRenderColor方法代码示例

本文整理汇总了C#中TgcViewer.Utils.TgcGeometry.TgcBoundingBox.setRenderColor方法的典型用法代码示例。如果您正苦于以下问题:C# TgcBoundingBox.setRenderColor方法的具体用法?C# TgcBoundingBox.setRenderColor怎么用?C# TgcBoundingBox.setRenderColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TgcViewer.Utils.TgcGeometry.TgcBoundingBox的用法示例。


在下文中一共展示了TgcBoundingBox.setRenderColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: loadHeightmap


//.........这里部分代码省略.........
        /// <param name="center">Centro de la malla del terreno</param>
        /// <param name="divisiones">Cantidad de filas y columnas en las que se va a dividir el terreno</param>
        public void loadHeightmap(string heightmapPath, float scaleXZ, float scaleY, Vector3 center, int divisiones)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;
            this.center = center;
            TgcBoundingBox box;
            vbTerrains = new List<VertexBuffer>();
            boundingBoxes = new List<TgcBoundingBox>();

            //Dispose de VertexBuffer anterior, si habia
            foreach (VertexBuffer vbTerrain in vbTerrains)
            {
                if (vbTerrain != null && !vbTerrain.Disposed)
                {
                    vbTerrain.Dispose();
                }
            }
            vbTerrains.Clear();

            //cargar heightmap
            heightmapData = loadHeightMap(d3dDevice, heightmapPath);
            float width = (float)heightmapData.GetLength(0);
            float length = (float)heightmapData.GetLength(1);

            //Crear vertexBuffer
            float nodeWidth = (width / divisiones);
            float nodeLength = (length / divisiones);

            for(int x=0; x < divisiones; x++)
            {
                for (int z = 0; z < divisiones; z++)
                {
                    VertexBuffer vbTerrain;

                    totalVertices = 2 * 3 * ((int)nodeWidth - 1) * ((int)nodeLength - 1);
                    vbTerrain = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

                    //Cargar vertices
                    int dataIdx = 0;
                    Vector3 pMin = Vector3.Empty;
                    Vector3 pMax = Vector3.Empty;
                    CustomVertex.PositionTextured[] data = new CustomVertex.PositionTextured[totalVertices];
                    Vector3 currentCenter;
                    currentCenter.X = center.X * scaleXZ - (width / 2) * scaleXZ;
                    currentCenter.Y = center.Y * scaleY;
                    currentCenter.Z = center.Z * scaleXZ - (length / 2) * scaleXZ;

                    for (int k = 0; k < (nodeWidth) - 1; k++)
                    {
                        for (int l = 0; l < (nodeLength) - 1; l++)
                        {
                            int i = k + (x*((int)nodeWidth -1));
                            int j = l + (z*((int)nodeLength -1));
                            //Vertices
                            Vector3 v1 = new Vector3(currentCenter.X + i * scaleXZ, currentCenter.Y + heightmapData[i, j] * scaleY, currentCenter.Z + j * scaleXZ);
                            Vector3 v2 = new Vector3(currentCenter.X + i * scaleXZ, currentCenter.Y + heightmapData[i, j + 1] * scaleY, currentCenter.Z + (j + 1) * scaleXZ);
                            Vector3 v3 = new Vector3(currentCenter.X + (i + 1) * scaleXZ, currentCenter.Y + heightmapData[i + 1, j] * scaleY, currentCenter.Z + j * scaleXZ);
                            Vector3 v4 = new Vector3(currentCenter.X + (i + 1) * scaleXZ, currentCenter.Y + heightmapData[i + 1, j + 1] * scaleY, currentCenter.Z + (j + 1) * scaleXZ);

                            //Coordendas de textura
                            Vector2 t1 = new Vector2(i / nodeWidth, j / nodeLength);
                            Vector2 t2 = new Vector2(i / nodeWidth, (j + 1) / nodeLength);
                            Vector2 t3 = new Vector2((i + 1) / nodeWidth, j / nodeLength);
                            Vector2 t4 = new Vector2((i + 1) / nodeWidth, (j + 1) / nodeLength);

                            //Cargar triangulo 1
                            data[dataIdx] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                            data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                            data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                            //Cargar triangulo 2
                            data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                            data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                            data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                            dataIdx += 6;

                            if(k == 0 && l==0){
                                pMin = v1;
                                pMin.Y = 0;
                            }
                            if (k == (nodeLength) - 2 && l == (nodeLength) - 2)
                            {
                                pMax = v4;
                                pMax.Y = 1500;
                            }
                        }
                    }

                    vbTerrain.SetData(data, 0, LockFlags.None);
                    vbTerrains.Add(vbTerrain);
                    //vbTerrain.Dispose();

                    box = new TgcBoundingBox(pMin, pMax);
                    box.setRenderColor(Color.Red);
                    boundingBoxes.Add(box);
                }
            }
        }
开发者ID:SantiagoFoster,项目名称:AlumnoEjemplos,代码行数:101,代码来源:CustomTerrain.cs

示例2: colisionar

        public bool colisionar(TgcBoundingBox objeto,List<Vector3> centros)
        {
            if (objeto.Position.Y - (centros[0].Y + escalaY ) - tolerancia > EPSILON)
            {//si esta lejos en el eje y, no tiene sentido testear lo demas.
                objeto.setRenderColor(Color.Yellow);
                return false;
            }
            objeto.setRenderColor(Color.Red);
            centros_probables.Clear();
            if (objeto.Position.Y < 0) { return true; } //Si el avion avanza demasiado rápido  y no se llega a checkear la colisión
            foreach (Vector3 centro in centros)
            {

                if((Math.Pow(objeto.Position.X - centro.X, 2) + Math.Pow(objeto.Position.Z - centro.Z,2)) - Math.Pow(tamanio_terrenos/2,2) < EPSILON)
                {//si el centro esta cerca en altura, y en horizontal lo guardo para colisionar
                    centros_probables.Add(centro);
                }
            }

            //veo si colisionan los terrenos
            Vector3 nuevaPosicion;
            List<Vector3> verticesEnEsfera = new List<Vector3>();
            TgcBoundingBox bounding = objeto.clone();
            foreach (Vector3 centro in centros_probables)
            {
                //desplazo el avion en vez del terreno para testear colisiones
                nuevaPosicion = Vector3.Subtract(objeto.Position,centro);

                bounding.move(Vector3.Multiply(centro,-1f));
                verticesEnEsfera.Clear();
                TgcBoundingSphere esfera = new TgcBoundingSphere(nuevaPosicion,tolerancia);
                Vector3 colision = new Vector3();
                for (int i = 0; i < verticesTerreno.Length; i += 3)
                {
                    if (TgcCollisionUtils.testSphereTriangle(esfera, verticesTerreno[i].Position, verticesTerreno[i + 1].Position, verticesTerreno[i + 2].Position,out colision))
                    {
                        if (TgcCollisionUtils.testTriangleAABB( verticesTerreno[i].Position, verticesTerreno[i + 1].Position, verticesTerreno[i + 2].Position,bounding))
                        {
                            return true;
                        }
                    }
                }
                /*
                foreach (CustomVertex.PositionTextured vertice in verticesTerreno)
                {
                    if ( Vector3.LengthSq(Vector3.Subtract(nuevaPosicion,vertice.Position)) - toleranciaSQ < EPSILON)
                    {
                        verticesEnEsfera.Add(vertice.Position);
                    }
                }

                foreach (Vector3 vertice in verticesEnEsfera)
                {
                    if (TgcCollisionUtils.sqDistPointAABB(vertice, bounding) < EPSILON)
                    {
                        return true;
                    }
                }*/

            }
            return false;
        }
开发者ID:Javier-Rotelli,项目名称:TGCJetPilot,代码行数:62,代码来源:Colisionador.cs


注:本文中的TgcViewer.Utils.TgcGeometry.TgcBoundingBox.setRenderColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。