예제 #1
0
        public static void CreateFromAxisAngle(Vector3d axis, double angle, out SCNMatrix4 result)
        {
            double cos = System.Math.Cos(-angle);
            double sin = System.Math.Sin(-angle);
            double t   = 1.0f - cos;

            axis.Normalize();

            result = new SCNMatrix4((pfloat)(t * axis.X * axis.X + cos), (pfloat)(t * axis.X * axis.Y - sin * axis.Z), (pfloat)(t * axis.X * axis.Z + sin * axis.Y), (pfloat)(0.0f),
                                    (pfloat)(t * axis.X * axis.Y + sin * axis.Z), (pfloat)(t * axis.Y * axis.Y + cos), (pfloat)(t * axis.Y * axis.Z - sin * axis.X), (pfloat)0.0f,
                                    (pfloat)(t * axis.X * axis.Z - sin * axis.Y), (pfloat)(t * axis.Y * axis.Z + sin * axis.X), (pfloat)(t * axis.Z * axis.Z + cos), (pfloat)0.0f,
                                    0, 0, 0, 1);
        }
예제 #2
0
        public Vector3 UnProject(float[] winxyz, float[] model, float[] proj, int[] viewport)
        {
            global::OpenTK.Matrix4d projection;
            global::OpenTK.Matrix4d modelview;
            int[] _viewport = new int[4];

            if (model != null && proj != null && viewport != null)
            {
                throw new Exception("BUG");
            }
            else
            {
                GL.GetDouble(GetPName.ProjectionMatrix, out projection);
                GL.GetDouble(GetPName.ModelviewMatrix, out modelview);
                GL.GetInteger(GetPName.Viewport, _viewport);
            }
            global::OpenTK.Vector3d obj=new global::OpenTK.Vector3d();

            Imgui.Glu.UnProject(new global::OpenTK.Vector3d((double)winxyz[0], (double)winxyz[1], (double)winxyz[2]), modelview, projection, _viewport, ref obj);

            if (double.IsNaN(obj.X))
                throw new Exception("NaN");

            return new Vector3((float)obj.X,(float)obj.Y,(float)obj.Z);
        }
예제 #3
0
        public float[] GetRasterPosition(float[] pos3d)
        {
            global::OpenTK.Matrix4d projection;
            global::OpenTK.Matrix4d modelview;
            int[] viewport = new int[4];

            GL.GetDouble(GetPName.ProjectionMatrix, out projection);
            GL.GetDouble(GetPName.ModelviewMatrix, out modelview);
            GL.GetInteger(GetPName.Viewport, viewport);

            global::OpenTK.Vector3d win=new global::OpenTK.Vector3d();
            Imgui.Glu.Project(new global::OpenTK.Vector3d((double)pos3d[0], (double)pos3d[1], (double)pos3d[2]), modelview, projection, viewport, ref win);

            return new float[] { (float)win.X, (float)win.Y, (float)win.Z };
        }