public static bool IsColliding(AABB box1, AABB box2) { if (box1.Max.X < box2.Min.X || box1.Min.X > box2.Max.X) return false; if (box1.Max.Y < box2.Min.Y || box2.Max.Y < box1.Min.Y) return false; if (box1.Max.Z < box2.Min.Z || box2.Max.Z < box1.Min.Z) return false; return true; }
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; }
public static void TryToDrop(AABB box, string player) { foreach (Dropbox b in BoxList) { if (Collision.IsColliding(b.box, box) && !b.hidden) { if (((Player)Camera.FPSCam).Name == player) { if (b.type == Dropbox.Type.Health) { healthsound.Play(); TargetMgr.nextTimeup += 5; } if (b.type == Dropbox.Type.Munition) { munitsound.Play(); ((Player)Camera.FPSCam).ChargerCount = 10; ((Player)Camera.FPSCam).MunitCount = Player.munitMax; } } b.hidden = true; } } }
public void Update() { currframe += World.dt*4; teta += World.dt*2; if (teta >= 360) teta = 0; if (currframe >= 2 * Math.PI) currframe = 0; if (hidden) reappeartime -= World.dt; if (reappeartime < 0) { hidden = false; reappeartime = 60; } if (currframe >= Math.PI * 2) currframe = 0; if (teta >= Math.PI * 2) teta = 0; Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glPushMatrix(); Gl.glTranslatef(position.X, position.Y, position.Z - 30f - 0.3f + (float)Math.Sin(currframe) * 5f); Gl.glRotated(((teta * 180) / Math.PI), 0, 0, 1); Gl.glGetFloatv(Gl.GL_MODELVIEW_MATRIX, skin.Matrice.Mat); Gl.glPopMatrix(); box = skin.getAABB(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; }
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); }
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(); } }
public Q3CollisionData TraceBox(Vector3 startPosition, Vector3 endPosition, AABB bbox) { Q3CollisionData collision = new Q3CollisionData(); Vector3 boxMinimums = bbox.Min; Vector3 boxMaximums = bbox.Max; if (boxMinimums.X == 0 && boxMinimums.Y == 0 && boxMinimums.Z == 0 && boxMaximums.X == 0 && boxMaximums.Y == 0 && boxMaximums.Z == 0) { collision.type = Q3CollisionType.Ray; return Trace(startPosition, endPosition, ref collision); } if (boxMaximums.X < boxMinimums.X) { float x = boxMaximums.X; boxMaximums.X = boxMinimums.X; boxMinimums.X = x; } if (boxMaximums.Y < boxMinimums.Y) { float y = boxMaximums.Y; boxMaximums.Y = boxMinimums.Y; boxMinimums.Y = y; } if (boxMaximums.Z < boxMinimums.Z) { float z = boxMaximums.Z; boxMaximums.Z = boxMinimums.Z; boxMinimums.Z = z; } Vector3 boxExtents = new Vector3(); boxExtents.X = Math.Max(Math.Abs(boxMaximums.X), Math.Abs(boxMinimums.X)); boxExtents.Y = Math.Max(Math.Abs(boxMaximums.Y), Math.Abs(boxMinimums.Y)); boxExtents.Z = Math.Max(Math.Abs(boxMaximums.Z), Math.Abs(boxMinimums.Z)); collision.type = Q3CollisionType.Box; collision.boxMinimums = boxMinimums; collision.boxMaximums = boxMaximums; collision.boxExtents = boxExtents; return Trace(startPosition, endPosition, ref collision); }
public bool BoxInFrustrum(AABB Box) { return BoxInFrustrum(Box.Min.X, Box.Min.Y, Box.Min.Z, Box.Max.X, Box.Max.Y, Box.Max.Z); }