// https://github.com/dotnet/corefx/blob/master/src/System.Numerics.Vectors/src/System/Numerics/Matrix4x4.cs
        //  public static Matrix4x4 Add(Matrix4x4 value1, Matrix4x4 value2)
        public static ovrMatrix4f Add(ovrMatrix4f _a, ovrMatrix4f _b)
        {
            // when is this of any use?

            ovrMatrix4f _o;
            __Matrix4x4 o = &_o;
            __Matrix4x4 a = &_a;
            __Matrix4x4 b = &_b;

            {
                o.M[0, 0] = a.M[0, 0] + b.M[0, 0];
                o.M[1, 0] = a.M[1, 0] + b.M[1, 0];
                o.M[2, 0] = a.M[2, 0] + b.M[2, 0];
                o.M[3, 0] = a.M[3, 0] + b.M[3, 0];

                o.M[0, 1] = a.M[0, 1] + b.M[0, 1];
                o.M[1, 1] = a.M[1, 1] + b.M[1, 1];
                o.M[2, 1] = a.M[2, 1] + b.M[2, 1];
                o.M[3, 1] = a.M[3, 1] + b.M[3, 1];

                o.M[0, 2] = a.M[0, 2] + b.M[0, 2];
                o.M[1, 2] = a.M[1, 2] + b.M[1, 2];
                o.M[2, 2] = a.M[2, 2] + b.M[2, 2];
                o.M[3, 2] = a.M[3, 2] + b.M[3, 2];

                o.M[0, 3] = a.M[0, 3] + b.M[0, 3];
                o.M[1, 3] = a.M[1, 3] + b.M[1, 3];
                o.M[2, 3] = a.M[2, 3] + b.M[2, 3];
                o.M[3, 3] = a.M[3, 3] + b.M[3, 3];

                // operating on fixed buffers, yet we want the dimensional array magic.
            }

            return(_o);
        }
        static void Peek(mat4stack256 that, out ovrMatrix4f value)
        {
            var offset = that.__offset * 4 * 4;

            fixed(float *__value_M = value.M)
            //fixed (float* __value = that.__value)
            {
                //fixed ( &that.__value
                //fixed (that)

                //var current = &__value[offset];
                //var current_ovrMatrix4f = (ovrMatrix4f*)current;


                //// copy our floats out
                //value = *current_ovrMatrix4f;

                //jni/OVRWindWheelNDK.dll.c:354:16: error: incompatible types when assigning to type 'ovrMatrix4f' from type 'struct ovrMatrix4f *'
                //     (*(value)) = matrix4f_3;

                // lets do a slower copy?

                for (int i = 0; i < 4 * 4; i++)
                {
                    //var f = __value[offset + i];
                    var f = that.__value[offset + i];

                    // Error	19	You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\Library\Matrix4x4Stack.cs	92	21	OVRWindWheelNDK
                    //value.M[i] = f;
                    __value_M[i] = f;
                }
            }
        }
Exemple #3
0
        public static ovrMatrix4f vrapi_GetCenterEyeViewMatrix(ref ovrHeadModelParms headModelParms,
                                                               ref ovrTracking tracking,

                                                               // nullable struct?
                                                               ref ovrMatrix4f input)
        {
            throw null;
        }
Exemple #4
0
            // vrapi_GetHmdInfo
            // called by AppThreadFunction
            public void ovrRenderer_Create(ref ovrHmdInfo hmdInfo)
            {
                ConsoleExtensions.trace("enter ovrRenderer_Create");

                fixed(int *hmdInfo_SuggestedEyeResolution = hmdInfo.SuggestedEyeResolution)
                fixed(float *hmdInfo_SuggestedEyeFov = hmdInfo.SuggestedEyeFov)
                {
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:89 hmdInfo_SuggestedEyeResolution width  1024
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:90 hmdInfo_SuggestedEyeResolution height  1024
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:91 NUM_MULTI_SAMPLES  4
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:95 hmdInfo_SuggestedEyeFov[0]  90
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:96 hmdInfo_SuggestedEyeFov[1]  90
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:97 DisplayRefreshRate  60


                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeResolution width ", hmdInfo_SuggestedEyeResolution[0]);
                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeResolution height ", hmdInfo_SuggestedEyeResolution[1]);
                    ConsoleExtensions.tracei("NUM_MULTI_SAMPLES ", NUM_MULTI_SAMPLES);


                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeFov[0] ", (int)hmdInfo_SuggestedEyeFov[0]);
                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeFov[1] ", (int)hmdInfo_SuggestedEyeFov[1]);
                    ConsoleExtensions.tracei("DisplayRefreshRate ", (int)hmdInfo.DisplayRefreshRate);


                    // 1012
                    // Create the render Textures.
                    for (int i = 0; i < NUM_BUFFERS; i++)
                    {
                        for (int eye = 0; eye < NUM_EYES; eye++)
                        {
                            //ConsoleExtensions.tracei("call ovrRenderTexture_Create i ", i);

                            this.RenderTextures[i, eye].ovrRenderTexture_Create(
                                hmdInfo_SuggestedEyeResolution[0],
                                hmdInfo_SuggestedEyeResolution[1],
                                NUM_MULTI_SAMPLES,

                                i, eye
                                );
                        }
                    }

                    this.BufferIndex = 0;

                    // https://www.kickstarter.com/projects/wearality/wearality-sky-limitless-vr

                    // Setup the projection matrix.
                    this.ProjectionMatrix = VrApi_Helpers.ovrMatrix4f_CreateProjectionFov(
                        hmdInfo_SuggestedEyeFov[0] * ((float)Math.PI / 180.0f),
                        hmdInfo_SuggestedEyeFov[1] * ((float)Math.PI / 180.0f),
                        0.0f, 0.0f, 1.0f, 0.0f);

                    this.TanAngleMatrix = VrApi_Helpers.ovrMatrix4f_TanAngleMatrixFromProjection(ref this.ProjectionMatrix);
                }

                //ConsoleExtensions.trace("exit ovrRenderer_Create");
            }
Exemple #5
0
        public static ovrMatrix4f CreateRotation(float radiansX, float radiansY, float radiansZ)
        {
            // http://stackoverflow.com/questions/9087563/maximum-native-memory-that-can-be-allocated-to-an-android-app

            // Error	3	Cannot initialize object of type 'float*' with a collection initializer	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	248	17	OVRMyCubeWorldNDK


            float sinX = math.sinf(radiansX);
            float cosX = math.cosf(radiansX);

            // Error	3	Cannot take the address of, get the size of, or declare a pointer to a managed type ('float[*,*]')	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	292	61	OVRMyCubeWorldNDK

            // we will leak a lot of heap...
            // not the heap. the stack thankyou. almost playing GC?
            // since we are not returning this array, it should live on stack. this way we wont leak memory as we are running without GC..
            float[] rotationX =
            {
                1,    0,     0, 0,
                0, cosX, -sinX, 0,
                0, sinX, cosX,  0,
                0,    0,     0, 1
            };

            float sinY = math.sinf(radiansY);
            float cosY = math.cosf(radiansY);

            float[] rotationY =
            {
                cosY,  0, sinY, 0,
                0,     1,    0, 0,
                -sinY, 0, cosY, 0,
                0,     0,    0, 1
            };

            float sinZ = math.sinf(radiansZ);
            float cosZ = math.cosf(radiansZ);

            float[] rotationZ =
            {
                cosZ, -sinZ, 0, 0,
                sinZ, cosZ,  0, 0,
                0,        0, 1, 0,
                0,        0, 0, 1
            };


            __ovrMatrix4f x = rotationX;
            __ovrMatrix4f y = rotationY;
            __ovrMatrix4f z = rotationZ;

            //ovrMatrix4f o;

            ovrMatrix4f rotationXY  = __ovrMatrix4f.Multiply(y, x);
            ovrMatrix4f rotationXYZ = __ovrMatrix4f.Multiply(z, &rotationXY);

            // copy it back..
            return(rotationXYZ);
        }
        //public static ovrMatrix4f TanAngleMatrixFromProjection(__ovrMatrix4f projection)
        public static ovrMatrix4f TanAngleMatrixFromProjection(ovrMatrix4f __projection)
        {
            ConsoleExtensions.trace("enter TanAngleMatrixFromProjection");

            __Matrix4x4 projection = &__projection;

            // A projection matrix goes from a view point to NDC, or -1 to 1 space.
            // Scale and bias to convert that to a 0 to 1 space.
            //const ovrMatrix4f tanAngleMatrix =
            //float[,] tanAngleMatrix =
            //{
            //    { 0.5f * projection.M[0,0], 0.5f * projection.M[0,1], 0.5f * projection.M[0,2] - 0.5f, 0.5f * projection.M[0,3] },
            //    { 0.5f * projection.M[1,0], 0.5f * projection.M[1,1], 0.5f * projection.M[1,2] - 0.5f, 0.5f * projection.M[1,3] },
            //    {0.0f, 0.0f, -1.0f, 0.0f},
            //    {0.0f, 0.0f, -1.0f, 0.0f }
            //};

            float[] tanAngleMatrix =
            {
                0.5f * projection.M[0,   0], 0.5f * projection.M[0,   1], 0.5f * projection.M[0, 2] - 0.5f, 0.5f * projection.M[0, 3],
                0.5f * projection.M[1,   0], 0.5f * projection.M[1,   1], 0.5f * projection.M[1, 2] - 0.5f, 0.5f * projection.M[1, 3],
                0.0f,                  0.0f,                 -1.0f, 0.0f,
                0.0f,                  0.0f,                 -1.0f, 0.0f
            };

            ovrMatrix4f that_data;
            __Matrix4x4 that = &that_data;

            //that_data.M = tanAngleMatrix;
            //that_data.M[0] = tanAngleMatrix[0];
            //for (int i = 0; i < 16; i++)
            //{
            //    // this will cause stack corruption. why?
            //    that.M[i, i] = tanAngleMatrix[i];
            //}

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    //that.M[x, y] = tanAngleMatrix[x, y];
                    //that.M[x, y] = tanAngleMatrix[x + 4 * y];

                    // memorylayout the same as for CLR?
                    that.M[x, y] = tanAngleMatrix[y + 4 * x];
                }
            }

            //jni/OVRWindWheelNDK.dll.c:2651:28: error: expected expression before '?' token
            //     singleArray7 = calloc [?][?];
            //                            ^

            ConsoleExtensions.trace("exit TanAngleMatrixFromProjection, stack still valid?");
            return(that_data);
        }
        public static ovrMatrix4f GetEyeViewMatrix(ref ovrHeadModelParms headModelParms,
                                                   ref ovrMatrix4f centerEyeViewMatrix,
                                                   int eye)
        {
            var o = (eye > 0 ? -0.5f : 0.5f);

            //float eyeOffset = (eye > 0 ? -0.5f : 0.5f) * headModelParms.InterpupillaryDistance;
            float       eyeOffset       = o * headModelParms.InterpupillaryDistance;
            ovrMatrix4f eyeOffsetMatrix = CreateTranslation(eyeOffset, 0.0f, 0.0f);

            return(Multiply(ref eyeOffsetMatrix, ref centerEyeViewMatrix));
        }
Exemple #8
0
        public static ovrMatrix4f CreateRotation(float radiansX, float radiansY, float radiansZ)
        {
            // Error	3	Cannot initialize object of type 'float*' with a collection initializer	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	248	17	OVRMyCubeWorldNDK


            float sinX = math.sinf(radiansX);
            float cosX = math.cosf(radiansX);

            // Error	3	Cannot take the address of, get the size of, or declare a pointer to a managed type ('float[*,*]')	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	292	61	OVRMyCubeWorldNDK


            // jsc cannot handle it yet
            // this seems to be the only way to do matrix math in C# ?
            float[,] rotationX =
            {
                { 1,    0,     0, 0 },
                { 0, cosX, -sinX, 0 },
                { 0, sinX, cosX,  0 },
                { 0,    0,     0, 1 }
            };

            float sinY = math.sinf(radiansY);
            float cosY = math.cosf(radiansY);

            float[,] rotationY =
            {
                { cosY,  0, sinY, 0 },
                {     0, 1,    0, 0 },
                { -sinY, 0, cosY, 0 },
                {     0, 0,    0, 1 }
            };

            float sinZ = math.sinf(radiansZ);
            float cosZ = math.cosf(radiansZ);

            float[,] rotationZ =
            {
                { cosZ, -sinZ, 0, 0 },
                { sinZ, cosZ,  0, 0 },
                {    0,     0, 1, 0 },
                {    0,     0, 0, 1 }
            };



            ovrMatrix4f rotationXY  = __ovrMatrix4f.Multiply(rotationY, rotationX);
            ovrMatrix4f rotationXYZ = __ovrMatrix4f.Multiply(rotationZ, &rotationXY);

            // copy it back..
            return(rotationXYZ);
        }
        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        //static inline ovrMatrix4f vrapi_GetCenterEyeViewMatrix(
        //    ref ovrHeadModelParms headModelParms,
        //                                                ref ovrTracking tracking,
        //                                                ref ovrMatrix4f input
        //    )
        //{
        //    const ovrMatrix4f centerEyeTransform = vrapi_GetCenterEyeTransform( headModelParms, tracking, input );
        //    return ovrMatrix4f_Inverse( &centerEyeTransform );
        //}



        //public static ovrMatrix4f translate(ovrMatrix4f input, float x, float y, float z)
        //{
        //    ovrMatrix4f output;

        //    translate(ref output, ref input, x, y, z);


        //    return output;
        //}

        //public static void translate(ref ovrMatrix4f output, ref ovrMatrix4f input, float x, float y, float z)
        //{
        //    //float x = xyz[0], y = xyz[1], z = xyz[2];


        //    //if (input == output)
        //    //{
        //    //    output[12] = input[0] * x + input[4] * y + input[8] * z + input[12];
        //    //    output[13] = input[1] * x + input[5] * y + input[9] * z + input[13];
        //    //    output[14] = input[2] * x + input[6] * y + input[10] * z + input[14];
        //    //    output[15] = input[3] * x + input[7] * y + input[11] * z + input[15];

        //    //    return output;
        //    //}

        //    fixed (float* input_M = input.M)
        //    fixed (float* output_M = output.M)
        //    {
        //        float a00, a01, a02, a03,
        //            a10, a11, a12, a13,
        //            a20, a21, a22, a23;


        //        a00 = input_M[0]; a01 = input_M[1]; a02 = input_M[2]; a03 = input_M[3];
        //        a10 = input_M[4]; a11 = input_M[5]; a12 = input_M[6]; a13 = input_M[7];
        //        a20 = input_M[8]; a21 = input_M[9]; a22 = input_M[10]; a23 = input_M[11];

        //        output_M[0] = a00; output_M[1] = a01; output_M[2] = a02; output_M[3] = a03;
        //        output_M[4] = a10; output_M[5] = a11; output_M[6] = a12; output_M[7] = a13;
        //        output_M[8] = a20; output_M[9] = a21; output_M[10] = a22; output_M[11] = a23;

        //        output_M[12] = a00 * x + a10 * y + a20 * z + input_M[12];
        //        output_M[13] = a01 * x + a11 * y + a21 * z + input_M[13];
        //        output_M[14] = a02 * x + a12 * y + a22 * z + input_M[14];
        //        output_M[15] = a03 * x + a13 * y + a23 * z + input_M[15];
        //    }

        //}



        //public static float[] translate(float[] output, float[] input, float[] xyz)
        //{
        //    float x = xyz[0], y = xyz[1], z = xyz[2];

        //    if (input == output)
        //    {
        //        output[12] = input[0] * x + input[4] * y + input[8] * z + input[12];
        //        output[13] = input[1] * x + input[5] * y + input[9] * z + input[13];
        //        output[14] = input[2] * x + input[6] * y + input[10] * z + input[14];
        //        output[15] = input[3] * x + input[7] * y + input[11] * z + input[15];

        //        return output;
        //    }

        //    float a00, a01, a02, a03,
        //        a10, a11, a12, a13,
        //        a20, a21, a22, a23;


        //    a00 = input[0]; a01 = input[1]; a02 = input[2]; a03 = input[3];
        //    a10 = input[4]; a11 = input[5]; a12 = input[6]; a13 = input[7];
        //    a20 = input[8]; a21 = input[9]; a22 = input[10]; a23 = input[11];

        //    output[0] = a00; output[1] = a01; output[2] = a02; output[3] = a03;
        //    output[4] = a10; output[5] = a11; output[6] = a12; output[7] = a13;
        //    output[8] = a20; output[9] = a21; output[10] = a22; output[11] = a23;

        //    output[12] = a00 * x + a10 * y + a20 * z + input[12];
        //    output[13] = a01 * x + a11 * y + a21 * z + input[13];
        //    output[14] = a02 * x + a12 * y + a22 * z + input[14];
        //    output[15] = a03 * x + a13 * y + a23 * z + input[15];


        //    return output;
        //}


        //public static void Set(ref ovrMatrix4f xyz, byte* pBuffer)
        public static void Set(ref ovrMatrix4f xyz, byte[] aBuffer, int UDPMatrixIndex)
        {
            // Error	7	You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	808	21	OVRWindWheelNDK
            // Error	7	You cannot use the fixed statement to take the address of an already fixed expression	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	782	37	OVRWindWheelNDK

            //ConsoleExtensions.tracef("ovrRenderer_RenderFrame UDPDraw[] ", f);

            //fixed (float* __xyz_M = &xyz.M[0])
            fixed(float *__xyz_M = xyz.M)
            fixed(byte *pBuffer = &aBuffer[0])
            {
                var pFloatBuffer = (float *)pBuffer;

                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  2.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  3.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  4.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000

                for (int i = 0; i < 4 * 4; i++)
                {
                    var f = pFloatBuffer[i + UDPMatrixIndex * (64 / 4)];

                    //appThread.appState.tracef60("ovrRenderer_RenderFrame UDPDraw[] ", f);
                    //ConsoleExtensions.tracef("ovrRenderer_RenderFrame UDPDraw[] ", f);


                    __xyz_M[i] = f;
                    //xyz.M[i] = f;
                    // *(((float*)((&((&matrix4f2)->M)))) + (num5 * 4)) = single6;
                }
            }

            // I/DEBUG   (32762): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
            // new data available!
            //gpuInstanceTransformBuffer1[0] = __Matrix4x4.Transpose(&xyz);
            //appThread.appState.tracei60("ovrRenderer_RenderFrame UDPDraw ? crash?");
            //ConsoleExtensions.trace("ovrRenderer_RenderFrame UDPDraw ? crash?");
        }
Exemple #10
0
        //public ovrMatrix4f __value;

        // caller will keep the value on stack
        public static ovrMatrix4f Multiply(ref ovrMatrix4f ref_a, ref ovrMatrix4f ref_b)
        {
            // memory dereference magic
            // yet, in glsl we wont have pointers, all we will have is copy struct?
            // http://www.gamedev.net/topic/347232-glsl-pointers/

            // Error	3	A pointer must be indexed by only one value	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	93	98	OVRMyCubeWorldNDK
            //Error	5	The type of a local declared in a fixed statement must be a pointer type	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	92	20	OVRMyCubeWorldNDK

            ovrMatrix4f _o;


            //fixed (ovrMatrix4f* po = &o)
            fixed(ovrMatrix4f *pa = &ref_a)
            fixed(ovrMatrix4f * pb = &ref_b)
            {
                object so = (size_t)(void *)&_o;
                var    o  = (__ovrMatrix4f)so;

                object sa = (size_t)pa;
                var    a  = (__ovrMatrix4f)sa;

                object sb = (size_t)pb;
                var    b  = (__ovrMatrix4f)sb;

                o.M[0, 0] = a.M[0, 0] * b.M[0, 0] + a.M[0, 1] * b.M[1, 0] + a.M[0, 2] * b.M[2, 0] + a.M[0, 3] * b.M[3, 0];
                o.M[1, 0] = a.M[1, 0] * b.M[0, 0] + a.M[1, 1] * b.M[1, 0] + a.M[1, 2] * b.M[2, 0] + a.M[1, 3] * b.M[3, 0];
                o.M[2, 0] = a.M[2, 0] * b.M[0, 0] + a.M[2, 1] * b.M[1, 0] + a.M[2, 2] * b.M[2, 0] + a.M[2, 3] * b.M[3, 0];
                o.M[3, 0] = a.M[3, 0] * b.M[0, 0] + a.M[3, 1] * b.M[1, 0] + a.M[3, 2] * b.M[2, 0] + a.M[3, 3] * b.M[3, 0];

                o.M[0, 1] = a.M[0, 0] * b.M[0, 1] + a.M[0, 1] * b.M[1, 1] + a.M[0, 2] * b.M[2, 1] + a.M[0, 3] * b.M[3, 1];
                o.M[1, 1] = a.M[1, 0] * b.M[0, 1] + a.M[1, 1] * b.M[1, 1] + a.M[1, 2] * b.M[2, 1] + a.M[1, 3] * b.M[3, 1];
                o.M[2, 1] = a.M[2, 0] * b.M[0, 1] + a.M[2, 1] * b.M[1, 1] + a.M[2, 2] * b.M[2, 1] + a.M[2, 3] * b.M[3, 1];
                o.M[3, 1] = a.M[3, 0] * b.M[0, 1] + a.M[3, 1] * b.M[1, 1] + a.M[3, 2] * b.M[2, 1] + a.M[3, 3] * b.M[3, 1];

                o.M[0, 2] = a.M[0, 0] * b.M[0, 2] + a.M[0, 1] * b.M[1, 2] + a.M[0, 2] * b.M[2, 2] + a.M[0, 3] * b.M[3, 2];
                o.M[1, 2] = a.M[1, 0] * b.M[0, 2] + a.M[1, 1] * b.M[1, 2] + a.M[1, 2] * b.M[2, 2] + a.M[1, 3] * b.M[3, 2];
                o.M[2, 2] = a.M[2, 0] * b.M[0, 2] + a.M[2, 1] * b.M[1, 2] + a.M[2, 2] * b.M[2, 2] + a.M[2, 3] * b.M[3, 2];
                o.M[3, 2] = a.M[3, 0] * b.M[0, 2] + a.M[3, 1] * b.M[1, 2] + a.M[3, 2] * b.M[2, 2] + a.M[3, 3] * b.M[3, 2];

                o.M[0, 3] = a.M[0, 0] * b.M[0, 3] + a.M[0, 1] * b.M[1, 3] + a.M[0, 2] * b.M[2, 3] + a.M[0, 3] * b.M[3, 3];
                o.M[1, 3] = a.M[1, 0] * b.M[0, 3] + a.M[1, 1] * b.M[1, 3] + a.M[1, 2] * b.M[2, 3] + a.M[1, 3] * b.M[3, 3];
                o.M[2, 3] = a.M[2, 0] * b.M[0, 3] + a.M[2, 1] * b.M[1, 3] + a.M[2, 2] * b.M[2, 3] + a.M[2, 3] * b.M[3, 3];
                o.M[3, 3] = a.M[3, 0] * b.M[0, 3] + a.M[3, 1] * b.M[1, 3] + a.M[3, 2] * b.M[2, 3] + a.M[3, 3] * b.M[3, 3];
            }

            return(_o);
        }
Exemple #11
0
        public static ovrMatrix4f Multiply(ovrMatrix4f _a, ovrMatrix4f _b)
        {
            // perhaps the compiler could decide to optimize and move to a byref pointer version?


            // memory dereference magic
            // yet, in glsl we wont have pointers, all we will have is copy struct?
            // http://www.gamedev.net/topic/347232-glsl-pointers/

            // Error	3	A pointer must be indexed by only one value	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	93	98	OVRMyCubeWorldNDK
            //Error	5	The type of a local declared in a fixed statement must be a pointer type	X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorldNDK\References\VrApi.ovrMatrix4f.cs	92	20	OVRMyCubeWorldNDK

            ovrMatrix4f   _o;
            __ovrMatrix4f o = &_o;
            __ovrMatrix4f a = &_a;
            __ovrMatrix4f b = &_b;

            {
                o.M[0, 0] = a.M[0, 0] * b.M[0, 0] + a.M[0, 1] * b.M[1, 0] + a.M[0, 2] * b.M[2, 0] + a.M[0, 3] * b.M[3, 0];
                o.M[1, 0] = a.M[1, 0] * b.M[0, 0] + a.M[1, 1] * b.M[1, 0] + a.M[1, 2] * b.M[2, 0] + a.M[1, 3] * b.M[3, 0];
                o.M[2, 0] = a.M[2, 0] * b.M[0, 0] + a.M[2, 1] * b.M[1, 0] + a.M[2, 2] * b.M[2, 0] + a.M[2, 3] * b.M[3, 0];
                o.M[3, 0] = a.M[3, 0] * b.M[0, 0] + a.M[3, 1] * b.M[1, 0] + a.M[3, 2] * b.M[2, 0] + a.M[3, 3] * b.M[3, 0];

                o.M[0, 1] = a.M[0, 0] * b.M[0, 1] + a.M[0, 1] * b.M[1, 1] + a.M[0, 2] * b.M[2, 1] + a.M[0, 3] * b.M[3, 1];
                o.M[1, 1] = a.M[1, 0] * b.M[0, 1] + a.M[1, 1] * b.M[1, 1] + a.M[1, 2] * b.M[2, 1] + a.M[1, 3] * b.M[3, 1];
                o.M[2, 1] = a.M[2, 0] * b.M[0, 1] + a.M[2, 1] * b.M[1, 1] + a.M[2, 2] * b.M[2, 1] + a.M[2, 3] * b.M[3, 1];
                o.M[3, 1] = a.M[3, 0] * b.M[0, 1] + a.M[3, 1] * b.M[1, 1] + a.M[3, 2] * b.M[2, 1] + a.M[3, 3] * b.M[3, 1];

                o.M[0, 2] = a.M[0, 0] * b.M[0, 2] + a.M[0, 1] * b.M[1, 2] + a.M[0, 2] * b.M[2, 2] + a.M[0, 3] * b.M[3, 2];
                o.M[1, 2] = a.M[1, 0] * b.M[0, 2] + a.M[1, 1] * b.M[1, 2] + a.M[1, 2] * b.M[2, 2] + a.M[1, 3] * b.M[3, 2];
                o.M[2, 2] = a.M[2, 0] * b.M[0, 2] + a.M[2, 1] * b.M[1, 2] + a.M[2, 2] * b.M[2, 2] + a.M[2, 3] * b.M[3, 2];
                o.M[3, 2] = a.M[3, 0] * b.M[0, 2] + a.M[3, 1] * b.M[1, 2] + a.M[3, 2] * b.M[2, 2] + a.M[3, 3] * b.M[3, 2];

                o.M[0, 3] = a.M[0, 0] * b.M[0, 3] + a.M[0, 1] * b.M[1, 3] + a.M[0, 2] * b.M[2, 3] + a.M[0, 3] * b.M[3, 3];
                o.M[1, 3] = a.M[1, 0] * b.M[0, 3] + a.M[1, 1] * b.M[1, 3] + a.M[1, 2] * b.M[2, 3] + a.M[1, 3] * b.M[3, 3];
                o.M[2, 3] = a.M[2, 0] * b.M[0, 3] + a.M[2, 1] * b.M[1, 3] + a.M[2, 2] * b.M[2, 3] + a.M[2, 3] * b.M[3, 3];
                o.M[3, 3] = a.M[3, 0] * b.M[0, 3] + a.M[3, 1] * b.M[1, 3] + a.M[3, 2] * b.M[2, 3] + a.M[3, 3] * b.M[3, 3];

                // operating on fixed buffers, yet we want the dimensional array magic.
            }

            return(_o);
        }
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150717/matrix4x4
        // X:\jsc.svn\core\ScriptCoreLib\Shared\BCLImplementation\System\Numerics\Matrix4x4.cs




        static void Push(mat4stack256 that, ref ovrMatrix4f value)
        {
            that.__offset++;

            fixed (float* __value_M = value.M)
            //fixed (float* __value = that.__value)
            {
                //fixed ( &that.__value
                //fixed (that)

                //var current = &__value[offset];
                //var current_ovrMatrix4f = (ovrMatrix4f*)current;


                //// copy our floats out
                //value = *current_ovrMatrix4f;

                //jni/OVRWindWheelNDK.dll.c:354:16: error: incompatible types when assigning to type 'ovrMatrix4f' from type 'struct ovrMatrix4f *'
                //     (*(value)) = matrix4f_3;

                // lets do a slower copy?

                for (int i = 0; i < 4 * 4; i++)
                {
                    //var f = __value[offset + i];
                    //var f = that.__value[offset + i];

                    //// Error	19	You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\Library\Matrix4x4Stack.cs	92	21	OVRWindWheelNDK
                    ////value.M[i] = f;
                    //__value_M[i] = f;

                    //var f = value.M[i];
                    var f = __value_M[i];

                    that.__value[that.__offset + i] = f;

                }
            }
        }
Exemple #13
0
    public static Matrix4x4 ToMatrix4x4(this ovrMatrix4f ovrMat)
    {
        Matrix4x4 mat = new Matrix4x4();

        mat[0, 0] = ovrMat.m[0, 0];
        mat[0, 1] = ovrMat.m[0, 1];
        mat[0, 2] = ovrMat.m[0, 2];
        mat[0, 3] = ovrMat.m[0, 3];
        mat[1, 0] = ovrMat.m[1, 0];
        mat[1, 1] = ovrMat.m[1, 1];
        mat[1, 2] = ovrMat.m[1, 2];
        mat[1, 3] = ovrMat.m[1, 3];
        mat[2, 0] = ovrMat.m[2, 0];
        mat[2, 1] = ovrMat.m[2, 1];
        mat[2, 2] = ovrMat.m[2, 2];
        mat[2, 3] = ovrMat.m[2, 3];
        mat[3, 0] = ovrMat.m[3, 0];
        mat[3, 1] = ovrMat.m[3, 1];
        mat[3, 2] = ovrMat.m[3, 2];
        mat[3, 3] = ovrMat.m[3, 3];

        return(mat);
    }
Exemple #14
0
        public static ovrMatrix4f vrapi_GetCenterEyeViewMatrix(
            ref ovrHeadModelParms headModelParms,
            ref ovrTracking tracking,

            // nullable struct?
            ovrMatrix4f* input)
        {
            throw null;
        }
Exemple #15
0
 public static ovrMatrix4f vrapi_GetEyeViewMatrix(ref ovrHeadModelParms headModelParms,
                                             ref ovrMatrix4f centerEyeViewMatrix,
                                             int eye)
 {
     throw null;
 }
Exemple #16
0
 public static ovrMatrix4f ovrMatrix4f_Multiply(ref ovrMatrix4f a, ref ovrMatrix4f b)
 {
     throw null;
 }
Exemple #17
0
 public static ovrMatrix4f vrapi_GetEyeViewMatrix(ref ovrHeadModelParms headModelParms,
                                                  ref ovrMatrix4f centerEyeViewMatrix,
                                                  int eye)
 {
     throw null;
 }
        // https://github.com/dotnet/corefx/blob/master/src/System.Numerics.Vectors/src/System/Numerics/Matrix4x4.cs
        //  public static Matrix4x4 Add(Matrix4x4 value1, Matrix4x4 value2)
        public static ovrMatrix4f Add(ovrMatrix4f _a, ovrMatrix4f _b)
        {
            // when is this of any use?

            ovrMatrix4f _o;
            __Matrix4x4 o = &_o;
            __Matrix4x4 a = &_a;
            __Matrix4x4 b = &_b;

            {
                o.M[0, 0] = a.M[0, 0] + b.M[0, 0];
                o.M[1, 0] = a.M[1, 0] + b.M[1, 0];
                o.M[2, 0] = a.M[2, 0] + b.M[2, 0];
                o.M[3, 0] = a.M[3, 0] + b.M[3, 0];

                o.M[0, 1] = a.M[0, 1] + b.M[0, 1];
                o.M[1, 1] = a.M[1, 1] + b.M[1, 1];
                o.M[2, 1] = a.M[2, 1] + b.M[2, 1];
                o.M[3, 1] = a.M[3, 1] + b.M[3, 1];

                o.M[0, 2] = a.M[0, 2] + b.M[0, 2];
                o.M[1, 2] = a.M[1, 2] + b.M[1, 2];
                o.M[2, 2] = a.M[2, 2] + b.M[2, 2];
                o.M[3, 2] = a.M[3, 2] + b.M[3, 2];

                o.M[0, 3] = a.M[0, 3] + b.M[0, 3];
                o.M[1, 3] = a.M[1, 3] + b.M[1, 3];
                o.M[2, 3] = a.M[2, 3] + b.M[2, 3];
                o.M[3, 3] = a.M[3, 3] + b.M[3, 3];

                // operating on fixed buffers, yet we want the dimensional array magic.
            }

            return _o;
        }
        public static ovrMatrix4f GetEyeViewMatrix(ref ovrHeadModelParms headModelParms,
                                                    ref ovrMatrix4f centerEyeViewMatrix,
                                                    int eye)
        {
            var o = (eye > 0 ? -0.5f : 0.5f);

            //float eyeOffset = (eye > 0 ? -0.5f : 0.5f) * headModelParms.InterpupillaryDistance;
            float eyeOffset = o * headModelParms.InterpupillaryDistance;
            ovrMatrix4f eyeOffsetMatrix = CreateTranslation(eyeOffset, 0.0f, 0.0f);
            return Multiply(ref eyeOffsetMatrix, ref centerEyeViewMatrix);
        }
        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        //static inline ovrMatrix4f vrapi_GetCenterEyeViewMatrix(	
        //    ref ovrHeadModelParms headModelParms,
        //                                                ref ovrTracking tracking,
        //                                                ref ovrMatrix4f input 
        //    )
        //{
        //    const ovrMatrix4f centerEyeTransform = vrapi_GetCenterEyeTransform( headModelParms, tracking, input );
        //    return ovrMatrix4f_Inverse( &centerEyeTransform );
        //}






        //public static ovrMatrix4f translate(ovrMatrix4f input, float x, float y, float z)
        //{
        //    ovrMatrix4f output;

        //    translate(ref output, ref input, x, y, z);


        //    return output;
        //}

        //public static void translate(ref ovrMatrix4f output, ref ovrMatrix4f input, float x, float y, float z)
        //{
        //    //float x = xyz[0], y = xyz[1], z = xyz[2];


        //    //if (input == output)
        //    //{
        //    //    output[12] = input[0] * x + input[4] * y + input[8] * z + input[12];
        //    //    output[13] = input[1] * x + input[5] * y + input[9] * z + input[13];
        //    //    output[14] = input[2] * x + input[6] * y + input[10] * z + input[14];
        //    //    output[15] = input[3] * x + input[7] * y + input[11] * z + input[15];

        //    //    return output;
        //    //}

        //    fixed (float* input_M = input.M)
        //    fixed (float* output_M = output.M)
        //    {
        //        float a00, a01, a02, a03,
        //            a10, a11, a12, a13,
        //            a20, a21, a22, a23;


        //        a00 = input_M[0]; a01 = input_M[1]; a02 = input_M[2]; a03 = input_M[3];
        //        a10 = input_M[4]; a11 = input_M[5]; a12 = input_M[6]; a13 = input_M[7];
        //        a20 = input_M[8]; a21 = input_M[9]; a22 = input_M[10]; a23 = input_M[11];

        //        output_M[0] = a00; output_M[1] = a01; output_M[2] = a02; output_M[3] = a03;
        //        output_M[4] = a10; output_M[5] = a11; output_M[6] = a12; output_M[7] = a13;
        //        output_M[8] = a20; output_M[9] = a21; output_M[10] = a22; output_M[11] = a23;

        //        output_M[12] = a00 * x + a10 * y + a20 * z + input_M[12];
        //        output_M[13] = a01 * x + a11 * y + a21 * z + input_M[13];
        //        output_M[14] = a02 * x + a12 * y + a22 * z + input_M[14];
        //        output_M[15] = a03 * x + a13 * y + a23 * z + input_M[15];
        //    }

        //}



        //public static float[] translate(float[] output, float[] input, float[] xyz)
        //{
        //    float x = xyz[0], y = xyz[1], z = xyz[2];

        //    if (input == output)
        //    {
        //        output[12] = input[0] * x + input[4] * y + input[8] * z + input[12];
        //        output[13] = input[1] * x + input[5] * y + input[9] * z + input[13];
        //        output[14] = input[2] * x + input[6] * y + input[10] * z + input[14];
        //        output[15] = input[3] * x + input[7] * y + input[11] * z + input[15];

        //        return output;
        //    }

        //    float a00, a01, a02, a03,
        //        a10, a11, a12, a13,
        //        a20, a21, a22, a23;


        //    a00 = input[0]; a01 = input[1]; a02 = input[2]; a03 = input[3];
        //    a10 = input[4]; a11 = input[5]; a12 = input[6]; a13 = input[7];
        //    a20 = input[8]; a21 = input[9]; a22 = input[10]; a23 = input[11];

        //    output[0] = a00; output[1] = a01; output[2] = a02; output[3] = a03;
        //    output[4] = a10; output[5] = a11; output[6] = a12; output[7] = a13;
        //    output[8] = a20; output[9] = a21; output[10] = a22; output[11] = a23;

        //    output[12] = a00 * x + a10 * y + a20 * z + input[12];
        //    output[13] = a01 * x + a11 * y + a21 * z + input[13];
        //    output[14] = a02 * x + a12 * y + a22 * z + input[14];
        //    output[15] = a03 * x + a13 * y + a23 * z + input[15];


        //    return output;
        //}


        //public static void Set(ref ovrMatrix4f xyz, byte* pBuffer)
        public static void Set(ref ovrMatrix4f xyz, byte[] aBuffer, int UDPMatrixIndex)
        {
            // Error	7	You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	808	21	OVRWindWheelNDK
            // Error	7	You cannot use the fixed statement to take the address of an already fixed expression	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	782	37	OVRWindWheelNDK

            //ConsoleExtensions.tracef("ovrRenderer_RenderFrame UDPDraw[] ", f);

            //fixed (float* __xyz_M = &xyz.M[0])
            fixed (float* __xyz_M = xyz.M)
            fixed (byte* pBuffer = &aBuffer[0])
            {
                var pFloatBuffer = (float*)pBuffer;

                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  2.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  3.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  4.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  0.000000
                //I/xNativeActivity(15380): \VrCubeWorld.Renderer.cs:579 ovrRenderer_RenderFrame UDPDraw[]  1.000000

                for (int i = 0; i < 4 * 4; i++)
                {
                    var f = pFloatBuffer[i + UDPMatrixIndex * (64 / 4)];

                    //appThread.appState.tracef60("ovrRenderer_RenderFrame UDPDraw[] ", f);
                    //ConsoleExtensions.tracef("ovrRenderer_RenderFrame UDPDraw[] ", f);


                    __xyz_M[i] = f;
                    //xyz.M[i] = f;
                    // *(((float*)((&((&matrix4f2)->M)))) + (num5 * 4)) = single6;
                }
            }

            // I/DEBUG   (32762): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
            // new data available!
            //gpuInstanceTransformBuffer1[0] = __Matrix4x4.Transpose(&xyz);
            //appThread.appState.tracei60("ovrRenderer_RenderFrame UDPDraw ? crash?");
            //ConsoleExtensions.trace("ovrRenderer_RenderFrame UDPDraw ? crash?");
        }
 // transactional memory/historic undo button
 public void Push(ovrMatrix4f value)
 {
     Push(this, ref value);
 }
        //public ovrMatrix4f __value;

        // caller will keep the value on stack
        public static ovrMatrix4f Multiply(ref ovrMatrix4f ref_a, ref ovrMatrix4f ref_b)
        {
            // memory dereference magic
            // yet, in glsl we wont have pointers, all we will have is copy struct?
            // http://www.gamedev.net/topic/347232-glsl-pointers/

            // Error	3	A pointer must be indexed by only one value	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	93	98	OVRWindWheelNDK
            //Error	5	The type of a local declared in a fixed statement must be a pointer type	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	92	20	OVRWindWheelNDK

            ovrMatrix4f _o;


            //fixed (ovrMatrix4f* po = &o)
            fixed (ovrMatrix4f* pa = &ref_a)
            fixed (ovrMatrix4f* pb = &ref_b)
            {
                object so = (size_t)(void*)&_o;
                var o = (__Matrix4x4)so;

                object sa = (size_t)pa;
                var a = (__Matrix4x4)sa;

                object sb = (size_t)pb;
                var b = (__Matrix4x4)sb;

                o.M[0, 0] = a.M[0, 0] * b.M[0, 0] + a.M[0, 1] * b.M[1, 0] + a.M[0, 2] * b.M[2, 0] + a.M[0, 3] * b.M[3, 0];
                o.M[1, 0] = a.M[1, 0] * b.M[0, 0] + a.M[1, 1] * b.M[1, 0] + a.M[1, 2] * b.M[2, 0] + a.M[1, 3] * b.M[3, 0];
                o.M[2, 0] = a.M[2, 0] * b.M[0, 0] + a.M[2, 1] * b.M[1, 0] + a.M[2, 2] * b.M[2, 0] + a.M[2, 3] * b.M[3, 0];
                o.M[3, 0] = a.M[3, 0] * b.M[0, 0] + a.M[3, 1] * b.M[1, 0] + a.M[3, 2] * b.M[2, 0] + a.M[3, 3] * b.M[3, 0];

                o.M[0, 1] = a.M[0, 0] * b.M[0, 1] + a.M[0, 1] * b.M[1, 1] + a.M[0, 2] * b.M[2, 1] + a.M[0, 3] * b.M[3, 1];
                o.M[1, 1] = a.M[1, 0] * b.M[0, 1] + a.M[1, 1] * b.M[1, 1] + a.M[1, 2] * b.M[2, 1] + a.M[1, 3] * b.M[3, 1];
                o.M[2, 1] = a.M[2, 0] * b.M[0, 1] + a.M[2, 1] * b.M[1, 1] + a.M[2, 2] * b.M[2, 1] + a.M[2, 3] * b.M[3, 1];
                o.M[3, 1] = a.M[3, 0] * b.M[0, 1] + a.M[3, 1] * b.M[1, 1] + a.M[3, 2] * b.M[2, 1] + a.M[3, 3] * b.M[3, 1];

                o.M[0, 2] = a.M[0, 0] * b.M[0, 2] + a.M[0, 1] * b.M[1, 2] + a.M[0, 2] * b.M[2, 2] + a.M[0, 3] * b.M[3, 2];
                o.M[1, 2] = a.M[1, 0] * b.M[0, 2] + a.M[1, 1] * b.M[1, 2] + a.M[1, 2] * b.M[2, 2] + a.M[1, 3] * b.M[3, 2];
                o.M[2, 2] = a.M[2, 0] * b.M[0, 2] + a.M[2, 1] * b.M[1, 2] + a.M[2, 2] * b.M[2, 2] + a.M[2, 3] * b.M[3, 2];
                o.M[3, 2] = a.M[3, 0] * b.M[0, 2] + a.M[3, 1] * b.M[1, 2] + a.M[3, 2] * b.M[2, 2] + a.M[3, 3] * b.M[3, 2];

                o.M[0, 3] = a.M[0, 0] * b.M[0, 3] + a.M[0, 1] * b.M[1, 3] + a.M[0, 2] * b.M[2, 3] + a.M[0, 3] * b.M[3, 3];
                o.M[1, 3] = a.M[1, 0] * b.M[0, 3] + a.M[1, 1] * b.M[1, 3] + a.M[1, 2] * b.M[2, 3] + a.M[1, 3] * b.M[3, 3];
                o.M[2, 3] = a.M[2, 0] * b.M[0, 3] + a.M[2, 1] * b.M[1, 3] + a.M[2, 2] * b.M[2, 3] + a.M[2, 3] * b.M[3, 3];
                o.M[3, 3] = a.M[3, 0] * b.M[0, 3] + a.M[3, 1] * b.M[1, 3] + a.M[3, 2] * b.M[2, 3] + a.M[3, 3] * b.M[3, 3];
            }

            return _o;
        }
Exemple #23
0
 public static ovrMatrix4f ovrMatrix4f_TanAngleMatrixFromProjection(ref ovrMatrix4f projection)
 {
     throw null;
 }
Exemple #24
0
 public static ovrMatrix4f ovrMatrix4f_Transpose(ref ovrMatrix4f a)
 {
     throw null;
 }
 // transactional memory/historic undo button
 public void Push(ovrMatrix4f value)
 {
     Push(this, ref value);
 }
        //public static ovrMatrix4f TanAngleMatrixFromProjection(__ovrMatrix4f projection)
        public static ovrMatrix4f TanAngleMatrixFromProjection(ovrMatrix4f __projection)
        {
            ConsoleExtensions.trace("enter TanAngleMatrixFromProjection");

            __Matrix4x4 projection = &__projection;

            // A projection matrix goes from a view point to NDC, or -1 to 1 space.
            // Scale and bias to convert that to a 0 to 1 space.
            //const ovrMatrix4f tanAngleMatrix =
            //float[,] tanAngleMatrix =
            //{ 
            //    { 0.5f * projection.M[0,0], 0.5f * projection.M[0,1], 0.5f * projection.M[0,2] - 0.5f, 0.5f * projection.M[0,3] },
            //    { 0.5f * projection.M[1,0], 0.5f * projection.M[1,1], 0.5f * projection.M[1,2] - 0.5f, 0.5f * projection.M[1,3] },
            //    {0.0f, 0.0f, -1.0f, 0.0f},
            //    {0.0f, 0.0f, -1.0f, 0.0f }
            //};

            float[] tanAngleMatrix =
	        { 
                 0.5f * projection.M[0,0], 0.5f * projection.M[0,1], 0.5f * projection.M[0,2] - 0.5f, 0.5f * projection.M[0,3] ,
		         0.5f * projection.M[1,0], 0.5f * projection.M[1,1], 0.5f * projection.M[1,2] - 0.5f, 0.5f * projection.M[1,3] ,
		        0.0f, 0.0f, -1.0f, 0.0f ,
		        0.0f, 0.0f, -1.0f, 0.0f 
	        };

            ovrMatrix4f that_data;
            __Matrix4x4 that = &that_data;

            //that_data.M = tanAngleMatrix;
            //that_data.M[0] = tanAngleMatrix[0];
            //for (int i = 0; i < 16; i++)
            //{
            //    // this will cause stack corruption. why?
            //    that.M[i, i] = tanAngleMatrix[i];
            //}

            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                {
                    //that.M[x, y] = tanAngleMatrix[x, y];
                    //that.M[x, y] = tanAngleMatrix[x + 4 * y];

                    // memorylayout the same as for CLR?
                    that.M[x, y] = tanAngleMatrix[y + 4 * x];
                }

            //jni/OVRWindWheelNDK.dll.c:2651:28: error: expected expression before '?' token
            //     singleArray7 = calloc [?][?];
            //                            ^

            ConsoleExtensions.trace("exit TanAngleMatrixFromProjection, stack still valid?");
            return that_data;
        }
            // vrapi_GetHmdInfo
            // called by AppThreadFunction
            public void ovrRenderer_Create(ref ovrHmdInfo hmdInfo)
            {
                ConsoleExtensions.trace("enter ovrRenderer_Create");

                fixed (int* hmdInfo_SuggestedEyeResolution = hmdInfo.SuggestedEyeResolution)
                fixed (float* hmdInfo_SuggestedEyeFov = hmdInfo.SuggestedEyeFov)
                {
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:89 hmdInfo_SuggestedEyeResolution width  1024
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:90 hmdInfo_SuggestedEyeResolution height  1024
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:91 NUM_MULTI_SAMPLES  4
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:95 hmdInfo_SuggestedEyeFov[0]  90
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:96 hmdInfo_SuggestedEyeFov[1]  90
                    //I/xNativeActivity(26905): \VrCubeWorld.Renderer.cs:97 DisplayRefreshRate  60


                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeResolution width ", hmdInfo_SuggestedEyeResolution[0]);
                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeResolution height ", hmdInfo_SuggestedEyeResolution[1]);
                    ConsoleExtensions.tracei("NUM_MULTI_SAMPLES ", NUM_MULTI_SAMPLES);


                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeFov[0] ", (int)hmdInfo_SuggestedEyeFov[0]);
                    ConsoleExtensions.tracei("hmdInfo_SuggestedEyeFov[1] ", (int)hmdInfo_SuggestedEyeFov[1]);
                    ConsoleExtensions.tracei("DisplayRefreshRate ", (int)hmdInfo.DisplayRefreshRate);


                    // 1012
                    // Create the render Textures.
                    for (int i = 0; i < NUM_BUFFERS; i++)
                        for (int eye = 0; eye < NUM_EYES; eye++)
                        {
                            //ConsoleExtensions.tracei("call ovrRenderTexture_Create i ", i);

                            this.RenderTextures[i, eye].ovrRenderTexture_Create(
                                hmdInfo_SuggestedEyeResolution[0],
                                hmdInfo_SuggestedEyeResolution[1],
                                NUM_MULTI_SAMPLES,

                                i, eye
                            );
                        }

                    this.BufferIndex = 0;

                    // https://www.kickstarter.com/projects/wearality/wearality-sky-limitless-vr

                    // Setup the projection matrix.
                    this.ProjectionMatrix = VrApi_Helpers.ovrMatrix4f_CreateProjectionFov(
                                                        hmdInfo_SuggestedEyeFov[0] * ((float)Math.PI / 180.0f),
                                                        hmdInfo_SuggestedEyeFov[1] * ((float)Math.PI / 180.0f),
                                                        0.0f, 0.0f, 1.0f, 0.0f);

                    this.TanAngleMatrix = VrApi_Helpers.ovrMatrix4f_TanAngleMatrixFromProjection(ref this.ProjectionMatrix);
                }

                //ConsoleExtensions.trace("exit ovrRenderer_Create");
            }
Exemple #28
0
 public static ovrMatrix4f ovrMatrix4f_TanAngleMatrixFromProjection(ref  ovrMatrix4f projection)
 {
     throw null;
 }
        public static ovrMatrix4f Multiply(ovrMatrix4f _a, ovrMatrix4f _b)
        {
            // perhaps the compiler could decide to optimize and move to a byref pointer version?


            // memory dereference magic
            // yet, in glsl we wont have pointers, all we will have is copy struct?
            // http://www.gamedev.net/topic/347232-glsl-pointers/

            // Error	3	A pointer must be indexed by only one value	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	93	98	OVRWindWheelNDK
            //Error	5	The type of a local declared in a fixed statement must be a pointer type	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	92	20	OVRWindWheelNDK

            ovrMatrix4f _o;
            __Matrix4x4 o = &_o;
            __Matrix4x4 a = &_a;
            __Matrix4x4 b = &_b;

            {
                o.M[0, 0] = a.M[0, 0] * b.M[0, 0] + a.M[0, 1] * b.M[1, 0] + a.M[0, 2] * b.M[2, 0] + a.M[0, 3] * b.M[3, 0];
                o.M[1, 0] = a.M[1, 0] * b.M[0, 0] + a.M[1, 1] * b.M[1, 0] + a.M[1, 2] * b.M[2, 0] + a.M[1, 3] * b.M[3, 0];
                o.M[2, 0] = a.M[2, 0] * b.M[0, 0] + a.M[2, 1] * b.M[1, 0] + a.M[2, 2] * b.M[2, 0] + a.M[2, 3] * b.M[3, 0];
                o.M[3, 0] = a.M[3, 0] * b.M[0, 0] + a.M[3, 1] * b.M[1, 0] + a.M[3, 2] * b.M[2, 0] + a.M[3, 3] * b.M[3, 0];

                o.M[0, 1] = a.M[0, 0] * b.M[0, 1] + a.M[0, 1] * b.M[1, 1] + a.M[0, 2] * b.M[2, 1] + a.M[0, 3] * b.M[3, 1];
                o.M[1, 1] = a.M[1, 0] * b.M[0, 1] + a.M[1, 1] * b.M[1, 1] + a.M[1, 2] * b.M[2, 1] + a.M[1, 3] * b.M[3, 1];
                o.M[2, 1] = a.M[2, 0] * b.M[0, 1] + a.M[2, 1] * b.M[1, 1] + a.M[2, 2] * b.M[2, 1] + a.M[2, 3] * b.M[3, 1];
                o.M[3, 1] = a.M[3, 0] * b.M[0, 1] + a.M[3, 1] * b.M[1, 1] + a.M[3, 2] * b.M[2, 1] + a.M[3, 3] * b.M[3, 1];

                o.M[0, 2] = a.M[0, 0] * b.M[0, 2] + a.M[0, 1] * b.M[1, 2] + a.M[0, 2] * b.M[2, 2] + a.M[0, 3] * b.M[3, 2];
                o.M[1, 2] = a.M[1, 0] * b.M[0, 2] + a.M[1, 1] * b.M[1, 2] + a.M[1, 2] * b.M[2, 2] + a.M[1, 3] * b.M[3, 2];
                o.M[2, 2] = a.M[2, 0] * b.M[0, 2] + a.M[2, 1] * b.M[1, 2] + a.M[2, 2] * b.M[2, 2] + a.M[2, 3] * b.M[3, 2];
                o.M[3, 2] = a.M[3, 0] * b.M[0, 2] + a.M[3, 1] * b.M[1, 2] + a.M[3, 2] * b.M[2, 2] + a.M[3, 3] * b.M[3, 2];

                o.M[0, 3] = a.M[0, 0] * b.M[0, 3] + a.M[0, 1] * b.M[1, 3] + a.M[0, 2] * b.M[2, 3] + a.M[0, 3] * b.M[3, 3];
                o.M[1, 3] = a.M[1, 0] * b.M[0, 3] + a.M[1, 1] * b.M[1, 3] + a.M[1, 2] * b.M[2, 3] + a.M[1, 3] * b.M[3, 3];
                o.M[2, 3] = a.M[2, 0] * b.M[0, 3] + a.M[2, 1] * b.M[1, 3] + a.M[2, 2] * b.M[2, 3] + a.M[2, 3] * b.M[3, 3];
                o.M[3, 3] = a.M[3, 0] * b.M[0, 3] + a.M[3, 1] * b.M[1, 3] + a.M[3, 2] * b.M[2, 3] + a.M[3, 3] * b.M[3, 3];

                // operating on fixed buffers, yet we want the dimensional array magic.
            }

            return _o;
        }
Exemple #30
0
 public static ovrMatrix4f ovrMatrix4f_Transpose(ref ovrMatrix4f a)
 {
     throw null;
 }
        public static ovrMatrix4f CreateRotation(float radiansX, float radiansY, float radiansZ)
        {
            // X:\jsc.svn\examples\c\Test\TestStackFloatArray\TestStackFloatArray\Class1.cs

            // http://stackoverflow.com/questions/9087563/maximum-native-memory-that-can-be-allocated-to-an-android-app

            // Error	3	Cannot initialize object of type 'float*' with a collection initializer	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	248	17	OVRWindWheelNDK

            // I/DEBUG   ( 9747): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8

            float sinX = math.sinf(radiansX);
            float cosX = math.cosf(radiansX);

            // Error	3	Cannot take the address of, get the size of, or declare a pointer to a managed type ('float[*,*]')	X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\OVRWindWheelNDK\References\VrApi.ovrMatrix4f.cs	292	61	OVRWindWheelNDK

            // we will leak a lot of heap...
            // not the heap. the stack thankyou. almost playing GC?
            // since we are not returning this array, it should live on stack. this way we wont leak memory as we are running without GC..
            //float[] rotationX = stackalloc float[16];
            //float[] rotationXx = new float[16];

            //// I/xNativeActivity( 7804): \VrApi.ovrMatrix4f.cs:338 out of heap? errno: 12 Out of memory
            //if (rotationXx == null)
            //{
            //    // https://android.googlesource.com/platform/development/+/c817c5210e4207908b83faaf08a2c5b95251f871/ndk/platforms/android-5/arch-x86/usr/include/malloc.h

            //    ConsoleExtensions.trace("out of heap?");

            //    //I/System.Console(19158): 4ad6:480b enter GetAllNetworkInterfaces
            //    //I/xNativeActivity(18481): \VrApi.ovrMatrix4f.cs:343 out of heap? errno: 12 Out of memory
            //    //I/xNativeActivity(18481): \VrCubeWorld.AppThread.cs:71 mallinfo  total allocated space:  -2083023504
            //    //I/xNativeActivity(18481): \VrCubeWorld.AppThread.cs:72 mallinfo  total free  space:  76049040

            //    //malloc_h.malloc_stats();

            //    VrCubeWorld.ovrAppThread.xmallinfo();

            //    unistd._exit(43);
            //}


            //stdlib_h.free(rotationXx);


            float[] rotationX =
            {
                1,    0,     0, 0,
                0, cosX, -sinX, 0,
                0, sinX, cosX,  0,
                0,    0,     0, 1
            };

            float sinY = math.sinf(radiansY);
            float cosY = math.cosf(radiansY);

            float[] rotationY =
            {
                cosY,  0, sinY, 0,
                0,     1,    0, 0,
                -sinY, 0, cosY, 0,
                0,     0,    0, 1
            };


            float sinZ = math.sinf(radiansZ);
            float cosZ = math.cosf(radiansZ);

            float[] rotationZ =
            {
                cosZ, -sinZ, 0, 0,
                sinZ, cosZ,  0, 0,
                0,        0, 1, 0,
                0,        0, 0, 1
            };



            __Matrix4x4 x = rotationX;
            __Matrix4x4 y = rotationY;
            __Matrix4x4 z = rotationZ;

            //ovrMatrix4f o;

            ovrMatrix4f rotationXY  = __Matrix4x4.Multiply(y, x);
            ovrMatrix4f rotationXYZ = __Matrix4x4.Multiply(z, &rotationXY);

            // copy it back..
            return(rotationXYZ);
        }
Exemple #32
0
 public static ovrMatrix4f ovrMatrix4f_Multiply(ref ovrMatrix4f a, ref ovrMatrix4f b)
 {
     throw null;
 }