/// <summary> /// This is my chance to draw any objects I may be creating /// </summary> public void Draw() { if (_mode != AddingMode.Inactive && _isMouseDown && _drawingBall != null) { // They are in the middle of dragging a ball into existance. Draw it in an intermidiate form switch (_mode) { case AddingMode.AddBall: _renderer.DrawBall((Ball)_drawingBall, ObjectRenderer.DrawMode.Building, _newBallProps.CollisionStyle, false); break; case AddingMode.AddSolidBall: _renderer.DrawSolidBall((SolidBall)_drawingBall, ObjectRenderer.DrawMode.Building, _newBallProps.CollisionStyle, false); break; case AddingMode.AddRigidBody: _renderer.DrawRigidBody((RigidBody)_drawingBall, ObjectRenderer.DrawMode.Building, _newBallProps.CollisionStyle, false); break; default: throw new ApplicationException("Unknown AddingMode: " + _mode.ToString()); } } // Nothing else to draw }
private void DrawScene(RadarBlip[] blips) { pictureBox1.ZoomFit(); pictureBox1.PrepareForNewDraw(); // _personalRenderer.Viewer is picturebox1 // Draw all the blips foreach (RadarBlip blip in blips) { // Draw the blip if (blip.Sphere is RigidBody) { _personalRenderer.DrawRigidBody((RigidBody)blip.Sphere, ObjectRenderer.DrawMode.Standard, blip.CollisionStyle, false); } else if (blip.Sphere is SolidBall) { _personalRenderer.DrawSolidBall((SolidBall)blip.Sphere, ObjectRenderer.DrawMode.Standard, blip.CollisionStyle, false); } else if (blip.Sphere is Ball) { _personalRenderer.DrawBall((Ball)blip.Sphere, ObjectRenderer.DrawMode.Standard, blip.CollisionStyle, false); } else { throw new ApplicationException("Unknown Blip"); } } pictureBox1.FinishedDrawing(); }
// Timer private void timer1_Tick(object sender, EventArgs e) { Collision[] collisions = null; if (btnRunning.Checked) { #region Physics _map.PrepareForNewTimerCycle(); if (_gravMouse.Active) { _gravMouse.Timer(); } _shipController.Timer(ELAPSEDTIME); _gravController.Timer(); collisions = _map.Timer(ELAPSEDTIME); if (_selector.Active) { _selector.TimerTick(ELAPSEDTIME); } #endregion } #region Examine Collisions if (collisions != null) { foreach (Collision collision in collisions) { #region Check Temps bool wasTemp = false; if (_tempObjects.Contains(collision.Blip1.Token)) { _tempObjects.Remove(collision.Blip1.Token); _map.Remove(collision.Blip1.Token); wasTemp = true; } if (_tempObjects.Contains(collision.Blip2.Token)) { _tempObjects.Remove(collision.Blip2.Token); _map.Remove(collision.Blip2.Token); wasTemp = true; } if (wasTemp) { continue; } #endregion if (_ignoreTokens.Contains(collision.Blip1.Token) || _ignoreTokens.Contains(collision.Blip2.Token)) { continue; } if (collision.Blip1 is Projectile && !(collision.Blip2 is Projectile)) { HurtBlip((Projectile)collision.Blip1, collision.Blip2); } else if (collision.Blip2 is Projectile && !(collision.Blip1 is Projectile)) { HurtBlip((Projectile)collision.Blip2, collision.Blip1); } } } #endregion #region Reset Z _zeroResetCntr++; if (_zeroResetCntr % 100000 == 0) { _zeroResetCntr = 0; foreach (RadarBlip blip in _map.GetAllBlips()) { blip.Sphere.Position.Z = 0; if (blip is BallBlip) { if (((BallBlip)blip).Ball.Velocity.Z != 0d) { MessageBox.Show("not zero velocity"); } ((BallBlip)blip).Ball.Velocity.Z = 0; } } } #endregion #region Draw pictureBox1.PrepareForNewDraw(); if (_gravMouse.Active) { _gravMouse.Draw(); } RadarBlip[] blips = _map.GetAllBlips(); // Draw all the blips for (int blipCntr = 0; blipCntr < blips.Length; blipCntr++) { if (_ignoreTokens.Contains(blips[blipCntr].Token)) { continue; } // Ask the selecter if this is selected ObjectRenderer.DrawMode drawMode = ObjectRenderer.DrawMode.Standard; if (_selector.IsSelected(blips[blipCntr].Token)) { drawMode = ObjectRenderer.DrawMode.Selected; } // See if it should be displayed as standard CollisionStyle collisionStyle = blips[blipCntr].CollisionStyle; if (_selector.TempStationaryObjects.Contains(blips[blipCntr].Token)) { collisionStyle = CollisionStyle.Standard; } // Draw the blip if (blips[blipCntr] is Projectile) { _renderer.DrawProjectile((Projectile)blips[blipCntr], drawMode, false); } else if (blips[blipCntr].Sphere is RigidBody) { _renderer.DrawRigidBody((RigidBody)blips[blipCntr].Sphere, drawMode, collisionStyle, false); } else if (blips[blipCntr].Sphere is SolidBall) { _renderer.DrawSolidBall((SolidBall)blips[blipCntr].Sphere, drawMode, collisionStyle, false); } else if (blips[blipCntr].Sphere is Ball) { _renderer.DrawBall((Ball)blips[blipCntr].Sphere, drawMode, collisionStyle, false); } else { MessageBox.Show("Unknown blip", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } _shipController.Draw(); // Let the active adder/selecter have a chance to draw if (_ballAdder.Mode != BallAdder.AddingMode.Inactive) { _ballAdder.Draw(); } else if (_selector.Active) { _selector.Draw(); } pictureBox1.FinishedDrawing(); #endregion }