예제 #1
0
파일: Shape.cs 프로젝트: Reavenk/PxPre-Wing
            public void AddSimpleCube(Vector3 pos, Quaternion rot, float width, float height, float depth)
            {
                Vector3 rad = new Vector3(width / 2.0f, height / 2.0f, depth / 2.0f);

                Vector3 v0 = new Vector3(-rad.x, rad.y, rad.z);
                Vector3 v1 = new Vector3(rad.x, rad.y, rad.z);
                Vector3 v2 = new Vector3(rad.x, rad.y, -rad.z);
                Vector3 v3 = new Vector3(-rad.x, rad.y, -rad.z);
                Vector3 v4 = new Vector3(-rad.x, -rad.y, rad.z);
                Vector3 v5 = new Vector3(rad.x, -rad.y, rad.z);
                Vector3 v6 = new Vector3(rad.x, -rad.y, -rad.z);
                Vector3 v7 = new Vector3(-rad.x, -rad.y, -rad.z);

                ShapeConstructionUtil scu = new ShapeConstructionUtil(this);

                // top
                scu.CreateFace(v0, v1, v2, v3);
                // bottom
                scu.CreateFace(v7, v6, v5, v4);
                // front
                scu.CreateFace(v3, v2, v6, v7);
                // back
                scu.CreateFace(v1, v0, v4, v5);
                // left
                scu.CreateFace(v0, v3, v7, v4);
                // right
                scu.CreateFace(v2, v1, v5, v6);
            }
예제 #2
0
파일: Shape.cs 프로젝트: Reavenk/PxPre-Wing
            public void AddSimplePlane(Vector3 pos, Quaternion rot, float width, float depth)
            {
                Vector2 rad = new Vector2(width / 2.0f, depth / 2.0f);

                Vector3 v0 = new Vector3(-rad.x, 0.0f, rad.y);
                Vector3 v1 = new Vector3(rad.x, 0.0f, rad.y);
                Vector3 v2 = new Vector3(rad.x, 0.0f, -rad.y);
                Vector3 v3 = new Vector3(-rad.x, 0.0f, -rad.y);

                ShapeConstructionUtil scu = new ShapeConstructionUtil(this);

                scu.CreateFace(v0, v1, v2, v3);
                scu.CreateFace(v3, v2, v1, v0);
            }
예제 #3
0
파일: Shape.cs 프로젝트: Reavenk/PxPre-Wing
            public void AddUVSphere(Vector3 pos, Quaternion rot, Axis axis, float heightRad, float beltRad, int slices, int rings)
            {
                slices = Mathf.Max(slices, 3);
                rings  = Mathf.Max(rings, 0);

                Vector3 vpoleTop = new Vector3(0.0f, heightRad, 0.0f);
                Vector3 vpoleBot = new Vector3(0.0f, -heightRad, 0.0f);

                ShapeConstructionUtil scu = new ShapeConstructionUtil(this);

                // Instead of recalculating as needed, we're going to store all the verts we use.
                //
                // While this may help with avoiding recalculations, this is more done as a saftey measure
                // for the possibility of floating point errors.
                List <Vector3> lstv3 = new List <Vector3>();

                lstv3.Add(vpoleTop);
                lstv3.Add(vpoleBot);

                int topSt = lstv3.Count;

                // Figure out all the vertices we would be producing
                int vrings = rings + 2;

                for (int s = 0; s < vrings; ++s)
                {
                    float hl = (float)(s + 1) / (float)(vrings + 1);

                    float rad = Mathf.Sin(hl * Mathf.PI) * beltRad;

                    float ypos = Mathf.Cos(hl * Mathf.PI) * heightRad;
                    //float ypos = Mathf.Lerp(heightRad, -heightRad, hl);

                    for (int i = 0; i < slices; ++i)
                    {
                        float lambda = (float)i / slices;
                        float angle  = lambda * 2.0f * Mathf.PI;

                        float fx = Mathf.Cos(angle);
                        float fy = Mathf.Sin(angle);

                        lstv3.Add(new Vector3(fx * rad, ypos, fy * rad));
                    }
                }

                // Stitch the top pole
                for (int i = 0; i < slices; ++i)
                {
                    const int topPoleIdx = 0;
                    int       triIdx1    = topSt + i;
                    int       triIdx2    = topSt + ((i + 1) % slices);
                    scu.CreateFace(
                        lstv3[topPoleIdx],
                        lstv3[triIdx2],
                        lstv3[triIdx1]);
                }

                // Stitch the bottom pole
                int botSt = lstv3.Count - slices;

                for (int i = 0; i < slices; ++i)
                {
                    const int botPoleIdx = 1;
                    int       triIdx1    = botSt + i;
                    int       triIdx2    = botSt + ((i + 1) % slices);
                    scu.CreateFace(
                        lstv3[botPoleIdx],
                        lstv3[triIdx1],
                        lstv3[triIdx2]);
                }

                // Stitch the body
                for (int j = 0; j < rings + 1; ++j)
                {
                    int s1 = topSt + ((j + 0) * slices);
                    int s2 = topSt + ((j + 1) * slices);

                    for (int i = 0; i < slices; ++i)
                    {
                        int a = s1 + i;
                        int b = s1 + (i + 1) % slices;
                        int c = s2 + (i + 1) % slices;
                        int d = s2 + i;

                        scu.CreateFace(
                            lstv3[a],
                            lstv3[b],
                            lstv3[c],
                            lstv3[d]);
                    }
                }
            }