// called by AppThreadFunction
            // called after VRAPI_FRAME_INIT_LOADING_ICON_FLUSH
            public void ovrScene_Create()
            {
                // 864
                ConsoleExtensions.trace("enter ovrScene_Create, invoke ovrProgram_Create, ovrGeometry_CreateCube");


                var vert = new Shaders.VrCubeWorldVertexShader();
                var frag = new Shaders.VrCubeWorldFragmentShader();

                this.Program.ovrProgram_Create(
                    // jsc should keep typeinfo/virtal function pointer table tagged on objects?
                    vert.ToString(),
                    frag.ToString()
                    );

                this.Cube.ovrGeometry_CreateCube();

                // Create the instance transform attribute buffer.
                gl3.glGenBuffers(1, out this.InstanceTransformBuffer0);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, this.InstanceTransformBuffer0);
                gl3.glBufferData(gl3.GL_ARRAY_BUFFER, NUM_INSTANCES * 4 * 4 * sizeof(float), null, gl3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, 0);

                gl3.glGenBuffers(1, out this.InstanceTransformBuffer1);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, this.InstanceTransformBuffer1);
                gl3.glBufferData(gl3.GL_ARRAY_BUFFER, NUM_INSTANCES1 * 4 * 4 * sizeof(float), null, gl3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, 0);


                #region init data
                // Setup random cube positions and rotations.
                for (int i = 0; i < NUM_INSTANCES; i++)
                {
                    // Using volatile keeps the compiler from optimizing away multiple calls to drand48().
                    //volatile float rx; ry, rz;
                    float rx = 0, ry = 0, rz = 0;


                    rx = 2.0f * (((i / floors) / floorwidth) - floors);

                    rz = 2.0f * (((i / floors) % floorwidth) - floors);


                    ry = (i % floors - 1.0f) * 0.6f;

                    //// can we offset the thing?
                    //rx = (float)(stdlib_h.drand48() - 0.5f) * (5.0f + (float)Math.Sqrt(NUM_INSTANCES));

                    //// ah its only done once?
                    ////rx += com.oculus.gles3jni.GLES3JNILib.fields_xvalue;
                    //ry = (float)(stdlib_h.drand48() - 0.5f) * (5.0f + (float)Math.Sqrt(NUM_INSTANCES));

                    //// cool now we have a set of cubes in front of us.
                    ////rz = (float)(stdlib_h.drand48() - 1.5f) * (15.0f + (float)Math.Sqrt(NUM_INSTANCES));
                    //rz = (float)(stdlib_h.drand48() - 1.5f) * (10.0f + (float)Math.Sqrt(NUM_INSTANCES));

                    //rz = (float)(stdlib_h.drand48() - 0.5f) * (15.0f + (float)Math.Sqrt(NUM_INSTANCES));
                    // how do we record our changes?
                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150629/mod



                    // keep the original around
                    this.CubePositions0[i].x = rx;
                    this.CubePositions0[i].y = ry;
                    this.CubePositions0[i].z = rz;

                    // for the offset
                    this.CubePositions[i].x = rx;
                    this.CubePositions[i].y = ry;
                    this.CubePositions[i].z = rz;

                    //ConsoleExtensions.tracei("ovrScene_Create CubePositions i: ", insert);

                    //this.CubeRotations[i].x = (float)stdlib_h.drand48();
                    //this.CubeRotations[i].y = (float)stdlib_h.drand48();
                    //this.CubeRotations[i].z = (float)stdlib_h.drand48();
                }
                #endregion


                this.CreatedScene = true;

                this.ovrScene_CreateVAOs();


                // elapsed?
                ConsoleExtensions.tracei("exit ovrScene_Create NUM_INSTANCES: ", NUM_INSTANCES);
            }
            // called by AppThreadFunction
            // called after VRAPI_FRAME_INIT_LOADING_ICON_FLUSH
            public void ovrScene_Create()
            {
                // 864
                ConsoleExtensions.trace("enter ovrScene_Create, invoke ovrProgram_Create, ovrGeometry_CreateCube");


                var vert = new Shaders.VrCubeWorldVertexShader();
                var frag = new Shaders.VrCubeWorldFragmentShader();

                this.Program.ovrProgram_Create(
                    vert.ToString(),
                    frag.ToString()
                );

                this.Cube.ovrGeometry_CreateCube();

                // Create the instance transform attribute buffer.
                gl3.glGenBuffers(1, out this.InstanceTransformBuffer);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, this.InstanceTransformBuffer);
                gl3.glBufferData(gl3.GL_ARRAY_BUFFER, NUM_INSTANCES * 4 * 4 * sizeof(float), null, gl3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, 0);

                // Setup random cube positions and rotations.
                for (int i = 0; i < NUM_INSTANCES; i++)
                {
                    // Using volatile keeps the compiler from optimizing away multiple calls to drand48().
                    //volatile float rx; ry, rz;
                    float rx = 0, ry = 0, rz = 0;


                    rx = 2.0f * (((i / floors) / 8) - floors);

                    rz = 2.0f * (((i / floors) % 8) - floors);


                    ry = (i % floors - 1.0f) * 0.6f;

                    //// can we offset the thing?
                    //rx = (float)(stdlib_h.drand48() - 0.5f) * (5.0f + (float)Math.Sqrt(NUM_INSTANCES));

                    //// ah its only done once?
                    ////rx += com.oculus.gles3jni.GLES3JNILib.fields_xvalue;
                    //ry = (float)(stdlib_h.drand48() - 0.5f) * (5.0f + (float)Math.Sqrt(NUM_INSTANCES));

                    //// cool now we have a set of cubes in front of us.
                    ////rz = (float)(stdlib_h.drand48() - 1.5f) * (15.0f + (float)Math.Sqrt(NUM_INSTANCES));
                    //rz = (float)(stdlib_h.drand48() - 1.5f) * (10.0f + (float)Math.Sqrt(NUM_INSTANCES));

                    //rz = (float)(stdlib_h.drand48() - 0.5f) * (15.0f + (float)Math.Sqrt(NUM_INSTANCES));
                    // how do we record our changes?
                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150629/mod




                    // keep the original around
                    this.CubePositions0[i].x = rx;
                    this.CubePositions0[i].y = ry;
                    this.CubePositions0[i].z = rz;

                    // for the offset
                    this.CubePositions[i].x = rx;
                    this.CubePositions[i].y = ry;
                    this.CubePositions[i].z = rz;

                    //ConsoleExtensions.tracei("ovrScene_Create CubePositions i: ", insert);

                    //this.CubeRotations[i].x = (float)stdlib_h.drand48();
                    //this.CubeRotations[i].y = (float)stdlib_h.drand48();
                    //this.CubeRotations[i].z = (float)stdlib_h.drand48();
                }


                this.CreatedScene = true;

                this.ovrScene_CreateVAOs();


                // elapsed?
                ConsoleExtensions.tracei("exit ovrScene_Create NUM_INSTANCES: ", NUM_INSTANCES);
            }
            // called by AppThreadFunction
            // called after VRAPI_FRAME_INIT_LOADING_ICON_FLUSH
            public void ovrScene_Create()
            {
                // 864
                ConsoleExtensions.trace("enter ovrScene_Create, invoke ovrProgram_Create, ovrGeometry_CreateCube");


                var vert = new Shaders.VrCubeWorldVertexShader();
                var frag = new Shaders.VrCubeWorldFragmentShader();

                this.Program.ovrProgram_Create(
                    vert.ToString(),
                    frag.ToString()
                );

                this.Cube.ovrGeometry_CreateCube();

                // Create the instance transform attribute buffer.
                gl3.glGenBuffers(1, out this.InstanceTransformBuffer);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, this.InstanceTransformBuffer);
                gl3.glBufferData(gl3.GL_ARRAY_BUFFER, NUM_INSTANCES * 4 * 4 * sizeof(float), null, gl3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, 0);

                // Setup random cube positions and rotations.
                for (int i = 0; i < NUM_INSTANCES; i++)
                {
                    // Using volatile keeps the compiler from optimizing away multiple calls to drand48().
                    //volatile float rx; ry, rz;
                    float rx = 0, ry = 0, rz = 0;

                    //for (; ; )

                    var notfound = true;
                    while (notfound)
                    {
                        rx = (float)(stdlib_h.drand48() - 0.5f) * (50.0f + (float)Math.Sqrt(NUM_INSTANCES));
                        ry = (float)(stdlib_h.drand48() - 0.5f) * (50.0f + (float)Math.Sqrt(NUM_INSTANCES));
                        rz = (float)(stdlib_h.drand48() - 0.5f) * (1500.0f + (float)Math.Sqrt(NUM_INSTANCES));


                        // If too close to 0,0,0
                        var too_closex = Math.Abs(rx) < 4.0f;
                        var too_closey = Math.Abs(ry) < 4.0f;
                        var too_closez = Math.Abs(rz) < 4.0f;

                        if (too_closex)
                            if (too_closey)
                                if (too_closez)
                                {
                                    continue;
                                }

                        // Test for overlap with any of the existing cubes.
                        bool overlap = false;
                        for (int j = 0; j < i; j++)
                        {
                            if (Math.Abs(rx - this.CubePositions[j].x) < 4.0f)
                                if (Math.Abs(ry - this.CubePositions[j].y) < 4.0f)
                                    if (Math.Abs(rz - this.CubePositions[j].z) < 4.0f)
                                    {
                                        overlap = true;
                                        break;
                                    }
                        }
                        if (!overlap)
                        {
                            //break;
                            notfound = false;
                        }
                    }

                    // Insert into list sorted based on distance.
                    int insert = 0;
                    float distSqr = rx * rx + ry * ry + rz * rz;
                    for (int j = i; j > 0; j--)
                    {
                        var otherDistSqr = default(float);

                        // fixed/break does a try/finally to zero out the pointer
                        fixed (ovrVector3f* otherPos = &this.CubePositions[j - 1])
                            otherDistSqr = otherPos->x * otherPos->x + otherPos->y * otherPos->y + otherPos->z * otherPos->z;

                        if (distSqr > otherDistSqr)
                        {
                            insert = j;
                            break;
                        }


                        this.CubePositions[j] = this.CubePositions[j - 1];
                        this.CubeRotations[j] = this.CubeRotations[j - 1];
                    }

                    this.CubePositions[insert].x = rx;
                    this.CubePositions[insert].y = ry;
                    this.CubePositions[insert].z = rz;

                    //ConsoleExtensions.tracei("ovrScene_Create CubePositions i: ", insert);

                    this.CubeRotations[insert].x = (float)stdlib_h.drand48();
                    this.CubeRotations[insert].y = (float)stdlib_h.drand48();
                    this.CubeRotations[insert].z = (float)stdlib_h.drand48();
                }


                this.CreatedScene = true;

                this.ovrScene_CreateVAOs();


                // elapsed?
                ConsoleExtensions.tracei("exit ovrScene_Create NUM_INSTANCES: ", NUM_INSTANCES);
            }
Beispiel #4
0
            // called by AppThreadFunction
            // called after VRAPI_FRAME_INIT_LOADING_ICON_FLUSH
            public void ovrScene_Create()
            {
                // 864
                ConsoleExtensions.trace("enter ovrScene_Create, invoke ovrProgram_Create, ovrGeometry_CreateCube");


                var vert = new Shaders.VrCubeWorldVertexShader();
                var frag = new Shaders.VrCubeWorldFragmentShader();

                this.Program.ovrProgram_Create(
                    vert.ToString(),
                    frag.ToString()
                    );

                this.Cube.ovrGeometry_CreateCube();

                // Create the instance transform attribute buffer.
                gl3.glGenBuffers(1, out this.InstanceTransformBuffer);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, this.InstanceTransformBuffer);
                gl3.glBufferData(gl3.GL_ARRAY_BUFFER, NUM_INSTANCES * 4 * 4 * sizeof(float), null, gl3.GL_DYNAMIC_DRAW);
                gl3.glBindBuffer(gl3.GL_ARRAY_BUFFER, 0);

                // Setup random cube positions and rotations.
                for (int i = 0; i < NUM_INSTANCES; i++)
                {
                    // Using volatile keeps the compiler from optimizing away multiple calls to drand48().
                    //volatile float rx; ry, rz;
                    float rx = 0, ry = 0, rz = 0;

                    //for (; ; )

                    var notfound = true;
                    while (notfound)
                    {
                        rx = (float)(stdlib_h.drand48() - 0.5f) * (50.0f + (float)Math.Sqrt(NUM_INSTANCES));
                        ry = (float)(stdlib_h.drand48() - 0.5f) * (50.0f + (float)Math.Sqrt(NUM_INSTANCES));
                        rz = (float)(stdlib_h.drand48() - 0.5f) * (1500.0f + (float)Math.Sqrt(NUM_INSTANCES));


                        // If too close to 0,0,0
                        var too_closex = Math.Abs(rx) < 4.0f;
                        var too_closey = Math.Abs(ry) < 4.0f;
                        var too_closez = Math.Abs(rz) < 4.0f;

                        if (too_closex)
                        {
                            if (too_closey)
                            {
                                if (too_closez)
                                {
                                    continue;
                                }
                            }
                        }

                        // Test for overlap with any of the existing cubes.
                        bool overlap = false;
                        for (int j = 0; j < i; j++)
                        {
                            if (Math.Abs(rx - this.CubePositions[j].x) < 4.0f)
                            {
                                if (Math.Abs(ry - this.CubePositions[j].y) < 4.0f)
                                {
                                    if (Math.Abs(rz - this.CubePositions[j].z) < 4.0f)
                                    {
                                        overlap = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!overlap)
                        {
                            //break;
                            notfound = false;
                        }
                    }

                    // Insert into list sorted based on distance.
                    int   insert  = 0;
                    float distSqr = rx * rx + ry * ry + rz * rz;
                    for (int j = i; j > 0; j--)
                    {
                        var otherDistSqr = default(float);

                        // fixed/break does a try/finally to zero out the pointer
                        fixed(ovrVector3f *otherPos = &this.CubePositions[j - 1])
                        otherDistSqr = otherPos->x * otherPos->x + otherPos->y * otherPos->y + otherPos->z * otherPos->z;

                        if (distSqr > otherDistSqr)
                        {
                            insert = j;
                            break;
                        }


                        this.CubePositions[j] = this.CubePositions[j - 1];
                        this.CubeRotations[j] = this.CubeRotations[j - 1];
                    }

                    this.CubePositions[insert].x = rx;
                    this.CubePositions[insert].y = ry;
                    this.CubePositions[insert].z = rz;

                    //ConsoleExtensions.tracei("ovrScene_Create CubePositions i: ", insert);

                    this.CubeRotations[insert].x = (float)stdlib_h.drand48();
                    this.CubeRotations[insert].y = (float)stdlib_h.drand48();
                    this.CubeRotations[insert].z = (float)stdlib_h.drand48();
                }


                this.CreatedScene = true;

                this.ovrScene_CreateVAOs();


                // elapsed?
                ConsoleExtensions.tracei("exit ovrScene_Create NUM_INSTANCES: ", NUM_INSTANCES);
            }