Example #1
0
        public LtVector3f[] CalculateJumpPoints(float xCurrent, float yCurrent, float zCurrent, float xDestination, float yDestination, float zDestination, long maxHeight, int countParts, long timeEstimation)
        {
            LtVector3f[] Points = new LtVector3f[countParts + 1];
            // ToDo: Calculate the positions between

            return(Points);
        }
Example #2
0
        public int generatePathTable()
        {
            // We firs test this with just one moove from point x to y
            // To calc this we need to know the time the object needs to reach this point,
            // the new point and the rotation to calc pretty to sync client and server position is right
            // to get a smooth walking :)
            Maths math = new Maths();

            // First choose a new pos in the range
            LtVector3f newPos = math.RandomPointOnCircle((float)xBase, (float)yBase, (float)zBase, 5.0f * 100);

            Output.WriteDebugLog("Mob Goes from X: " + this.getXPos() + " , Z: " + this.getZPos() + " to X: " + newPos.a + ", Z: " + newPos.c);


            double xNew = (double)newPos.a;
            double zNew = (double)newPos.c;

            this.destination = newPos;
            // Try to calculate rotation


            // Oh this seems to match ...needs more testing later when we fixed random pos


            double yaw = Math.Atan((double)(xNew - getXPos()) / (zNew - getZPos())) * 128 / Math.PI;

            double calcRotation = Math.Atan2(Math.Cos(xNew), Math.Sin(zNew) * Math.Sin(zNew)) * 128 / Math.PI;

            double testRot  = Math.Atan2(xNew, zNew) * 180 / Math.PI;
            double testRot2 = Math.Atan2(xNew, zNew) * 128 / Math.PI;


            Output.WriteDebugLog("Test Rot with 360 : " + testRot + "| 255 : " + testRot2 + " AND THE YAW: " + yaw + " (Cast to uint16 : " + Convert.ToInt16(yaw) + " )");


            int yawVal = (int)Convert.ToInt16(yaw);

            if (zNew < this.getZPos() || xNew < this.getXPos())
            {
                Output.WriteDebugLog("Need to adjust YAW + 128 from :" + yawVal.ToString() + " to: " + (yawVal + 128).ToString());
                yawVal = yawVal + 128;
            }
            else
            {
                Output.WriteDebugLog("Need to adjust YAW - 128 from :" + yawVal.ToString() + " to: " + (yawVal - 128).ToString());
                yawVal = yawVal - 128;
            }

            Output.WriteDebugLog("YAW VAL :" + yawVal.ToString());

            this.rotation = (ushort)yawVal;
            Output.WriteDebugLog("Calc Rotation : " + calcRotation.ToString() + " and to UINT : " + (uint)calcRotation);

            // Calculate the distance for seconds to move
            int requiredSeconds = (int)(((math.distance2Coords((float)xPos, (float)xNew, (float)zPos, (float)zNew) / 0.176) / 500) * 0.9586);

            return(requiredSeconds);
        }
Example #3
0
        // ToDo: Implement the methods from the file..it could be the paradise^^
        public LtVector3f RandomPointOnCircle(float xCurrent, float yCurrent, float zCurrent, float radius)
        {
            double     angle  = (double)RandomBetween(0.0f, (float)Math.PI * 2);
            LtVector3f newPos = new LtVector3f();

            newPos.a = xCurrent + radius * (float)Math.Cos(angle);
            newPos.b = yCurrent;
            newPos.c = zCurrent + radius * (float)Math.Sin(angle);

            return(newPos);
        }
Example #4
0
        // https://gamedev.stackexchange.com/questions/133794/parabolic-movement-of-a-gameobject-in-unity
        public static LtVector3f[] ParabolicMovement(LtVector3f startingPos, LtVector3f arrivingPos, float maxHeight, int framesCount)
        {
            // float ANIMATION_DURATION = 2.0f;
            // float FRAMES_PER_SECOND = 30.0f;
            // int framesNum = (int)(ANIMATION_DURATION * FRAMES_PER_SECOND);
            int framesNum = framesCount;

            LtVector3f[] frames = new LtVector3f[framesNum];


            //PROJECTING ON Z AXIS
            LtVector3f stP = new LtVector3f(0, startingPos.y, startingPos.z);
            LtVector3f arP = new LtVector3f(0, arrivingPos.y, arrivingPos.z);

            LtVector3f diff = new LtVector3f((arP.x - stP.x) / 2 + maxHeight, (arP.y - stP.y) / 2 + maxHeight, (arP.z - stP.z) / 2 + maxHeight);

            LtVector3f vertex = new LtVector3f(stP.x + diff.x, stP.y + diff.y, stP.z + diff.z);

            float x1 = startingPos.z;
            float y1 = startingPos.y;
            float x2 = arrivingPos.z;
            float y2 = arrivingPos.y;
            float x3 = vertex.z;
            float y3 = vertex.y;

            float denom = (x1 - x2) * (x1 - x3) * (x2 - x3);

            var z_dist = (arrivingPos.z - startingPos.z) / framesNum;
            var x_dist = (arrivingPos.x - startingPos.x) / framesNum;

            float A = (x3 * (y2 - y1) + x2 * (y1 - y3) + x1 * (y3 - y2)) / denom;
            float B = (float)(Math.Pow(x3, 2) * (y1 - y2) + Math.Pow(x2, 2) * (y3 - y1) + Math.Pow(x1, 2) * (y2 - y3)) / denom;
            float C = (x2 * x3 * (x2 - x3) * y1 + x3 * x1 * (x3 - x1) * y2 + x1 * x2 * (x1 - x2) * y3) / denom;

            float newX = startingPos.z;
            float newZ = startingPos.x;

            for (int i = 0; i < framesNum; i++)
            {
                newX += z_dist;
                newZ += x_dist;
                float yToBeFound = A * (newX * newX) + B * newX + C;
                frames[i] = new LtVector3f(newZ, yToBeFound, newX);
            }
            return(frames);
        }
Example #5
0
        public LtVector3f RandomPointInCircleV2(float xCurrent, float zCurrent, float radius)
        {
            // new vector
            LtVector3f newPos = new LtVector3f();

            newPos.a = 0.0f;
            newPos.c = 0.0f;

            int    u     = this.rand.Next(1, 32000);
            int    v     = this.rand.Next(1, 32000);
            double theta = 2 * Math.PI * u;
            var    phi   = Math.Acos(2 * v - 1);
            double x     = xCurrent + (radius * Math.Sin(phi) * Math.Cos(theta));
            double y     = 95.0;
            double z     = zCurrent + (radius * Math.Cos(phi));

            newPos.a = (float)x;
            newPos.b = (float)y;
            newPos.c = (float)z;
            return(newPos);
        }
Example #6
0
        public LtVector3f RadnomPointInCircle(float xCurrent, float zCurrent, float radius)
        {
            // calc http://stackoverflow.com/questions/5531827/random-point-on-a-given-sphere
            // http://freespace.virgin.net/hugo.elias/routines/r_dist.htm - Distance
            LtVector3f newPos = new LtVector3f();
            newPos.a = 0.0f;
            newPos.c = 0.0f;

            int randMax = 254;
            float angle = (float)(rand.Next(1, randMax) * (Math.PI * 2) / randMax);
            float distance = (float)Math.Sqrt(rand.Next(1, (int)radius) * 1.0 / randMax) * radius / 100;

            float x = (float)Math.Cos(angle) * distance + (xCurrent/100);
            float z = (float)Math.Sin(angle) * distance + (zCurrent/100);

            Output.WriteDebugLog("Distance : " + distance);

            newPos.a = x;
            newPos.c = z;
            return newPos;
        }
Example #7
0
        public void SendHyperJumpStepUpdate(LtVector3f currentPos, double xDestPos, double yDestPos, double zDestPos,
                                            float jumpHeight, uint endtime, ushort stepJumpId, uint maybeTimeBasedValue, bool isLastStep = false)
        {
            PacketContent pak = new PacketContent();

            pak.addUint16(2, 1);
            pak.addByte(0x03);
            pak.addByte(0x0d);
            pak.addByte(0x08);
            pak.addByte(0x00);
            pak.addUintShort(Store.currentClient.playerData.getJumpID());
            pak.addFloatLtVector3f(currentPos.x, currentPos.y, currentPos.z);
            pak.addUintShort(stepJumpId);
            pak.addUint32(maybeTimeBasedValue, 1);
            // ToDo: Insert 2 missing bytes (or 4 as the next 2 bytes MAYBE wrong)
            pak.addByte(0x8a);
            pak.addByte(0x04);
            pak.addByte(0x80);
            pak.addByte(0x88);
            pak.addByteArray(new byte[] { 0x00, 0x00, 0x00, 0x00, 0xbc });
            pak.addFloat(jumpHeight, 1);
            pak.addUint16(4, 1);
            pak.addUint32(endtime, 1);
            pak.addDoubleLtVector3d(xDestPos, yDestPos, zDestPos);
            pak.addByteArray(new byte[] { 0x80, 0x81, 0x00, 0x02 });
            if (isLastStep)
            {
                pak.addByte(0x00);
                Store.currentClient.playerData.isJumping = false;
            }
            else
            {
                pak.addByte(0x01);
            }

            Store.currentClient.messageQueue.addObjectMessage(pak.returnFinalPacket(), false);
            Store.currentClient.FlushQueue();
        }
Example #8
0
        public void SendHyperJumpStepUpdate(LtVector3f currentPos, double xDestPos, double yDestPos, double zDestPos, float jumpHeight, UInt32 endtime)
        {
            PacketContent pak = new PacketContent();

            pak.addUint16(2, 1);
            pak.addByte(0x03);
            pak.addByte(0x0d);
            pak.addByte(0x08);
            pak.addByte(0x00);
            pak.addFloatLtVector3f(currentPos.x, currentPos.y, currentPos.z);
            pak.addByte(0x8a);
            pak.addByte(0x04);
            pak.addByte(0x80);
            pak.addByte(0x88);
            pak.addByteArray(new byte[] { 0x00, 0x00, 0x00, 0x00, 0xbc });
            pak.addFloat(jumpHeight, 1);
            pak.addUint16(4, 1);
            pak.addUint32(endtime, 1);
            pak.addDoubleLtVector3d(xDestPos, yDestPos, zDestPos);
            pak.addByteArray(new byte[] { 0x80, 0x81, 0x00, 0x02, 0x01, 0x00 });
            Store.currentClient.messageQueue.addObjectMessage(pak.returnFinalPacket(), false);
            Store.currentClient.FlushQueue();
        }
Example #9
0
        public LtVector3f RadnomPointInCircle(float xCurrent, float zCurrent, float radius)
        {
            // calc http://stackoverflow.com/questions/5531827/random-point-on-a-given-sphere
            // http://freespace.virgin.net/hugo.elias/routines/r_dist.htm - Distance
            LtVector3f newPos = new LtVector3f();

            newPos.a = 0.0f;
            newPos.c = 0.0f;


            int   randMax  = 254;
            float angle    = (float)(rand.Next(1, randMax) * (Math.PI * 2) / randMax);
            float distance = (float)Math.Sqrt(rand.Next(1, (int)radius) * 1.0 / randMax) * radius / 100;


            float x = (float)Math.Cos(angle) * distance + (xCurrent / 100);
            float z = (float)Math.Sin(angle) * distance + (zCurrent / 100);

            Output.WriteDebugLog("Distance : " + distance);

            newPos.a = x;
            newPos.c = z;
            return(newPos);
        }
Example #10
0
File: npc.cs Project: hdneo/mxo-hd
        public int generatePathTable()
        {
            // We firs test this with just one moove from point x to y
            // To calc this we need to know the time the object needs to reach this point,
            // the new point and the rotation to calc pretty to sync client and server position is right
            // to get a smooth walking :)
            Maths math = new Maths();

            // First choose a new pos in the range
            LtVector3f newPos = math.RandomPointOnCircle((float)xBase,(float)yBase, (float)zBase, 5.0f * 100);
            Output.WriteDebugLog("Mob Goes from X: " + this.getXPos() + " , Z: " + this.getZPos() + " to X: " + newPos.a + ", Z: " + newPos.c);

            double xNew = (double)newPos.a;
            double zNew = (double)newPos.c;

            this.destination = newPos;
            // Try to calculate rotation

            // Oh this seems to match ...needs more testing later when we fixed random pos

            double yaw = Math.Atan((double)(xNew - getXPos()) / (zNew - getZPos()))*128/Math.PI;

            double calcRotation = Math.Atan2(Math.Cos(xNew), Math.Sin(zNew) * Math.Sin(zNew)) * 128/Math.PI;

            double testRot = Math.Atan2(xNew, zNew) * 180 / Math.PI;
            double testRot2 = Math.Atan2(xNew, zNew) * 128 / Math.PI;

            Output.WriteDebugLog("Test Rot with 360 : " + testRot.ToString() + "| 255 : " + testRot2.ToString() + " AND THE YAW: " + yaw.ToString() + " (Cast to uint16 : " + Convert.ToInt16(yaw).ToString() + " )");

            int yawVal = (int)Convert.ToInt16(yaw);

            if (zNew < this.getZPos() || xNew < this.getXPos())
            {
                Output.WriteDebugLog("Need to adjust YAW + 128 from :" + yawVal.ToString() + " to: " + (yawVal + 128).ToString());
                yawVal = yawVal + 128;
            }
            else
            {
                Output.WriteDebugLog("Need to adjust YAW - 128 from :" + yawVal.ToString() + " to: " + (yawVal - 128).ToString());
                yawVal = yawVal - 128;
            }

            Output.WriteDebugLog("YAW VAL :" + yawVal.ToString() );

            this.rotation = (ushort)yawVal;
            Output.WriteDebugLog("Calc Rotation : " + calcRotation.ToString() + " and to UINT : " + (uint)calcRotation);

            // Calculate the distance for seconds to move
            int requiredSeconds = (int)(((math.distance2Coords((float)xPos, (float)xNew, (float)zPos, (float)zNew) / 0.176) / 500) * 0.9586);
            return requiredSeconds;
        }
Example #11
0
        // ToDo: Implement the methods from the file..it could be the paradise^^
        public LtVector3f RandomPointOnCircle(float xCurrent, float yCurrent, float zCurrent, float radius)
        {
            double angle = (double)RandomBetween(0.0f, (float)Math.PI*2);
            LtVector3f newPos = new LtVector3f();
            newPos.a = xCurrent + radius * (float)Math.Cos(angle);
            newPos.b = yCurrent;
            newPos.c = zCurrent + radius * (float)Math.Sin(angle);

            return newPos;
        }
Example #12
0
        public LtVector3f RandomPointInCircleV2(float xCurrent, float zCurrent, float radius)
        {
            // new vector
            LtVector3f newPos = new LtVector3f();
            newPos.a = 0.0f;
            newPos.c = 0.0f;

            int u = this.rand.Next(1,32000);
            int v = this.rand.Next(1,32000);
            double theta = 2 * Math.PI * u;
            var phi = Math.Acos(2 * v - 1);
            double x = xCurrent + (radius * Math.Sin(phi) * Math.Cos(theta));
            double y = 95.0;
            double z = zCurrent + (radius * Math.Cos(phi));
            newPos.a = (float)x;
            newPos.b = (float)y;
            newPos.c = (float)z;
            return newPos;
        }