Esempio n. 1
0
        public void Initialize()
        {
            health    = 1.0f;
            dead      = false;
            speed     = 0.5f;
            mPosition = new vec3(0, 0, 0);
            float scale_value = 0.05f;
            vec3  scale_vec   = new vec3(scale_value);

            model.rotationMatrix    = glm.rotate((float)((-1.0f) * Math.PI), new vec3(0, 1, 1));
            model.scaleMatrix       = glm.scale(new mat4(1), scale_vec);
            model.TranslationMatrix = glm.translate(new mat4(1), mPosition);
            camera = new Camera();
            camera.Reset(mPosition.x, mPosition.y + 2.25f, mPosition.z, 0, 0, 0, 0, 1, 0);
            fireRate = 0.25f;
            nextFire = 0.0f;
            now      = DateTime.Now;
            //model.AnimationSpeed = 0.001f;
            //model.StartAnimation(animType_LOL.STAND);

            collider = new AABoundingBox(model.GetCurrentVertices(model.animSt), ColliderType.Player);
            collider.Scale(scale_vec);
            collider.SetCenter(mPosition);

            healthBar = new HealthBar(mPosition, health, HealthType.Player);
        }
        public void Initialize()
        {
            string projectPath = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            Shader3D    = new Shader(projectPath + "\\Shaders\\SimpleVertexShader.vertexshader", projectPath + "\\Shaders\\SimpleFragmentShader.fragmentshader");
            WaterShader = new Shader(projectPath + "\\Shaders\\WaterVertexShader.vertexshader", projectPath + "\\Shaders\\WaterFragmentShader.fragmentshader");

            //SkyBox
            BackTexture   = new Texture(projectPath + "\\Textures\\back.jpg", 3, false);
            BottomTexture = new Texture(projectPath + "\\Textures\\bottom.jpg", 4, false);
            FrontTexture  = new Texture(projectPath + "\\Textures\\front.jpg", 5, false);
            LeftTexture   = new Texture(projectPath + "\\Textures\\left.jpg", 6, false);
            RightTexture  = new Texture(projectPath + "\\Textures\\right.jpg", 7, false);
            TopTexture    = new Texture(projectPath + "\\Textures\\top.jpg", 8, false);

            Gl.glClearColor(0, 0, 0.4f, 1);

            float[] SkyboxVertices =
            {
                // front
                -1, -1,  1, 1, 0, 1, 0, 0,        //0
                -1,  1,  1, 1, 0, 1, 0, 1,        //1
                1,  -1,  1, 1, 0, 1, 1, 0,        //2

                1,  -1,  1, 1, 0, 1, 1, 0,        //3
                1,   1,  1, 1, 0, 1, 1, 1,        //4
                -1,  1,  1, 1, 0, 1, 0, 1,        //5

                // back
                -1,  1, -1, 1, 0, 1, 0, 1,         //6
                -1, -1, -1, 1, 0, 1, 0, 0,         //7
                1,  -1, -1, 1, 0, 1, 1, 0,         //8

                1,  -1, -1, 1, 0, 1, 1, 0,         //9
                -1,  1, -1, 1, 0, 1, 0, 1,         //10
                1,   1, -1, 1, 0, 1, 1, 1,         //11

                // top
                -1,  1,  1, 1, 0, 1, 0, 0,         //12
                1,   1,  1, 1, 0, 1, 1, 0,         //13
                -1,  1, -1, 1, 0, 1, 0, 1,         //14

                1,   1,  1, 1, 0, 1, 1, 0,         //15
                -1,  1, -1, 1, 0, 1, 0, 1,         //16
                1,   1, -1, 1, 0, 1, 1, 1,         //17

                // bottom
                -1, -1,  1, 1, 0, 1, 0, 0,         //18
                1,  -1,  1, 1, 0, 1, 1, 0,         //19
                -1, -1, -1, 1, 0, 1, 0, 1,         //20

                1,  -1,  1, 1, 0, 1, 1, 0,         //21
                -1, -1, -1, 1, 0, 1, 0, 1,         //22
                1,  -1, -1, 1, 0, 1, 1, 1,         //23

                // right
                1,  -1,  1, 1, 0, 1, 0, 0,         //24
                1,   1,  1, 1, 0, 1, 0, 1,         //25
                1,   1, -1, 1, 0, 1, 1, 1,         //26

                1,   1, -1, 1, 0, 1, 1, 1,         //27
                1,  -1,  1, 1, 0, 1, 0, 0,         //28
                1,  -1, -1, 1, 0, 1, 1, 0,         //29

                // left
                -1, -1,  1, 1, 0, 1, 1, 0,       //30
                -1, -1, -1, 1, 0, 1, 0, 0,       //31
                -1,  1, -1, 1, 0, 1, 0, 1,       //32

                -1,  1, -1, 1, 0, 1, 0, 1,       //33
                -1, -1,  1, 1, 0, 1, 1, 0,       //34
                -1,  1,  1, 1, 0, 1, 1, 1,       //35
            };

            //Terrain
            TerrainImage    = (Bitmap)Bitmap.FromFile("heightMap.jpg");
            heights         = new float[TerrainImage.Width, TerrainImage.Height];
            TerrainVertices = new List <float>();
            float h_size = TerrainImage.Height;
            float w_size = TerrainImage.Width;
            Color pixel;
            int   x, y;

            for (x = 0; x < TerrainImage.Width; x++)
            {
                for (y = 0; y < TerrainImage.Height; y++)
                {
                    pixel         = TerrainImage.GetPixel(x, y); //get pixel di btrg3 el height"color" bta3 el pixel
                    heights[x, y] = pixel.R;                     //bakhod el R component, kan momken akhod g,b bs msh fr2a 3shan hya grey scale
                }
            }

            for (int i = 0; i < TerrainImage.Width - 1; i++)                // blef 3la TerrainImage, btl3 el pixel wl neighbours
            {                                                               // kda el list di feha vertices(x,y,z) w uv
                for (int j = 0; j < TerrainImage.Height - 1; j++)
                {
                    TerrainVertices.Add(i);
                    TerrainVertices.Add(heights[i, j] / 4);
                    TerrainVertices.Add(j);
                    TerrainVertices.Add(0);
                    TerrainVertices.Add(1);

                    TerrainVertices.Add(i + 1);
                    TerrainVertices.Add(heights[i + 1, j] / 4);
                    TerrainVertices.Add(j);
                    TerrainVertices.Add(1);
                    TerrainVertices.Add(1);

                    TerrainVertices.Add(i);
                    TerrainVertices.Add(heights[i, j + 1] / 4);
                    TerrainVertices.Add(j);
                    TerrainVertices.Add(0);
                    TerrainVertices.Add(0);

                    TerrainVertices.Add(i + 1);
                    TerrainVertices.Add(heights[i + 1, j + 1] / 4);
                    TerrainVertices.Add(j + 1);
                    TerrainVertices.Add(1);
                    TerrainVertices.Add(0);

                    ////////////////////////////repeted SkyboxVertices 3shan arsm square m7taga six vertices msh 4 bs


                    TerrainVertices.Add(i);
                    TerrainVertices.Add(heights[i, j] / 4);
                    TerrainVertices.Add(j);
                    TerrainVertices.Add(0);
                    TerrainVertices.Add(0);

                    TerrainVertices.Add(i + 1);
                    TerrainVertices.Add(heights[i, j] / 4);
                    TerrainVertices.Add(j);
                    TerrainVertices.Add(1);
                    TerrainVertices.Add(1);
                }
            }

            scaleMatrix = glm.scale(new mat4(1), new vec3(50, 50, 50));

            //grass
            GrassTexture  = new Texture(projectPath + "\\Textures\\grass.jpg", 10, false);
            GrassVertices = new List <float>();
            for (int i = 0; i < TerrainImage.Width - 1; i++)   // blef 3la TerrainImage, btl3 el pixel wl neighbours
            {                                                  // kda el list di feha vertices(x,y,z) w uv
                for (int j = 0; j < TerrainImage.Height - 1; j++)
                {
                    GrassVertices.Add(i);
                    GrassVertices.Add(heights[i, j] / 4);
                    GrassVertices.Add(j);
                    GrassVertices.Add(0);
                    GrassVertices.Add(1);

                    GrassVertices.Add(i + 1);
                    GrassVertices.Add(heights[i + 1, j] / 4);
                    GrassVertices.Add(j);
                    GrassVertices.Add(1);
                    GrassVertices.Add(1);

                    GrassVertices.Add(i);
                    GrassVertices.Add(heights[i, j + 1] / 4);
                    GrassVertices.Add(j);
                    GrassVertices.Add(0);
                    GrassVertices.Add(0);

                    GrassVertices.Add(i + 1);
                    GrassVertices.Add(heights[i + 1, j + 1] / 4);
                    GrassVertices.Add(j + 1);
                    GrassVertices.Add(1);
                    GrassVertices.Add(0);

                    GrassVertices.Add(i);
                    GrassVertices.Add(heights[i, j] / 4);
                    GrassVertices.Add(j);
                    GrassVertices.Add(0);
                    GrassVertices.Add(0);

                    GrassVertices.Add(i + 1);
                    GrassVertices.Add(heights[i, j] / 4);
                    GrassVertices.Add(j);
                    GrassVertices.Add(1);
                    GrassVertices.Add(1);
                    j += 8;
                }
                i += 8;
            }

            //Tree
            tree = new Model3D();
            tree.LoadFile(projectPath + "\\ModelFiles\\static\\tree", 11, "Tree.obj");

            TreeVertices = new List <float>();
            for (int i = 0; i < TerrainImage.Width / 4; i++)
            {
                for (int j = 0; j < TerrainImage.Height / 4; j++)
                {
                    TreeVertices.Add(i);
                    TreeVertices.Add(heights[i, j] / 4);
                    TreeVertices.Add(j);

                    TreeVertices.Add(i + 1);
                    TreeVertices.Add(heights[i + 1, j] / 4);
                    TreeVertices.Add(j);

                    TreeVertices.Add(i);
                    TreeVertices.Add(heights[i, j + 1] / 4);
                    TreeVertices.Add(j);
                }
            }


            //Water
            List <float> WaterVertices = new List <float>();

            for (int i = 0; i < TerrainImage.Width / 4; i++)   // blef 3la TerrainImage, btl3 el pixel wl neighbours
            {                                                  // kda el list di feha vertices(x,y,z) w uv
                for (int j = 0; j < TerrainImage.Height / 4; j++)
                {
                    WaterVertices.Add(i);
                    WaterVertices.Add(heights[i, j] / 4);
                    WaterVertices.Add(j);
                    WaterVertices.Add(0);
                    WaterVertices.Add(1);

                    WaterVertices.Add(i + 1);
                    WaterVertices.Add(heights[i + 1, j] / 4);
                    WaterVertices.Add(j);
                    WaterVertices.Add(1);
                    WaterVertices.Add(1);

                    WaterVertices.Add(i);
                    WaterVertices.Add(heights[i, j + 1] / 4);
                    WaterVertices.Add(j);
                    WaterVertices.Add(0);
                    WaterVertices.Add(0);

                    WaterVertices.Add(i + 1);
                    WaterVertices.Add(heights[i + 1, j + 1] / 4);
                    WaterVertices.Add(j + 1);
                    WaterVertices.Add(1);
                    WaterVertices.Add(0);

                    WaterVertices.Add(i);
                    WaterVertices.Add(heights[i, j] / 4);
                    WaterVertices.Add(j);
                    WaterVertices.Add(0);
                    WaterVertices.Add(0);

                    WaterVertices.Add(i + 1);
                    WaterVertices.Add(heights[i, j] / 4);
                    WaterVertices.Add(j);
                    WaterVertices.Add(1);
                    WaterVertices.Add(1);
                }
            }

            WaterTexture = new Texture(projectPath + "\\Textures\\water.PNG", 2);
            WaterTimeID  = Gl.glGetUniformLocation(Shader3D.ID, "t");

            //ground
            //ground = new Ground(256, 256, 0, 8);

            //Camera
            camera = new Camera();
            camera.Reset(0, 5, 5, 0, 0, 0, 0, 1, 0);
            ProjectionMatrix = camera.GetProjectionMatrix();
            ViewMatrix       = camera.GetViewMatrix();

            //Transformations and Shader Configurations
            transID = Gl.glGetUniformLocation(Shader3D.ID, "model");
            projID  = Gl.glGetUniformLocation(Shader3D.ID, "projection");
            viewID  = Gl.glGetUniformLocation(Shader3D.ID, "view");
            DataID  = Gl.glGetUniformLocation(Shader3D.ID, "data");
            vec2 data = new vec2(100, 50);

            Gl.glUniform2fv(DataID, 1, data.to_array());

            //Light
            int  LightPositionID = Gl.glGetUniformLocation(Shader3D.ID, "LightPosition_worldspace");
            vec3 lightPosition   = new vec3(1.0f, 20f, 4.0f);

            Gl.glUniform3fv(LightPositionID, 1, lightPosition.to_array());

            //setup the ambient light component.
            AmbientLightID = Gl.glGetUniformLocation(Shader3D.ID, "ambientLight");
            vec3 ambientLight = new vec3(0.2f, 0.18f, 0.01f);

            Gl.glUniform3fv(AmbientLightID, 1, ambientLight.to_array());

            //setup the eye position.
            EyePositionID = Gl.glGetUniformLocation(Shader3D.ID, "EyePosition_worldspace");

            SkyboxBufferID  = GPU.GenerateBuffer(SkyboxVertices);
            TerrainBufferID = GPU.GenerateBuffer(TerrainVertices.ToArray());
            GrassBufferID   = GPU.GenerateBuffer(GrassVertices.ToArray());
            WaterBufferID   = GPU.GenerateBuffer(WaterVertices.ToArray());

            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LESS);
        }
Esempio n. 3
0
        public void Initialize()
        {
            string projectPath = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            sh = new Shader(projectPath + "\\Shaders\\SimpleVertexShader.vertexshader", projectPath + "\\Shaders\\SimpleFragmentShader.fragmentshader");

            //tex1 = new Texture(projectPath + "\\Textures\\grass_mix_d.jpg", 2);
            tex1 = new Texture(projectPath + "\\Textures\\ground_cracks2v_d.jpg", 2);

            tex     = new Texture(projectPath + "\\Textures\\crate.jpg", 3);
            textri2 = new Texture(projectPath + "\\Textures\\crate.jpg", 4);


            //m = new md2LOL(projectPath + "\\ModelFiles\\animated\\md2LOL\\fiora.md2"); //bytl3 ghreb!!!!!!!!!!
            m = new md2LOL(projectPath + "\\ModelFiles\\zombie.md2");
            m.StartAnimation(animType_LOL.STAND);
            m.rotationMatrix    = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            m.scaleMatrix       = glm.scale(new mat4(1), new vec3(0.8f, 0.8f, 0.8f));
            m.TranslationMatrix = glm.translate(new mat4(1), new vec3(15, 1, 20));

            // enemy2 = new md2LOL(projectPath + "\\ModelFiles\\animated\\md2LOL\\zombie1.md2");
            enemy2 = new md2LOL(projectPath + "\\ModelFiles\\zombie.md2");
            enemy2.StartAnimation(animType_LOL.STAND);
            enemy2.rotationMatrix    = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            enemy2.scaleMatrix       = glm.scale(new mat4(1), new vec3(0.8f, 0.8f, 0.8f));
            enemy2.TranslationMatrix = glm.translate(new mat4(1), new vec3(30, 1, 20));

            //building PROBLEM HERE
            building = new Model3D();
            building.LoadFile(projectPath + "\\ModelFiles\\static\\building", 5, "Building 02.obj");
            building.scalematrix = glm.scale(new mat4(1), new vec3(20, 20, 30));
            building.transmatrix = glm.translate(new mat4(1), new vec3(200, 40, -300));

            //tree
            tree = new Model3D();
            tree.LoadFile(projectPath + "\\ModelFiles\\static\\tree", 6, "Tree.obj");
            tree.scalematrix = glm.scale(new mat4(1), new vec3(5f, 10f, 5f));
            tree.transmatrix = glm.translate(new mat4(1), new vec3(-70, 10, 1));

            //spider
            spider = new Model3D();
            spider.LoadFile(projectPath + "\\ModelFiles\\static\\spider", 7, "spider.obj");
            spider.scalematrix = glm.scale(new mat4(1), new vec3(0.099f, 0.099f, 0.099f));
            spider.transmatrix = glm.translate(new mat4(1), new vec3(-70, 2, 1));

            //jeep
            jeep = new Model3D();
            jeep.LoadFile(projectPath + "\\ModelFiles\\static\\car", 8, "dpv.obj");
            jeep.scalematrix = glm.scale(new mat4(1), new vec3(0.1f, 0.1f, 0.1f));
            jeep.transmatrix = glm.translate(new mat4(1), new vec3(-50, 5, 1));
            jeep.rotmatrix   = glm.rotate((float)((1 / 180) * Math.PI), new vec3(1, 0, 0));

            //house
            house = new Model3D();
            house.LoadFile(projectPath + "\\ModelFiles\\static\\house", 9, "house.obj");
            house.scalematrix = glm.scale(new mat4(1), new vec3(9, 9, 9));
            house.transmatrix = glm.translate(new mat4(1), new vec3(-60, 10, -45));


            // skybox
            Downtex  = new Texture(projectPath + "\\Textures\\nottingham_dn.jpg", 2); //ground
            Uptex    = new Texture(projectPath + "\\Textures\\nottingham_up.jpg", 3); //up
            Fronttex = new Texture(projectPath + "\\Textures\\nottingham_ft.jpg", 4); //front
            Righttex = new Texture(projectPath + "\\Textures\\nottingham_rt.jpg", 5); //right
            Backtex  = new Texture(projectPath + "\\Textures\\nottingham_bk.jpg", 6); ///back
            Lefttex  = new Texture(projectPath + "\\Textures\\nottingham_lf.jpg", 7); //left



            //define normal for each vertex
            float[] ground =
            {
                -10.0f, 0.0f,  10.0f,
                0,         0,      1,
                0,         1,
                0,         1,      0,

                10.0f,  0.0f, -10.0f,
                0,         0,      1,
                1,         0,
                0,         1,      0,


                -10.0f, 0.0f, -10.0f,
                0,         0,      1,
                0,         0,
                0,         1,      0,

                10.0f,  0.0f,  10.0f,
                0,         0,      1,
                1,         1,
                0,         1,      0,

                -10.0f, 0.0f,  10.0f,
                0,         0,      1,
                0,         1,
                0,         1,      0,

                10.0f,  0.0f, -10.0f,
                0,         0,      1,
                1,         0,
                0,         1,      0,
            };
            vertexBufferID = GPU.GenerateBuffer(ground);

            //skybox

            Gl.glClearColor(1.0f, 1.0f, 1.0f, 1);

            float[] myCube =
            {
                //ground
                -10.0f, -1.0f,-10.0f, //0
                1,          0, 0,
                0,          1, 0,

                -10.0f, -1.0f,10.0f, //1
                1,          0, 0,
                0,          1, 0,

                10.0f,  -1.0f,10.0f,//2
                1,          0, 0,
                0,          1, 0,

                10.0f,  -1.0f,-10.0f,//3
                1,          0, 0,
                0,          1, 0,

                //roof
                -10.0f,  9.0f,-10.0f,//4
                1,          0, 0,
                0,          1, 0,

                -10.0f,  9.0f,10.0f,//10
                1,          0, 0,
                0,          1, 0,

                10.0f,   9.0f,10.0f,//6
                1,          0, 0,
                0,          1, 0,

                10.0f,   9.0f,-10.0f,//7
                1,          0, 0,
                0,          1, 0,

                //back
                -10.0f, -1.0f,-10.0f, //8
                1,          0, 0,
                0,          1, 0,

                -10.0f,  9.0f,-10.0f,//10
                1,          0, 0,
                0,          1, 0, //normal

                10.0f,   9.0f,-10.0f,//9
                1,          0, 0,
                0,          1, 0,

                10.0f,  -1.0f,-10.0f,//11
                1,          0, 0,
                0,          1, 0,

                //right
                10.0f,  -1.0f,-10.0f,//12
                1,          0, 0,
                0,          1, 0,

                10.0f,   9.0f,-10.0f,//14
                1,          0, 0,
                0,          1, 0,

                10.0f,   9.0f,10.0f,//13
                1,          0, 0,
                0,          1, 0,

                10.0f,  -1.0f,10.0f,//110
                1,          0, 0,
                0,          1, 0,

                //front
                -10.0f, -1.0f,10.0f, //8
                1,          0, 0,
                0,          1, 0,

                10.0f,  -1.0f,10.0f,//11
                1,          0, 0,
                0,          1, 0,

                10.0f,   9.0f,10.0f,//10
                1,          0, 0,
                0,          1, 0,

                -10.0f,  9.0f,10.0f,//9
                1,          0, 0,
                0,          1, 0,

                //left
                -10.0f, -1.0f,-10.0f,  //20
                1,          0, 0,
                0,          1, 0,

                -10.0f, -1.0f,10.0f,//23
                1,          0, 0,
                0,          1, 0,

                -10.0f,  9.0f,10.0f,//21
                1,          0, 0,
                0,          1, 0,

                -10.0f,  9.0f,-10.0f,//22
                1,          0, 0,
                0,          1, 0,
            };


            float[] CubeCoord =
            {
                //down

                1, 0,
                0, 0,
                0, 1,
                1, 1,
                /////22222   up

                0, 0,
                1, 0,
                1, 1,
                0, 1,
                /////333333  BACK

                0, 1,
                0, 0,
                1, 0,
                1, 1,

                /////444444  right
                0, 1,
                0, 0,
                1, 0,
                1, 1,

                /////555555 front


                1, 1,
                0, 1,
                0, 0,
                1, 0,


                /////66666   left
                1, 1,
                0, 1,
                0, 0,
                1, 0,
            };



            SkyboxBufferID = GPU.GenerateBuffer(myCube);
            cubeCoordID    = GPU.GenerateBuffer(CubeCoord);

            //triangle
            float[] TrianleCoord =
            {
                0, 0,
                1, 1,
                0, 1,
            };

            float[] triangle =
            {
                -1.0f, -1.0f, 0.0f,
                0,         0,    0,
                1.0f,  -1.0f, 0.0f,
                0,         0,    0,
                0.0f,   1.0f, 0.0f,
                0,         0,    0,
            };

            vertexBufferID2 = GPU.GenerateBuffer(triangle);
            TriangleCoordID = GPU.GenerateBuffer(TrianleCoord);

            //2nd triangle
            //triangle
            float[] TrianleCoord2 =
            {
                0, 0,
                1, 1,
                0, 1,
            };

            float[] triangle2 =
            {
                -1.0f, -1.0f, 0.0f,
                0,         0,    0,
                1.0f,  -1.0f, 0.0f,
                0,         0,    0,
                0.0f,   1.0f, 0.0f,
                0,         0,    0,
            };

            vertexBuffer2ID2 = GPU.GenerateBuffer(triangle2);
            TriangleCoord2ID = GPU.GenerateBuffer(TrianleCoord2);


            Gl.glClearColor(0, 0, 0.4f, 1);

            cam = new Camera();
            cam.Reset(0, 34, 100, 0, 0, 0, 0, 1, 0);

            ProjectionMatrix = cam.GetProjectionMatrix();
            ViewMatrix       = cam.GetViewMatrix();

            transID = Gl.glGetUniformLocation(sh.ID, "trans"); //7ala m7l l model kman fl vertex shader
            projID  = Gl.glGetUniformLocation(sh.ID, "projection");
            viewID  = Gl.glGetUniformLocation(sh.ID, "view");
            //modelID = Gl.glGetUniformLocation(sh.ID, "model");

            modelmatrix = glm.scale(new mat4(1), new vec3(50, 50, 50)) * glm.translate(new mat4(1), new vec3(1, 1, 1)); //here! zombies
            // modelmatrix2 = glm.scale(new mat4(1), new vec3(15,15,15)) * glm.translate(new mat4(1), new vec3(80, 100, -100)); //wooden triangle1

            sh.UseShader();

            //get location of specular and attenuation then send their values
            //get location of light position and send its value
            //setup the ambient light component.
            //setup the eye position.

            camposID = Gl.glGetUniformLocation(sh.ID, "campos");

            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LESS);
        }
Esempio n. 4
0
        public void Initialize()
        {
            string projectPath = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            sh            = new Shader(projectPath + "\\Shaders\\SimpleVertexShader.vertexshader", projectPath + "\\Shaders\\SimpleFragmentShader.fragmentshader");
            d             = new Texture(projectPath + "\\Textures\\skybox\\bottom.jpg", 1, true);
            u             = new Texture(projectPath + "\\Textures\\skybox\\top.jpg", 2, true);
            l             = new Texture(projectPath + "\\Textures\\skybox\\left.jpg", 3, true);
            r             = new Texture(projectPath + "\\Textures\\skybox\\right.jpg", 4, true);
            f             = new Texture(projectPath + "\\Textures\\skybox\\front.jpg", 5, true);
            b             = new Texture(projectPath + "\\Textures\\skybox\\back.jpg", 6, true);
            groundTexture = new Texture(projectPath + "\\Textures\\ground.jpg", 7, true);
            shoot         = new Texture(projectPath + "\\Textures\\gunshot.png", 8, true);
            cam           = new Camera();
            cam.Reset(0, 34, 55, 0, 0, 0, 0, 1, 0);

            float[] square =
            {
                -1, 0,  1, 1, 0, 0, 0, 0,
                1,  0,  1, 1, 0, 0, 1, 0,
                -1, 0, -1, 1, 0, 0, 0, 1,

                1,  0,  1, 1, 0, 0, 1, 0,
                -1, 0, -1, 1, 0, 0, 0, 1,
                1,  0, -1, 1, 0, 0, 1, 1
            };
            skyboxBuffer_ID = GPU.GenerateBuffer(square);

            up = MathHelper.MultiplyMatrices(new List <mat4> {
                glm.rotate(3.1412f, new vec3(1, 0, 0)),
                glm.translate(new mat4(1), new vec3(0, 1, 0))
            });

            down = glm.translate(new mat4(1), new vec3(0, -1, 0));
            // Dclare Matrices For transformation edges
            front = MathHelper.MultiplyMatrices(new List <mat4> {
                glm.rotate(90.0f / 180.0f * 3.1412f, new vec3(1, 0, 0)),
                glm.translate(new mat4(1), new vec3(0, 0, -1))
            });
            left = MathHelper.MultiplyMatrices(new List <mat4> {
                glm.rotate(90.0f / 180.0f * 3.1412f, new vec3(1, 0, 0)),
                glm.rotate(90.0f / 180.0f * 3.1412f, new vec3(0, 1, 0)),
                glm.translate(new mat4(1), new vec3(-1, 0, 0))
            });
            back = MathHelper.MultiplyMatrices(new List <mat4> {
                glm.rotate(90.0f / 180.0f * 3.1412f, new vec3(1, 0, 0)),
                glm.rotate(3.1412f, new vec3(0, 1, 0)),
                glm.translate(new mat4(1), new vec3(0, 0, 1))
            });
            right = MathHelper.MultiplyMatrices(new List <mat4> {
                glm.rotate(90.0f / 180.0f * 3.1412f, new vec3(1, 0, 0)),
                glm.rotate(-90.0f / 180.0f * 3.1412f, new vec3(0, 1, 0)),
                glm.translate(new mat4(1), new vec3(1, 0, 0))
            });

            ground = MathHelper.MultiplyMatrices(new List <mat4>
            {
                glm.scale(new mat4(1), new vec3(6000, 6000, 6000)),
                glm.translate(new mat4(1), new vec3(0, -45, 0))
            });
            building = new Model3D();
            building.LoadFile(projectPath + "\\ModelFiles\\static\\building", 1, "Building 02.obj");
            building.scalematrix = glm.scale(new mat4(1), new vec3(30, 30, 30));
            building.transmatrix = glm.translate(new mat4(1), new vec3(1, 1, 1));

            car = new Model3D();
            car.LoadFile(projectPath + "\\ModelFiles\\static\\car", 3, "dpv.obj");
            car.scalematrix = glm.scale(new mat4(1), new vec3(0.15f, 0.25f, 0.15f));
            car.transmatrix = glm.translate(new mat4(1), new vec3(-150, -45.0f, 0.5f));
            car.rotmatrix   = glm.rotate(3.1412f, new vec3(0, 1, 0));

            tree = new Model3D();
            tree.LoadFile(projectPath + "\\ModelFiles\\static\\tree", 2, "Tree.obj");
            tree.scalematrix = glm.scale(new mat4(1), new vec3(50, 50, 50));
            tree.transmatrix = glm.translate(new mat4(1), new vec3(-240, -45.0f, 0.5f));
            tree.rotmatrix   = glm.rotate(3.1412f, new vec3(0, 1, 0));

            Blade = new md2(projectPath + "\\ModelFiles\\animated\\md2\\blade\\Blade.md2");
            Blade.StartAnimation(animType.STAND);
            Blade.rotationMatrix    = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            Blade.scaleMatrix       = glm.scale(new mat4(1), new vec3(0.8f, 0.8f, 0.8f));
            Blade.TranslationMatrix = glm.translate(new mat4(1), new vec3(20, 19, -20));

            zombie = new md2LOL(projectPath + "\\ModelFiles\\animated\\md2LOL\\zombie.md2");
            zombie.StartAnimation(animType_LOL.STAND);
            zombie.rotationMatrix = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            zombie.scaleMatrix    = glm.scale(new mat4(1), new vec3(0.8f, 0.8f, 0.8f));


            spider = new Model3D();
            spider.LoadFile(projectPath + "\\ModelFiles\\static\\spider", 4, "spider.obj");
            spider.transmatrix = glm.translate(new mat4(1), new vec3(240, 0.0f, 0));
            spider.rotmatrix   = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(0, 1, 0));

            HandsWGun = new Model3D();
            HandsWGun.LoadFile(projectPath + "\\ModelFiles\\hands with gun", 8, "gun.obj");
            HandsWGun.scalematrix = glm.scale(new mat4(1), new vec3(0.2f, 0.2f, 0.2f));

            bulletModel = new Model3D();
            bulletModel.LoadFile(projectPath + "\\ModelFiles\\static\\bullet", 8, "bullet.obj");


            sh.UseShader();
            Gl.glClearColor(0, 0, 0.4f, 1);



            ProjectionMatrix = cam.GetProjectionMatrix();
            ViewMatrix       = cam.GetViewMatrix();

            modelID = Gl.glGetUniformLocation(sh.ID, "model");
            projID  = Gl.glGetUniformLocation(sh.ID, "projection");
            viewID  = Gl.glGetUniformLocation(sh.ID, "view");

            sh.UseShader();

            c = timer;
        }
Esempio n. 5
0
        public void Initialize()
        {
            string projectPath = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            sh = new Shader(projectPath + "\\Shaders\\SimpleVertexShader.vertexshader", projectPath + "\\Shaders\\SimpleFragmentShader.fragmentshader");
            Gl.glClearColor(0.6f, 0.6f, 0.6f, 1);

            float[] backGroundVertices =
            {
                //plane
                -2.0f,  0.0f,  2.0f,
                1.0f,   1.0f,  1.0f, //color w
                -2.0f,  0.0f, -2.0f,
                1.0f,   1.0f,  1.0f, //color w
                2.0f,   0.0f, -2.0f,
                1.0f,   1.0f,  1.0f, //color w
                2.0f,   0.0f,  2.0f,
                1.0f,   1.0f,  1.0f, //color w

                //Axis
                //x
                -2.0f,  0.0f,  0.0f,
                1.0f,   0.0f,  0.0f, //R
                2.0f,   0.0f,  0.0f,
                1.0f,   0.0f,  0.0f, //R

                //y
                0.0f,  -2.0f,  0.0f,
                0.0f,   1.0f,  0.0f, //G
                0.0f,   2.0f,  0.0f,
                0.0f,   1.0f,  0.0f, //G

                //z
                0.0f,   0.0f,  2.0f,
                0.0f,   0.0f,  1.0f, //B
                0.0f,   0.0f, -2.0f,
                0.0f,   0.0f,  1.0f, //B
            };
            sh.UseShader();

            planeBufferID = GPU.GenerateBuffer(backGroundVertices);
            vertexID      = GPU.GenerateBuffer(verts.ToArray());


            transID = Gl.glGetUniformLocation(sh.ID, "trans");
            projID  = Gl.glGetUniformLocation(sh.ID, "projection");
            viewID  = Gl.glGetUniformLocation(sh.ID, "view");

            DataID          = Gl.glGetUniformLocation(sh.ID, "data");
            EyePositionID   = Gl.glGetUniformLocation(sh.ID, "EyePosition_worldspace");
            AmbientLightID  = Gl.glGetUniformLocation(sh.ID, "ambientLight");
            DiffuseLightID  = Gl.glGetUniformLocation(sh.ID, "diffuseLight");
            SpecularLightID = Gl.glGetUniformLocation(sh.ID, "specularLight");

            LightPosID     = Gl.glGetUniformLocation(sh.ID, "LightPosition_worldspace");
            checkTextureID = Gl.glGetUniformLocation(sh.ID, "checkTextureOut");
            checkLightID   = Gl.glGetUniformLocation(sh.ID, "checkLightOut");

            cam = new Camera();
            cam.Reset(0, 2, 5, 0, 0, 0, 0, 1, 0);

            ProjectionMatrix = cam.GetProjectionMatrix();
            ViewMatrix       = cam.GetViewMatrix();



            // Model matrix: apply transformations to the model
            List <mat4> transformations = new List <mat4>();

            transformations.Add(glm.scale(new mat4(1), new vec3(1, 2, 1)));
            transformations.Add(glm.rotate(-30.0f / 180 * 3.14f, new vec3(0, 1, 0)));
            ModelMatrix = MathHelper.MultiplyMatrices(transformations);
        }
Esempio n. 6
0
        public void Initialize()
        {
            string projectPath = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            sh = new Shader(projectPath + "\\Shaders\\SimpleVertexShader.vertexshader", projectPath + "\\Shaders\\SimpleFragmentShader.fragmentshader");

            tex   = new Texture(projectPath + "\\Textures\\crate.jpg", 0);
            down  = new Texture(projectPath + "\\Textures\\down.jpg", 1);
            right = new Texture(projectPath + "\\Textures\\right.jpg", 2);
            left  = new Texture(projectPath + "\\Textures\\left.jpg", 3);
            up    = new Texture(projectPath + "\\Textures\\up.jpg", 4);
            front = new Texture(projectPath + "\\Textures\\front.jpg", 5);
            back  = new Texture(projectPath + "\\Textures\\back.jpg", 6);
            tex1  = new Texture(projectPath + "\\Textures\\Ground.jpg", 2);

            m = new md2LOL(projectPath + "\\ModelFiles\\zombie.md2");
            m.StartAnimation(animType_LOL.RUN);
            m.rotationMatrix    = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            m.scaleMatrix       = glm.scale(new mat4(1), new vec3(0.0093f, 0.0093f, 0.0093f));
            m.TranslationMatrix = glm.translate(new mat4(1), new vec3(0, -2, 5));
            ////define normal for each vertex
            m2 = new md2LOL(projectPath + "\\ModelFiles\\wolf.md2");
            m2.StartAnimation(animType_LOL.ATTACK1);
            m2.rotationMatrix    = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            m2.scaleMatrix       = glm.scale(new mat4(1), new vec3(0.008f, 0.008f, 0.008f));
            m2.TranslationMatrix = glm.translate(new mat4(1), new vec3(-2, -2, 5));


            Gl.glClearColor(0, 0, 0, 1);
            float ground = 1;


            float[] skybox =
            {
                -ground, -ground, -ground, 0, 0,
                ground,  -ground, -ground, 1, 0,
                ground,  ground,  -ground, 1, 1,

                -ground, -ground, -ground, 0, 0,
                -ground, ground,  -ground, 0, 1,
                ground,  ground,  -ground, 1, 1
            };
            float[] verts =
            {
                -1.0f, -1.0f, 0.0f,

                0,         0,
                1.0f,  -1.0f, 0.0f,

                1,         0,
                0.0f,   1.0f, 0.0f,

                0.5f, 1
            };

            vertexBufferID  = GPU.GenerateBuffer(skybox);
            vertexBufferID2 = GPU.GenerateBuffer(verts);

            scaleMat = glm.scale(new mat4(1), new vec3(200f, 200f, 200f));

            cam = new Camera();

            ProjectionMatrix = cam.GetProjectionMatrix();
            ViewMatrix       = cam.GetViewMatrix();
            transID          = Gl.glGetUniformLocation(sh.ID, "model");
            projID           = Gl.glGetUniformLocation(sh.ID, "projection");
            viewID           = Gl.glGetUniformLocation(sh.ID, "view");

            leftmatrix = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(90.0f / 180.0f * 3.1412f, new vec3(0, 1, 0)),
                glm.translate(new mat4(1), new vec3(0, 0, 0)),
                scaleMat
            });

            rightmatrix = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(270f / 180.0f * 3.1412f, new vec3(0, 1, 0)),
                glm.translate(new mat4(1), new vec3(0, 0, 0)),
                scaleMat
            });

            upmatrix = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(90 / 180.0f * 3.1412f, new vec3(1, 0, 0)),
                glm.translate(new mat4(1), new vec3(0, 0, 0)),
                scaleMat
            });

            backmatrix = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(180f / 180f * 3.1412f, new vec3(0, 1, 0)),
                glm.translate(new mat4(1), new vec3(0, 0, 0)),
                scaleMat
            });

            groundmatrix = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(90f / 180.0f * 3.1412f, new vec3(1, 0, 0)),
                glm.translate(new mat4(1), new vec3(0, -2, 0)),
                scaleMat
            });

            //Gl.glClearColor(0, 0, 0.4f, 1);

            //cam = new Camera();
            cam.Reset(0, -1.75f, 0, 0, 0, 0, 0, 0, 0);

            ProjectionMatrix = cam.GetProjectionMatrix();
            ViewMatrix       = cam.GetViewMatrix();



            modelmatrix = glm.scale(new mat4(1), new vec3(50, 50, 50));

            tree = new Model3D();
            tree.LoadFile(projectPath + "\\ModelFiles\\tree", 6, "Tree.obj");
            tree.scalematrix = glm.scale(new mat4(1), new vec3(0.1f, 0.1f, 0.1f));
            tree.transmatrix = glm.translate(new mat4(1), new vec3(0.6f, -2, 0.4f));

            //tree2 = new Model3D();
            //tree2.LoadFile(projectPath + "\\ModelFiles\\Tree1", 6, "Tree1.obj");
            //tree2.scalematrix = glm.scale(new mat4(1), new vec3(30, 30, 30));

            treee3 = new Model3D();
            treee3.LoadFile(projectPath + "\\ModelFiles\\Wolf Rigged and Game Ready", 6, "Wolf.fbx");
            treee3.scalematrix = glm.scale(new mat4(1), new vec3(0.1f, 0.1f, 0.1f));
            treee3.transmatrix = glm.translate(new mat4(1), new vec3(-0.6f, -2, 0.4f));
            treee3.rotmatrix   = glm.rotate((float)((-180.0f / 180) * Math.PI), new vec3(1, 0, 0));


            //car = new Model3D();
            //car.LoadFile(projectPath + "\\ModelFiles\\car", 6, "dpv.obj");
            //car.scalematrix = glm.scale(new mat4(1), new vec3(15, 1, 15));

            cottage = new Model3D();
            cottage.LoadFile(projectPath + "\\ModelFiles\\House", 6, "house.obj");
            cottage.scalematrix = glm.scale(new mat4(1), new vec3(0.1f, 0.1f, 0.1f));

            cottage.transmatrix = glm.translate(new mat4(1), new vec3(-0.6f, -2f, 0.4f));

            jeep = new Model3D();
            jeep.LoadFile(projectPath + "\\ModelFiles\\jeep", 9, "jeep1.3ds");
            jeep.scalematrix = glm.scale(new mat4(1), new vec3(0.05f, 0.05f,
                                                               0.05f));
            jeep.transmatrix = glm.translate(new mat4(1), new vec3(1f, -2f, 1f));
            jeep.rotmatrix   = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));

            //jeep2 = new Model3D();
            //jeep2.LoadFile(projectPath + "\\ModelFiles\\jeep", 10, "jeep1.3ds");
            //jeep2.scalematrix = glm.scale(new mat4(1), new vec3(5, 5, 5));
            //jeep2.transmatrix = glm.translate(new mat4(1), new vec3(-80, 1, 180));
            //jeep2.rotmatrix = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));

            //get location of specular and attenuation then send their values
            //get location of light position and send its value
            //setup the ambient light component.
            //setup the eye position.

            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LESS);
        }