Beispiel #1
0
 public void Update(float deltaTime)
 {
     cam.UpdateViewMatrix();
     Gl.glUniform3fv(camposID, 1, cam.GetCameraPosition().to_array());
     ProjectionMatrix = cam.GetProjectionMatrix();
     ViewMatrix       = cam.GetViewMatrix();
     m.UpdateExportedAnimation();
     enemy2.UpdateExportedAnimation();
 }
Beispiel #2
0
 public void Fire(List <Bullet> bulletList)
 {
     if (nextFire >= fireRate)
     {
         Bullet bullet = new Bullet(camera.GetCameraPosition(), camera.GetLookDirection());
         bulletList.Add(bullet);
         nextFire = 0.0f;
         mySound.Play();
     }
 }
Beispiel #3
0
        public bullet(Model3D model, Camera cam)
        {
            shootPosition    = cam.GetCameraPosition();
            shootPosition.y -= 1.5f;
            shootPosition   += cam.GetLookDirection() * 8;

            bulletModel             = model;
            mPosition               = shootPosition;
            mDirection              = cam.GetLookDirection();
            bulletModel.transmatrix = glm.translate(new mat4(1), mPosition);
            bulletModel.rotmatrix   = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate((float)((90.0 / 180.0) * Math.PI), new vec3(1, 0, 0)),
                glm.rotate(-cam.mAngleY, new vec3(1, 0, 0)),
                glm.rotate(cam.mAngleX, new vec3(0, 1, 0))
            });
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        public void Draw()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LESS);

            Gl.glLineWidth(1.5f);

            Gl.glUniform1f(checkTextureID, 0); //bb3t bool b 0 3shan 23rf hrsm b color wala texture
            Gl.glUniform1f(checkLightID, 0);   //bb3t bool b 0 3shan 23rf ha apply light wla la2

            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, ModelMatrix.to_array());
            Gl.glUniform3fv(EyePositionID, 1, cam.GetCameraPosition().to_array());


            Gl.glEnableVertexAttribArray(0);                    //pos
            Gl.glEnableVertexAttribArray(1);                    //color
            Gl.glEnableVertexAttribArray(2);                    //uv
            Gl.glEnableVertexAttribArray(3);                    //normal

            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, planeBufferID); //plane

            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 6 * sizeof(float), (IntPtr)0);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 6 * sizeof(float), (IntPtr)(3 * sizeof(float)));

            Gl.glDrawArrays(Gl.GL_LINE_LOOP, 0, 4);
            Gl.glDrawArrays(Gl.GL_LINES, 4, 6);

            if (setInterpolationId == true)
            {
                vertexID           = GPU.GenerateBuffer(interpolatedList.ToArray());
                setInterpolationId = false;
            }
            else
            {
                vertexID = GPU.GenerateBuffer(verts.ToArray());
            }

            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vertexID);                                                             //vertices

            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), IntPtr.Zero);                 //pos
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(3 * sizeof(float))); //color
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(6 * sizeof(float))); //uv
            Gl.glVertexAttribPointer(3, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(8 * sizeof(float))); //normal

            Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, indiciesBufferID);                                             //indicies

            if (selectedVertex == true)
            {
                Gl.glPointSize(5);
                Gl.glDrawArrays(Gl.GL_POINTS, selectedVertexIndex, 1);
            }
            if (GraphicsForm.applyTexture)
            {
                Gl.glUniform1f(checkTextureID, 1); //bb3t bool b 1 3shan arsm texture
            }
            if (GraphicsForm.applyLight)
            {
                Gl.glUniform1f(checkLightID, 1); //bb3t bool b 1 3shan arsm texture
            }
            for (int i = 0; i < GraphicsForm.modesDict.Count; i++)
            {
                string   key         = GraphicsForm.modesDict.Keys.ElementAt(i);
                string[] arr         = key.Split(' ');
                string   drawingMode = arr[0];


                if (drawingMode == "GL_TRIANGLE_FAN")
                {
                    Gl.glDrawElements(Gl.GL_TRIANGLE_FAN, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    if (GraphicsForm.applyTexture)
                    {
                        Gl.glDrawElements(Gl.GL_TRIANGLE_FAN, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    }
                }
                else if (drawingMode == "GL_TRIANGLES")
                {
                    Gl.glDrawElements(Gl.GL_TRIANGLES, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    if (GraphicsForm.applyTexture)
                    {
                        Gl.glDrawElements(Gl.GL_TRIANGLES, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    }
                }
                else if (drawingMode == "GL_LINES")
                {
                    Gl.glDrawElements(Gl.GL_LINES, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    if (GraphicsForm.applyTexture)
                    {
                        Gl.glDrawElements(Gl.GL_LINES, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    }
                }
                else if (drawingMode == "GL_LINE_LOOP")
                {
                    Gl.glDrawElements(Gl.GL_LINE_LOOP, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    if (GraphicsForm.applyTexture)
                    {
                        Gl.glDrawElements(Gl.GL_LINE_LOOP, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    }
                }
                else if (drawingMode == "GL_POINTS")
                {
                    Gl.glPointSize(15);
                    Gl.glDrawElements(Gl.GL_POINTS, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    //Gl.glUniform1f(checkTextureID, 0);
                }
                else if (drawingMode == "GL_LINE_STRIP")
                {
                    Gl.glDrawElements(Gl.GL_LINE_STRIP, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    if (GraphicsForm.applyTexture)
                    {
                        Gl.glDrawElements(Gl.GL_LINE_STRIP, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    }
                }
                else if (drawingMode == "GL_TRIANGLE_STRIP")
                {
                    Gl.glDrawElements(Gl.GL_TRIANGLE_STRIP, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    if (GraphicsForm.applyTexture)
                    {
                        Gl.glDrawElements(Gl.GL_TRIANGLE_STRIP, GraphicsForm.modesDict[key].Item2, Gl.GL_UNSIGNED_SHORT, (IntPtr)(sizeof(ushort) * (GraphicsForm.modesDict[key].Item1)));
                    }
                }
            }

            Gl.glDisableVertexAttribArray(0);
            Gl.glDisableVertexAttribArray(1);
            Gl.glDisableVertexAttribArray(2);
            Gl.glDisableVertexAttribArray(3);
        }