Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        /// <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
        }
Esempio n. 3
0
        public void Draw()
        {
            if ((_isShiftPressed || _isCtrlPressed) && _myClipboard.Count > 0)
            {
                double opacity = GetPastingBallsOpacity();

                if (opacity > 0d)
                {
                    #region Draw Pasting Balls

                    Ball tempBall = null;

                    foreach (BallBlip blip in _myClipboard)
                    {
                        // Clone the ball
                        tempBall = blip.Ball.CloneBall();

                        // Figure out where to place the pasted object
                        MyVector newPosition = tempBall.Position - _clipboardPositionCenter;
                        newPosition.Add(_curMousePoint);
                        tempBall.Position.StoreNewValues(newPosition);

                        // Draw it
                        if (tempBall is SolidBall)
                        {
                            _renderer.DrawSolidBall((SolidBall)tempBall, ObjectRenderer.DrawMode.Building, blip.CollisionStyle, false, opacity);
                        }
                        else
                        {
                            _renderer.DrawBall(tempBall, ObjectRenderer.DrawMode.Building, blip.CollisionStyle, false, opacity);
                        }
                    }

                    #endregion
                }
            }

            if (_isMouseDown == MouseButtonDown.Left && _mode == SelectionMode.Rectangle)
            {
                #region Draw Rectangle

                MyVector topLeft, bottomRight;
                GetProperCorners(out topLeft, out bottomRight, _mouseDownPoint, _curMousePoint);

                _picturebox.DrawRectangle(Color.Silver, DashStyle.Dash, 1d, topLeft, bottomRight);

                #endregion
            }
            else if (_isMouseDown == MouseButtonDown.Right)
            {
                // Draw Velocity
                _picturebox.DrawLine(Color.Chartreuse, 12d, _mouseDownPoint, _curMousePoint);
            }

            //TODO:  draw the angular velocity
        }
Esempio n. 4
0
        // 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
        }