Exemple #1
0
        private void display()
        {
            if (!loaded) // Play nice
            {
                return;
            }
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            /* kamerata se naogja vo 0,0,transZ i gleda kon 0,0,0
             * nagore za kamerata e vo pravec na vektorot 0,1,0
             */
            GL.PolygonMode(MaterialFace.FrontAndBack, poly); // 114 transz rotateA=-15.94 k vis =84.3
            OpenTK.Matrix4d modelview = OpenTK.Matrix4d.LookAt(nasoka_x + transZ * Math.Cos(rotateA), k_visina, nasoka_z + transZ * Math.Sin(rotateA),
                                                               nasoka_x, nasoka_y, nasoka_z,
                                                               0, 1, 0);
            GL.LoadMatrix(ref modelview);

            GL.MatrixMode(MatrixMode.Modelview);
            kocki.Draw();
            GL.Color3(Color.YellowGreen);
            topce.Draw(kocki.get(kocki.Topka_Place).X_, kocki.get(kocki.Topka_Place).Y_ + topce.visina + topce.Radius, kocki.get(kocki.Topka_Place).Z_);

            glControl1.SwapBuffers();
        }
Exemple #2
0
        public OpenTK.Matrix4d RotMatrix44()
        {
            OpenTK.Matrix4d rot = new OpenTK.Matrix4d();

            var rot1 = RotMatrix33();

            rot[0, 0] = rot1[0, 0];
            rot[1, 0] = rot1[1, 0];
            rot[2, 0] = rot1[2, 0];
            rot[3, 0] = 0.0;

            rot[0, 1] = rot1[0, 1];
            rot[1, 1] = rot1[1, 1];
            rot[2, 1] = rot1[2, 1];
            rot[3, 1] = 0.0;

            rot[0, 2] = rot1[0, 2];
            rot[1, 2] = rot1[1, 2];
            rot[2, 2] = rot1[2, 2];
            rot[3, 2] = 0.0;

            rot[0, 3] = 0.0;
            rot[1, 3] = 0.0;
            rot[2, 3] = 0.0;
            rot[3, 3] = 1.0;

            return(rot);
        }
Exemple #3
0
        public static void SetModelViewTransform(Camera camera)
        {
            //System.Diagnostics.Debug.WriteLine("SetModelViewTransform");
            {
                // pan the object
                double x;
                double y;
                double z;
                camera.GetCenterPosition(out x, out y, out z);
                //System.Diagnostics.Debug.WriteLine("CenterPosition = " + x + ", " + y + ", " + z);

                GL.Translate(x, y, z);
            }
            {
                // rotate
                OpenTK.Matrix4d rot = camera.RotMatrix44();

                GL.MultMatrix(ref rot);
            }
            {
                // put the origin at the center of object
                double          x;
                double          y;
                double          z;
                OpenTK.Vector3d objCenter = camera.ObjectCenter;
                x = objCenter.X;
                y = objCenter.Y;
                z = objCenter.Z;
                //System.Diagnostics.Debug.WriteLine("objCenter = " + x + ", " + y + ", " + z);

                GL.Translate(-x, -y, -z);
            }
        }
Exemple #4
0
        public static void SetProjectionTransform(Camera camera)
        {
            //System.Diagnostics.Debug.WriteLine("SetProjectionTransform");
            if (camera.IsPers)
            {
                // 透視投影変換
                double fovY;
                double aspect;
                double clipNear;
                double clipFar;
                camera.GetPerspective(out fovY, out aspect, out clipNear, out clipFar);

                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();
                OpenTK.Matrix4d perspective = OpenTK.Matrix4d.CreatePerspectiveFieldOfView(
                    fovY, aspect, clipNear, clipFar);
                GL.LoadMatrix(ref perspective);
            }
            else
            {
                // 正規投影変換
                //System.Diagnostics.Debug.WriteLine("正規投影変換");
                //System.Diagnostics.Debug.WriteLine("scale = " + camera.Scale +
                //    " windowAspect = " + camera.WindowAspect +
                //    " halfViewHeight = " + camera.HalfViewHeight);
                double invScale = 1.0 / camera.Scale;
                double asp      = camera.WindowAspect;
                double hH       = camera.HalfViewHeight * invScale;
                double hW       = camera.HalfViewHeight * invScale * asp;
                double depth    = 2.0 * (hH + hW);

                GL.Ortho(-hW, hW, -hH, hH, -depth, depth);
            }
        }
Exemple #5
0
 public Frustum(OpenTK.Matrix4d matrix)
 {
     Planes[0] = new Plane(new Vector3(-matrix.M14 - matrix.M11, -matrix.M24 - matrix.M21, -matrix.M34 - matrix.M31), -matrix.M44 - matrix.M41);
     Planes[1] = new Plane(new Vector3(matrix.M11 - matrix.M14, matrix.M21 - matrix.M24, matrix.M31 - matrix.M34), matrix.M41 - matrix.M44);
     Planes[2] = new Plane(new Vector3(matrix.M12 - matrix.M14, matrix.M22 - matrix.M24, matrix.M32 - matrix.M34), matrix.M42 - matrix.M44);
     Planes[3] = new Plane(new Vector3(-matrix.M14 - matrix.M12, -matrix.M24 - matrix.M22, -matrix.M34 - matrix.M32), -matrix.M44 - matrix.M42);
     Planes[4] = new Plane(new Vector3(-matrix.M13, -matrix.M23, -matrix.M33), -matrix.M43);
     Planes[5] = new Plane(new Vector3(matrix.M13 - matrix.M14, matrix.M23 - matrix.M24, matrix.M33 - matrix.M34), matrix.M43 - matrix.M44);
 }
Exemple #6
0
 public static void MultiplyMatrix4x4ByVector4(out OpenTK.Vector4d resultvector,
                                               OpenTK.Matrix4d matrix, OpenTK.Vector4d pvector)
 {
     resultvector.X = matrix.M11 * pvector.X + matrix.M12 * pvector.Y +
                      matrix.M13 * pvector.Z + matrix.M14 * pvector.W;
     resultvector.Y = matrix.M21 * pvector.X + matrix.M22 * pvector.Y +
                      matrix.M23 * pvector.Z + matrix.M24 * pvector.W;
     resultvector.Z = matrix.M31 * pvector.X + matrix.M32 * pvector.Y +
                      matrix.M33 * pvector.Z + matrix.M34 * pvector.W;
     resultvector.W = matrix.M41 * pvector.X + matrix.M42 * pvector.Y +
                      matrix.M43 * pvector.Z + matrix.M44 * pvector.W;
 }
Exemple #7
0
        public static OpenTK.Matrix4 ToMatrix4(this OpenTK.Matrix4d matrix)
        {
            var result = new OpenTK.Matrix4();

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    result[y, x] = (float)matrix[y, x];
                }
            }
            return(result);
        }
Exemple #8
0
 public override void Render()
 {
     if (vbo == null)
     {
         return;
     }
     TheClient.SetVox();
     OpenTK.Matrix4d mat = OpenTK.Matrix4d.Scale(ClientUtilities.ConvertD(scale)) * OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(shapeOffs)) * GetTransformationMatrix();
     TheClient.MainWorldView.SetMatrix(2, mat);
     TheClient.Rendering.SetColor(Color, TheClient.MainWorldView);
     vbo.Render();
     TheClient.Rendering.SetColor(Color4.White, TheClient.MainWorldView);
 }
Exemple #9
0
        public static int GluUnProject(double winx, double winy, double winz,
                                       double[] modelview, double[] projection, int[] viewport,
                                       out double objectX, out double objectY, out double objectZ)
        {
            objectX = 0;
            objectY = 0;
            objectZ = 0;

            // Transformation matrices
            OpenTK.Matrix4d projectionM = new OpenTK.Matrix4d(
                projection[0], projection[4], projection[8], projection[12],
                projection[1], projection[5], projection[9], projection[13],
                projection[2], projection[6], projection[10], projection[14],
                projection[3], projection[7], projection[11], projection[15]);
            OpenTK.Matrix4d modelviewM = new OpenTK.Matrix4d(
                modelview[0], modelview[4], modelview[8], modelview[12],
                modelview[1], modelview[5], modelview[9], modelview[13],
                modelview[2], modelview[6], modelview[10], modelview[14],
                modelview[3], modelview[7], modelview[11], modelview[15]);
            // Calculation for inverting a matrix, compute projection x modelview
            // and store in A[16]
            OpenTK.Matrix4d AM = projectionM * modelviewM;
            // Now compute the inverse of matrix A
            OpenTK.Matrix4d mM = OpenTK.Matrix4d.Invert(AM);

            // Transformation of normalized coordinates between -1 and 1
            OpenTK.Vector4d inV = new OpenTK.Vector4d();
            inV.X = ((winx - viewport[0]) / viewport[2] * 2.0 - 1.0);
            inV.Y = ((winy - viewport[1]) / viewport[3] * 2.0 - 1.0);
            inV.Z = (2.0 * winz - 1.0);
            inV.W = 1.0;
            OpenTK.Vector4d outV;
            // Objects coordinates
            MultiplyMatrix4x4ByVector4(out outV, mM, inV);
            if (outV.Z == 0.0)
            {
                return(0);
            }
            outV.W  = (1.0 / outV.W);
            objectX = outV.X * outV.W;
            objectY = outV.Y * outV.W;
            objectZ = outV.Z * outV.W;

            /*
             * System.Diagnostics.Debug.WriteLine("GluUnProject");
             * System.Diagnostics.Debug.WriteLine("objectX = " + objectX);
             * System.Diagnostics.Debug.WriteLine("objectY = " + objectY);
             * System.Diagnostics.Debug.WriteLine("objectZ = " + objectZ);
             */
            return(1);
        }
Exemple #10
0
 void LookAt(double eyeX,double eyeY,double eyeZ,double centerX,double centerY,double centerZ,double upX,double upY,double upZ)
 {
     OpenTK.Vector3d F = new OpenTK.Vector3d(centerX - eyeX, centerX - eyeY, centerZ - eyeZ);
     OpenTK.Vector3d UP = new OpenTK.Vector3d(upX, upY, upZ);
     F.Normalize();
     UP.Normalize();
     OpenTK.Vector3d s = new OpenTK.Vector3d(F.Y * UP.Z - F.Z * UP.Y,
                                             F.Z * UP.X - F.X * UP.Z,
                                             F.X * UP.Y - F.Y * UP.X);
     OpenTK.Vector3d u = new OpenTK.Vector3d(s.Y * F.Z - s.Z * F.Y,
                                             s.Z * F.X - s.X * F.Z,
                                             s.X * F.Y - s.Y * F.X);
     OpenTK.Matrix4d m = new OpenTK.Matrix4d(s.X, s.Y, s.Z, 0, u.X, u.Y, u.Z, 0, -F.X, -F.Y, -F.Z, 0, 0, 0, 0, 1);
     GL.MultMatrix(ref m);
     GL.Translate(-eyeX, -eyeY, -eyeZ);
 }
Exemple #11
0
        private static void DetectMapperMarkerVisible(int myMarkerID, ref List <clsPGPoint> pts, bool useDatums)
        {
            double[] myMatrix = new double[16] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            ARToolKitFunctions.Instance.arwGetTrackablePatternConfig(myMarkerID, 0, myMatrix, out float width, out float height, out int imageSizeX, out int imageSizeY, out int barcodeID);

            double[] mv = new double[16] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            if (ARToolKitFunctions.Instance.arwQueryTrackableMapperTransformation(myMapperMarkerID, barcodeID, mv))
            {
                OpenTK.Matrix4d matrix = new OpenTK.Matrix4d(mv[0], mv[1], mv[2], mv[3], mv[4], mv[5], mv[6], mv[7], mv[8], mv[9], mv[10], mv[11], mv[12], mv[13], mv[14], mv[15]);
                var             pt     = new OpenTK.Vector4d(mv[12], mv[13], mv[14], 0);
                if (!useDatums)
                {
                    if (myMarkerID < 50)
                    {
                        pt = new OpenTK.Vector4d(140.0f, -45.0f, 0.0f, 1);
                        pt = OpenTK.Vector4d.Transform(pt, matrix);
                    }
                    else if (myMarkerID < 100)
                    {
                        pt = new OpenTK.Vector4d(140.0, 45.0, 0.0f, 1);
                        pt = OpenTK.Vector4d.Transform(pt, matrix);
                    }
                }
                else
                {
                    if (myMarkerID - 2 >= 0 && myMarkerID - 2 < 50)
                    {
                        pt = new OpenTK.Vector4d(160.0f, -45.0f, 0.0f, 1);
                        pt = OpenTK.Vector4d.Transform(pt, matrix);
                    }
                    else if (myMarkerID - 2 >= 50 && myMarkerID - 2 < 100)
                    {
                        pt = new OpenTK.Vector4d(160.0, 45.0, 0.0f, 1);
                        pt = OpenTK.Vector4d.Transform(pt, matrix);
                    }
                }

                pts.Add(new clsPGPoint(pt.X, pt.Y, pt.Z, myMarkerID, barcodeID));
            }
        }
Exemple #12
0
        public void Test_ToUnityMatrix()
        {
            OpenTK.Matrix4d openTKmatrix = new OpenTK.Matrix4d(
                row0: new OpenTK.Vector4d(1.0, 2.0, 3.0, 4.0),
                row1: new OpenTK.Vector4d(5.0, 6.0, 7.0, 8.0),
                row2: new OpenTK.Vector4d(9.0, 1.1, 1.2, 1.3),
                row3: new OpenTK.Vector4d(1.4, 1.5, 1.6, 1.7)
                );

            Matrix4x4 actual = openTKmatrix.ToUnityMatrix();

            Matrix4x4 expected = new Matrix4x4(
                column0: new Vector4(1.0f, 5.0f, 9.0f, 1.4f),
                column1: new Vector4(2.0f, 6.0f, 1.1f, 1.5f),
                column2: new Vector4(3.0f, 7.0f, 1.2f, 1.6f),
                column3: new Vector4(4.0f, 8.0f, 1.3f, 1.7f)
                );

            Assert.AreEqual(
                actual: actual,
                expected: expected
                );
        }
Exemple #13
0
        public override void Render()
        {
            Location renderrelpos = GetWeldSpot();

            TheClient.SetEnts();
            // TODO: Merge with base.Render() as much as possible!
            if (TheClient.CVars.n_debugmovement.ValueB)
            {
                TheClient.Rendering.RenderLine(ServerLocation, renderrelpos);
                TheClient.Rendering.RenderLineBox(ServerLocation + new Location(-0.2), ServerLocation + new Location(0.2));
            }
            OpenTK.Matrix4d mat = OpenTK.Matrix4d.Scale(1.5f)
                                  * OpenTK.Matrix4d.CreateRotationZ((Direction.Yaw * Utilities.PI180))
                                  * PlayerAngleMat
                                  * OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos));
            TheClient.MainWorldView.SetMatrix(2, mat);
            TheClient.Rendering.SetMinimumLight(0.0f);
            model.CustomAnimationAdjustments = new Dictionary <string, OpenTK.Matrix4>(SavedAdjustmentsOTK);
            // TODO: safe (no-collision) rotation check?
            model.CustomAnimationAdjustments["spine04"] = GetAdjustmentOTK("spine04") * OpenTK.Matrix4.CreateRotationX(-(float)(Direction.Pitch / 2f * Utilities.PI180));
            if (!TheClient.MainWorldView.RenderingShadows && TheClient.CVars.g_firstperson.ValueB)
            {
                model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01") * OpenTK.Matrix4.CreateRotationX(-(float)(160f * Utilities.PI180));
            }
            else
            {
                model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01");
            }
            model.Draw(aHTime, hAnim, aTTime, tAnim, aLTime, lAnim);
            Model mod   = TheClient.GetItemForSlot(TheClient.QuickBarPos).Mod;
            bool  hasjp = HasJetpack();

            if (!hasjp && tAnim != null && mod != null)
            {
                mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos));
                TheClient.MainWorldView.SetMatrix(2, mat);
                Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments);
                Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f)));
                adjs["spine04"] = GetAdjustment("spine04") * rotforw;
                SingleAnimationNode hand = tAnim.GetNode("metacarpal2.r");
                Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f)
                            * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f))
                               * hand.GetBoneTotalMatrix(aTTime, adjs))
                            * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-90) * Utilities.PI180) % 360f));
                OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14,
                                                            (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24,
                                                            (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34,
                                                            (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44);
                GL.UniformMatrix4(40, false, ref bonemat);
                mod.LoadSkin(TheClient.Textures);
                mod.Draw();
                bonemat = OpenTK.Matrix4.Identity;
                GL.UniformMatrix4(40, false, ref bonemat);
            }
            if (hasjp)
            {
                // TODO: Abstractify!
                Model jetp = GetHeldItem().Mod;
                mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos));
                TheClient.MainWorldView.SetMatrix(2, mat);
                Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>();
                Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f)));
                adjs["spine04"] = GetAdjustment("spine04") * rotforw;
                SingleAnimationNode spine = tAnim.GetNode("spine04");
                Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f)
                            * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f))
                               * spine.GetBoneTotalMatrix(aTTime, adjs))
                            * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)((90) * Utilities.PI180) % 360f));
                OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24,
                                                            (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44);
                GL.UniformMatrix4(40, false, ref bonemat);
                jetp.LoadSkin(TheClient.Textures);
                jetp.Draw();
                bonemat = OpenTK.Matrix4.Identity;
                GL.UniformMatrix4(40, false, ref bonemat);
            }
            if (IsTyping)
            {
                TheClient.Textures.GetTexture("ui/game/typing").Bind(); // TODO: store!
                TheClient.Rendering.RenderBillboard(renderrelpos + new Location(0, 0, 4), new Location(2), TheClient.MainWorldView.CameraPos);
            }
        }
Exemple #14
0
        /// <summary>Renders a static frustrum based background</summary>
        /// <param name="data">The background to render</param>
        /// <param name="alpha">The alpha level</param>
        /// <param name="scale">The scale</param>
        private void RenderStaticBackgroundImmediate(StaticBackground data, float alpha, float scale)
        {
            //return;
            if (data.Texture != null && renderer.currentHost.LoadTexture(data.Texture, OpenGlTextureWrapMode.RepeatClamp))
            {
                GL.MatrixMode(MatrixMode.Projection);
                GL.PushMatrix();
                GL.LoadIdentity();
                OpenTK.Matrix4d perspective = OpenTK.Matrix4d.Perspective(renderer.Camera.VerticalViewingAngle, -renderer.Screen.AspectRatio, 0.2, 1000.0);
                GL.MultMatrix(ref perspective);
                double          dx     = renderer.Camera.AbsoluteDirection.X;
                double          dy     = renderer.Camera.AbsoluteDirection.Y;
                double          dz     = renderer.Camera.AbsoluteDirection.Z;
                double          ux     = renderer.Camera.AbsoluteUp.X;
                double          uy     = renderer.Camera.AbsoluteUp.Y;
                double          uz     = renderer.Camera.AbsoluteUp.Z;
                OpenTK.Matrix4d lookat = OpenTK.Matrix4d.LookAt(0.0, 0.0, 0.0, dx, dy, dz, ux, uy, uz);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.PushMatrix();
                GL.LoadMatrix(ref lookat);
                GL.Disable(EnableCap.Lighting);
                GL.Enable(EnableCap.Texture2D);
                if (alpha == 1.0f)
                {
                    GL.Disable(EnableCap.Blend);
                }
                else
                {
                    GL.Enable(EnableCap.Blend);
                }
                GL.BindTexture(TextureTarget.Texture2D, data.Texture.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp].Name);
                renderer.LastBoundTexture = data.Texture.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp];
                GL.Color4(1.0f, 1.0f, 1.0f, alpha);
                if (renderer.OptionFog)
                {
                    GL.Enable(EnableCap.Fog);
                }
                if (data.DisplayList > 0)
                {
                    GL.CallList(data.DisplayList);
                    GL.Disable(EnableCap.Texture2D);
                    GL.Enable(EnableCap.Blend);
                    GL.PopMatrix();
                    GL.MatrixMode(MatrixMode.Projection);
                    GL.PopMatrix();
                    return;
                }

                data.DisplayList = GL.GenLists(1);
                GL.NewList(data.DisplayList, ListMode.Compile);
                float y0, y1;
                if (data.KeepAspectRatio)
                {
                    int    tw = data.Texture.Width;
                    int    th = data.Texture.Height;
                    double hh = Math.PI * data.BackgroundImageDistance * th / (tw * data.Repetition);
                    y0 = (float)(-0.5 * hh);
                    y1 = (float)(1.5 * hh);
                }
                else
                {
                    y0 = (float)(-0.125 * data.BackgroundImageDistance);
                    y1 = (float)(0.375 * data.BackgroundImageDistance);
                }
                const int    n              = 32;
                Vector3[]    bottom         = new Vector3[n];
                Vector3[]    top            = new Vector3[n];
                double       angleValue     = 2.61799387799149 - 3.14159265358979 / n;
                const double angleIncrement = 6.28318530717958 / n;

                /*
                 * To ensure that the whole background cylinder is rendered inside the viewing frustum,
                 * the background is rendered before the scene with z-buffer writes disabled. Then,
                 * the actual distance from the camera is irrelevant as long as it is inside the frustum.
                 * */
                for (int i = 0; i < n; i++)
                {
                    float x = (float)(data.BackgroundImageDistance * Math.Cos(angleValue));
                    float z = (float)(data.BackgroundImageDistance * Math.Sin(angleValue));
                    bottom[i]   = new Vector3(scale * x, scale * y0, scale * z);
                    top[i]      = new Vector3(scale * x, scale * y1, scale * z);
                    angleValue += angleIncrement;
                }
                float  textureStart     = 0.5f * (float)data.Repetition / n;
                float  textureIncrement = -(float)data.Repetition / n;
                double textureX         = textureStart;
                for (int i = 0; i < n; i++)
                {
                    int j = (i + 1) % n;
                    // side wall
                    GL.Begin(PrimitiveType.Quads);
                    GL.TexCoord2(textureX, 0.005f);
                    GL.Vertex3(top[i].X, top[i].Y, top[i].Z);
                    GL.TexCoord2(textureX, 0.995f);
                    GL.Vertex3(bottom[i].X, bottom[i].Y, bottom[i].Z);
                    GL.TexCoord2(textureX + textureIncrement, 0.995f);
                    GL.Vertex3(bottom[j].X, bottom[j].Y, bottom[j].Z);
                    GL.TexCoord2(textureX + textureIncrement, 0.005f);
                    GL.Vertex3(top[j].X, top[j].Y, top[j].Z);
                    GL.End();
                    // top cap
                    GL.Begin(PrimitiveType.Triangles);
                    GL.TexCoord2(textureX, 0.005f);
                    GL.Vertex3(top[i].X, top[i].Y, top[i].Z);
                    GL.TexCoord2(textureX + textureIncrement, 0.005f);
                    GL.Vertex3(top[j].X, top[j].Y, top[j].Z);
                    GL.TexCoord2(textureX + 0.5 * textureIncrement, 0.1f);
                    GL.Vertex3(0.0f, top[i].Y, 0.0f);
                    // bottom cap
                    GL.TexCoord2(textureX + 0.5 * textureIncrement, 0.9f);
                    GL.Vertex3(0.0f, bottom[i].Y, 0.0f);
                    GL.TexCoord2(textureX + textureIncrement, 0.995f);
                    GL.Vertex3(bottom[j].X, bottom[j].Y, bottom[j].Z);
                    GL.TexCoord2(textureX, 0.995f);
                    GL.Vertex3(bottom[i].X, bottom[i].Y, bottom[i].Z);
                    GL.End();
                    // finish
                    textureX += textureIncrement;
                }
                GL.EndList();
                GL.CallList(data.DisplayList);
                GL.Disable(EnableCap.Texture2D);
                GL.Enable(EnableCap.Blend);
                GL.PopMatrix();
                GL.MatrixMode(MatrixMode.Projection);
                GL.PopMatrix();
            }
        }
Exemple #15
0
        /// <summary>Draws a 3D cube in immediate mode</summary>
        /// <param name="Position">The position in world-space</param>
        /// <param name="Direction">The direction vector</param>
        /// <param name="Up">The up vector</param>
        /// <param name="Side">The side vector</param>
        /// <param name="Size">A 3D vector describing the size of the cube</param>
        /// <param name="Camera">The camera position</param>
        /// <param name="TextureIndex">The texture to apply</param>
        private void DrawImmediate(Vector3 Position, Vector3 Direction, Vector3 Up, Vector3 Side, Vector3 Size, Vector3 Camera, Texture TextureIndex)
        {
            renderer.LastBoundTexture = null;
            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadIdentity();
            OpenTK.Matrix4d perspective = OpenTK.Matrix4d.Perspective(renderer.Camera.VerticalViewingAngle, -renderer.Screen.AspectRatio, 0.2, 1000.0);
            GL.MultMatrix(ref perspective);
            double dx = renderer.Camera.AbsoluteDirection.X;
            double dy = renderer.Camera.AbsoluteDirection.Y;
            double dz = renderer.Camera.AbsoluteDirection.Z;
            double ux = renderer.Camera.AbsoluteUp.X;
            double uy = renderer.Camera.AbsoluteUp.Y;
            double uz = renderer.Camera.AbsoluteUp.Z;

            OpenTK.Matrix4d lookat = OpenTK.Matrix4d.LookAt(0.0, 0.0, 0.0, dx, dy, dz, ux, uy, uz);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();
            GL.LoadMatrix(ref lookat);
            Vector3[] v = new Vector3[8];
            v[0] = new Vector3(Size.X, Size.Y, -Size.Z);
            v[1] = new Vector3(Size.X, -Size.Y, -Size.Z);
            v[2] = new Vector3(-Size.X, -Size.Y, -Size.Z);
            v[3] = new Vector3(-Size.X, Size.Y, -Size.Z);
            v[4] = new Vector3(Size.X, Size.Y, Size.Z);
            v[5] = new Vector3(Size.X, -Size.Y, Size.Z);
            v[6] = new Vector3(-Size.X, -Size.Y, Size.Z);
            v[7] = new Vector3(-Size.X, Size.Y, Size.Z);
            for (int i = 0; i < 8; i++)
            {
                v[i].Rotate(Direction, Up, Side);
                v[i] += Position - Camera;
            }
            int[][] Faces = new int[6][];
            Faces[0] = new[] { 0, 1, 2, 3 };
            Faces[1] = new[] { 0, 4, 5, 1 };
            Faces[2] = new[] { 0, 3, 7, 4 };
            Faces[3] = new[] { 6, 5, 4, 7 };
            Faces[4] = new[] { 6, 7, 3, 2 };
            Faces[5] = new[] { 6, 2, 1, 5 };
            if (TextureIndex == null || !renderer.currentHost.LoadTexture(ref TextureIndex, OpenGlTextureWrapMode.ClampClamp))
            {
                GL.Disable(EnableCap.Texture2D);
                for (int i = 0; i < 6; i++)
                {
                    GL.Begin(PrimitiveType.Quads);
                    for (int j = 0; j < 4; j++)
                    {
                        GL.Vertex3(v[Faces[i][j]].X, v[Faces[i][j]].Y, v[Faces[i][j]].Z);
                    }
                    GL.End();
                }
                GL.PopMatrix();

                GL.MatrixMode(MatrixMode.Projection);
                GL.PopMatrix();
                return;
            }
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, TextureIndex.OpenGlTextures[(int)OpenGlTextureWrapMode.ClampClamp].Name);
            Vector2[][] t = new Vector2[6][];
            t[0] = new[] { new Vector2(1.0, 0.0), new Vector2(1.0, 1.0), new Vector2(0.0, 1.0), new Vector2(0.0, 0.0) };
            t[1] = new[] { new Vector2(0.0, 0.0), new Vector2(1.0, 0.0), new Vector2(1.0, 1.0), new Vector2(0.0, 1.0) };
            t[2] = new[] { new Vector2(1.0, 1.0), new Vector2(0.0, 1.0), new Vector2(0.0, 0.0), new Vector2(1.0, 0.0) };
            t[3] = new[] { new Vector2(1.0, 1.0), new Vector2(0.0, 1.0), new Vector2(0.0, 0.0), new Vector2(1.0, 0.0) };
            t[4] = new[] { new Vector2(0.0, 1.0), new Vector2(0.0, 0.0), new Vector2(1.0, 0.0), new Vector2(1.0, 1.0) };
            t[5] = new[] { new Vector2(0.0, 1.0), new Vector2(0.0, 0.0), new Vector2(1.0, 0.0), new Vector2(1.0, 1.0) };
            for (int i = 0; i < 6; i++)
            {
                GL.Begin(PrimitiveType.Quads);
                GL.Color3(1.0, 1.0, 1.0);
                for (int j = 0; j < 4; j++)
                {
                    GL.TexCoord2(t[i][j].X, t[i][j].Y);
                    GL.Vertex3(v[Faces[i][j]].X, v[Faces[i][j]].Y, v[Faces[i][j]].Z);
                }
                GL.End();
            }
            GL.PopMatrix();

            GL.MatrixMode(MatrixMode.Projection);
            GL.PopMatrix();
        }
Exemple #16
0
        // TODO: Merge with base.Render() as much as possible!
        public override void Render()
        {
            View3D.CheckError("Render - Player - Pre");
            Location renderrelpos = GetWeldSpot();

            if (TheClient.IsMainMenu || !TheClient.CVars.r_drawself.ValueB)
            {
                return;
            }
            TheClient.SetEnts();
            if (TheClient.CVars.n_debugmovement.ValueB)
            {
                if (ServerLocation.IsInfinite() || ServerLocation.IsNaN() || renderrelpos.IsInfinite() || renderrelpos.IsNaN())
                {
                    SysConsole.Output(OutputType.WARNING, "NaN server data");
                }
                else
                {
                    TheClient.Rendering.RenderLine(ServerLocation, renderrelpos);
                    View3D.CheckError("Render - Player - Line");
                    TheClient.Rendering.RenderLineBox(ServerLocation + new Location(-0.2), ServerLocation + new Location(0.2));
                    if (View3D.CheckError("Render - Player - LineBox"))
                    {
                        SysConsole.Output(OutputType.DEBUG, "Caught: " + (ServerLocation + new Location(-0.2)) + "::: " + (ServerLocation + new Location(0.2)));
                    }
                }
            }
            if (TheClient.VR != null)
            {
                return;
            }
            View3D.CheckError("Render - Player - 0");
            OpenTK.Matrix4d mat = OpenTK.Matrix4d.Scale(1.5f)
                                  * OpenTK.Matrix4d.CreateRotationZ((Direction.Yaw * Utilities.PI180))
                                  * PlayerAngleMat
                                  * OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos));
            TheClient.MainWorldView.SetMatrix(2, mat);
            TheClient.Rendering.SetMinimumLight(0.0f);
            model.CustomAnimationAdjustments = new Dictionary <string, OpenTK.Matrix4>(SavedAdjustmentsOTK)
            {
                // TODO: safe (no-collision) rotation check?
                { "spine04", GetAdjustmentOTK("spine04") * OpenTK.Matrix4.CreateRotationX(-(float)(Direction.Pitch / 2f * Utilities.PI180)) }
            };
            View3D.CheckError("Render - Player - 1");
            if (!TheClient.MainWorldView.RenderingShadows && TheClient.CVars.g_firstperson.ValueB)
            {
                model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01") * OpenTK.Matrix4.CreateRotationX(-(float)(160f * Utilities.PI180));
            }
            else
            {
                model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01");
            }
            model.Draw(aHTime, hAnim, aTTime, tAnim, aLTime, lAnim);
            Model mod   = TheClient.GetItemForSlot(TheClient.QuickBarPos).Mod;
            bool  hasjp = HasJetpack();

            View3D.CheckError("Render - Player - 2");
            if (!hasjp && tAnim != null && mod != null)
            {
                mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos));
                TheClient.MainWorldView.SetMatrix(2, mat);
                Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments);
                // TODO: Logic of this rotation math?
                Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f)));
                adjs["spine04"] = GetAdjustment("spine04") * rotforw;
                SingleAnimationNode hand = tAnim.GetNode("metacarpal2.r");
                Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f)
                            * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f))
                               * hand.GetBoneTotalMatrix(aTTime, adjs))
                            * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-90) * Utilities.PI180) % 360f));
                OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14,
                                                            (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24,
                                                            (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34,
                                                            (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44);
                GL.UniformMatrix4(100, false, ref bonemat);
                mod.LoadSkin(TheClient.Textures);
                mod.Draw();
                bonemat = OpenTK.Matrix4.Identity;
                GL.UniformMatrix4(100, false, ref bonemat);
            }
            View3D.CheckError("Render - Player - 3");
            if (hasjp)
            {
                // TODO: Abstractify!
                Model jetp = GetHeldItem().Mod;
                mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos));
                TheClient.MainWorldView.SetMatrix(2, mat);
                Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>();
                Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f)));
                adjs["spine04"] = GetAdjustment("spine04") * rotforw;
                SingleAnimationNode spine = tAnim.GetNode("spine04");
                Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f)
                            * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f))
                               * spine.GetBoneTotalMatrix(aTTime, adjs))
                            * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)((90) * Utilities.PI180) % 360f));
                OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24,
                                                            (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44);
                GL.UniformMatrix4(100, false, ref bonemat);
                jetp.LoadSkin(TheClient.Textures);
                jetp.Draw();
                bonemat = OpenTK.Matrix4.Identity;
                GL.UniformMatrix4(100, false, ref bonemat);
            }
            View3D.CheckError("Render - Player - 4");
            if (IsTyping)
            {
                TheClient.Textures.GetTexture("ui/game/typing").Bind(); // TODO: store!
                TheClient.Rendering.RenderBillboard(renderrelpos + new Location(0, 0, 4), new Location(2), TheClient.MainWorldView.CameraPos);
            }
            View3D.CheckError("Render - Player - Post");
        }
Exemple #17
0
 /// <summary>
 /// 拡張メソッド.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static V4d Mult(this M4d m, V4d v) => new V4d(
     m.M11 * v.X + m.M12 * v.Y + m.M13 * v.Z + m.M14 * v.W,
     m.M21 * v.X + m.M22 * v.Y + m.M23 * v.Z + m.M24 * v.W,
     m.M31 * v.X + m.M32 * v.Y + m.M33 * v.Z + m.M34 * v.W,
     m.M41 * v.X + m.M42 * v.Y + m.M43 * v.Z + m.M44 * v.W
     );
Exemple #18
0
        internal void SetupRender()
        {
            Parent.Window.Visible = true;

            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(Color4.CornflowerBlue);

            View = Parent.Camera.OpenTKViewMatrix;
            Projection = OpenTK.Matrix4d.CreatePerspectiveFieldOfView(OpenTK.MathHelper.PiOver3, (float)Parent.Window.Width / Parent.Window.Height, 0.1F, 10000.0F);

            GraphicsContext.CurrentContext.VSync = true;

            TextureShader = new ShaderProgram(ShaderProgram.TextureVertexShaderSource, ShaderProgram.TextureFragmentShaderSource);
            ScreenShader = new ShaderProgram(ShaderProgram.ScreenFragmentShaderSource);

            ColorFramebuffer = new Framebuffer(Parent.Window.Width, Parent.Window.Height);
        }
Exemple #19
0
 /// <summary>
 /// 拡張メソッド.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static M4d Mult(this M4d m, double c) => new M4d(
     c * m.M11, c * m.M12, c * m.M13, c * m.M14,
     c * m.M21, c * m.M22, c * m.M23, c * m.M24,
     c * m.M31, c * m.M32, c * m.M33, c * m.M34,
     c * m.M41, c * m.M42, c * m.M43, c * m.M44
     );
Exemple #20
0
 public static LDDModder.Simple3D.Matrix4d ToLDD(this OpenTK.Matrix4d matrix)
 {
     return(new Simple3D.Matrix4d(matrix.Row0.ToLDD(), matrix.Row1.ToLDD(), matrix.Row2.ToLDD(), matrix.Row3.ToLDD()));
 }
Exemple #21
0
 /// <summary>
 /// 拡張メソッド.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static V4f Mult(this M4d m, V4f v) => new V4f(
     (float)(m.M11 * v.X + m.M12 * v.Y + m.M13 * v.Z + m.M14 * v.W),
     (float)(m.M21 * v.X + m.M22 * v.Y + m.M23 * v.Z + m.M24 * v.W),
     (float)(m.M31 * v.X + m.M32 * v.Y + m.M33 * v.Z + m.M34 * v.W),
     (float)(m.M41 * v.X + m.M42 * v.Y + m.M43 * v.Z + m.M44 * v.W)
     );
Exemple #22
0
 /// <summary>
 /// 拡張メソッド.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static Matrix3D ToMatrix3D(this M4d m) => new Matrix3D(
     m.M11, m.M21, m.M31,
     m.M12, m.M22, m.M32,
     m.M13, m.M23, m.M33
     );
Exemple #23
0
 /// <summary>
 /// 拡張メソッド.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static M4f ToM4f(this M4d m) => new M4f(
     (float)m.M11, (float)m.M12, (float)m.M13, (float)m.M14,
     (float)m.M21, (float)m.M22, (float)m.M23, (float)m.M24,
     (float)m.M31, (float)m.M32, (float)m.M33, (float)m.M34,
     (float)m.M41, (float)m.M42, (float)m.M43, (float)m.M44
     );