protected BoxDescription MakeRotatedBoxBounds(int x1, int y1, int z1, int x2, int y2, int z2)
        {
            BoxDescription desc = default(BoxDescription)
                                  .SetModelBounds(x1, y1, z1, x2, y2, z2);

            desc.SidesW = Math.Abs(y2 - y1);
            desc.BodyW  = Math.Abs(x2 - x1);
            desc.BodyH  = Math.Abs(z2 - z1);
            return(desc);
        }
        /// <summary>Builds a box model assuming the follow texture layout:<br/>
        /// let SW = sides width, BW = body width, BH = body height<br/>
        /// ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃S┈┈┈┈┈┈┈┈┈┈┈S┃S┈┈┈┈top┈┈┈┈S┃S┈┈bottom┈┈┈S┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃W┈┈┈┈┈┈┈┈┈W┃W┈┈┈┈tex┈┈┈W┃W┈┈┈┈tex┈┈┈┈W┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━━━┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┃B┈┈┈left┈┈┈┈┈B┃B┈┈front┈┈┈┈B┃B┈┈┈right┈┈┈┈B┃B┈┈┈back┈┈┈B┃ <br/>
        /// ┃H┈┈┈tex┈┈┈┈┈H┃H┈┈tex┈┈┈┈┈H┃H┈┈┈tex┈┈┈┈┈H┃H┈┈┈┈tex┈┈┈H┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ </summary>
        protected ModelPart BuildBox(BoxDescription desc)
        {
            int   sidesW = desc.SidesW, bodyW = desc.BodyW, bodyH = desc.BodyH;
            float x1 = desc.X1, y1 = desc.Y1, z1 = desc.Z1;
            float x2 = desc.X2, y2 = desc.Y2, z2 = desc.Z2;
            int   x = desc.TexX, y = desc.TexY;

            YQuad(x + sidesW, y, bodyW, sidesW, x2, x1, z2, z1, y2);                          // top
            YQuad(x + sidesW + bodyW, y, bodyW, sidesW, x2, x1, z1, z2, y1);                  // bottom
            ZQuad(x + sidesW, y + sidesW, bodyW, bodyH, x2, x1, y1, y2, z1);                  // front
            ZQuad(x + sidesW + bodyW + sidesW, y + sidesW, bodyW, bodyH, x1, x2, y1, y2, z2); // back
            XQuad(x, y + sidesW, sidesW, bodyH, z2, z1, y1, y2, x2);                          // left
            XQuad(x + sidesW + bodyW, y + sidesW, sidesW, bodyH, z1, z2, y1, y2, x1);         // right
            return(new ModelPart(index - 6 * 4, 6 * 4));
        }
        /// <summary>
        /// Creates a box shape in the world
        /// </summary>
        /// <param name="boxDescription"></param>
        /// <param name="colliderDescription"> </param>
        /// <returns></returns>
        public IWorldObject CreateWorldObject(BoxDescription boxDescription, ColliderDescription colliderDescription)
        {
            lock (this)
            {
                var size      = boxDescription.Size;
                var rigidBody = new RuneRigidbody(new RuneBoxShape(size.X, size.Y, size.Z))
                {
                    Pose  = new Pose(boxDescription.Position.ToRuneVector(), boxDescription.Rotation.ToRuneQuaternion()),
                    Scale = boxDescription.Scale.ToRuneVector(),
                };
                UpdateRigidbodyCollisionSettings(rigidBody, ref colliderDescription);
                this.simulation.RigidBodies.Add(rigidBody);

                return(rigidBody);
            }
        }
Exemple #4
0
        void MakeFurModel()
        {
            FurHead = BuildBox(MakeBoxBounds(-3, -3, -3, 3, 3, 3)
                               .SetTexOrigin(0, 0)
                               .SetModelBounds(-3.5f, 15.5f, -12.5f, 3.5f, 22.5f, -5.5f));
            FurTorso = BuildRotatedBox(MakeRotatedBoxBounds(-4, 12, -8, 4, 18, 8)
                                       .SetTexOrigin(28, 8)
                                       .SetModelBounds(-6f, 10.5f, -10f, 6f, 19.5f, 10f));
            BoxDescription legDesc = MakeBoxBounds(-2, -3, -2, 2, 3, 2)
                                     .SetTexOrigin(0, 16);

            FurLeftLegFront  = BuildBox(legDesc.SetModelBounds(-5.5f, 5.5f, -7.5f, -0.5f, 12.5f, -2.5f));
            FurRightLegFront = BuildBox(legDesc.SetModelBounds(0.5f, 5.5f, -7.5f, 5.5f, 12.5f, -2.5f));
            FurLeftLegBack   = BuildBox(legDesc.SetModelBounds(-5.5f, 5.5f, 4.5f, -0.5f, 12.5f, 9.5f));
            FurRightLegBack  = BuildBox(legDesc.SetModelBounds(0.5f, 5.5f, 4.5f, 5.5f, 12.5f, 9.5f));
        }
Exemple #5
0
    // Search if these is a BoxDescription has the same parameters and return it,
    // if not, create new one, add it to the list and return it.
    public BoxDescription GetBoxDescription(string backImage, Size size)
    {
        BoxDescription description = null;

        Descriptions.ForEach(x => {
            if (x.BackImage == backImage && x.Size == size)
            {
                description = x;
            }
        });

        if (description == null)
        {
            description = new BoxDescription {
                BackImage = backImage, Size = size
            };
        }

        return(description);
    }
Exemple #6
0
    // Get an exact same object as this one.
    public override Component Clone()
    {
        BoxDescription boxDescription = BoxFactory.GetBoxDescription(Description.BackImage, Description.Size);
        HiddenObject   hiddenObject   = new HiddenObject {
            Image = HiddenObject.Image
        };
        BoxState boxState = new BoxState {
            State = State.State
        };
        ImageBinder imageBinder = new ImageBinder();
        BoxFactory  boxFactory  = BoxFactory.GetInstance();
        string      image       = (string)CurrentImage.Clone();

        return(new Box {
            Description = boxDescription, HiddenObject = hiddenObject,
            State = boxState, ImageBinder = imageBinder,
            BoxFactory = boxFactory, CurrentImage = image, Position = this.Position,
            IsEnabled = this.IsEnabled
        });
    }
        /// <summary>Builds a box model assuming the follow texture layout:<br/>
        /// let SW = sides width, BW = body width, BH = body height<br/>
        /// ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃S┈┈┈┈┈┈┈┈┈┈┈S┃S┈┈┈┈front┈┈┈S┃S┈┈┈back┈┈┈┈S┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃W┈┈┈┈┈┈┈┈┈W┃W┈┈┈┈tex┈┈┈W┃W┈┈┈┈tex┈┈┈┈W┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━━━┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┃B┈┈┈left┈┈┈┈┈B┃B┈┈bottom┈┈B┃B┈┈┈right┈┈┈┈B┃B┈┈┈┈top┈┈┈B┃ <br/>
        /// ┃H┈┈┈tex┈┈┈┈┈H┃H┈┈tex┈┈┈┈┈H┃H┈┈┈tex┈┈┈┈┈H┃H┈┈┈┈tex┈┈┈H┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ </summary>
        protected ModelPart BuildRotatedBox(BoxDescription desc)
        {
            int   sidesW = desc.SidesW, bodyW = desc.BodyW, bodyH = desc.BodyH;
            float x1 = desc.X1, y1 = desc.Y1, z1 = desc.Z1;
            float x2 = desc.X2, y2 = desc.Y2, z2 = desc.Z2;
            int   x = desc.TexX, y = desc.TexY;

            YQuad(x + sidesW + bodyW + sidesW, y + sidesW, bodyW, bodyH, x1, x2, z1, z2, y2); // top
            YQuad(x + sidesW, y + sidesW, bodyW, bodyH, x2, x1, z1, z2, y1);                  // bottom
            ZQuad(x + sidesW, y, bodyW, sidesW, x2, x1, y1, y2, z1);                          // front
            ZQuad(x + sidesW + bodyW, y, bodyW, sidesW, x1, x2, y2, y1, z2);                  // back
            XQuad(x, y + sidesW, sidesW, bodyH, y2, y1, z2, z1, x2);                          // left
            XQuad(x + sidesW + bodyW, y + sidesW, sidesW, bodyH, y1, y2, z2, z1, x1);         // right

            // rotate left and right 90 degrees
            for (int i = index - 8; i < index; i++)
            {
                ModelVertex vertex = vertices[i];
                float       z      = vertex.Z; vertex.Z = vertex.Y; vertex.Y = z;
                vertices[i] = vertex;
            }
            return(new ModelPart(index - 6 * 4, 6 * 4));
        }
Exemple #8
0
 /// <summary>
 /// Creates a box shape in the world
 /// </summary>
 /// <param name="boxDescription"></param>
 /// <param name="colliderDescription"> </param>
 /// <returns></returns>
 public IWorldObject CreateWorldObject(BoxDescription boxDescription, ColliderDescription colliderDescription)
 {
     return(null);
 }
        /// <summary>Builds a box model assuming the follow texture layout:<br/>
        /// let SW = sides width, BW = body width, BH = body height<br/>
        /// ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃S┈┈┈┈┈┈┈┈┈┈┈S┃S┈┈┈┈front┈┈┈S┃S┈┈┈back┈┈┈┈S┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃W┈┈┈┈┈┈┈┈┈W┃W┈┈┈┈tex┈┈┈W┃W┈┈┈┈tex┈┈┈┈W┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━━━┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┃B┈┈┈left┈┈┈┈┈B┃B┈┈bottom┈┈B┃B┈┈┈right┈┈┈┈B┃B┈┈┈┈top┈┈┈B┃ <br/>
        /// ┃H┈┈┈tex┈┈┈┈┈H┃H┈┈tex┈┈┈┈┈H┃H┈┈┈tex┈┈┈┈┈H┃H┈┈┈┈tex┈┈┈H┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ </summary>
        protected ModelPart BuildRotatedBox( BoxDescription desc )
        {
            int sidesW = desc.SidesW, bodyW = desc.BodyW, bodyH = desc.BodyH;
            float x1 = desc.X1, y1 = desc.Y1, z1 = desc.Z1;
            float x2 = desc.X2, y2 = desc.Y2, z2 = desc.Z2;
            int x = desc.TexX, y = desc.TexY;

            ZQuad( x + sidesW, y, bodyW, sidesW, x2, x1, y1, y2, z1 ); // front
            ZQuad( x + sidesW + bodyW, y, bodyW, sidesW, x1, x2, y2, y1, z2 ); // back
            YQuad( x + sidesW + bodyW + sidesW, y + sidesW, bodyW, bodyH, x1, x2, z1, z2, y2 ); // top
            YQuad( x + sidesW, y + sidesW, bodyW, bodyH, x2, x1, z1, z2, y1 ); // bottom
            XQuad( x, y + sidesW, sidesW, bodyH, y2, y1, z2, z1, x2 ); // left
            XQuad( x + sidesW + bodyW, y + sidesW, sidesW, bodyH, y1, y2, z2, z1, x1 ); // right

            // rotate left and right 90 degrees
            for( int i = index - 8; i < index; i++ ) {
                ModelVertex vertex = vertices[i];
                float z = vertex.Z; vertex.Z = vertex.Y; vertex.Y = z;
                vertices[i] = vertex;
            }
            return new ModelPart( index - 6 * 4, 6 * 4 );
        }
        /// <summary>Builds a box model assuming the follow texture layout:<br/>
        /// let SW = sides width, BW = body width, BH = body height<br/>
        /// ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃S┈┈┈┈┈┈┈┈┈┈┈S┃S┈┈┈┈top┈┈┈┈S┃S┈┈bottom┈┈┈S┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃W┈┈┈┈┈┈┈┈┈W┃W┈┈┈┈tex┈┈┈W┃W┈┈┈┈tex┈┈┈┈W┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈┈┈┈┈┈┈┈┃ <br/>
        /// ┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━━━┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┃B┈┈┈left┈┈┈┈┈B┃B┈┈front┈┈┈┈B┃B┈┈┈right┈┈┈┈B┃B┈┈┈back┈┈┈B┃ <br/>
        /// ┃H┈┈┈tex┈┈┈┈┈H┃H┈┈tex┈┈┈┈┈H┃H┈┈┈tex┈┈┈┈┈H┃H┈┈┈┈tex┈┈┈H┃ <br/>
        /// ┃┈┈┈┈┈SW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┃┈┈┈┈┈BW┈┈┈┈┈┈┃┈┈┈┈┈SW┈┈┈┈┃ <br/>
        /// ┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛ </summary>
        protected ModelPart BuildBox( BoxDescription desc )
        {
            int sidesW = desc.SidesW, bodyW = desc.BodyW, bodyH = desc.BodyH;
            float x1 = desc.X1, y1 = desc.Y1, z1 = desc.Z1;
            float x2 = desc.X2, y2 = desc.Y2, z2 = desc.Z2;
            int x = desc.TexX, y = desc.TexY;

            YQuad( x + sidesW, y, bodyW, sidesW, x2, x1, z2, z1, y2 ); // top
            YQuad( x + sidesW + bodyW, y, bodyW, sidesW, x2, x1, z1, z2, y1 ); // bottom
            ZQuad( x + sidesW, y + sidesW, bodyW, bodyH, x2, x1, y1, y2, z1 ); // front
            ZQuad( x + sidesW + bodyW + sidesW, y + sidesW, bodyW, bodyH, x1, x2, y1, y2, z2 ); // back
            XQuad( x, y + sidesW, sidesW, bodyH, z2, z1, y1, y2, x2 ); // left
            XQuad( x + sidesW + bodyW, y + sidesW, sidesW, bodyH, z1, z2, y1, y2, x1 ); // right
            return new ModelPart( index - 6 * 4, 6 * 4 );
        }
        public void Run()
        {
            var worldBounds = new Bounds()
            {
                Min = new Vector3(0, -5000, 0), Max = new Vector3(2000, 5000, 1600)
            };
            var serialNumber = @"tgCcAQADXEY+784BLMKfsg8O0AEnACNQcmF2ZWVuIFB1dmFuYXNpbmdhbSMxIzEjTm9uQ29tbWVyY2lhbECDssOQzVFUBAMB/A9Wt80a70/+9vKHaeL+Sj8kTFNIChTkCbzgKeebsjGh6Gx5YhufqQqjlT4HHZLRuk8=";
            var physics      = new RunePhysicsWorld(worldBounds, serialNumber);

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "map0.map");

            float[,] heights;
            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var buffer = new byte[sizeof(int)];
                stream.Read(buffer, 0, buffer.Length);
                var c = BitConverter.ToInt32(buffer, 0);

                buffer = new byte[sizeof(int)];
                stream.Read(buffer, 0, buffer.Length);
                var r = BitConverter.ToInt32(buffer, 0);

                heights = new float[c, r];
                for (var z = 0; z < r; z++)
                {
                    for (var x = 0; x < c; x++)
                    {
                        buffer = new byte[sizeof(float)];
                        stream.Read(buffer, 0, sizeof(float));

                        heights[x, z] = BitConverter.ToSingle(buffer, 0);
                    }
                }
            }

            var heightFieldDescription = new HeightFieldDescription()
            {
                Heights  = heights,
                Position = Vector3.Zero,
                WidthX   = 2000,
                WidthZ   = 1600,
            };

            physics.CreateHeightField(heightFieldDescription);
            var boxDescription = new BoxDescription()
            {
                Position = new Vector3(1, 100, 1),
                Rotation = Quaternion.Identity,
                Size     = new Vector3(1, 1, 1)
            };

            physics.CreateWorldObject(boxDescription, CollisionHelper.AvatarObjectColliderDescription);

            var rnd = new Random();
            var characterControllerDescription = new CharacterControllerDescription()
            {
                Height     = 2f,
                Radius     = .5f,
                SkinWidth  = .03f,
                SlopeLimit = 45,
                StepOffset = .3f,
                Position   = new Vector3(200, 20, 200),
            };
            var controller = physics.CreateCharacterController(characterControllerDescription);

            controller.Position      = new Vector3(rnd.Next(1, 1999), 100, rnd.Next(1, 1599));
            controller.LocalVelocity = new Vector3(0, 0, 5);

            var body = new RigidBody(new BoxShape(10, 10, 1))
            {
                MotionType = MotionType.Static,
            };

            body.CollisionObject.Type = CollisionObjectType.Trigger;

            Console.WriteLine("simulation stated...");
            try
            {
                var timer2 = Stopwatch.StartNew();
                timer2.Start();

                while (true)
                {
                    Thread.Sleep(60);

                    controller.LocalVelocity = new Vector3(0, 0, timer2.ElapsedMilliseconds / 60f);
                    Console.WriteLine(controller.Position);
                    timer2.Restart();
                }
            }
            finally
            {
                Console.WriteLine("simulation ended...");
            }
        }