devNotes 5-17-16 particle system positioning, world space and ps threading

poper

dfghfghfh-7

 

using UnityEngine;
using System.Collections;
using ProceduralToolkit;
using System.Collections.Generic;
using System.IO;
using UnityEngine.UI;


public class ArgosMoon : MonoBehaviour
{
    //StreamWriter sWrite;

    public float radius = 1f;
    public int longitudeSegments = 64;
    public int latitudeSegments = 64;

    //public Slider angVelSlider;
    //public Text avSlideVal;
    //float angularVelDegsPerSec = 0f;

    //public Text DBG_Text;

    public class H_Element
    {
        public MeshDraft mdH = new MeshDraft();
        public float timer;
        public int[] neighborLoc = new int[6];
        public int myIndex;

        public Vector3 GetCenter()
        {
            Vector3 vc = mdH.vertices[0] + mdH.vertices[1] + mdH.vertices[2] + mdH.vertices[3];
            return vc / 4f;
        }

        public Quaternion GetQuat()
        {
            Vector3 vFwd = GetCenter().normalized;
            Vector3 vUp = (mdH.vertices[0] - mdH.vertices[1]).normalized;
            return Quaternion.LookRotation(vFwd, vUp);
        }
    }

    public class Quad_Element
    {
        public MeshDraft mdQuad = new MeshDraft();
        public H_Element[] H = new H_Element[4];
        public int[] H_idx = new int[4]; //Hex locations
        public int myIndex;
    }

    public List<Quad_Element> LLQuads = new List<Quad_Element>();
    public List<H_Element> HexQuads = new List<H_Element>();

    MeshDraft meshDraft_Sphere = new MeshDraft();

    private void Awake()
    {
        //sWrite = new StreamWriter("Argos_Topology.txt");

        meshDraft_Sphere = new MeshDraft();
        meshDraft_Sphere = MeshDraft.Sphere(radius, longitudeSegments, latitudeSegments);
        GetComponent<MeshFilter>().mesh = meshDraft_Sphere.ToMesh();

        //Build_LLQuad_List();
        //Build_HexQuad_List();
        //LinkLists();

        transform.RotateAround(transform.position, transform.forward, 0f);
    }

    void OnApplicationQuit()
    {
        //sWrite.Close();
    }

    public void OnSliderChanged()
    {
        //angularVelDegsPerSec  = angVelSlider.value;
        //avSlideVal.text = angularVelDegsPerSec.ToString("F0") + " dps";
    }

    private void Update()
    {
        //transform.RotateAround(transform.position, transform.up, angularVelDegsPerSec * Time.deltaTime);
    }

    public Vector2 getLatLong(Vector3 point)
    {
        float fLat, fLong;

        fLong = Mathf.Atan2(point.x, point.z);
        if (fLong < 0.0f)
        {
            fLong = 2f * Mathf.PI + fLong;
        }
        fLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x * point.x + point.z * point.z));
        return new Vector2(fLat, fLong);
    }

    public int getHexIdx(Vector3 point)//error code means point outside of 1% tolerance
    {
        int qIdx = getLLQuadIdx(point);

        if (qIdx == -1) return -1; //point outside of 1% radius tolerance 

        //DBG_Text.text = "qIdx = " + qIdx.ToString() + "   H0 = " + LLQuads[qIdx].H_idx[0].ToString() + " H1 = " + LLQuads[qIdx].H_idx[1].ToString() + " H2 = " + LLQuads[qIdx].H_idx[2].ToString() + " H3 = " + LLQuads[qIdx].H_idx[3].ToString();

        Vector3 v0 = LLQuads[qIdx].mdQuad.vertices[0];
        Vector3 v1 = LLQuads[qIdx].mdQuad.vertices[1];
        Vector3 v2 = LLQuads[qIdx].mdQuad.vertices[2];
        Vector3 v3 = LLQuads[qIdx].mdQuad.vertices[3];

        Vector3 vXn = v2 - v0; float magX = vXn.magnitude;  vXn.Normalize();
        Vector3 vYn = v1 - v0; float magY = vYn.magnitude; vYn.Normalize();

        Vector3 vP = point - v0;
        //float magP = vP.magnitude;

        if (Vector3.Dot(vXn, vP) < (1f / 6f) * magX) return LLQuads[qIdx].H_idx[0];

        if (Vector3.Dot(vXn, vP) > (5f / 6f) * magX) return LLQuads[qIdx].H_idx[3];

        if (Vector3.Dot(vXn, vP) > ((1f / 3f) * magX) && Vector3.Dot(vXn, vP) < ((2f / 3f) * magX))
        {
            if (Vector3.Dot(vYn, vP) < (1f / 2f) * magY) return LLQuads[qIdx].H_idx[1];
            else return LLQuads[qIdx].H_idx[2];
        }

        Vector3 A = v0 + (1f / 6f) * vXn * magX;
        Vector3 B = v0 + (1f / 3f) * vXn * magX + (1f/2f) * vYn * magY;
        Vector3 C = v1 + (1f / 6f) * vXn * magX; 
        Vector3 D = v2 - (1f / 6f) * vXn * magX; 
        Vector3 E = v2 - (1f / 3f) * vXn * magX + (1f / 2f) * vYn * magY;
        Vector3 F = v3 - (1f / 6f) * vXn * magX; 

        Vector3 APos = point - A;
        Vector3 AB = B - A;

        Vector3 CPos = point - C;
        Vector3 CB = B - C;

        Vector3 vFwd = point.normalized;

        //float yDot = Vector3.Dot(vYn, vP);
        //float halfMag = (1f / 2f) * magY;
        //float outDot = Vector3.Dot(Vector3.Cross(DPos, DE), vFwd);
        //DBG_Text.text = "qIdx = " + qIdx.ToString() + "   H0 = " + LLQuads[qIdx].H_idx[0].ToString() + " H1 = " + LLQuads[qIdx].H_idx[1].ToString() + " H2 = " + LLQuads[qIdx].H_idx[2].ToString() + " H3 = " + LLQuads[qIdx].H_idx[3].ToString();
        //DBG_Text.text = "yDot = " + yDot.ToString("F4") + "   (1f/2f)* magY " + halfMag.ToString("F4") + " outDot = " + outDot.ToString("F4") + " H2 = " + LLQuads[qIdx].H_idx[2].ToString() + " H3 = " + LLQuads[qIdx].H_idx[3].ToString();

        if (Vector3.Dot(vXn, vP) > (1f/6f)*magX && Vector3.Dot(vXn, vP) < (1f/3f)*magX)
        {
            if (Vector3.Dot(vYn, vP) < (1f/2f)* magY)
            {
                if (Vector3.Dot(Vector3.Cross(APos, AB), vFwd) > 0) return LLQuads[qIdx].H_idx[0];
                return LLQuads[qIdx].H_idx[1];
            }
            else
            {
                if (Vector3.Dot(Vector3.Cross(CPos, CB), vFwd) < 0) return LLQuads[qIdx].H_idx[0];
                return LLQuads[qIdx].H_idx[2];
            }
        }

        Vector3 DPos = point - D;
        Vector3 DE = E - D;

        Vector3 FPos = point - F;
        Vector3 FE = E - F;       

        if (Vector3.Dot(vXn, vP) > (2f/3f) * magX && Vector3.Dot(vXn, vP) < (5f/6f) * magX)
        {
            if (Vector3.Dot(vYn, vP) < (1f/2f)*magY)
            {
                if(Vector3.Dot(Vector3.Cross(DPos, DE), vFwd) > 0) return LLQuads[qIdx].H_idx[1];
                return LLQuads[qIdx].H_idx[3];
            }
            else
            {
                if (Vector3.Dot(Vector3.Cross(FPos, FE), vFwd) > 0) return LLQuads[qIdx].H_idx[3];
                return LLQuads[qIdx].H_idx[2];
            }
        }
        return -1;
    }

 

 

dome_grid5

 

moon-surface1k

Selden’s Gallery of Celestia Pictures, Part 3: Moon by Prospector

fghjghfj3

 

 

opop

 

958699eb-e49e-477a-a4bb-24e28c4cbf40_scaled