예제 #1
0
        public BilateralFiltering(float[,] image, float sigmaD, float sigmaR)
        {
            this.image = image;
            var sigmaMax = (int)FastMath.Max(sigmaD, sigmaR);

            kernelRadius = (int)FastMath.Ceiling(2 * sigmaMax);

            var twoSigmaRSquared = 2 * sigmaR * sigmaR;

            var kernelSize = kernelRadius * 2 + 1;

            kernelD = new float[kernelSize, kernelSize];

            var center = (kernelSize - 1) / 2;

            for (var x = -center; x < -center + kernelSize; x++)
            {
                for (var y = -center; y < -center + kernelSize; y++)
                {
                    kernelD[x + center, y + center] = gauss(sigmaD, x, y);
                }
            }

            gaussSimilarity = new float[256];
            for (var i = 0; i < gaussSimilarity.Length; i++)
            {
                gaussSimilarity[i] = FastMath.Exp(-(i / twoSigmaRSquared));
            }

            //rimage = cvCloneImage(image);
        }
예제 #2
0
        public BilateralFiltering(float[,] image, float sigmaD, float sigmaR)
        {
            this.image = image;
            int sigmaMax = (int)FastMath.Max(sigmaD, sigmaR);

            this.kernelRadius = (int)FastMath.Ceiling(2 * sigmaMax);


            float twoSigmaRSquared = 2 * sigmaR * sigmaR;

            int kernelSize = this.kernelRadius * 2 + 1;

            this.kernelD = new float[kernelSize, kernelSize];

            int center = (kernelSize - 1) / 2;

            for (int x = -center; x < -center + kernelSize; x++)
            {
                for (int y = -center; y < -center + kernelSize; y++)
                {
                    this.kernelD[x + center, y + center] = this.gauss(sigmaD, x, y);
                }
            }


            this.gaussSimilarity = new float[256];
            for (int i = 0; i < this.gaussSimilarity.Length; i++)
            {
                this.gaussSimilarity[i] = FastMath.Exp((float)-((i) / twoSigmaRSquared));
            }



            //rimage = cvCloneImage(image);
        }
        /// <summary>
        ///     testea colisiones de picking
        /// </summary>
        private void testPicking()
        {
            //de los objetos visibles, testeo colisiones con el picking ray
            foreach (InteractiveObject objeto in MyWorld.Objetos)
            {
                if (objeto.mesh.Enabled)
                {
                    collided = TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, objeto.mesh.BoundingBox, out collisionPoint);
                    if (collided)
                    {
                        Vector3 aux = new Vector3(0f, 0f, 0f);
                        aux.Add(Camara.Position);
                        aux.Subtract(objeto.mesh.Position);
                        if (FastMath.Ceiling(aux.Length()) < 65)
                        {
                            pickedObject = objeto;
                            if (pickedObject.getHit(Player1.getDamage()))
                            {
                                setCenterText(Player1.getDamage().ToString() + " Damage");
                                MyWorld.destroyObject(pickedObject);

                                if (pickedObject.Equals(collidedObject))
                                {
                                    MyCamera.Collisioned = false;
                                }

                                List <InventoryObject> drops = pickedObject.getDrops();
                                foreach (InventoryObject invObject in drops)
                                {
                                    //agrego los drops al inventario del usuario
                                    if (!Player1.addInventoryObject(invObject))
                                    {
                                        //no pudo agregar el objeto
                                        setTopRightText("No hay espacio en el inventario");
                                    }
                                }
                            }
                            break;
                        }
                        else
                        {
                            collided = false;
                        }
                    }
                }
            }

            //si hubo colisión
            if (collided)
            {
                //a darle átomos
                emit             = true;
                emittedTime      = 0;
                emitter.Position = pickedObject.mesh.Position;
            }
        }
        public Tuple <TGCBox, RigidBody> addBox(TGCVector3 pos, TGCVector3 size, TgcTexture text, float mass = 0f, float friction = 0f, float?inertia = null)
        {
            var box = TGCBox.fromSize(size, text);
            var uv  = FastMath.Max(size.Y, FastMath.Max(size.X, size.Z));

            box.UVTiling = new TGCVector2(FastMath.Ceiling(uv / 80), FastMath.Ceiling(uv / 80));
            box.updateValues();
            var boxBody = BulletRigidBodyConstructor.CreateBox(box.Size * 0.5f, mass, pos, 0, 0, 0, friction, inertia);

            dynamicsWorld.AddRigidBody(boxBody);
            var pair = new Tuple <TGCBox, RigidBody>(box, boxBody);

            boxes.Add(pair);
            box.AutoTransform   = false;
            boxBody.Restitution = 0f;
            return(pair);
        }
예제 #5
0
        /// <summary>
        ///     Construye la grilla
        /// </summary>
        private GrillaRegularNode[,,] buildGrid(List <TgcMesh> modelos, TgcBoundingAxisAlignBox sceneBounds, Vector3 cellDim)
        {
            var sceneSize = sceneBounds.calculateSize();

            var gx = (int)FastMath.Ceiling(sceneSize.X / cellDim.X) + 1;
            var gy = (int)FastMath.Ceiling(sceneSize.Y / cellDim.Y) + 1;
            var gz = (int)FastMath.Ceiling(sceneSize.Z / cellDim.Z) + 1;

            var grid = new GrillaRegularNode[gx, gy, gz];

            //Construir grilla
            for (var x = 0; x < gx; x++)
            {
                for (var y = 0; y < gy; y++)
                {
                    for (var z = 0; z < gz; z++)
                    {
                        //Crear celda
                        var node = new GrillaRegularNode();

                        //Crear BoundingBox de celda
                        var pMin = new Vector3(sceneBounds.PMin.X + x * cellDim.X, sceneBounds.PMin.Y + y * cellDim.Y,
                                               sceneBounds.PMin.Z + z * cellDim.Z);
                        var pMax = Vector3.Add(pMin, cellDim);
                        node.BoundingBox = new TgcBoundingAxisAlignBox(pMin, pMax);

                        //Cargar modelos en celda
                        node.Models = new List <TgcMesh>();
                        addModelsToCell(node, modelos);

                        grid[x, y, z] = node;
                    }
                }
            }

            return(grid);
        }
예제 #6
0
        public virtual bool editTerrain(float elapsedTime)
        {
            var speed = elapsedTime * getSpeedAdjustment();

            if (Invert)
            {
                speed *= -1;
            }

            var radius       = Radius / terrain.ScaleXZ;
            var innerRadius  = radius * (Hardness / 100);
            var radius2      = FastMath.Pow2(radius);
            var innerRadius2 = FastMath.Pow2(innerRadius);

            TGCVector2 coords;
            var        heightmapData = terrain.HeightmapData;
            var        changed       = false;

            if (!terrain.xzToHeightmapCoords(Position.X, Position.Z, out coords))
            {
                return(false);
            }

            //Calculo un cuadrado alrededor del vertice seleccionado
            int[] min = { (int)FastMath.Ceiling(coords.X - radius), (int)FastMath.Ceiling(coords.Y - radius) };

            float[] max = { coords.X + radius, coords.Y + radius };

            for (var i = 0; i < 2; i++)
            {
                if (min[i] < 0)
                {
                    min[i] = 0;
                }
                if (max[i] > heightmapData.GetLength(i))
                {
                    max[i] = heightmapData.GetLength(i);
                }
            }

            for (var i = min[0]; i < max[0]; i++)
            {
                for (var j = min[1]; j < max[1]; j++)
                {
                    var dx = i - coords.X;
                    var dz = j - coords.Y;

                    var d2 = FastMath.Pow2(dx) + FastMath.Pow2(dz);

                    //Si es cuadrado o el vertice esta dentro del circulo
                    if (!Rounded || d2 <= radius2)
                    {
                        var intensity = intensityFor(heightmapData, i, j);

                        if (intensity != 0)
                        {
                            if (Hardness != 100)
                            {
                                //Si esta entre el circulo/cuadrado interno, disminuyo la intensidad.
                                if (Rounded)
                                {
                                    var outterIntensity = intensity * (1 - d2 / radius2);

                                    if (d2 > innerRadius2)
                                    {
                                        intensity = outterIntensity;
                                    }
                                    else
                                    {
                                        var alpha = 1 - d2 / innerRadius2;
                                        intensity = outterIntensity + alpha * (intensity - outterIntensity);
                                    }
                                }
                                else
                                {
                                    var maxD = FastMath.Max(FastMath.Abs(dx), FastMath.Abs(dz));
                                    if (maxD > innerRadius)
                                    {
                                        intensity = intensity * (1 - (maxD - innerRadius) / (radius - innerRadius));
                                    }
                                }
                            }

                            var newHeight = FastMath.Max(0, FastMath.Min(heightmapData[i, j] + intensity * speed, 255));

                            if (heightmapData[i, j] != newHeight)
                            {
                                heightmapData[i, j] = newHeight;
                                changed             = true;
                            }
                        }
                    }
                }
            }

            if (changed)
            {
                terrain.setHeightmapData(heightmapData);

                float y;
                terrain.interpoledHeight(bBrush.Position.X, bBrush.Position.Z, out y);
                bBrush.Position = new TGCVector3(bBrush.Position.X, y + 50, bBrush.Position.Z);
            }
            return(changed);
        }
예제 #7
0
        public override void UpdateCamera(float elapsedTime)
        {
            var moveVector = new Vector3(0, 0, 0);

            // Al mover el mouse se mueve la cabeza (genera mayor realismo)
            LockCam = true;

            //Aplicar movimiento hacia adelante o atras segun la orientacion actual del Mesh
            var lastPos = this.Position;

            if (!env.personaje.Muerto && !env.partidoGanado)
            {
                //Forward
                if (Input.keyDown(Key.W))
                {
                    // Fuerzo a que el Personaje este siempre sobre la Isla
                    if (env.terreno.estaDentroTerreno())
                    {
                        moveVector += new Vector3(0, 0, -1) * MovementSpeed;
                    }
                    else
                    {
                        moveVector -= new Vector3(0, 0, -10) * MovementSpeed;
                    }
                }

                //Backward
                if (Input.keyDown(Key.S))
                {
                    // Fuerzo a que el Personaje este siempre sobre la Isla
                    if (env.terreno.estaDentroTerreno())
                    {
                        moveVector += new Vector3(0, 0, 1) * MovementSpeed;
                    }
                    else
                    {
                        moveVector -= new Vector3(0, 0, 10) * MovementSpeed;
                    }
                }

                //Strafe right
                if (Input.keyDown(Key.D))
                {
                    // Fuerzo a que el Personaje este siempre sobre la Isla
                    if (env.terreno.estaDentroTerreno())
                    {
                        moveVector += new Vector3(-1, 0, 0) * MovementSpeed;
                    }
                    else
                    {
                        moveVector -= new Vector3(-10, 0, 0) * MovementSpeed;
                    }
                }

                //Strafe left
                if (Input.keyDown(Key.A))
                {
                    // Fuerzo a que el Personaje este siempre sobre la Isla
                    if (env.terreno.estaDentroTerreno())
                    {
                        moveVector += new Vector3(1, 0, 0) * MovementSpeed;
                    }
                    else
                    {
                        moveVector -= new Vector3(10, 0, 0) * MovementSpeed;
                    }
                }

                // Gods
                if (Input.keyDown(Key.G))
                {
                    env.alturaCamara = 200f;
                    env.modoDios     = true;
                }

                // Normal
                if (Input.keyDown(Key.N))
                {
                    env.alturaCamara = 10f;
                    env.modoDios     = false;
                }

                // Teclas de Menu
                if (Input.keyPressed(Key.UpArrow) && env.opcionMenuSelecionado > 0)
                {
                    env.opcionMenuSelecionado -= 1;
                }
                if (Input.keyPressed(Key.DownArrow) && env.opcionMenuSelecionado < 2)
                {
                    env.opcionMenuSelecionado += 1;
                }


                switch (env.opcionMenuSelecionado)
                {
                case 0:
                    env.buttonSelected.Position = new Vector2(((float)D3DDevice.Instance.Width / 2) - 150, 210);
                    break;

                case 1:
                    env.buttonSelected.Position = new Vector2(((float)D3DDevice.Instance.Width / 2) - 150, 280);
                    break;

                case 2:
                    env.buttonSelected.Position = new Vector2(((float)D3DDevice.Instance.Width / 2) - 150, 350);
                    break;
                }

                //Run
                if (Input.keyDown(Key.LeftShift))
                {
                    // Fuerzo a que el Personaje este siempre sobre la Isla
                    if (env.terreno.estaDentroTerreno())
                    {
                        moveVector += new Vector3(0, 1, 0) * JumpSpeed;
                    }
                    else
                    {
                        moveVector -= new Vector3(0, 10, 0) * JumpSpeed;
                    }
                }
            }


            //Detectar colisiones
            var collide = false;

            foreach (var obstaculo in env.terreno.SceneMeshes)
            {
                if (TgcCollisionUtils.testSphereAABB(env.personaje.BoundingSphere, obstaculo.BoundingBox))
                {
                    env.personaje.BoundingSphere.setRenderColor(Color.Red);
                    collide = true;
                    break;
                }
            }

            if (!env.personaje.Muerto && !env.partidoGanado)
            {
                //Si hubo colision, restaurar la posicion anterior de la camara
                if (collide)
                {
                    moveVector -= new Vector3(0, 0, -1) * MovementSpeed;
                }

                // Aplico la rotacion de la camara
                leftrightRot -= -Input.XposRelative * RotationSpeed;
                updownRot    -= Input.YposRelative * RotationSpeed;
                //Se actualiza matrix de rotacion, para no hacer este calculo cada vez y solo cuando en verdad es necesario.
                cameraRotation = Matrix.RotationX(updownRot) * Matrix.RotationY(leftrightRot);

                if (lockCam)
                {
                    Cursor.Position = mouseCenter;
                }

                //Calculamos la nueva posicion del ojo segun la rotacion actual de la camara.
                var cameraRotatedPositionEye = Vector3.TransformNormal(moveVector * elapsedTime, cameraRotation);
                positionEye += cameraRotatedPositionEye;

                //Calculamos el target de la camara, segun su direccion inicial y las rotaciones en screen space x,y.
                var cameraRotatedTarget = Vector3.TransformNormal(directionView, cameraRotation);
                var cameraFinalTarget   = positionEye + cameraRotatedTarget;

                var cameraOriginalUpVector = DEFAULT_UP_VECTOR;
                var cameraRotatedUpVector  = Vector3.TransformNormal(cameraOriginalUpVector, cameraRotation);

                base.SetCamera(positionEye, cameraFinalTarget, cameraRotatedUpVector);

                // Posiciono la Camara a la Altura del Terreno según las coordenadas actuales
                var posicionCamaraTerrenoOriginal = env.terreno.CalcularAlturaTerreno(
                    FastMath.Ceiling(positionEye.X / env.terreno.SceneScaleXZ),
                    FastMath.Ceiling(positionEye.Z / env.terreno.SceneScaleXZ)
                    , true) + env.alturaCamara;

                var newpositionEye       = new Vector3(positionEye.X, posicionCamaraTerrenoOriginal * env.terreno.SceneScaleY, positionEye.Z);
                var newcameraFinalTarget = newpositionEye + cameraRotatedTarget;

                base.SetCamera(newpositionEye, newcameraFinalTarget, cameraRotatedUpVector);


                //var posicionHacha = new Vector3(env.personaje.hachaPersonaje.Position.X + leftrightRot - 1, env.personaje.hachaPersonaje.Position.Y, env.personaje.hachaPersonaje.Position.Z);


                //Vector3 dirView = env.Camara.LookAt - env.Camara.Position;

                //env.personaje.hachaPersonaje.Transform = Matrix.Translation(posicionHacha) * cameraRotation;

                //env.personaje.hachaPersonaje.Transform = env.Camara.LookAt;
                //env.personaje.hachaPersonaje.Rotation = cameraRotatedPositionEye;
                //env.personaje.hachaPersonaje.Rotation = dirView;
            }
        }