Esempio n. 1
0
        private void UpdateSenzorToCamera()
        {
            // - translate by (-0.5, -aspectRatio * 0.5)
            // - scale by (width, height, 1)
            // - translate by (shiftX, shiftY, distanceZ)
            // - [tilt around X by tiltX, ...]
            var matrix = Matrix4d.CreateTranslation(-0.5, AspectRatio * -0.5, 0);

            matrix     = Matrix4d.Mult(matrix, Matrix4d.Scale(Width, Width, 1));
            matrix     = Matrix4d.Mult(matrix, Matrix4d.CreateTranslation(Shift));
            TiltMatrix = Matrix4d.Identity;
            if (Tilt.X != 0)
            {
                TiltMatrix = Matrix4d.CreateRotationX(Tilt.X);
            }
            if (Tilt.Y != 0)
            {
                TiltMatrix = Matrix4d.Mult(TiltMatrix, Matrix4d.CreateRotationY(Tilt.Y));
            }
            if (Tilt.Z != 0)
            {
                TiltMatrix = Matrix4d.Mult(TiltMatrix, Matrix4d.CreateRotationZ(Tilt.Z));
            }
            matrix         = Matrix4d.Mult(matrix, TiltMatrix);
            SenzorToCamera = matrix;
        }
Esempio n. 2
0
        // we rotate around the centre point. hoff/voff allows you to place the bitmap to the side
        public static Vector3d[] GetVertices(Vector3d centre, Vector3 rotationdeg, float width, float height, float hoffset = 0, float voffset = 0)
        {
            Matrix4d rm = Matrix4d.Identity;

            if (rotationdeg.X != 0)
            {
                rm *= Matrix4d.CreateRotationX((float)(rotationdeg.X * Math.PI / 180.0f));
            }
            if (rotationdeg.Y != 0)
            {
                rm *= Matrix4d.CreateRotationY((float)(rotationdeg.Y * Math.PI / 180.0f));
            }
            if (rotationdeg.Z != 0)
            {
                rm *= Matrix4d.CreateRotationZ((float)(rotationdeg.Z * Math.PI / 180.0f));
            }

            width  /= 2;
            height /= 2;

            Vector3d[] points = new Vector3d[]                                                         // bitmap is placed on map, centred if hoff,voff=0.
            {
                Vector3d.Transform(new Vector3d(-width + hoffset, 0, height + voffset), rm) + centre,  // top left, rotate and transform
                Vector3d.Transform(new Vector3d(width + hoffset, 0, height + voffset), rm) + centre,   // top right
                Vector3d.Transform(new Vector3d(width + hoffset, 0, -height + voffset), rm) + centre,  // bot right
                Vector3d.Transform(new Vector3d(-width + hoffset, 0, -height + voffset), rm) + centre, // bot left
            };

            return(points);
        }
Esempio n. 3
0
        public Matrix4d GetMatrix()
        {
            Matrix4d matrix = Matrix4d.CreateRotationY(Utils.DEGREES_TO_RADIANS(this.Rotation));

            matrix = Matrix4d.Mult(matrix, Matrix4d.CreateTranslation(Translation.X, 0, Translation.Y));
            matrix = Matrix4d.Mult(matrix, Matrix4d.Scale(Scale, 1f, Scale));
            return(matrix);
        }
Esempio n. 4
0
        /// <summary> From current lookat, calculate eyeposition, given a camera angle and a distance</summary>
        public static Vector3d CalculateEyePositionFromLookat(this Vector3d lookat, Vector2d cameradirdegreesp, double distance)
        {
            Matrix4d transform = Matrix4d.Identity;                                          // identity nominal matrix, dir is in degrees

            transform *= Matrix4d.CreateRotationX((cameradirdegreesp.X * Math.PI / 180.0f)); // we rotate the camera vector around X and Y to get a vector which points from eyepos to lookat pos
            transform *= Matrix4d.CreateRotationY((cameradirdegreesp.Y * Math.PI / 180.0f));

            Vector3d eyerel = Vector3d.Transform(new Vector3d(0, 1, 0), transform);       // the 0,1,0 sets the axis of the camera dir

            return(lookat - eyerel * distance);
        }
Esempio n. 5
0
        /// <summary>
        /// Render a cylinder between two points.
        /// </summary>
        /// <param name="start">The initial point.</param>
        /// <param name="end">The ending point.</param>
        /// <param name="width">The width of the cylinder.</param>
        public void RenderCylinder(Location start, Location end, float width)
        {
            float    len    = (float)(end - start).Length();
            Location vecang = Utilities.VectorToAngles(start - end);
            Matrix4d mat    = Matrix4d.CreateRotationY((float)(90 * Utilities.PI180))
                              * Matrix4d.Scale(len, width, width)
                              * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180))
                              * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180))
                              * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(start));

            Client.Central.MainWorldView.SetMatrix(2, mat);
            Client.Central.Models.Cylinder.Draw(); // TODO: Models reference in constructor - or client reference?
        }
Esempio n. 6
0
        /// <summary>
        /// Render a line between two points.
        /// </summary>
        /// <param name="start">The initial point.</param>
        /// <param name="end">The ending point.</param>
        public void RenderLine(Location start, Location end)
        {
            // TODO: Efficiency!
            float    len    = (float)(end - start).Length();
            Location vecang = Utilities.VectorToAngles(start - end);
            Matrix4d mat    = Matrix4d.Scale(len, 1, 1)
                              * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180))
                              * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180))
                              * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(start));

            Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference!
            GL.BindVertexArray(Line._VAO);
            GL.DrawElements(PrimitiveType.Lines, 2, DrawElementsType.UnsignedInt, IntPtr.Zero);
        }
Esempio n. 7
0
        /// <summary>
        /// Render a cylinder between two points.
        /// </summary>
        /// <param name="start">The initial point.</param>
        /// <param name="end">The ending point.</param>
        /// <param name="width">The width of the cylinder.</param>
        /// <param name="view">The relevant view.</param>
        public void RenderCylinder(Location start, Location end, float width, View3D view)
        {
            float    len    = (float)(end - start).Length();
            Location vecang = Utilities.VectorToAngles(start - end);

            vecang.Yaw += 180;
            Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * Utilities.PI180))
                           * Matrix4d.Scale(len, width, width)
                           * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180))
                           * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180))
                           * Matrix4d.CreateTranslation(start.ToOpenTK3D());

            view.SetMatrix(2, mat);
            Models.Cylinder.Draw(); // TODO: Models reference in constructor - or client reference?
        }
Esempio n. 8
0
        /// <summary>
        /// Goes round the central point (lookAt).
        /// One complete turn for the whole time interval.
        /// </summary>
        protected virtual void setTime(double newTime)
        {
            Debug.Assert(Start != End);

            time = newTime; // Here Start & End define a periodicity, not bounds!

            // change the camera position:
            double   angle  = MathHelper.TwoPi * (time - Start) / (End - Start);
            Vector3d radial = Vector3d.TransformVector(center0 - lookAt, Matrix4d.CreateRotationY(-angle));

            center    = lookAt + radial;
            direction = -radial;
            direction.Normalize();
            prepare();
        }
Esempio n. 9
0
        /// <summary>
        /// Render a cylinder between two points.
        /// </summary>
        /// <param name="context">The sourcing render context.</param>
        /// <param name="start">The initial point.</param>
        /// <param name="end">The ending point.</param>
        /// <param name="width">The width of the cylinder.</param>
        /// <param name="view">The relevant view.</param>
        public void RenderCylinder(RenderContext context, Location start, Location end, float width, View3D view)
        {
            float    len    = (float)(end - start).Length();
            Location vecang = MathUtilities.VectorToAngles(start - end);

            vecang.Yaw += 180;
            Matrix4d mat = Matrix4d.CreateRotationY((float)(90 * MathUtilities.PI180))
                           * Matrix4d.Scale(len, width, width)
                           * Matrix4d.CreateRotationY((float)(vecang.Y * MathUtilities.PI180))
                           * Matrix4d.CreateRotationZ((float)(vecang.Z * MathUtilities.PI180))
                           * Matrix4d.CreateTranslation(start.ToOpenTK3D());

            view.SetMatrix(2, mat);
            Models.Cylinder.Draw(context);
        }
Esempio n. 10
0
        /// <summary>
        /// Render a line between two points.
        /// </summary>
        /// <param name="start">The initial point.</param>
        /// <param name="end">The ending point.</param>
        /// <param name="view">The relevant view.</param>
        public void RenderLine(Location start, Location end, View3D view)
        {
            // TODO: Efficiency!
            float    len    = (float)(end - start).Length();
            Location vecang = Utilities.VectorToAngles(start - end);

            vecang.Yaw += 180;
            Matrix4d mat = Matrix4d.Scale(len, 1, 1)
                           * Matrix4d.CreateRotationY((float)(vecang.Y * Utilities.PI180))
                           * Matrix4d.CreateRotationZ((float)(vecang.Z * Utilities.PI180))
                           * Matrix4d.CreateTranslation(start.ToOpenTK3D());

            view.SetMatrix(2, mat);
            GL.BindVertexArray(Line._VAO);
            GL.DrawElements(PrimitiveType.Lines, 2, DrawElementsType.UnsignedInt, IntPtr.Zero);
        }
Esempio n. 11
0
        private Vector3d MapMoveToSphere(double radius, Vector2 startPosition, Vector2 endPosition)
        {
            var deltaFromStartPixels = endPosition - startPosition;
            var deltaOnSurface       = new Vector2d(
                deltaFromStartPixels.X / radius,
                deltaFromStartPixels.Y / radius);

            var lengthOnSurfaceRadi = deltaOnSurface.Length;

            // get this rotation on the surface of the sphere about y
            var positionAboutY = Vector3d.Transform(Vector3d.UnitZ, Matrix4d.CreateRotationY(lengthOnSurfaceRadi));

            // get the angle that this distance travels around the sphere
            var angleToTravel = Math.Atan2(-deltaOnSurface.Y, deltaOnSurface.X);

            // now rotate that position about z in the direction of the screen vector
            return(Vector3d.Transform(positionAboutY, Matrix4d.CreateRotationZ(angleToTravel)));
        }
Esempio n. 12
0
        private void WriteNextMtx(int hnumber, sbyte bnumber, sbyte pnumber, Matrix4d testmtx, ref int ofs)
        {
            sbyte child   = Hierarchies[hnumber][bnumber].Child;
            sbyte sibling = Hierarchies[hnumber][bnumber].Sibling;

            Matrix4d localmtx = testmtx;

            localmtx = Matrix4d.Mult(Matrix4d.CreateTranslation(Hierarchies[hnumber][bnumber].Translation), testmtx);
            localmtx = Matrix4d.Mult(Matrix4d.CreateRotationZ(MathHelper.DegreesToRadians((float)Hierarchies[hnumber][bnumber].Rotation.Z / 182.0444444f)), localmtx);
            localmtx = Matrix4d.Mult(Matrix4d.CreateRotationY(MathHelper.DegreesToRadians((float)Hierarchies[hnumber][bnumber].Rotation.Y / 182.0444444f)), localmtx);
            localmtx = Matrix4d.Mult(Matrix4d.CreateRotationX(MathHelper.DegreesToRadians((float)Hierarchies[hnumber][bnumber].Rotation.X / 182.0444444f)), localmtx);

            if (Hierarchies[hnumber][bnumber].DisplayList != 0)
            {
                WriteMtxData(localmtx.M11, hnumber, ref ofs);
                WriteMtxData(localmtx.M12, hnumber, ref ofs);
                WriteMtxData(localmtx.M13, hnumber, ref ofs);
                WriteMtxData(localmtx.M14, hnumber, ref ofs);
                WriteMtxData(localmtx.M21, hnumber, ref ofs);
                WriteMtxData(localmtx.M22, hnumber, ref ofs);
                WriteMtxData(localmtx.M23, hnumber, ref ofs);
                WriteMtxData(localmtx.M24, hnumber, ref ofs);
                WriteMtxData(localmtx.M31, hnumber, ref ofs);
                WriteMtxData(localmtx.M32, hnumber, ref ofs);
                WriteMtxData(localmtx.M33, hnumber, ref ofs);
                WriteMtxData(localmtx.M34, hnumber, ref ofs);
                WriteMtxData(localmtx.M41, hnumber, ref ofs);
                WriteMtxData(localmtx.M42, hnumber, ref ofs);
                WriteMtxData(localmtx.M43, hnumber, ref ofs);
                WriteMtxData(localmtx.M44, hnumber, ref ofs);
                ofs += 0x20;
            }

            if (child > -1 && child != bnumber)
            {
                WriteNextMtx(hnumber, child, bnumber, localmtx, ref ofs);
            }
            if (sibling > -1 && sibling != bnumber)
            {
                WriteNextMtx(hnumber, sibling, pnumber, testmtx, ref ofs);
            }
        }
Esempio n. 13
0
        public void RenderBillboard(Location pos, Location scale, Location facing)
        {
            // TODO: Quaternion magic?
            Location relang = Utilities.VectorToAngles(pos - facing);

            if (relang.IsInfinite() || relang.IsNaN())
            {
                throw new Exception("Unable to handle billboard: relang=" + relang);
            }
            Matrix4d mat =
                Matrix4d.Scale(ClientUtilities.ConvertD(scale))
                * Matrix4d.CreateTranslation(-0.5f, -0.5f, 0f)
                * Matrix4d.CreateRotationY((float)((relang.Y - 90) * Utilities.PI180))
                * Matrix4d.CreateRotationZ((float)(relang.Z * Utilities.PI180))
                * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(pos));

            Client.Central.MainWorldView.SetMatrix(2, mat); // TODO: Client reference!
            GL.BindVertexArray(Square._VAO);
            GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);
            GL.BindVertexArray(0);
        }
        public override Entity Create(Region tregion, byte[] data)
        {
            DataStream             ds  = new DataStream(data);
            DataReader             dr  = new DataReader(ds);
            GenericCharacterEntity ent = new GenericCharacterEntity(tregion);

            ent.SetPosition(Location.FromDoubleBytes(dr.ReadBytes(24), 0));
            ent.SetOrientation(new BEPUutilities.Quaternion(dr.ReadFloat(), dr.ReadFloat(), dr.ReadFloat(), dr.ReadFloat()));
            ent.SetMass(dr.ReadFloat());
            ent.CBAirForce         = dr.ReadFloat();
            ent.CBAirSpeed         = dr.ReadFloat();
            ent.CBCrouchSpeed      = dr.ReadFloat();
            ent.CBDownStepHeight   = dr.ReadFloat();
            ent.CBGlueForce        = dr.ReadFloat();
            ent.CBHHeight          = dr.ReadFloat();
            ent.CBJumpSpeed        = dr.ReadFloat();
            ent.CBMargin           = dr.ReadFloat();
            ent.CBMaxSupportSlope  = dr.ReadFloat();
            ent.CBMaxTractionSlope = dr.ReadFloat();
            ent.CBProneSpeed       = dr.ReadFloat();
            ent.CBRadius           = dr.ReadFloat();
            ent.CBSlideForce       = dr.ReadFloat();
            ent.CBSlideJumpSpeed   = dr.ReadFloat();
            ent.CBSlideSpeed       = dr.ReadFloat();
            ent.CBStandSpeed       = dr.ReadFloat();
            ent.CBStepHeight       = dr.ReadFloat();
            ent.CBTractionForce    = dr.ReadFloat();
            ent.PreRot            *= Matrix4d.CreateRotationX(dr.ReadFloat() * Utilities.PI180);
            ent.PreRot            *= Matrix4d.CreateRotationY(dr.ReadFloat() * Utilities.PI180);
            ent.PreRot            *= Matrix4d.CreateRotationZ(dr.ReadFloat() * Utilities.PI180);
            ent.mod_scale          = dr.ReadFloat();
            ent.PreRot             = Matrix4d.Scale(ent.mod_scale) * ent.PreRot;
            ent.color = System.Drawing.Color.FromArgb(dr.ReadInt());
            byte dtx = dr.ReadByte();

            ent.Visible     = (dtx & 1) == 1;
            ent.ShouldShine = (dtx & 32) == 32;
            int solidity = (dtx & (2 | 4 | 8 | 16));

            if (solidity == 2)
            {
                ent.CGroup = CollisionUtil.Solid;
            }
            else if (solidity == 4)
            {
                ent.CGroup = CollisionUtil.NonSolid;
            }
            else if (solidity == (2 | 4))
            {
                ent.CGroup = CollisionUtil.Item;
            }
            else if (solidity == 8)
            {
                ent.CGroup = CollisionUtil.Player;
            }
            else if (solidity == (2 | 8))
            {
                ent.CGroup = CollisionUtil.Water;
            }
            else if (solidity == (2 | 4 | 8))
            {
                ent.CGroup = CollisionUtil.WorldSolid;
            }
            else if (solidity == 16)
            {
                ent.CGroup = CollisionUtil.Character;
            }
            ent.model = tregion.TheClient.Models.GetModel(tregion.TheClient.Network.Strings.StringForIndex(dr.ReadInt()));
            dr.Close();
            return(ent);
        }
Esempio n. 15
0
 public void RotateY(double angle)
 {
     matrix          = Matrix4d.CreateRotationY(angle) * matrix;
     inverse_matrix *= Matrix4d.CreateRotationY(-angle);
 }