Exemplo n.º 1
0
        public void Initialize(vec3 pos, vec3 dir)
        {
            damage      = 0.25f;
            speed       = 0.1f;
            maxDistance = 100.0f;
            mPosition   = pos;
            mDirection  = dir;
            mDirection  = glm.normalize(mDirection);
            float  scale_value = 0.005f;
            vec3   scale_vec   = new vec3(scale_value);
            double angle       = glm.atan(mDirection.z, mDirection.x);

            model.rotmatrix   = glm.rotate((float)(-angle), new vec3(0, 1, 0));
            model.scalematrix = glm.scale(new mat4(1), scale_vec);
            model.transmatrix = glm.translate(new mat4(1), mPosition);

            collider = new AABoundingBox(model.GetCurrentVertices(), ColliderType.Bullet);
            collider.Scale(scale_vec);
            collider.SetCenter(mPosition);
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            string projectPath = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            sh      = new Shader(projectPath + "\\Shaders\\SimpleVertexShader.vertexshader", projectPath + "\\Shaders\\SimpleFragmentShader.fragmentshader");
            mySound = new SoundPlayer(projectPath + "\\Sounds\\ChillingMusic.wav");
            mySound.PlayLooping();

            startScreen    = new Screen("CALLofDUTY.jpg");
            screenTex      = startScreen.GetScreenTexture();
            screenBufferID = GPU.GenerateBuffer(startScreen.GetScreenSquare());
            started        = false;

            float[] skybox = LoadSkybox(projectPath);
            vertexBufferID = GPU.GenerateBuffer(skybox);

            hero        = new Player();
            enemiesList = new List <Enemy>();
            enemiesList.Add(new Enemy());
            enemiesList.Add(new Enemy());
            enemiesList.Add(new Enemy());
            enemiesList.Add(new Enemy());
            enemiesList.Add(new Enemy());
            enemiesList.Add(new Enemy());
            bulletsList        = new List <Bullet>();
            ObstaclesColliders = new List <AABoundingBox>();

            //House
            house = new Model3D();
            house.LoadFile(projectPath + "\\ModelFiles\\models\\3DS\\House", 9, "house.obj");
            house.transmatrix = glm.translate(new mat4(1), new vec3(20, 0, -10));
            AABoundingBox box = new AABoundingBox(house.GetCurrentVertices(), ColliderType.Obstacle);

            box.SetCenter(new vec3(20, 0, -10));
            ObstaclesColliders.Add(box);

            //jeep
            jeep = new Model3D();
            jeep.LoadFile(projectPath + "\\ModelFiles\\models\\3DS\\jeep", 10, "jeep1.3ds");
            jeep.scalematrix = glm.scale(new mat4(1), new vec3(0.3f, 0.3f, 0.3f));
            jeep.transmatrix = glm.translate(new mat4(1), new vec3(14, 0, 0));
            jeep.rotmatrix   = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            box = new AABoundingBox(jeep.GetCurrentVertices(), ColliderType.Obstacle);
            box.Scale(new vec3(0.3f, 0.3f, 0.3f));
            box.SetCenter(new vec3(14, 0, 0));
            ObstaclesColliders.Add(box);

            //jeep2
            jeep2 = new Model3D();
            jeep2.LoadFile(projectPath + "\\ModelFiles\\models\\3DS\\jeep", 10, "jeep1.3ds");
            jeep2.scalematrix = glm.scale(new mat4(1), new vec3(0.3f, 0.3f, 0.3f));
            jeep2.transmatrix = glm.translate(new mat4(1), new vec3(26, 0, 0));
            jeep2.rotmatrix   = glm.rotate((float)((-90.0f / 180) * Math.PI), new vec3(1, 0, 0));
            box = new AABoundingBox(jeep2.GetCurrentVertices(), ColliderType.Obstacle);
            box.Scale(new vec3(0.3f, 0.3f, 0.3f));
            box.SetCenter(new vec3(26, 0, 0));
            ObstaclesColliders.Add(box);

            //Weapon
            weaponTex = new Texture(projectPath + "\\Textures\\engineflare1.jpg", 7);
            Weapon    = new Model3D();
            Weapon.LoadFile(projectPath + "\\ModelFiles\\models\\3DS\\M4A4", 11, "m4a1.obj");
            Weapon.scalematrix = glm.scale(new mat4(1), new vec3(0.1f, 0.1f, 0.1f));
            Weapon.transmatrix = glm.translate(new mat4(1), new vec3(hero.camera.GetCameraPosition().x,
                                                                     hero.camera.GetCameraPosition().y - 1.5f,
                                                                     hero.camera.GetCameraPosition().z));
            double angle = glm.atan(hero.camera.GetLookDirection().z, hero.camera.GetLookDirection().x);

            Weapon.rotmatrix = glm.rotate((float)(0.5f * Math.PI), new vec3(0, 1, 0));
            Weapon.rotmatrix = glm.rotate(Weapon.rotmatrix, (float)(-angle), new vec3(0, 1, 0));

            Gl.glClearColor(0, 0, 0.4f, 1);
            //hero.camera = new Camera();
            //hero.camera.Reset(0, 4, 20, 0, 0, 0, 0, 1, 0);

            ProjectionMatrix = hero.camera.GetProjectionMatrix();
            ViewMatrix       = hero.camera.GetViewMatrix();

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

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

            sh.UseShader();

            DataID = Gl.glGetUniformLocation(sh.ID, "data");
            vec2 data = new vec2(5, 50);

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

            int  LightPositionID = Gl.glGetUniformLocation(sh.ID, "LightPosition_worldspace");
            vec3 lightPosition   = new vec3(100.0f, 55.0f, 48.0f);

            Gl.glUniform3fv(LightPositionID, 1, lightPosition.to_array());
            //setup the ambient light component.
            AmbientLightID = Gl.glGetUniformLocation(sh.ID, "ambientLight");
            vec3 ambientLight = new vec3(1.5f, 1.3f, 1.3f);

            Gl.glUniform3fv(AmbientLightID, 1, ambientLight.to_array());
            //setup the eye position.
            EyePositionID = Gl.glGetUniformLocation(sh.ID, "EyePosition_worldspace");
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LESS);
        }