コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        car = new BoxsterS(x0, y0, z0, vx0, vy0, vz0, t, density);

        car.S = 0.0;       //  time set to zero
        car.SetQ(0.0, 0);  //  vx0 set to zero
        car.SetQ(0.0, 1);  //  x0 set to zero
        car.OmegaE     = 1000.0;
        car.GearNumber = 1;

        car.Mode = "crusing";
    }
コード例 #2
0
 private void Start()
 {
     x0      = 0.0;
     y0      = 0.0;
     z0      = 0.0;
     vx0     = 0.0;
     vy0     = 0.0;
     vz0     = 0.0;
     time    = 0.0;
     density = 1.2;
     car     = new BoxsterS(x0, y0, z0, vx0, vy0, vz0, time, density);
     carRB   = this.transform.GetComponent <Rigidbody>();
 }
コード例 #3
0
        public CarSimulator()
        {
            //  Create a BoxsterS object with default values to
            //  initialize the display.
            double x0      = 0.0;
            double y0      = 0.0;
            double z0      = 0.0;
            double vx0     = 0.0;
            double vy0     = 0.0;
            double vz0     = 0.0;
            double time    = 0.0;
            double density = 1.2;

            car = new BoxsterS(x0, y0, z0, vx0, vy0, vz0, time, density);

            //  Set up images
            carIcon   = Image.FromFile("C:/Users/hhj32/Desktop/GamePhysics_RealisticCarPhysics/CS_Car_Simulator/porscheCartoon.jpg");
            carWidth  = carIcon.Width;
            carHeight = carIcon.Height;

            //  Create a Timer object that will be used
            //  to slow the action down.
            gameTimer          = new Timer();
            gameTimer.Interval = 50;  //  delay in milliseconds.
            gameTimer.Tick    += new EventHandler(ActionPerformed);

            //  Initialize the x-locations of the rectangular markers
            rectangleOneX = 0.0;
            rectangleTwoX = 200.0;

            //  Create some Labels
            velocityLabel       = new Label();
            velocityLabel.Text  = "Velocity (km/hr)";
            velocityLabel.Font  = new Font(velocityLabel.Font, FontStyle.Bold);
            velocityLabel.Top   = 300;
            velocityLabel.Left  = 280;
            velocityLabel.Width = 120;

            rpmLabel       = new Label();
            rpmLabel.Text  = "Engine rpm";
            rpmLabel.Font  = new Font(rpmLabel.Font, FontStyle.Bold);
            rpmLabel.Top   = 330;
            rpmLabel.Left  = 280;
            rpmLabel.Width = 80;

            gearLabel       = new Label();
            gearLabel.Text  = "Gear";
            gearLabel.Font  = new Font(gearLabel.Font, FontStyle.Bold);
            gearLabel.Top   = 360;
            gearLabel.Left  = 280;
            gearLabel.Width = 50;

            distanceLabel       = new Label();
            distanceLabel.Text  = "Distance traveled (m)";
            distanceLabel.Font  = new Font(distanceLabel.Font, FontStyle.Bold);
            distanceLabel.Top   = 390;
            distanceLabel.Left  = 280;
            distanceLabel.Width = 120;

            timeLabel       = new Label();
            timeLabel.Text  = "Time (s)";
            timeLabel.Font  = new Font(timeLabel.Font, FontStyle.Bold);
            timeLabel.Top   = 420;
            timeLabel.Left  = 280;
            timeLabel.Width = 50;

            //  Create TextBox objects to display the inputs.
            velocityTextBox          = new TextBox();
            velocityTextBox.Width    = 50;
            velocityTextBox.Text     = "0.0";
            velocityTextBox.AutoSize = true;
            velocityTextBox.Top      = velocityLabel.Top;
            velocityTextBox.Left     = 420;

            rpmTextBox          = new TextBox();
            rpmTextBox.Width    = 50;
            rpmTextBox.Text     = "1000.0";
            rpmTextBox.AutoSize = true;
            rpmTextBox.Top      = rpmLabel.Top;
            rpmTextBox.Left     = 420;

            gearTextBox          = new TextBox();
            gearTextBox.Width    = 50;
            gearTextBox.Text     = "1";
            gearTextBox.AutoSize = true;
            gearTextBox.Top      = gearLabel.Top;
            gearTextBox.Left     = 420;

            distanceTextBox          = new TextBox();
            distanceTextBox.Width    = 60;
            distanceTextBox.Text     = "0.0";
            distanceTextBox.AutoSize = true;
            distanceTextBox.Top      = distanceLabel.Top;
            distanceTextBox.Left     = 420;

            timeTextBox          = new TextBox();
            timeTextBox.Width    = 60;
            timeTextBox.Text     = "0.0";
            timeTextBox.AutoSize = true;
            timeTextBox.Top      = timeLabel.Top;
            timeTextBox.Left     = 420;

            messageTextBox          = new TextBox();
            messageTextBox.Width    = 200;
            messageTextBox.Text     = "";
            messageTextBox.AutoSize = true;
            messageTextBox.Top      = 500;
            messageTextBox.Left     = 110;
            messageTextBox.ReadOnly = true;

            //  Create RadioButton objects
            int buttonHeight = 20;
            int buttonWidth  = 50;
            int buttonLeft   = 30;

            accelButton         = new RadioButton();
            accelButton.Text    = "Accelerate";
            accelButton.Height  = buttonHeight;
            accelButton.Width   = buttonWidth + 40;
            accelButton.Top     = 250;
            accelButton.Left    = buttonLeft;
            accelButton.Checked = true;

            cruiseButton        = new RadioButton();
            cruiseButton.Text   = "Cruise";
            cruiseButton.Height = buttonHeight;
            cruiseButton.Width  = buttonWidth + 40;
            cruiseButton.Top    = 280;
            cruiseButton.Left   = buttonLeft;

            brakeButton        = new RadioButton();
            brakeButton.Text   = "Brake";
            brakeButton.Height = buttonHeight;
            brakeButton.Width  = buttonWidth + 40;
            brakeButton.Top    = 310;
            brakeButton.Left   = buttonLeft;

            //  Create Button objects
            buttonHeight = 20;
            buttonWidth  = 45;
            buttonLeft   = 20;

            startButton        = new Button();
            startButton.Text   = "Start";
            startButton.Height = buttonHeight;
            startButton.Width  = buttonWidth;
            startButton.Top    = 340;
            startButton.Left   = buttonLeft;
            startButton.Click += new EventHandler(StartButtonClicked);

            shiftUpButton        = new Button();
            shiftUpButton.Text   = "Shift Up";
            shiftUpButton.Height = buttonHeight;
            shiftUpButton.Width  = buttonWidth + 30;
            shiftUpButton.Top    = 370;
            shiftUpButton.Left   = buttonLeft;
            shiftUpButton.Click += new EventHandler(ShiftUpButtonClicked);

            shiftDownButton        = new Button();
            shiftDownButton.Text   = "Shift Down";
            shiftDownButton.Height = buttonHeight;
            shiftDownButton.Width  = buttonWidth + 30;
            shiftDownButton.Top    = 400;
            shiftDownButton.Left   = buttonLeft;
            shiftDownButton.Click += new EventHandler(ShiftDownButtonClicked);

            stopButton        = new Button();
            stopButton.Text   = "Stop";
            stopButton.Height = buttonHeight;
            stopButton.Width  = buttonWidth;
            stopButton.Top    = 430;
            stopButton.Left   = buttonLeft;
            stopButton.Click += new EventHandler(StopButtonClicked);

            resetButton        = new Button();
            resetButton.Text   = "Reset";
            resetButton.Height = buttonHeight;
            resetButton.Width  = buttonWidth;
            resetButton.Top    = 460;
            resetButton.Left   = buttonLeft;
            resetButton.Click += new EventHandler(ResetButtonClicked);

            //  Create a drawing panel.
            drawingPanel             = new Panel();
            drawingPanel.Width       = 401;
            drawingPanel.Height      = 151;
            drawingPanel.Left        = 50;
            drawingPanel.Top         = 20;
            drawingPanel.BorderStyle = BorderStyle.FixedSingle;

            //  Add the GUI components to the Form
            this.Controls.Add(velocityLabel);
            this.Controls.Add(rpmLabel);
            this.Controls.Add(gearLabel);
            this.Controls.Add(distanceLabel);
            this.Controls.Add(timeLabel);
            this.Controls.Add(velocityTextBox);
            this.Controls.Add(rpmTextBox);
            this.Controls.Add(gearTextBox);
            this.Controls.Add(distanceTextBox);
            this.Controls.Add(timeTextBox);
            this.Controls.Add(messageTextBox);
            this.Controls.Add(startButton);
            this.Controls.Add(stopButton);
            this.Controls.Add(shiftUpButton);
            this.Controls.Add(shiftDownButton);
            this.Controls.Add(resetButton);
            this.Controls.Add(accelButton);
            this.Controls.Add(cruiseButton);
            this.Controls.Add(brakeButton);
            this.Controls.Add(drawingPanel);

            // Set the size and title of the form
            this.Width  = 500;
            this.Height = 550;
            this.Text   = "Car Simulator";

            //  Center the form on the screen and make
            //  it visible.
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Visible       = true;

            //  Update the GUI display
            UpdateDisplay();
        }