<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RocketSimulation : MonoBehaviour {

    public float dryMass;
    public float wetMass;
    public float windSpeed;
    public float drag;
    public float thrust;

    private float currentMass;
    private float scale;
    private Vector3 originalPos;
    private Vector3 windDirection;
    private Vector3 CoM;
    private Vector3 CoD;
    private Vector3 CoT;

    private bool simulating;

    Rigidbody myRigidbody;

    // Use this for initialization
    void Start () {
        originalPos = this.transform.localPosition;
        windDirection = new Vector3(1f, 0f, 0f);
        CoM = transform.Find("CoM").transform.localPosition;
        CoD = transform.Find("CoD").transform.localPosition;
        CoT = transform.Find("CoT").transform.localPosition;
        myRigidbody = this.gameObject.GetComponent<Rigidbody>();
        OnReset();
    }

    // Update is called once per frame
    private void Update()
    {
    }

    void FixedUpdate () {
        if (simulating)
        {
            // update rigid body (mass)
            if (currentMass > dryMass)
            {
                currentMass -= 0.01f;
                if (currentMass < dryMass) currentMass = dryMass;
            }
            myRigidbody.mass = currentMass;

            // simulate thrust
            if (currentMass > dryMass)
            {
                Vector3 thrustForce = transform.TransformDirection(Vector3.up) * thrust;
                var ct = transform.TransformPoint(CoT);
                myRigidbody.AddForceAtPosition(thrustForce, ct, ForceMode.Force);
            }

            // simulate gravity
            //var cg = transform.TransformPoint(CoM);
            //Vector3 gravity = Vector3.down * currentMass;
            //myRigidbody.AddForceAtPosition(gravity, cg, ForceMode.Force);

            var cp = transform.TransformPoint(CoD);

            // simulate drag
            Vector3 velocity = transform.TransformVector(myRigidbody.velocity);
            float v2 = velocity.sqrMagnitude;
            Vector3 dragForce = -velocity.normalized * v2 * drag / 2.0f;
            myRigidbody.AddForceAtPosition(dragForce, cp, ForceMode.Force);

            // simulate wind
            Vector3 windForce = windDirection.normalized * windSpeed * windSpeed * drag / 2.0f;
            myRigidbody.AddForceAtPosition(windForce, cp, ForceMode.Force);
        }
    }<commit_msg>working on scaled simulation.<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RocketSimulation : MonoBehaviour {

    public float dryMass;
    public float wetMass;
    public float windSpeed;
    public float drag;
    public float thrust;

    private float currentMass;
    private float scale;
    private Vector3 originalPos;
    private Vector3 windDirection;
    private Vector3 CoM;
    private Vector3 CoD;
    private Vector3 CoT;

    private bool simulating;

    Rigidbody myRigidbody;

    // Use this for initialization
    void Start () {
        originalPos = this.transform.localPosition;
        windDirection = new Vector3(1f, 0f, 0f);
        CoM = transform.Find("CoM").transform.localPosition;
        CoD = transform.Find("CoD").transform.localPosition;
        CoT = transform.Find("CoT").transform.localPosition;
        myRigidbody = this.gameObject.GetComponent<Rigidbody>();
        OnReset();
    }

    // Update is called once per frame
    private void Update()
    {
    }

    void FixedUpdate () {
        if (simulating)
        {
            scale = transform.root.transform.localScale.x;
            // update rigid body (mass)
            if (currentMass > dryMass)
            {
                currentMass -= 0.01f;
                if (currentMass < dryMass) currentMass = dryMass;
            }
            //myRigidbody.mass = currentMass;

            // simulate thrust
            if (currentMass > dryMass)
            {
                Vector3 thrustForce = transform.TransformDirection(Vector3.up) * thrust * scale * scale;
                var ct = transform.TransformPoint(CoT);
                myRigidbody.AddForceAtPosition(thrustForce, ct, ForceMode.Force);
            }

            // simulate gravity
            Physics.gravity = Vector3.down * 9.81f * scale * scale;
            //var cg = transform.TransformPoint(CoM);
            //Vector3 gravity = Vector3.down * currentMass;
            //myRigidbody.AddForceAtPosition(gravity, cg, ForceMode.Force);

            var cp = transform.TransformPoint(CoD);

            // simulate drag
            Vector3 velocity = myRigidbody.velocity;
            float v2 = velocity.sqrMagnitude;
            Vector3 dragForce = -velocity.normalized * v2 * scale * scale * drag / 2.0f;
            myRigidbody.AddForceAtPosition(dragForce, cp, ForceMode.Force);

            // simulate wind
            Vector3 windForce = windDirection.normalized * scale * scale * windSpeed * windSpeed * drag / 2.0f;
            myRigidbody.AddForceAtPosition(windForce, cp, ForceMode.Force);
        }
    }
{'fraction_non_alphanumeric': 0.08663558663558664, 'fraction_numerical': 0.01048951048951049, 'mean_word_length': 2.0813883901855177, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773057', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1372, 'n_words': 338}