예제 #1
0
        /// <summary>
        /// Indica si el gesto es valido para el cajon
        /// </summary>
        public bool validateGesture(Gesture gesture)
        {
            bool result = false;

            switch (gesture.Type)
            {
            //Abrir
            case GestureType.OpenZ:
                //Ver que este en el estado correcto y que el gesto haya sido cerca de la manija
                if (currentState == LockerState.Closed &&
                    waintElapsedTime >= WAIT_TIME &&
                    FastMath.Abs(gesture.Pos.X - handleSphere.Center.X) < handleSphere.Radius &&
                    FastMath.Abs(gesture.Pos.Y - handleSphere.Center.Y) < handleSphere.Radius)
                {
                    result = true;
                }
                break;

            //Cerrar
            case GestureType.CloseZ:
                //Ver que este en el estado correcto y que el gesto haya sido cerca de la manija
                if (currentState == LockerState.Opened &&
                    waintElapsedTime >= WAIT_TIME &&
                    FastMath.Abs(gesture.Pos.X - handleSphere.Center.X) < handleSphere.Radius &&
                    FastMath.Abs(gesture.Pos.Y - handleSphere.Center.Y) < handleSphere.Radius)
                {
                    result = true;
                }
                break;
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        ///     Input W must be a unit-length vector.  The output vectors {U,V} are
        ///     unit length and mutually perpendicular, and {U,V,W} is an orthonormal basis.
        /// </summary>
        private void generateComplementBasis(ref TGCVector3 u, ref TGCVector3 v, TGCVector3 w)
        {
            float invLength;

            if (FastMath.Abs(w.X) >= FastMath.Abs(w.Y))
            {
                // W.x or W.z is the largest magnitude component, swap them
                invLength = FastMath.InvSqrt(w.X * w.X + w.Z * w.Z);
                u.X       = -w.Z * invLength;
                u.Y       = 0f;
                u.Z       = +w.X * invLength;
                v.X       = w.Y * u.Z;
                v.Y       = w.Z * u.X - w.X * u.Z;
                v.Z       = -w.Y * u.X;
            }
            else
            {
                // W.y or W.z is the largest magnitude component, swap them
                invLength = FastMath.InvSqrt(w.Y * w.Y + w.Z * w.Z);
                u.X       = 0f;
                u.Y       = +w.Z * invLength;
                u.Z       = -w.Y * invLength;
                v.X       = w.Y * u.Z - w.Z * u.Y;
                v.Y       = -w.X * u.Z;
                v.Z       = w.X * u.Y;
            }
        }
예제 #3
0
        /// <summary>
        /// Indica si el gesto es valido para el cajon
        /// </summary>
        public bool validateGesture(Gesture gesture)
        {
            bool    result     = false;
            Vector3 doorCenter = mesh.BoundingBox.calculateBoxCenter();

            switch (gesture.Type)
            {
            //Abrir
            case GestureType.OpenLeft:
                //Ver que este en el estado correcto y que el gesto haya sido en el centro de la puerta
                if (currentState == DoorState.Closed &&
                    waintElapsedTime >= WAIT_TIME &&
                    FastMath.Abs(gesture.Pos.X - doorCenter.X) < 10f &&
                    FastMath.Abs(gesture.Pos.Y - doorCenter.Y) < 10f)
                {
                    result = true;
                }
                break;

            //Cerrar
            case GestureType.OpenRight:
                //Ver que este en el estado correcto y que el gesto haya sido en el centro de la puerta
                if (currentState == DoorState.Opened &&
                    waintElapsedTime >= WAIT_TIME &&
                    FastMath.Abs(gesture.Pos.X - doorCenter.X) < 10f &&
                    FastMath.Abs(gesture.Pos.Y - doorCenter.Y) < 10f)
                {
                    result = true;
                }
                break;
            }
            return(result);
        }
예제 #4
0
        public override void Update()
        {
            TwistedMetal tm = TwistedMetal.getInstance();

            if (cambiarCamara())
            {
                alternaCamara();
            }

            if (cambiarMusica())
            {
                tm.cambiarMusica();
            }


            if (moverArriba())
            {
                base.startSalto();
            }

            base.Update();
            camaraInterna.Target = this.getMesh().Position;
            camaraRotante.SetCamera(new Vector3(camaraInterna.Position.X, 150, camaraInterna.Position.Z),
                                    new Vector3(camaraInterna.Target.X, 100, camaraInterna.Target.Z));

            /*foreach (var rueda in base.getRueda())
             * {
             *  rueda.up
             * }*/
            this.velocimetro.Update(FastMath.Abs(this.getVelocidadX()));
        }
예제 #5
0
        /// <summary>
        ///     Recorrer recursivamente el Quadtree para encontrar los nodos visibles
        /// </summary>
        private void findVisibleMeshes(TgcFrustum frustum, QuadtreeNode node,
                                       float boxLowerX, float boxLowerY, float boxLowerZ,
                                       float boxUpperX, float boxUpperY, float boxUpperZ)
        {
            var children = node.children;

            //es hoja, cargar todos los meshes
            if (children == null)
            {
                selectLeafMeshes(node);
            }

            //recursividad sobre hijos
            else
            {
                var midX = FastMath.Abs((boxUpperX - boxLowerX) / 2);
                var midZ = FastMath.Abs((boxUpperZ - boxLowerZ) / 2);

                //00
                testChildVisibility(frustum, children[0], boxLowerX + midX, boxLowerY, boxLowerZ + midZ, boxUpperX,
                                    boxUpperY, boxUpperZ);

                //01
                testChildVisibility(frustum, children[1], boxLowerX + midX, boxLowerY, boxLowerZ, boxUpperX, boxUpperY,
                                    boxUpperZ - midZ);

                //10
                testChildVisibility(frustum, children[2], boxLowerX, boxLowerY, boxLowerZ + midZ, boxUpperX - midX,
                                    boxUpperY, boxUpperZ);

                //11
                testChildVisibility(frustum, children[3], boxLowerX, boxLowerY, boxLowerZ, boxUpperX - midX, boxUpperY,
                                    boxUpperZ - midZ);
            }
        }
예제 #6
0
 public void modificarVelocidadRotacion(Auto auto)
 {
     if (FastMath.Abs(auto.velocidadActual) > auto.velocidadActual / 3)
     {
         if (FastMath.Abs(auto.velocidadActual) > auto.velocidadActual / 2)
         {
             if (FastMath.Abs(auto.velocidadActual) > auto.velocidadActual / 1.2f)
             {
                 auto.velocidadRotacion = auto.velocidadRotacionOriginal * 1.7f;
             }
             else
             {
                 auto.velocidadRotacion = auto.velocidadRotacionOriginal * 1.4f;
             }
         }
         else
         {
             auto.velocidadRotacion = auto.velocidadRotacionOriginal * 1.2f;
         }
     }
     else
     {
         auto.velocidadRotacion = auto.velocidadRotacionOriginal;
     }
 }
예제 #7
0
        private void doCreateQuadtreeDebugBox(QuadtreeNode node, List <TgcDebugBox> debugBoxes,
                                              float boxLowerX, float boxLowerY, float boxLowerZ,
                                              float boxUpperX, float boxUpperY, float boxUpperZ, int step)
        {
            QuadtreeNode[] children = node.children;

            float midX = FastMath.Abs((boxUpperX - boxLowerX) / 2);
            float midZ = FastMath.Abs((boxUpperZ - boxLowerZ) / 2);

            //Crear caja debug
            TgcDebugBox box = createDebugBox(boxLowerX, boxLowerY, boxLowerZ, boxUpperX, boxUpperY, boxUpperZ, step);

            debugBoxes.Add(box);

            //es hoja, dibujar caja
            if (children == null)
            {
            }

            //recursividad sobre hijos
            else
            {
                step++;

                //000
                doCreateQuadtreeDebugBox(children[0], debugBoxes, boxLowerX + midX, boxLowerY, boxLowerZ + midZ, boxUpperX, boxUpperY, boxUpperZ, step);
                //001
                doCreateQuadtreeDebugBox(children[1], debugBoxes, boxLowerX + midX, boxLowerY, boxLowerZ, boxUpperX, boxUpperY, boxUpperZ - midZ, step);

                //100
                doCreateQuadtreeDebugBox(children[2], debugBoxes, boxLowerX, boxLowerY, boxLowerZ + midZ, boxUpperX - midX, boxUpperY, boxUpperZ, step);
                //101
                doCreateQuadtreeDebugBox(children[3], debugBoxes, boxLowerX, boxLowerY, boxLowerZ, boxUpperX - midX, boxUpperY, boxUpperZ - midZ, step);
            }
        }
        public TGCVector3 HallarCentroDeCara(String dirCara)
        {
            var PMin = mesh.BoundingBox().PMin;
            var PMax = mesh.BoundingBox().PMax;

            var centro = mesh.BoundingBox().calculateBoxCenter();

            switch (dirCara)
            {
            case "x":
                return(new TGCVector3(centro.X + (FastMath.Abs(PMax.X - PMin.X) / 2), centro.Y, centro.Z));

            case "-x":
                return(new TGCVector3(centro.X - (FastMath.Abs(PMax.X - PMin.X) / 2), centro.Y, centro.Z));

            case "y":
                return(new TGCVector3(centro.X, centro.Y + (FastMath.Abs(PMax.Y - PMin.Y) / 2), centro.Z));

            case "-y":
                return(new TGCVector3(centro.X, centro.Y - (FastMath.Abs(PMax.Y - PMin.Y) / 2), centro.Z));

            case "z":
                return(new TGCVector3(centro.X, centro.Y, centro.Z + (FastMath.Abs(PMax.Z - PMin.Z) / 2)));

            case "-z":
                return(new TGCVector3(centro.X, centro.Y, centro.Z - (FastMath.Abs(PMax.Z - PMin.Z) / 2)));

            default:
                throw new Exception("direccion invalida");
            }
        }
예제 #9
0
        /// <summary>
        ///     Calcular desplazamiento en unidades de grilla
        /// </summary>
        private float snapMovementToGrid(ref float currentMove, ref float acumMove, float cellSize)
        {
            //Se movio algo?
            var         totalMove = acumMove + currentMove;
            const float epsilon   = 0.1f;
            var         absMove   = FastMath.Abs(totalMove);
            float       snapMove  = 0;

            if (absMove > epsilon)
            {
                if (absMove > cellSize)
                {
                    //Moverse en unidades de la grilla
                    currentMove = (int)(totalMove / cellSize) * cellSize;
                    acumMove    = 0;
                }
                else
                {
                    //Acumular movimiento para la proxima
                    acumMove   += currentMove;
                    currentMove = 0;
                }
            }

            return(snapMove);
        }
예제 #10
0
파일: Zone.cs 프로젝트: JVirant/DOLSharp
        /// <summary>
        /// Checks that the minimal distance between a point and a subzone (defined by the four position of the sides) is lower or equal
        /// to the distance (given as a square distance)
        /// PRECONDITION : the point is not in the tested subzone
        /// </summary>
        /// <param name="x">X position of the point</param>
        /// <param name="y">Y position of the square</param>
        /// <param name="xLeft">X value of the left side of the square</param>
        /// <param name="xRight">X value of the right side of the square</param>
        /// <param name="yTop">Y value of the top side of the square</param>
        /// <param name="yBottom">Y value of the bottom side of the square</param>
        /// <param name="squareRadius">the square of the radius to check for</param>
        /// <returns>The distance</returns>
        private bool CheckMinDistance(int x, int y, int xLeft, int xRight, int yTop, int yBottom, uint squareRadius)
        {
            long distance = 0;

            if ((y >= yTop) && (y <= yBottom))
            {
                int xdiff = Math.Min(FastMath.Abs(x - xLeft), FastMath.Abs(x - xRight));
                distance = (long)xdiff * xdiff;
            }
            else
            {
                if ((x >= xLeft) && (x <= xRight))
                {
                    int ydiff = Math.Min(FastMath.Abs(y - yTop), FastMath.Abs(y - yBottom));
                    distance = (long)ydiff * ydiff;
                }
                else
                {
                    int xdiff = Math.Min(FastMath.Abs(x - xLeft), FastMath.Abs(x - xRight));
                    int ydiff = Math.Min(FastMath.Abs(y - yTop), FastMath.Abs(y - yBottom));
                    distance = (long)xdiff * xdiff + (long)ydiff * ydiff;
                }
            }

            return(distance <= squareRadius);
        }
예제 #11
0
 /// <summary>
 ///     Actualiza la posicion e inclinacion del cilindro
 /// </summary>
 public void updateValues()
 {
     BoundingCylinder.Radius = FastMath.Max(
         FastMath.Abs(TopRadius), FastMath.Abs(BottomRadius));
     BoundingCylinder.updateValues();
     updateDraw();
 }
예제 #12
0
        /// <summary>
        /// {@inheritDoc} </summary>
        protected internal override double DoIntegrate()
        {
            // compute first estimate with a single step
            double oldt = Stage(1);

            int n = 2;

            while (true)
            {
                // improve integral with a larger number of steps
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double t = stage(n);
                double t = Stage(n);

                // estimate error
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double delta = org.apache.commons.math3.util.FastMath.abs(t - oldt);
                double delta = FastMath.Abs(t - oldt);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double limit = org.apache.commons.math3.util.FastMath.max(getAbsoluteAccuracy(), getRelativeAccuracy() * (org.apache.commons.math3.util.FastMath.abs(oldt) + org.apache.commons.math3.util.FastMath.abs(t)) * 0.5);
                double limit = FastMath.Max(GetAbsoluteAccuracy(), GetRelativeAccuracy() * (FastMath.Abs(oldt) + FastMath.Abs(t)) * 0.5);

                // check convergence
                if ((GetIterations() + 1 >= GetMinimalIterationCount()) && (delta <= limit))
                {
                    return(t);
                }

                // prepare next iteration
                double ratio = FastMath.min(4, FastMath.Pow(delta / limit, 0.5 / abscissas.Length));
                n    = FastMath.Max((int)(ratio * n), n + 1);
                oldt = t;
                IncrementCount();
            }
        }
예제 #13
0
        public override float obtenerAlturaInstantanea(TGCVector3 posicionPersonaje)
        {
            List <TGCVector3> listaVertices = new List <TGCVector3>();
            var vertices = getVertexPositions().GetEnumerator();

            while (vertices.MoveNext())
            {
                listaVertices.Add((TGCVector3)(vertices.Current));
            }
            listaVertices.Sort(new ComparadorYTgcVector3());

            TGCVector3 verticeMasAlto = listaVertices[0];

            listaVertices.Reverse();
            TGCVector3 verticeMasBajo = listaVertices[0];


            float longitudRampa = FastMath.Abs(verticeMasAlto.Z - verticeMasBajo.Z);


            float pendienteRampa           = (verticeMasAlto.Y - verticeMasBajo.Y) / FastMath.Abs(verticeMasAlto.Z - verticeMasBajo.Z);
            float diferenciaPersonajeRampa = FastMath.Abs(verticeMasAlto.Z - posicionPersonaje.Z);


            float YPorDesnivel = pendienteRampa * FastMath.Abs(longitudRampa - diferenciaPersonajeRampa);


            return(YPorDesnivel);
        }
예제 #14
0
        private void doCreateOctreeDebugBox(OctreeNode node, List <TgcBoxDebug> debugBoxes,
                                            float boxLowerX, float boxLowerY, float boxLowerZ,
                                            float boxUpperX, float boxUpperY, float boxUpperZ, int step)
        {
            if (node == null)
            {
                return;
            }

            var children = node.children;

            var midX = FastMath.Abs((boxUpperX - boxLowerX) / 2);
            var midY = FastMath.Abs((boxUpperY - boxLowerY) / 2);
            var midZ = FastMath.Abs((boxUpperZ - boxLowerZ) / 2);

            //Crear caja debug
            var box = createDebugBox(boxLowerX, boxLowerY, boxLowerZ, boxUpperX, boxUpperY, boxUpperZ, step);

            debugBoxes.Add(box);

            //es hoja, dibujar caja
            if (children == null)
            {
            }

            //recursividad sobre hijos
            else
            {
                step++;

                //000
                doCreateOctreeDebugBox(children[0], debugBoxes, boxLowerX + midX, boxLowerY + midY, boxLowerZ + midZ,
                                       boxUpperX, boxUpperY, boxUpperZ, step);
                //001
                doCreateOctreeDebugBox(children[1], debugBoxes, boxLowerX + midX, boxLowerY + midY, boxLowerZ, boxUpperX,
                                       boxUpperY, boxUpperZ - midZ, step);

                //010
                doCreateOctreeDebugBox(children[2], debugBoxes, boxLowerX + midX, boxLowerY, boxLowerZ + midZ, boxUpperX,
                                       boxUpperY - midY, boxUpperZ, step);
                //011
                doCreateOctreeDebugBox(children[3], debugBoxes, boxLowerX + midX, boxLowerY, boxLowerZ, boxUpperX,
                                       boxUpperY - midY, boxUpperZ - midZ, step);

                //100
                doCreateOctreeDebugBox(children[4], debugBoxes, boxLowerX, boxLowerY + midY, boxLowerZ + midZ,
                                       boxUpperX - midX, boxUpperY, boxUpperZ, step);
                //101
                doCreateOctreeDebugBox(children[5], debugBoxes, boxLowerX, boxLowerY + midY, boxLowerZ, boxUpperX - midX,
                                       boxUpperY, boxUpperZ - midZ, step);

                //110
                doCreateOctreeDebugBox(children[6], debugBoxes, boxLowerX, boxLowerY, boxLowerZ + midZ, boxUpperX - midX,
                                       boxUpperY - midY, boxUpperZ, step);
                //111
                doCreateOctreeDebugBox(children[7], debugBoxes, boxLowerX, boxLowerY, boxLowerZ, boxUpperX - midX,
                                       boxUpperY - midY, boxUpperZ - midZ, step);
            }
        }
예제 #15
0
        /// <summary>
        /// <para>Reduce {@code |a - offset|} to the primary interval
        /// {@code [0, |period|)}.</para>
        ///
        /// <para>Specifically, the value returned is <br/>
        /// {@code a - |period| * floor((a - offset) / |period|) - offset}.</para>
        ///
        /// <para>If any of the parameters are {@code NaN} or infinite, the result is
        /// {@code NaN}.</para>
        /// </summary>
        /// <param name="a"> Value to reduce. </param>
        /// <param name="period"> Period. </param>
        /// <param name="offset"> Value that will be mapped to {@code 0}. </param>
        /// <returns> the value, within the interval {@code [0 |period|)},
        /// that corresponds to {@code a}. </returns>
        public static double Reduce(double a, double period, double offset)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double p = FastMath.abs(period);
            double p = FastMath.Abs(period);

            return(a - p * FastMath.Floor((a - offset) / p) - offset);
        }
예제 #16
0
 public void FlotacionEspacial(float tiempoRenderizado)
 {
     Modelo.move(0, Flotacion * DireccionFlotacion * tiempoRenderizado * 2, 0);
     if (FastMath.Abs(Modelo.Position.Y) > 7f)
     {
         DireccionFlotacion *= -1;
     }
 }
예제 #17
0
        public CoordenadaEsferica Diferencia(CoordenadaEsferica coordenadaEsferica)
        {
            float deltaAcimutal = FastMath.Abs(this.acimutal - coordenadaEsferica.acimutal);
            float deltaPolar    = FastMath.Abs(this.polar - coordenadaEsferica.polar);

            return(new CoordenadaEsferica(FastMath.Min(deltaAcimutal, FastMath.TWO_PI - deltaAcimutal),
                                          FastMath.Min(deltaPolar, FastMath.TWO_PI - deltaPolar)));
        }
예제 #18
0
        private void UpdateHub()
        {
            float velocidadMaxima = (this.auto.GetVelocidadActual() < 0) ? this.auto.GetMaxBackwardVelocity() : this.auto.GetMaxForwardVelocity();
            float maxAngle        = (this.auto.GetVelocidadActual() > 0) ? FastMath.PI + FastMath.PI / 3 : FastMath.PI_HALF;

            this.arrowVelocimeter.Rotation = (FastMath.Abs(this.auto.GetVelocidadActual()) * (maxAngle)) / velocidadMaxima - FastMath.PI;
            this.barOfLifeGreen.Scaling    = new TGCVector2((this.auto.GetLife() * 0.07f) / 100f, 0.05f);
        }
예제 #19
0
        /// <summary>
        /// Hacer analisis estadistico de los datos de posicion de una mano del esqueleto, en un eje determinado.
        /// Guarda los datos en el AxisAnalysisData de ese eje, para esa mano
        /// </summary>
        private void computeAxisAnalysis(TgcKinectSkeletonData data, int handIndex, int axisIndex)
        {
            //Lugar donde tenemos que almacenar el resultado
            TgcKinectSkeletonData.AxisAnalysisData analysis = data.HandsAnalysisData[handIndex][axisIndex];

            int framesCount = data.HandsFrames.Count;

            analysis.Min = float.MaxValue;
            analysis.Max = float.MinValue;
            float sum       = 0;
            int   i         = 0;
            float value     = 0;
            float lastValue = 0;
            float sumDiff   = 0;

            foreach (TgcKinectSkeletonData.HandFrame frame in data.HandsFrames)
            {
                lastValue = value;
                value     = frame.get3DValue(handIndex, axisIndex);
                sum      += value;

                //min
                if (value < analysis.Min)
                {
                    analysis.Min = value;
                }
                //max
                if (value > analysis.Max)
                {
                    analysis.Max = value;
                }

                //diff con el anterior
                if (i > 0)
                {
                    sumDiff += value - lastValue;
                }


                i++;
            }

            //avg
            analysis.Avg = sum / framesCount;

            //diff
            analysis.DiffAvg = sumDiff / (framesCount - 1);

            //variance
            float sumVariance = 0;

            foreach (TgcKinectSkeletonData.HandFrame frame in data.HandsFrames)
            {
                value        = frame.get3DValue(handIndex, axisIndex);
                sumVariance += FastMath.Abs(analysis.Avg - value);
            }
            analysis.Variance = sumVariance / framesCount;
        }
예제 #20
0
        public void Add(object key, object value)
        {
            int bucketNumber = (key.GetHashCode() & Int32.MaxValue) % BUCKET_NUMBER;

            for (int i = bucketListIndexes[bucketNumber]; i < nextInsertIndex[bucketNumber]; i++)
            {
                if (internalArray[i].key.Equals(key))
                {
                    // object found => replace associated value
                    internalArray[i].value = value;
                    return;
                }
            }

            // object not found
            // => add it
            DictionaryEntry entry = new DictionaryEntry();

            entry.key   = key;
            entry.value = value;
            if (nextInsertIndex[bucketNumber] >= bucketListIndexes[bucketNumber + 1])
            {
                // current bucket list is full

                if (LoadFactor >= loadFactor)
                {
                    //Console.WriteLine(this.GetType() + " LoadFactor exceeded - rehashing... (" + loadFactor + ", " + LoadFactor + ")");
                    Rehash();
                    ForceAdd(entry);

                    return;
                }

                // try to get a slot from another bucket
                int usedBucket = GetForwardFreeSlot(bucketNumber);

                if (usedBucket == -1)
                {
                    usedBucket = GetBackwardFreeSlot(bucketNumber);
                }

                if ((usedBucket == -1) || (FastMath.Abs(usedBucket - bucketNumber) >= 7))
                {
                    // no free slots left or getting one becomes too costly

                    Rehash();
                    ForceAdd(entry);

                    return;
                }
            }

            // normal add (a free slot has been granted by another bucket or there was enough space left in this bucket)
            internalArray[nextInsertIndex[bucketNumber]++] = entry;

            usedSlots++;
        }
예제 #21
0
 /// <summary>
 /// Check whether the given complex root is actually a real zero
 /// in the given interval, within the solver tolerance level.
 /// </summary>
 /// <param name="min"> Lower bound for the interval. </param>
 /// <param name="max"> Upper bound for the interval. </param>
 /// <param name="z"> Complex root. </param>
 /// <returns> {@code true} if z is a real zero. </returns>
 public virtual bool IsRoot(double min, double max, Complex z)
 {
     if (outerInstance.IsSequence(min, z.GetReal(), max))
     {
         double tolerance = FastMath.Max(outerInstance.GetRelativeAccuracy() * z.Abs(), outerInstance.GetAbsoluteAccuracy());
         return((FastMath.Abs(z.GetImaginary()) <= tolerance) || (z.Abs() <= outerInstance.GetFunctionValueAccuracy()));
     }
     return(false);
 }
예제 #22
0
        private void ajustarPosicionDeCamara()
        {
            //Actualizar valores de camara segun modifiers
            camaraInterna.OffsetHeight  = 150;
            camaraInterna.OffsetForward = 300;
            var displacement = new TGCVector3(0, 60, 200);

            camaraInterna.TargetDisplacement = new TGCVector3(displacement.X, displacement.Y, 0);

            //Pedirle a la camara cual va a ser su proxima posicion
            TGCVector3 position;
            TGCVector3 target;

            camaraInterna.CalculatePositionTarget(out position, out target);

            //Detectar colisiones entre el segmento de recta camara-personaje y todos los objetos del escenario
            TGCVector3 q;
            var        minDistSq = FastMath.Pow2(camaraInterna.OffsetForward);

            objectsBehind.Clear();
            objectsInFront.Clear();
            foreach (var mesh in scene.Meshes)
            {
                TGCVector3 colisionCamara;
                if (TgcCollisionUtils.intersectSegmentAABB(camaraInterna.Position, camaraInterna.Target, mesh.BoundingBox, out colisionCamara)) //ACA ESTAMOS GUARDANDO EN UNA LISTA TODOS LOS OBJETOS QUE SE CHOCAN CON LA CAMARA POR DETRAS Y POR ADELANTE.
                {
                    objectsBehind.Add(mesh);
                }
                else
                {
                    objectsInFront.Add(mesh);
                    if (Math.Abs(mesh.BoundingBox.PMax.Y - mesh.BoundingBox.PMin.Y) < 60)
                    {
                        continue;
                    }
                    if (TgcCollisionUtils.intersectSegmentAABB(target, position, mesh.BoundingBox, out q))
                    {
                        //Si hay colision, guardar la que tenga menor distancia
                        float distSq = TGCVector3.Subtract(q, target).LengthSq();
                        //Hay dos casos singulares, puede que tengamos mas de una colision hay que quedarse con el menor offset.
                        //Si no dividimos la distancia por 2 se acerca mucho al target.
                        minDistSq = FastMath.Min(distSq * 0.75f, minDistSq);
                    }
                }
            }
            float newOffsetForward = -FastMath.Sqrt(minDistSq);

            if (FastMath.Abs(newOffsetForward) < 10)
            {
                newOffsetForward = 10;
            }
            camaraInterna.OffsetForward = -newOffsetForward;
            camaraInterna.CalculatePositionTarget(out position, out target);
            camaraInterna.SetCamera(position, target);
        }
예제 #23
0
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        protected internal override double DoSolve()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double min = getMin();
            double min = GetMin();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double max = getMax();
            double max = GetMax();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double initial = getStartValue();
            double initial = GetStartValue();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double functionValueAccuracy = getFunctionValueAccuracy();
            double functionValueAccuracy = GetFunctionValueAccuracy();

            VerifySequence(min, initial, max);

            // check for zeros before verifying bracketing
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double fMin = computeObjectiveValue(min);
            double fMin = ComputeObjectiveValue(min);

            if (FastMath.Abs(fMin) < functionValueAccuracy)
            {
                return(min);
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double fMax = computeObjectiveValue(max);
            double fMax = ComputeObjectiveValue(max);

            if (FastMath.Abs(fMax) < functionValueAccuracy)
            {
                return(max);
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final double fInitial = computeObjectiveValue(initial);
            double fInitial = ComputeObjectiveValue(initial);

            if (FastMath.Abs(fInitial) < functionValueAccuracy)
            {
                return(initial);
            }

            VerifyBracketing(min, max);

            if (IsBracketing(min, initial))
            {
                return(Solve(min, initial, fMin, fInitial));
            }
            else
            {
                return(Solve(initial, max, fInitial, fMax));
            }
        }
예제 #24
0
        public void deformacion_esfera()
        {
            timer += ElapsedTime;

            var variacionY = FastMath.Max(2f, 6f * FastMath.Abs(FastMath.Cos(timer * 1.5f)));
            var variacionZ = FastMath.Max(2f, 6f * FastMath.Abs(FastMath.Sin(timer * 1.5f)));

            var escalado = new TGCVector3(6f, variacionY, variacionZ);

            sphereOne.Transform = TGCMatrix.RotationY(timer) * TGCMatrix.Scaling(escalado) * TGCMatrix.Translation(spheresCenter);
        }
예제 #25
0
    public void UpdateValue(ulong move, int increment)
    {
        // Update value with decay.  Idea from Ethereal chess engine.
        // This function approaches an asymptotic limit of +/- Move.HistoryMaxValue.
        var piece    = Move.Piece(move);
        var toSquare = Move.To(move);
        var value    = _moveHistory[(int)piece][(int)toSquare];

        value += (increment * _multiplier) - ((value * FastMath.Abs(increment)) / _divisor);
        _moveHistory[(int)piece][(int)toSquare] = value;
    }
예제 #26
0
파일: Zone.cs 프로젝트: JVirant/DOLSharp
        /// <summary>
        /// Checks that the maximal distance between a point and a subzone (defined by the four position of the sides) is lower or equal
        /// to the distance (given as a square distance)
        /// </summary>
        /// <param name="x">X position of the point</param>
        /// <param name="y">Y position of the square</param>
        /// <param name="xLeft">X value of the left side of the square</param>
        /// <param name="xRight">X value of the right side of the square</param>
        /// <param name="yTop">Y value of the top side of the square</param>
        /// <param name="yBottom">Y value of the bottom side of the square</param>
        /// <param name="squareRadius">the square of the radius to check for</param>
        /// <returns>The distance</returns>
        private bool CheckMaxDistance(int x, int y, int xLeft, int xRight, int yTop, int yBottom, uint squareRadius)
        {
            long distance = 0;

            int xdiff = Math.Max(FastMath.Abs(x - xLeft), FastMath.Abs(x - xRight));
            int ydiff = Math.Max(FastMath.Abs(y - yTop), FastMath.Abs(y - yBottom));

            distance = (long)xdiff * xdiff + (long)ydiff * ydiff;

            return(distance <= squareRadius);
        }
 public float FuerzaAlGirar()
 {
     if (FastMath.Abs(Velocidad) > 20)
     {
         return(400);
     }
     else
     {
         return(0);
     }
 }
예제 #28
0
        private void PonerTorretasYObstaculos(TGCVector3 posInicial, TGCVector3 posFinal, TGCVector3 rotation,
                                              float mitadAnchoPista, int cantidad)
        {
            float signoZFinal = (float)Math.Sign(posFinal.Z);
            //mejor hacer abs de zinicial - zfinal y usar el signo de zfinal p sumarle a zinicial
            int zLargo = (int)FastMath.Abs(posInicial.Z - posFinal.Z);

            for (int i = 0; i < cantidad; i++)
            {//@@Problema aca con el random, solo sirve pa ints positivos, cambiarlo y obtener el + o - afuera, esta tirando exception
                //CrearObstaculo(new TGCVector3(posInicial.X + mitadAnchoPista * MyRandom() + 30 + 200, posInicial.Y - 65, posInicial.Z + signoZFinal * (float)random.Next(zLargo)), rotation);
                CrearTorreta(new TGCVector3(posInicial.X + mitadAnchoPista * MyRandom() + 30, posInicial.Y - 65, posInicial.Z + signoZFinal * (float)random.Next(zLargo)), rotation);
            }
        }
예제 #29
0
        public override void calcularTraslacionYRotacion(float elapsedTime, TerrenoSimple agua, float time, Vector3 lastPosition)
        {
            distance = player.popa() - this.getPosition();
            Vector3 iaDirectionVersor = this.vectorDireccion();

            iaDirectionVersor.Normalize();
            Vector3 lookAtPopaVersor = new Vector3(distance.X, distance.Y, distance.Z);

            lookAtPopaVersor.Normalize();

            float   rotationAngle = FastMath.Acos(Vector3.Dot(iaDirectionVersor, lookAtPopaVersor));
            Vector3 cross         = Vector3.Cross(lookAtPopaVersor, iaDirectionVersor);

            //Vector3 lastPosition = getPosition();

            if (cross.Length() > 0.1)
            {
                if (cross.Y > 0.1)
                {
                    anguloRotacion -= elapsedTime * ROTATION_SPEED;
                }
                if (cross.Y < -0.1)
                {
                    anguloRotacion += elapsedTime * ROTATION_SPEED;
                }

                rotacion = Matrix.RotationY(anguloRotacion);
            }

            if (FastMath.Abs(distance.Length()) > 1000)
            {
                movementSpeed = Math.Min(movementSpeed + ESCALON_VEL, VEL_MAXIMA);
            }
            if (FastMath.Abs(distance.Length()) <= 1000)
            {
                if (FastMath.Abs(distance.Length()) > 400)
                {
                    movementSpeed = Math.Max(movementSpeed - movementSpeed / distance.Length(), 0);
                }
                else
                {
                    movementSpeed = 0;
                }
            }

            movZ -= movementSpeed * FastMath.Cos(anguloRotacion) * elapsedTime;
            movX -= movementSpeed * FastMath.Sin(anguloRotacion) * elapsedTime;
            movY  = agua.aplicarOlasA(getPosition(), time).Y + AltoBote / 2;

            administrarColisiones(lastPosition, new Vector3(movX, movY, movZ));
        }
예제 #30
0
        /// <summary>
        /// Returns true if the arguments are equal or within the range of allowed
        /// error (inclusive).
        /// <para>
        /// Two float numbers are considered equal if there are {@code (maxUlps - 1)}
        /// (or fewer) floating point numbers between them, i.e. two adjacent
        /// floating point numbers are considered equal.
        /// </para>
        /// <para>
        /// Adapted from <a
        /// href="http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/">
        /// Bruce Dawson</a>. Returns {@code false} if either of the arguments is NaN.
        /// </para>
        /// </summary>
        /// <param name="x"> first value </param>
        /// <param name="y"> second value </param>
        /// <param name="maxUlps"> {@code (maxUlps - 1)} is the number of floating point
        /// values between {@code x} and {@code y}. </param>
        /// <returns> {@code true} if there are fewer than {@code maxUlps} floating
        /// point values between {@code x} and {@code y}. </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public static boolean equals(final double x, final double y, final int maxUlps)
        public static bool Equals(double x, double y, int maxUlps)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long xInt = Double.doubleToRawLongBits(x);
            long xInt = Double.doubleToRawLongBits(x);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long yInt = Double.doubleToRawLongBits(y);
            long yInt = Double.doubleToRawLongBits(y);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean isEqual;
            bool isEqual;

            if (((xInt ^ yInt) & SGN_MASK) == 0l)
            {
                // number have same sign, there is no risk of overflow
                isEqual = FastMath.Abs(xInt - yInt) <= maxUlps;
            }
            else
            {
                // number have opposite signs, take care of overflow
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long deltaPlus;
                long deltaPlus;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long deltaMinus;
                long deltaMinus;
                if (xInt < yInt)
                {
                    deltaPlus  = yInt - POSITIVE_ZERO_DOUBLE_BITS;
                    deltaMinus = xInt - NEGATIVE_ZERO_DOUBLE_BITS;
                }
                else
                {
                    deltaPlus  = xInt - POSITIVE_ZERO_DOUBLE_BITS;
                    deltaMinus = yInt - NEGATIVE_ZERO_DOUBLE_BITS;
                }

                if (deltaPlus > maxUlps)
                {
                    isEqual = false;
                }
                else
                {
                    isEqual = deltaMinus <= (maxUlps - deltaPlus);
                }
            }

            return(isEqual && !double.IsNaN(x) && !double.IsNaN(y));
        }