Ejemplo n.º 1
0
 public AABB getAABB(int frame)
 {
     AABB ret = new AABB();
     Vector3 v1, v2, v3;
     for (int i = 0; i < triangleCount; i++)
     {
         v1 = resize(framesBuffer[frame][trianglesIndexBuffer[i * 3]]);
         v2 = resize(framesBuffer[frame][trianglesIndexBuffer[i * 3 + 1]]);
         v3 = resize(framesBuffer[frame][trianglesIndexBuffer[i * 3 + 2]]);
         ret.AddVertex(v1);
         ret.AddVertex(v2);
         ret.AddVertex(v3);
     }
     return ret;
 }
Ejemplo n.º 2
0
        void CheckForMovement()
        {
            Vector3 trans = new Vector3();

            if (EventMgr.Keyboard['w'])
            {
                trans += Camera.Forward;
            }
            if (EventMgr.Keyboard['s'])
            {
                trans -= Camera.Forward;
            }
            if (EventMgr.Keyboard['a'])
            {
                trans -= Camera.Left;
            }
            if (EventMgr.Keyboard['d'])
            {
                trans += Camera.Left;
            }

            trans = trans.Normalized;

            vVelocity -= World.g * World.dt * World.Up;
            Vector3 newPos = Camera.Position + trans * f_speed * World.dt;

            Vector3 transX = newPos - Camera.Position;
            transX.Z = 0;
            transX.Y = 0;

            Vector3 transZ = newPos - Camera.Position;
            transZ.X = 0;
            transZ.Y = 0;

            Vector3 transY = newPos - Camera.Position;
            transY.Z = 0;
            transY.X = 0;

            Vector3 stepup = new Vector3();

            AABB cambox = new AABB();

            cambox.AddVertex(new Vector3(-10, -10, -60));
            cambox.AddVertex(new Vector3(10, 10, 20));

            Q3CollisionData coldata = World.Map.Level.TraceBox(Camera.Position, Camera.Position + transX, cambox);
            if (coldata.collisionPoint != coldata.endPosition)
            {
                // try to step
                Vector3 currstep = new Vector3();
                for (float step = 1f; coldata.collisionPoint != coldata.endPosition && step < 10; step++)
                {
                    currstep = new Vector3(0, 0, step);
                    coldata = World.Map.Level.TraceBox(Camera.Position + currstep, Camera.Position + currstep + transX, cambox);
                }
                if (coldata.collisionPoint != coldata.endPosition)
                    transX.X = 0;
                else
                    stepup = currstep;
            }

            coldata = World.Map.Level.TraceBox(Camera.Position, Camera.Position + transY, cambox);
            if (coldata.collisionPoint != coldata.endPosition)
            {
                Vector3 currstep = new Vector3();
                for (float step = 1f; coldata.collisionPoint != coldata.endPosition && step < 10; step++)
                {
                    currstep = new Vector3(0, 0, step);
                    coldata = World.Map.Level.TraceBox(Camera.Position + currstep, Camera.Position + currstep + transY, cambox);
                }
                if (coldata.collisionPoint != coldata.endPosition)
                    transY.Y = 0;
                else
                    stepup.Z = Math.Max(currstep.Z,stepup.Z);
            }

            Camera.Position += transX + transY + stepup;

            coldata = World.Map.Level.TraceBox(Camera.Position, Camera.Position + vVelocity, cambox);
            if (coldata.collisionPoint != coldata.endPosition)
            {
                vVelocity = new Vector3();
                if (EventMgr.Keyboard[' '])
                {
                    vVelocity.Z = World.JumpAcc;

                    coldata = World.Map.Level.TraceBox(Camera.Position, Camera.Position + vVelocity, cambox);
                    if (coldata.collisionPoint != coldata.endPosition)
                        vVelocity.Z = 0;
                }
                else if(transX.X != 0 || transY.Y != 0)
                {
                    vVelocity.Z = 1f;

                    coldata = World.Map.Level.TraceBox(Camera.Position, Camera.Position + vVelocity, cambox);
                    if (coldata.collisionPoint != coldata.endPosition)
                        vVelocity.Z = 0;
                }
            }

            Camera.Position += vVelocity;
        }
Ejemplo n.º 3
0
        public override void Update()
        {
            base.Update();

            weapofs -= 2f * World.dt;
            if (weapofs < 0) weapofs = 0;

            shootfreq -= World.dt;
            if (shootfreq < 0) shootfreq = 0;

            if (EventMgr.Mouse.Button[Sdl.SDL_BUTTON_LEFT] && shootfreq == 0 && nb_munit > 0)
            {

                Vector3 startpos = Camera.Position;
                Vector3 endpos = Camera.Position + 900 * Camera.Forward;
                Vector3 emmitpos = World.Map.Level.TraceRay(startpos,endpos).collisionPoint;
                if (TargetMgr.ActiveTarget != -1 && Collision.IsColliding(TargetMgr.Targets[TargetMgr.ActiveTarget].Poly, new Vector3[] { startpos, emmitpos }, 4))
                {
                    TargetMgr.ChooseTarget();
                    point++;
                    TargetMgr.nextTimeup += 10;
                }
                else
                {
                    Emitter emit = new Emitter(emmitpos, 100);
                    emit.SetColor(0, 0, 0);
                    EmitterMgr.emitters.Add(emit);
                }
                tir.Play();
                nb_munit--;
                weapofs = 0.5f;
                shootfreq = 0.1f;
            }
            if ((EventMgr.Keyboard['r'] && nb_munit < munitMax) ||  nb_munit == 0)
            {
                if (nb_rech > 0)
                {
                    nb_rech--;
                    nb_munit = munitMax;
                    shootfreq = 1.2f;
                }
            }
            AABB cambox = new AABB();

            cambox.AddVertex(new Vector3(-10, -10, -60));
            cambox.AddVertex(new Vector3(10, 10, 20));
            cambox.Min += Camera.Position;
            cambox.Max += Camera.Position;
            DropboxMgr.TryToDrop(cambox, s_name);
        }
Ejemplo n.º 4
0
        void LoadVertices(BinaryReader br, int offset, int n)
        {
            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            VBO_position = new float[n * 3];
            VBO_normal = new float[n * 3];
            VBO_texcoord = new float[n * 2];
            VBO_lmcoord = new float[n * 2];
            VBO_color = new byte[n * 4];
            m_box = new AABB();
            for (int i = 0; i < n; i++)
            {
                VBO_position[i * 3] = br.ReadSingle();
                VBO_position[i * 3 + 1] = br.ReadSingle();
                VBO_position[i * 3 + 2] = br.ReadSingle();

                m_box.AddVertex(new Vector3(VBO_position[i * 3], VBO_position[i * 3 + 1], VBO_position[i * 3 + 2]));

                VBO_texcoord[i * 2] = br.ReadSingle();
                VBO_texcoord[i * 2 + 1] = br.ReadSingle();

                VBO_lmcoord[i * 2] = br.ReadSingle();
                VBO_lmcoord[i * 2 + 1] = br.ReadSingle();

                VBO_normal[i * 3] = br.ReadSingle();
                VBO_normal[i * 3 + 1] = br.ReadSingle();
                VBO_normal[i * 3 + 2] = br.ReadSingle();

                VBO_color[i * 4] = br.ReadByte();
                VBO_color[i * 4 + 1] = br.ReadByte();
                VBO_color[i * 4 + 2] = br.ReadByte();
                VBO_color[i * 4 + 3] = br.ReadByte();
            }
        }