Exemplo n.º 1
0
 public Skybox()
 {
     _geometry = new CubeGeometry();
     _world    = Matrix.Identity;
     _skyboxRasterizerState          = new RasterizerState();
     _skyboxRasterizerState.CullMode = CullMode.None;
 }
Exemplo n.º 2
0
        public void init()
        {
            renderer = new OpenGLRenderer();

            renderer.setSize(width, height);

            camera            = new PerspectiveCamera((float)(System.Math.PI / 180.0f) * 70.0f, width / (float)height, 1.0f, 100.0f);
            camera.position.Z = 400.0f;

            scene = new Scene();

            CubeGeometry geometry = new CubeGeometry(200, 200, 200);


            Texture texture = (new ImageUtils()).loadTexture("textures/crate.gif");

            texture.anisotropy = renderer.getMaxAnisotropy();


            MeshBasicMaterial material = new MeshBasicMaterial(texture);

            mesh = new Mesh(geometry, material);
            scene.add(mesh);

            renderer.render(scene, camera);
        }
Exemplo n.º 3
0
        protected override void OnInitGLProgram(object sender, EventArgs args)
        {
            string vs = @"
                uniform mat4 u_mvpMatrix;
                attribute vec4 a_position;
                attribute vec2 a_texcoord;
                varying vec2 v_texcoord;
                void main()
                {
                        gl_Position = u_mvpMatrix * a_position;
                        v_texcoord = a_texcoord;
                }
            ";

            string fs = @"
                  precision mediump float;
                  varying vec2 v_texcoord;
                  void main()
                  {
                       gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0);
                  }
            ";


            mProgram = ES2Utils.CompileProgram(vs, fs);
            if (mProgram == 0)
            {
                //return false
                throw new NotSupportedException();
            }


            //GL.Enable(EnableCap.Blend);
            //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // Get the attribute locations

            mPositionLoc = GL.GetAttribLocation(mProgram, "a_position");
            mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texcoord");


            // Get the uniform locations
            mMVPMatrixLoc = GL.GetUniformLocation(mProgram, "u_mvpMatrix");


            cube = new CubeGeometry();
            GeometryUtils.GenerateCubeGeometry(-0.5f, cube);
            mRotation = 45.0f;

            GL.ClearColor(0, 0, 0, 0);
            GL.CullFace(CullFaceMode.Front);
            GL.Enable(EnableCap.CullFace);

            this.EnableAnimationTimer = true;
            isGLInit = true;
        }
Exemplo n.º 4
0
            public ClockwiseSequenceGroup(Side face)
            {
                _face = face;
                _clockwiseAdjacent = CubeGeometry.GetClockwiseAdjacentFaces(face);

                Append4PositionSequence(MakeLeftCorners());
                Append4PositionSequence(MakeRightCorners());
                Append4PositionSequence(MakeFaceCorners());
                Append4PositionSequence(MakeEdges());
                Append4PositionSequence(MakeFaceEdges());
            }
Exemplo n.º 5
0
        private void OnGUI()
        {
            if (GUILayout.Button("Generate CONE"))
            {
                var meshFilter   = this.GetComponent <MeshFilter>();
                var meshRenderer = this.GetComponent <MeshRenderer>();

                Mesh mesh = new Mesh();
                mesh.name = "CONE";

                ConeGeometry cone = new ConeGeometry();
                cone.bottom     = new Vector3(0, 0, 0);
                cone.height     = 1.5f;
                cone.radius     = 1.2f;
                cone.smoothness = 3;
                cone.FillGeometry();

                ConeGeometry cone2 = new ConeGeometry();
                cone2.bottom     = new Vector3(5, 0, 0);
                cone2.height     = 10f;
                cone2.radius     = 3f;
                cone2.smoothness = 3;
                cone2.FillGeometry();
                cone.geometryBuffer.CombineGeometry(cone2.geometryBuffer);

                CubeGeometry cube = new CubeGeometry();
                cube.FillGeometry();
                cone.geometryBuffer.CombineGeometry(cube.geometryBuffer);

                cone.geometryBuffer.FillMesh(mesh, MeshTopology.Triangles);

                meshFilter.mesh       = mesh;
                meshRenderer.material = new Material(Shader.Find("Standard"));
            }

            if (GUILayout.Button("Generate Cylinder"))
            {
                var meshFilter   = this.GetComponent <MeshFilter>();
                var meshRenderer = this.GetComponent <MeshRenderer>();

                Mesh mesh = new Mesh();
                mesh.name = "Cylinder";

                cylinder = this.GetComponent <Cylinder>().cylinder;
                percent  = cylinder.percent;
                cylinder.FillGeometry();
                cylinder.geometryBuffer.FillMesh(mesh, MeshTopology.Triangles);
                mesh.RecalculateNormals();
                mesh.RecalculateTangents();
                meshFilter.mesh       = mesh;
                meshRenderer.material = GameObject.Instantiate <Material>(pie3dMaterial);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Génération des murs de bordure.
        /// </summary>
        private void GenerateBorderWalls()
        {
            Vector3[] sizes = new Vector3[4]
            {
                new Vector3(_level.GetWorldWidth(), _level.BlockSizes.Height, 1),
                new Vector3(_level.GetWorldWidth(), _level.BlockSizes.Height, 1),
                new Vector3(1, _level.BlockSizes.Height, _level.GetWorldDepth()),
                new Vector3(1, _level.BlockSizes.Height, _level.GetWorldDepth())
            };

            Vector3[] positions = new Vector3[4]
            {
                new Vector3(_level.GetWorldWidth(), _level.BlockSizes.Height, 0),
                new Vector3(_level.GetWorldWidth(), _level.BlockSizes.Height, 2 * _level.GetWorldDepth()),
                new Vector3(0, _level.BlockSizes.Height, _level.GetWorldWidth()),
                new Vector3(2 * _level.GetWorldDepth(), _level.BlockSizes.Height, _level.GetWorldWidth())
            };

            Color[] colors = new Color[4]
            {
                Color.Red, Color.Green, Color.Blue, Color.Yellow
            };

            CubeGeometry   cube = null;
            YnMeshGeometry mesh = null;

            for (int i = 0; i < 4; i++)
            {
                cube               = new CubeGeometry(sizes[i]);
                mesh               = new YnMeshGeometry(cube, new BasicMaterial(_level.BorderWallTexture));
                mesh.Position      = positions[i];
                mesh.Name          = "WALL";
                mesh.TextureRepeat = new Vector2(8, 3);
                mesh.LoadContent();
                _groupWalls.Add(mesh);
            }
        }
Exemplo n.º 7
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            IntPtr eglPostSubBufferNVFuncPtr = OpenTK.Platform.Egl.Egl.GetProcAddress("eglPostSubBufferNV");

            if (eglPostSubBufferNVFuncPtr == IntPtr.Zero)
            {
                throw new NotSupportedException();
            }

            mPostSubBufferNV = (PFNEGLPOSTSUBBUFFERNVPROC)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(eglPostSubBufferNVFuncPtr, typeof(PFNEGLPOSTSUBBUFFERNVPROC));
            //   mPostSubBufferNV = (PFNEGLPOSTSUBBUFFERNVPROC)eglGetProcAddress("eglPostSubBufferNV");
            //if (!mPostSubBufferNV)
            //{
            //    std::cerr << "Could not load eglPostSubBufferNV.";
            //    return false;
            //}
            string vs = @"
                 uniform mat4 u_mvpMatrix;
                 attribute vec4 a_position;
                 attribute vec2 a_texcoord;
                 varying vec2 v_texcoord;
                 void main()
                 {
                        gl_Position = u_mvpMatrix * a_position;
                        v_texcoord = a_texcoord;
                 }
            ";
            string fs = @"
                precision mediump float;
                varying vec2 v_texcoord;
                void main()
                {
                      gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0);
                }
            ";

            //mProgram = CompileProgram(vs, fs);
            //if (!mProgram)
            //{
            //    return false;
            //}
            mProgram = EsUtils.CompileProgram(vs, fs);
            if (mProgram == 0)
            {
                throw new NotSupportedException();
            }
            //// Get the attribute locations
            //mPositionLoc = glGetAttribLocation(mProgram, "a_position");
            mPositionLoc = GL.GetAttribLocation(mProgram, "a_position");
            //mTexcoordLoc = glGetAttribLocation(mProgram, "a_texcoord");
            mTexcoordLoc = GL.GetAttribLocation(mProgram, "a_texcoord");
            //// Get the uniform locations
            //mMVPMatrixLoc = glGetUniformLocation(mProgram, "u_mvpMatrix");
            mMVPMatrixLoc = GL.GetUniformLocation(mProgram, "u_mvpMatrix");
            //// Generate the geometry data
            //GenerateCubeGeometry(0.5f, &mCube);
            mCube = new CubeGeometry();
            GeometryUtils.GenerateCubeGeometry(0.5f, mCube);
            //// Set an initial rotation
            //mRotation = 45.0f;
            mRotation = 45.0f;
            //// Clear the whole window surface to blue.
            //glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
            GL.ClearColor(0, 0, 1, 0);
            //glClear(GL_COLOR_BUFFER_BIT);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            //SampleApplication::swap();

            //this.miniGLControl.SwapBuffers();

            //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.ClearColor(0, 0, 0, 0);
            //glCullFace(GL_BACK);
            GL.CullFace(CullFaceMode.Back);
            //glEnable(GL_CULL_FACE);
            GL.Enable(EnableCap.CullFace);
            //return true;
            isGLInit = true;
            this.EnableAnimationTimer = true;
        }