/// <summary> /// Crear un nuevo mesh igual /// </summary> /// <param name="cloneName">Nombre del mesh clonado</param> /// <returns>Mesh clonado</returns> public TgcMesh clone(string cloneName) { //Clonar D3dMesh var d3dCloneMesh = d3dMesh.Clone(MeshFlags.Managed, d3dMesh.Declaration, D3DDevice.Instance.Device); //Crear mesh de TGC y cargar atributos generales var cloneMesh = new TgcMesh(d3dCloneMesh, cloneName, renderType); cloneMesh.Materials = Materials; cloneMesh.layer = layer; cloneMesh.boundingBox = boundingBox.clone(); cloneMesh.alphaBlendEnable = alphaBlendEnable; cloneMesh.enabled = true; cloneMesh.AutoUpdateBoundingBox = AutoUpdateBoundingBox; //Transformaciones cloneMesh.translation = translation; cloneMesh.rotation = rotation; cloneMesh.scale = scale; cloneMesh.transform = transform; cloneMesh.autoTransformEnable = autoTransformEnable; //Clonar userProperties if (UserProperties != null) { cloneMesh.UserProperties = new Dictionary <string, string>(); foreach (var entry in UserProperties) { cloneMesh.UserProperties.Add(entry.Key, entry.Value); } } //Clonar DiffuseMaps if (diffuseMaps != null) { cloneMesh.diffuseMaps = new TgcTexture[diffuseMaps.Length]; for (var i = 0; i < diffuseMaps.Length; i++) { cloneMesh.diffuseMaps[i] = diffuseMaps[i].clone(); } } //Clonar LightMap if (lightMap != null) { cloneMesh.lightMap = lightMap.clone(); } return(cloneMesh); }
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); }