public void UpdateBullets(GameTime gameTime, NS_Camera.FirstPersonCamera camera, float bulletTime) { bulletModel.CopyAbsoluteBoneTransformsTo(bulletTransforms); bulletWorldMatrix = camera.SpawnWorldMatrix(WEAPON_X_OFFSET, WEAPON_Y_OFFSET, WEAPON_Z_OFFSET * bulletTime, WEAPON_SCALE); }
public void DrawText(bool displayHelp, bool enableParallax, NS_Camera.FirstPersonCamera camera) { StringBuilder buffer = new StringBuilder(); if (displayHelp) { buffer.AppendLine("Move mouse to free look"); buffer.AppendLine(); buffer.AppendLine("Press W and S to move forwards and backwards"); buffer.AppendLine("Press A and D to strafe left and right"); buffer.AppendLine("Press SPACE to jump"); buffer.AppendLine("Press and hold LEFT CTRL to crouch"); buffer.AppendLine("Press and hold LEFT SHIFT to run"); buffer.AppendLine(); buffer.AppendLine("Press M to toggle mouse smoothing"); buffer.AppendLine("Press P to toggle between parallax normal mapping and normal mapping"); buffer.AppendLine("Press NUMPAD +/- to change camera rotation speed"); buffer.AppendLine("Press ALT + ENTER to toggle full screen"); buffer.AppendLine(); buffer.AppendLine("Press H to hide help"); } else { buffer.AppendFormat("FPS: {0}\n", framesPerSecond); buffer.AppendFormat("Technique: {0}\n", (enableParallax ? "Parallax normal mapping" : "Normal mapping")); buffer.AppendFormat("Mouse smoothing: {0}\n\n", (camera.EnableMouseSmoothing ? "on" : "off")); buffer.Append("Camera:\n"); buffer.AppendFormat(" Position: x:{0} y:{1} z:{2}\n", camera.Position.X.ToString("f2"), camera.Position.Y.ToString("f2"), camera.Position.Z.ToString("f2")); buffer.AppendFormat(" Orientation: heading:{0} pitch:{1}\n", camera.HeadingDegrees.ToString("f2"), camera.PitchDegrees.ToString("f2")); buffer.AppendFormat(" Velocity: x:{0} y:{1} z:{2}\n", camera.CurrentVelocity.X.ToString("f2"), camera.CurrentVelocity.Y.ToString("f2"), camera.CurrentVelocity.Z.ToString("f2")); buffer.AppendFormat(" Rotation speed: {0}\n", camera.RotationSpeed.ToString("f2")); buffer.Append("\nPress H to display help"); } spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); Vector2 fontPos; // Initial position for text rendering. fontPos = new Vector2(1.0f, 1.0f); spriteBatch.DrawString(spriteFont, buffer.ToString(), fontPos, Color.Yellow); spriteBatch.End(); }
public void UpdateEffect(bool enableParallax, NS_Camera.FirstPersonCamera camera) { if (enableParallax) effect.CurrentTechnique = effect.Techniques["ParallaxNormalMappingPointLighting"]; else effect.CurrentTechnique = effect.Techniques["NormalMappingPointLighting"]; effect.Parameters["worldMatrix"].SetValue(Matrix.Identity); effect.Parameters["worldInverseTransposeMatrix"].SetValue(Matrix.Identity); effect.Parameters["worldViewProjectionMatrix"].SetValue(camera.ViewMatrix * camera.ProjectionMatrix); effect.Parameters["cameraPos"].SetValue(camera.Position); effect.Parameters["globalAmbient"].SetValue(globalAmbient.ToVector4()); effect.Parameters["scaleBias"].SetValue(scaleBias); effect.Parameters["light"].StructureMembers["dir"].SetValue(light.Direction); effect.Parameters["light"].StructureMembers["pos"].SetValue(light.Position); effect.Parameters["light"].StructureMembers["ambient"].SetValue(light.Ambient.ToVector4()); effect.Parameters["light"].StructureMembers["diffuse"].SetValue(light.Diffuse.ToVector4()); effect.Parameters["light"].StructureMembers["specular"].SetValue(light.Specular.ToVector4()); effect.Parameters["light"].StructureMembers["spotInnerCone"].SetValue(light.SpotInnerConeRadians); effect.Parameters["light"].StructureMembers["spotOuterCone"].SetValue(light.SpotOuterConeRadians); effect.Parameters["light"].StructureMembers["radius"].SetValue(light.Radius); effect.Parameters["material"].StructureMembers["ambient"].SetValue(material.Ambient.ToVector4()); effect.Parameters["material"].StructureMembers["diffuse"].SetValue(material.Diffuse.ToVector4()); effect.Parameters["material"].StructureMembers["emissive"].SetValue(material.Emissive.ToVector4()); effect.Parameters["material"].StructureMembers["specular"].SetValue(material.Specular.ToVector4()); effect.Parameters["material"].StructureMembers["shininess"].SetValue(material.Shininess); }
public void Draw(NS_Camera.FirstPersonCamera camera) { DrawModel(bulletModel, bulletTransforms, bulletWorldMatrix, camera.ViewMatrix, camera.ProjectionMatrix); }
public void ToggleFullScreen(ref GraphicsDeviceManager graphics, NS_Camera.FirstPersonCamera camera, float CAMERA_FOVX, float CAMERA_ZNEAR, float CAMERA_ZFAR) { int newWidth = 0; int newHeight = 0; graphics.IsFullScreen = !graphics.IsFullScreen; if (graphics.IsFullScreen) { newWidth = graphics.GraphicsDevice.DisplayMode.Width; newHeight = graphics.GraphicsDevice.DisplayMode.Height; } else { newWidth = graphics.GraphicsDevice.DisplayMode.Width / 2; newHeight = graphics.GraphicsDevice.DisplayMode.Height / 2; } graphics.PreferredBackBufferWidth = newWidth; graphics.PreferredBackBufferHeight = newHeight; graphics.PreferMultiSampling = true; graphics.ApplyChanges(); float aspectRatio = (float)newWidth / (float)newHeight; camera.Perspective(CAMERA_FOVX, aspectRatio, CAMERA_ZNEAR, CAMERA_ZFAR); }