예제 #1
0
    private void instantiateNewDynamicShip(dynamicAIS i)
    {
        //transform.position = new Vector3(transform.position.x + 0.001f, transform.position.y, transform.position.z);

        /*foreach (GameObjectt i in SpawnBoats.ships)
         * {
         *  ships.Add(newShip);
         * }
         */
    }
예제 #2
0
    private void instantiateNewDynamicShip(dynamicAIS i)
    {
        lon = i.Longitude;
        lat = i.Latitude;
        //Instantiate ship (cube) and get a ref to it in newObj
        //float x = (float)(460 / 360.0) * (180 + float.Parse(i.Longtitude));
        //float y = (int)((450 / 180.0) * (90 - float.Parse(i.Latitude)));
        //pos = new Vector3(float.Parse(i.Longtitude), 1, (float.Parse(i.Latitude)));

        //lon = (100000) * (180 + lat) / 360;
        //lat = (100000) * (90 - lon) / 180;
        //Debug.Log("LONG: " + i.Longitude + " LAT: " + i.Latitude);
        lat = lat * radians;
        lon = lon * radians;

        double x = 6371 * (Math.Cos((float)lat) * Math.Cos((float)lon));

        x = (x * 20) + 101200;
        double y = 6371 * (Math.Cos((float)lat) * Math.Sin((float)lon));

        y = (y * 20) - 51000;
        //Debug.Log("X: " + x + " Y: " + y);

        pos = new Vector3((float)x, (float)0, (float)y);

        //pos = new Vector3(lon, 1 , lat);
        newShip = (GameObject)Instantiate(obj, pos, rotation);

        newShip.name = i.MMSI.ToString();
        newShip.transform.localScale += new Vector3(1, 1, 1);

        rb = newShip.GetComponent <Rigidbody>();
        //rb = transform.forward * 20;
        Vector3 r        = new Vector3(0.0f, i.True_heading, 0.0f);
        Vector3 velocity = new Vector3(0.0f, 0.0f, i.SOG.ToFloat());

        newShip.transform.eulerAngles = r;
        rb.AddForce(velocity);

        //rb.rotation(0, i.ROT, 0);

        //rb.velocity = transform.forward * i.SOG.ToFloat();
        rb.velocity = r * (i.SOG.ToFloat());

        //rb.transform.Translate(transform.TransformDirection(r));
        //rb.transform.TransformDirection(r);
        //
        //rb.AddForce(transform.forward * i.SOG.ToFloat() * Time.deltaTime);
        //rb.velocity = transform.InverseTransformDirection(Vector3.forward) * i.SOG.ToFloat();

        //newShip.transform.position += -transform.forward * Time.deltaTime;

        //Instantiate text and get a red to it in newTextObj
        //newTextObj = (GameObject)Instantiate(textObj, pos + offset, transform.rotation);
        newTextObj = (GameObject)Instantiate(textObj, pos + new Vector3(0, 5, 0), transform.rotation);

        //sets textObj as child of generated ship object
        newTextObj.transform.parent = newShip.transform;


        //tc = newTextObj.GetComponent<TextController>();
        //tc.target = newShip;
        //tc.offset = offset;

        //change text code here
        //newTextObj.GetComponent<TextMesh>().text = names[index];
        newTextObj.GetComponent <TextMesh>().fontSize = 80;
        newTextObj.GetComponent <TextMesh>().text     = i.MMSI.ToString();


        //textObjects.Add(tc);
        ships.Add(newShip);
    }