public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; sky = new Sky(); cam = camBoat; }
public void Draw(Camera cam, GameTime gt, Texture2D reflectionMap) { vb.GraphicsDevice.SetVertexBuffer(vb); effect.Parameters["WVP"].SetValue(local * Matrix.CreateTranslation(cam.Position.X, 0, cam.Position.Z) * cam.View * cam.Projection); effect.Parameters["World"].SetValue(local * Matrix.CreateTranslation(cam.Position.X, 0, cam.Position.Z)); effect.Parameters["CamPos"].SetValue(cam.Position); effect.Parameters["SunDir"].SetValue(Vector3.Normalize(new Vector3(-0.2f, -0.5f, -1))); effect.Parameters["NormMap"].SetValue(normalMap); effect.Parameters["ReflectionMap"].SetValue(reflectionMap); effect.Parameters["T"].SetValue((float)gt.TotalGameTime.TotalSeconds); effect.CurrentTechnique.Passes[0].Apply(); vb.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); }
public void Draw(Camera cam) { sphere.effect.World = Matrix.CreateScale(1000)*Matrix.CreateTranslation(cam.Position.X, -1, cam.Position.Z); sphere.Draw(cam.View, cam.Projection); }
public void Draw(Camera cam) { var device = vb.GraphicsDevice; effect.CurrentTechnique.Passes[0].Apply(); effect.World = local; effect.View = cam.View; effect.Projection = cam.Projection; device.SetVertexBuffer(vb); device.Indices = ib; var oldRS = device.RasterizerState; device.RasterizerState = RasterizerState; foreach(var world in worlds) { effect.World = local * world; effect.CurrentTechnique.Passes[0].Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, vb.VertexCount, 0, ib.IndexCount - 2); } device.RasterizerState = oldRS; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); var ks = Keyboard.GetState(); bool w = false, a = false, s = false, d = false, q = false, e = false, o = false, l = false; if (autoHover) { if (ks.IsKeyDown(Keys.Space)) autoHover = false; } else { if (ks.IsKeyDown(Keys.Space)) autoHover = true; } if(cam == freeCam) { if (ks.IsKeyDown(Keys.Tab)) cam = camBoat; if (ks.IsKeyDown(Keys.W)) cam.Position += cam.Direction; if (ks.IsKeyDown(Keys.S)) cam.Position -= cam.Direction; if (ks.IsKeyDown(Keys.D)) cam.Position += cam.Right; if (ks.IsKeyDown(Keys.A)) cam.Position -= cam.Right; } else { if (ks.IsKeyDown(Keys.Tab)) cam = freeCam; w = ks.IsKeyDown(Keys.W); a = ks.IsKeyDown(Keys.A); s = ks.IsKeyDown(Keys.S); d = ks.IsKeyDown(Keys.D); q = ks.IsKeyDown(Keys.Q); e = ks.IsKeyDown(Keys.E); o = ks.IsKeyDown(Keys.O); l = ks.IsKeyDown(Keys.L); } heli.Step(w,s,a,d,q,e,o,l, autoHover); camBoat.Position = heli.Position - new Vector3(heli.Direction.X, 0, heli.Direction.Z)*10+new Vector3(0,4,0); camBoat.Target = heli.Position + new Vector3(0, 2, 0); //camBoat.Direction = boat.Position; var ms = Mouse.GetState(); var pos = ms.Position; try { Mouse.SetPosition(100, 100); } catch { } var delta = pos - new Point(100, 100); var m = Matrix.CreateRotationY(-delta.X/200f)*Matrix.CreateFromAxisAngle(cam.Right, -delta.Y / 200f); cam.Direction = Vector3.Transform(cam.Direction, m); foreach (var b in helis.Values) b.Step(false, false, false, false, false, false, false, false, false); if (socket.Available > 0) { EndPoint ep = new IPEndPoint(IPAddress.Any, 0); int len = socket.ReceiveFrom(buffer, ref ep); if (!Array.Exists(localAdresses, x => x.Equals( ((IPEndPoint)ep).Address))) { string key = ep.ToString(); Heli b; if (!helis.TryGetValue(key, out b)) helis[key] = b = new Heli(); int p = 1 + b.Deserialize(buffer, 1); } //byte cmd // n byte boat // m byte control //string name // color } if (lastSend + TimeSpan.FromMilliseconds(1000) < gameTime.TotalGameTime) { int packetLength = 0; buffer[0] = 0; packetLength = 1 + heli.Serialize(buffer, 1); buffer[packetLength++] = (byte)( w ? 1 : 0); buffer[packetLength++] = (byte)(a ? 1 : 0); buffer[packetLength++] = (byte)(s ? 1 : 0); buffer[packetLength++] = (byte)(d ? 1 : 0); int len = socket.SendTo(buffer, packetLength, SocketFlags.None, broadcast); lastSend = gameTime.TotalGameTime; } base.Update(gameTime); }
public void Draw(Camera cam) { world = Matrix.CreateWorld(Position, Direction, Up); model.Draw(local*world, cam.View, cam.Projection); }