Пример #1
0
        public void Draw()
        {
            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());

            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            sh.UseShader();
            // FOR DONW SQUARE
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, skyboxBuffer_ID);
            //FOR POSITION
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(0 * sizeof(float)));
            //FOR COLOR
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            // FOR TEXTURE
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(6 * sizeof(float)));

            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
            float[] viewmat = cam.GetViewMatrix().to_array();
            viewmat[12] = 0;
            viewmat[13] = 0;
            viewmat[14] = 0;
            viewmat[15] = 1;
            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, viewmat);

            u.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, up.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            d.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, down.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            l.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, left.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            r.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, right.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            f.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, front.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            b.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, back.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            Gl.glUniform3fv(EyePositionID, 1, cam.GetCameraPosition().to_array());
            //ground
            Gl.glEnable(Gl.GL_DEPTH_TEST);

            groundTexture.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, ground.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            playerPos    = cam.GetCameraTarget();
            playerPos.y -= 2.8f;

            HandsWGun.transmatrix = glm.translate(new mat4(1), playerPos);
            HandsWGun.rotmatrix   = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(-cam.mAngleY, new vec3(1, 0, 0)),
                glm.rotate(3.1412f + cam.mAngleX, new vec3(0, 1, 0))
            });


            spider.Draw(modelID);
            building.Draw(modelID);
            car.Draw(modelID);
            Blade.Draw(modelID);
            zombie.Draw(modelID);
            tree.Draw(modelID);
            HandsWGun.Draw(modelID);

            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, skyboxBuffer_ID);

            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(0 * sizeof(float)));
            //FOR COLOR
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            // FOR TEXTURE
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(6 * sizeof(float)));


            shoot.Bind();
            vec3 shootpos = cam.GetCameraTarget();

            shootpos.y -= 1.5f;
            shootpos   += cam.GetLookDirection() * 8;

            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(cam.mAngleX, new vec3(0, 1, 0)), glm.rotate((float)c / 10, new vec3(0, 0, 1)),
                glm.translate(new mat4(1), shootpos)
            }).to_array());
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            if (draw)
            {
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
                c--;
                if (c < 0)
                {
                    c    = timer;
                    draw = false;
                }
            }
            Gl.glDisable(Gl.GL_BLEND);

            Gl.glDisable(Gl.GL_DEPTH_TEST);


            vec3 zombiePosition;

            zombiePosition.x = zombie.TranslationMatrix[3].x;
            zombiePosition.y = zombie.TranslationMatrix[3].y;
            zombiePosition.z = zombie.TranslationMatrix[3].z;

            vec3 zombieRotation = new vec3(0, -1, 0);

            zombieRotation = zombie.rotationMatrix.to_mat3() * zombieRotation;

            vec3 camposition = cam.GetCameraPosition();

            vec3 zombieDirection = camposition - zombiePosition;

            zombieDirection   = glm.normalize(zombieDirection);
            zombieDirection.y = 0;
            double distance = Math.Sqrt(Math.Pow(camposition.x - zombiePosition.x, 2) +
                                        Math.Pow(camposition.y - zombiePosition.y, 2) +
                                        Math.Pow(camposition.z - zombiePosition.z, 2));

            if (distance < Enemy_range_Run && distance > Enemy_range_Attack)
            {
                if (zombie.animSt.type != animType_LOL.RUN)
                {
                    zombie.StartAnimation(animType_LOL.RUN);
                }
                zombie.TranslationMatrix = glm.translate(zombie.TranslationMatrix, zombieDirection * zombieSpeed);
            }
            else if (distance < Enemy_range_Attack)
            {
                if (zombie.animSt.type != animType_LOL.ATTACK1)
                {
                    zombie.StartAnimation(animType_LOL.ATTACK1);
                }
            }
            else
            {
                if (zombie.animSt.type == animType_LOL.RUN)
                {
                    zombie.StartAnimation(animType_LOL.STAND);
                }
            }
            vec3 crossProduct = glm.cross(zombieRotation, zombieDirection);

            if (crossProduct.y != 0)
            {
                if (crossProduct.y > 0)
                {
                    zombie.rotationMatrix = glm.rotate(zombie.rotationMatrix, (float)(5.0 / 180.0 * Math.PI), new vec3(0, 0, 1));
                }
                else
                {
                    zombie.rotationMatrix = glm.rotate(zombie.rotationMatrix, (float)(-5.0 / 180.0 * Math.PI), new vec3(0, 0, 1));
                }
            }
            for (int i = 0; i < bullets.Count; i++)
            {
                bullets[i].Draw(modelID);
            }
        }