Exemple #1
0
    /// <summary>
    /// Sets the triangles from quad list which has been extracted from ReadPolyQuad method.
    /// </summary>
    void SetTrianglesFromQuad(ObjectProp objectProp)
    {
        Debug.Log("Setting up triangle from quad list");
        int i = 0;
        int a, b;

        a = b = 0;
        foreach (int ind in objectProp.indices)
        {
            if (i == 0)
            {
                a = ind;
                objectProp.triangles.Add(ind);
                i++;
            }
            else if (i == 1)
            {
                objectProp.triangles.Add(ind);
                i++;
            }
            else if (i == 2)
            {
                b = ind;
                objectProp.triangles.Add(ind);
                i++;
            }
            else
            {
                objectProp.triangles.Add(a);
                objectProp.triangles.Add(ind);
                objectProp.triangles.Add(b);
                i = 0;
            }
        }
    }
Exemple #2
0
        public static void Main(string[] args)
        {
            double     time     = 3.0;
            double     init     = 0.0;
            double     final    = 9.0;
            Velocity1D velocity = new Velocity1D();
            double     vel      = velocity.getInstantVelocity(init, final, time);

            Console.WriteLine("velocity:{0}m/s", vel);

            Point p1 = new Point(1, 2);

            Console.WriteLine("p1.R:{0}", p1.R);
            Point p2 = new Point(4, 4);

            Console.WriteLine("p2.R:{0}", p2.R);
            int result = p1.CompareTo(p2);

            Console.WriteLine("result:{0}", result);

            List <Point> pointList = new List <Point>();

            pointList.Add(p1);
            pointList.Add(p2);
            pointList.Sort();
            foreach (var point in pointList)
            {
                Console.WriteLine(point);
            }
            ObjectProp obj = new ObjectProp(100, 40);

            Console.WriteLine("mass: {0}, volume:{1}, density:{2}", obj.Mass, obj.Volume, obj.Density);
        }
Exemple #3
0
 public void Remove(ObjectProp value)
 {
     _state &= ~value;
 }
Exemple #4
0
 public void Add(ObjectProp value)
 {
     _state |= value;
 }
Exemple #5
0
 public bool Is(ObjectProp value)
 {
     return(_state == value);
 }
Exemple #6
0
 public bool Has(ObjectProp value)
 {
     return((_state & value) == value);
 }
Exemple #7
0
    /// <summary>
    /// Reads the normals.
    /// </summary>
    /// <param name="sr">Stream reader that has loaded up the file.</param>
    /// <param name="line">Line that contains all the values.</param>
    void ReadNormals(StreamReader sr, string line, ObjectProp objectProp)
    {
        string  snum = "";
        int     num;
        Vector3 currNorm;
        Double  x, y, z;

        x = y = z = 0;
        bool readX = true, readY = false, readZ = false;

        foreach (char c in line)
        {
            if (Char.IsDigit(c) || c == '.' || c == 'e' || c == 'E' || c == '-')
            {
                snum += c.ToString();
            }
            //Debug.Log (c);
            if (c == ',')
            {
                if (readX)
                {
                    x     = double.Parse(snum);
                    readX = false;
                    readY = true;
                    //Debug.Log (x);
                }
                else if (readY)
                {
                    y     = double.Parse(snum);
                    readY = false;
                    readZ = true;
                    //Debug.Log (y);
                }
                else
                {
                    z        = double.Parse(snum);
                    currNorm = new Vector3((float)x, (float)y, (float)z);
                    //Debug.Log (currVert);
                    objectProp.normals.Add(currNorm);
                    readZ = false;
                    readX = true;
                    //Debug.Log (z);
                    x = y = z = 0;
                }
                //Debug.Log (snum+"_____"+c.ToString());
                snum = "";
            }
            else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
            {
                z        = double.Parse(snum);
                currNorm = new Vector3((float)x, (float)y, (float)z);
                //Debug.Log (currVert);
                objectProp.normals.Add(currNorm);
                readX = true;
                x     = y = z = 0;
                snum  = "";
            }
            else if (c == '}')
            {
                break;
            }
        }

        if (readZ)
        {
            z        = double.Parse(snum);
            currNorm = new Vector3((float)x, (float)y, (float)z);
            //Debug.Log (currVert);
            objectProp.normals.Add(currNorm);
            readX = true;
            x     = y = z = 0;
            snum  = "";
        }

        Debug.Log(objectProp.normals.Count.ToString() + " normals added");
    }
Exemple #8
0
    /// <summary>
    /// Reads the poly quad from the ASCII file.
    /// </summary>
    /// <param name="sr">Stream reader that has loaded up the file.</param>
    /// <param name="line">the exact line that contains all the values.</param>
    void ReadPolyQuad(StreamReader sr, string line, ObjectProp objectProp)
    {
        string snum = "";
        int    num;
        int    index;
        bool   read = true;

        foreach (char c in line)
        {
            if (Char.IsDigit(c) || c == '-')
            {
                snum += c.ToString();
            }
            //Debug.Log (c);
            if (c == ',')
            {
                index = int.Parse(snum);
                if (index < 0)
                {
                    index = index * (-1) - 1;
                }
                objectProp.indices.Add(index);
                //Debug.Log (index);
                //Debug.Log (snum+"_____"+c.ToString());
                snum = "";
            }
            else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
            {
                index = int.Parse(snum);
                //FBX SPECIFIC WAY OF DEFINING END OF QUAD/POLY
                if (index < 0)
                {
                    index = index * (-1) - 1;
                }
                //Debug.Log (index);
                objectProp.indices.Add(index);
                snum = "";
            }
            else if (c == '}')
            {
                break;
            }
        }

        if (snum != "")
        {
            index = int.Parse(snum);
            if (index < 0)
            {
                index = index * (-1) - 1;
            }
            //Debug.Log (index);
            objectProp.indices.Add(index);
            snum = "";
        }

        if (objectProp.indices.Count % 4 == 0)
        {
            SetTrianglesFromQuad(objectProp);
        }
        else
        {
            Debug.LogError("[ShuLog]: Error reading quad poly's from file.");
        }
    }
Exemple #9
0
    /// <summary>
    /// Reads the properties of Mesh.
    /// </summary>
    /// <param name="sr">loaded StreamReader.</param>
    /// <param name="line">currLine.</param>
    /// <param name="objectProp">Object property.</param>
    void ReadMeshProperties(StreamReader sr, string line, ObjectProp objectProp, ref int lineCounter)
    {
        while (!line.Contains("}"))
        {
            if (line.Contains("Lcl Translation"))
            {
                line = line.Remove(0, line.IndexOf("A+") + 4);
                line = line.TrimEnd(trimChars);

                string name = "";
                double px, py, pz;
                px = py = pz = 0;
                bool readX, readY, readZ;
                readX = true;
                readY = readZ = false;
                for (int i = 0; i < line.Length; i++)
                {
                    if (Char.IsDigit(line [i]) || line [i] == '-' || line [i] == '.')
                    {
                        name += line [i];
                    }
                    else if (line [i] == ',')
                    {
                        if (readX)
                        {
                            px    = double.Parse(name);
                            readX = false;
                            readY = true;
                        }
                        else if (readY)
                        {
                            py    = double.Parse(name);
                            readY = false;
                            readZ = true;
                        }
                        name = "";
                    }
                }
                if (readZ)
                {
                    pz    = double.Parse(name);
                    readZ = false;
                }
                objectProp.objPosition = new Vector3((float)px, (float)py, (float)pz);
            }            //end translation
            else if (line.Contains("Lcl Rotation"))
            {
                line = line.Remove(0, line.IndexOf("A+") + 4);
                line = line.TrimEnd(trimChars);

                string name = "";
                double px, py, pz;
                px = py = pz = 0;
                bool readX, readY, readZ;
                readX = true;
                readY = readZ = false;
                for (int i = 0; i < line.Length; i++)
                {
                    if (Char.IsDigit(line [i]) || line [i] == '-' || line [i] == '.')
                    {
                        name += line [i];
                    }
                    else if (line [i] == ',')
                    {
                        if (readX)
                        {
                            px    = double.Parse(name);
                            readX = false;
                            readY = true;
                        }
                        else if (readY)
                        {
                            py    = double.Parse(name);
                            readY = false;
                            readZ = true;
                        }
                        name = "";
                    }
                }
                if (readZ)
                {
                    pz    = double.Parse(name);
                    readZ = false;
                }
                objectProp.ObjRotation = new Vector3((float)px, (float)py, (float)pz);
            }            //end rotation
            else if (line.Contains("Lcl Scaling"))
            {
                line = line.Remove(0, line.IndexOf("A+") + 4);
                line = line.TrimEnd(trimChars);

                string name = "";
                double px, py, pz;
                px = py = pz = 1;
                bool readX, readY, readZ;
                readX = true;
                readY = readZ = false;
                for (int i = 0; i < line.Length; i++)
                {
                    if (Char.IsDigit(line [i]) || line [i] == '-' || line [i] == '.')
                    {
                        name += line [i];
                    }
                    else if (line [i] == ',')
                    {
                        if (readX)
                        {
                            px    = double.Parse(name);
                            readX = false;
                            readY = true;
                        }
                        else if (readY)
                        {
                            py    = double.Parse(name);
                            readY = false;
                            readZ = true;
                        }
                        name = "";
                    }
                }
                if (readZ)
                {
                    pz    = double.Parse(name);
                    readZ = false;
                }
                objectProp.objScale = new Vector3((float)px, (float)py, (float)pz);
            }            //end scale

            lineCounter++;
            line = sr.ReadLine();
        }        //end while

//		Debug.Log (objectProp.objPosition);
//		Debug.Log (objectProp.ObjRotation);
//		Debug.Log (objectProp.objScale);
    }    //end read property func
Exemple #10
0
 public static void Remove(this ObjectProp type, ObjectProp value)
 {
     type &= ~value;
 }
Exemple #11
0
 public static void Add(this ObjectProp type, ObjectProp value)
 {
     type |= value;
 }
Exemple #12
0
 public static bool Is(this ObjectProp type, ObjectProp value)
 {
     return(type == value);
 }
Exemple #13
0
 public static bool Has(this ObjectProp type, ObjectProp value)
 {
     return((type & value) == value);
 }