public void Draw(PerspectiveCamera camera) { foreach (ModelMesh mesh in _model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = Dancer.ModelAdjustment * _worldMatrix; effect.Projection = camera.ProjectionMatrix; effect.View = camera.ViewMatrix; effect.EnableDefaultLighting(); } mesh.Draw(); DancePartyGame.DrawsPerFrame++; } }
/// <summary> /// Draws all the instances specified /// </summary> private void Draw( Matrix[] transformMatrices, Matrix[][] boneMatrices, int totalInstances, PerspectiveCamera camera, Texture2D skin) { _skinnedEffect.Texture = skin; _skinnedEffect.View = camera.ViewMatrix; _skinnedEffect.Projection = camera.ProjectionMatrix; _graphicsDevice.SetVertexBuffer(_instancedVertexBuffer); _graphicsDevice.Indices = _instancedIndexBuffer; for (int i = 0; i < totalInstances; i += _maxInstances) { // How many instances can we fit into this batch? int instanceCount = totalInstances - i; if (instanceCount > _maxInstances) instanceCount = _maxInstances; for (int batchedInstanceIndex = 0; batchedInstanceIndex < instanceCount; batchedInstanceIndex++) { int currentInstance = batchedInstanceIndex + i; for (int boneIndex = 0; boneIndex < boneMatrices[currentInstance].Length; boneIndex++) Utilities.CopyMatrix(ref boneMatrices[currentInstance][boneIndex], ref tempMatrices[batchedInstanceIndex * _originalModel.Bones.Count + boneIndex]); Utilities.CopyMatrix( ref transformMatrices[currentInstance] /*source*/, ref tempMatrices[batchedInstanceIndex * _originalModel.Bones.Count + _originalModel.Bones.Count - 1] /*dest*/); } // Set the especially bones into the effect _skinnedEffect.SetBoneTransforms(tempMatrices); foreach (EffectPass pass in _skinnedEffect.CurrentTechnique.Passes) { pass.Apply(); _graphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, instanceCount * _originalVertexCount, 0, instanceCount * _originalIndexCount / 3); DancePartyGame.DrawsPerFrame++; } } }
/// <summary> /// Draws all the instances of this model. /// </summary> /// <param name="camera"></param> public void DrawInstances(PerspectiveCamera camera, List<AnimatedModelInstance> activeInstances, Texture2D texture) { int numberOfInstances = activeInstances.Count; Matrix[] transforms = new Matrix[numberOfInstances]; Matrix[][] boneTransforms = new Matrix[numberOfInstances][]; for (int i = 0; i < activeInstances.Count; i++) { AnimatedModelInstance modelInstance = activeInstances[i]; Utilities.CopyMatrix(ref modelInstance.Transform, ref transforms[i]); boneTransforms[i] = new Matrix[modelInstance.SkinTransforms.Length]; for(int bone = 0; bone < modelInstance.SkinTransforms.Length; bone++) Utilities.CopyMatrix(ref modelInstance.SkinTransforms[bone], ref boneTransforms[i][bone]); } Draw(transforms, boneTransforms, numberOfInstances, camera, texture); }
public DrunkController(Dancer leadDancer, PerspectiveCamera camera) { _sound = SoundManager.Instance.GetPopSoundEffect(); _camera = camera; _leadDancer = leadDancer; }
public void DrawInstances(PerspectiveCamera camera) { foreach (BatchedAnimatedModelContainer modelContainer in _batchedAnimatedModelContainers) modelContainer.DrawInstances(camera); }
public void DrawInstances(PerspectiveCamera camera) { BatchedModel.DrawInstances(camera, ActiveInstances, Texture); }
public CameraController(PerspectiveCamera camera) { _camera = camera; }
private void DrawDanceFloor(PerspectiveCamera camera) { foreach (ModelMesh mesh in _danceFloor.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = Dancer.ModelAdjustment; effect.Projection = camera.ProjectionMatrix; effect.View = camera.ViewMatrix; effect.EnableDefaultLighting(); } mesh.Draw(); } }
/// <summary> /// Loads all the content for this State. /// You should show a loading screen here, it may take a while. /// </summary> public void LoadContent(LoadStateReporter loadStateReporter) { _isLoaded = false; loadStateReporter.CurrentStatus = "Loading Models"; BatchedModelManager.Instance.LoadContent(_contentManager, _graphicsDevice); BatchedModelManager.Instance.ClearInstances(); loadStateReporter.CurrentStatus = "Loading Animation"; AnimationManager.Instance.LoadContent(); loadStateReporter.CurrentStatus = "Creating CongaLine"; PerspectiveCamera camera = new PerspectiveCamera(_graphicsDevice); Dancer leader = DancerFactory.Instance.GetRandomDancer(); leader.SetDancerBehavior(new LeadDancerBehavior(leader)); _congaLine = new CongaLine(leader, camera); _cameraController = new CameraController(camera); _cameraController.SetCameraBehavior(new BehindViewBehavior(camera, _congaLine.LeadDancer)); _accelerometer.Start(); loadStateReporter.CurrentStatus = "Requesting DJ to play a song"; _music = SoundManager.Instance.GetRandomSong(); _loseSound = SoundManager.Instance.GetRecordScratchInstance(); _winSound = SoundManager.Instance.GetApplauseSoundEffect(); _mainHud = new MainGameHud(_graphicsDevice, _spriteBatch, FontManager.Instance.BangersMedium); loadStateReporter.CurrentStatus = "Loading DanceRoom"; _danceFloor = _contentManager.Load<Model>("Models\\DanceRoom"); _drinkEmitter.LoadContent(); //Instance our first Render Target to the same size as the back buffer. currentFrame = new RenderTarget2D(_graphicsDevice, _graphicsDevice.PresentationParameters.BackBufferWidth , _graphicsDevice.PresentationParameters.BackBufferHeight, false, _graphicsDevice.DisplayMode.Format, DepthFormat.Depth24); drunkFrame = new RenderTarget2D(_graphicsDevice, currentFrame.Width / 4, currentFrame.Height / 4, false, _graphicsDevice.DisplayMode.Format, DepthFormat.None); _score = new ScoreComponent(); GC.Collect(); _isLoaded = true; _beginGame = true; }
public CongaLine(Dancer leadDancer, PerspectiveCamera camera) { _dancers = new List<Dancer>(); _dancers.Add(leadDancer); _drunkController = new DrunkController(leadDancer, camera); }