Esempio n. 1
0
 public override void Rotate(float angle, Axis axis)
 {
     Pivot.Rotate(angle, axis);
     GlobalVertices = LocalVertices.Select(v => Pivot.ToGlobalCoords(v)).ToArray();
     OnRotateEvent(angle, axis);
     if (Enviroment != null)
     {
         Enviroment.OnChangeEvent();
     }
 }
Esempio n. 2
0
 public override void Move(Vector3 v)
 {
     Pivot.Move(v);
     GlobalVertices = GlobalVertices.Select(i => i + v).ToArray();
     OnMoveEvent(v);
     if (Enviroment != null)
     {
         Enviroment.OnChangeEvent();
     }
 }
Esempio n. 3
0
        public Function(Vector3 center, Func <float, float, float> f, float xstart, float ystart, float xend, float yend, float step)
        {
            Pivot = Pivot.BasePivot(center);
            int width  = (int)((xend - xstart) / step);
            int height = (int)((yend - ystart) / step);
            int len    = width * height;

            LocalVertices  = new Vector3[len];
            GlobalVertices = new Vector3[len];
            Indexes        = new int[width * height * 6];
            NormalIndexes  = new int[width * height * 6];
            Normals        = new Vector3[width * height];
            float x = xstart, y = ystart;

            for (int i = 0; i < width; i++)
            {
                y = ystart;
                for (int g = 0; g < height; g++)
                {
                    int ind   = g * width + i;
                    var local = LocalVertices[ind] = new Vector3(x, y, f.Invoke(x, y));
                    GlobalVertices[ind] = Pivot.ToGlobalCoords(local);
                    y += step;
                }
                x += step;
            }


            for (int i = 0; i < width - 1; i++)
            {
                for (int g = 0; g < height - 1; g++)
                {
                    int k  = (i * height + g) * 6;
                    int i1 = Indexes[k] = i * height + g;
                    int i2 = Indexes[k + 1] = i * height + g + 1;
                    int i3 = Indexes[k + 2] = (i + 1) * height + g;
                    int i4 = Indexes[k + 3] = i * height + g + 1;
                    int i5 = Indexes[k + 4] = (i + 1) * height + g + 1;
                    int i6 = Indexes[k + 5] = (i + 1) * height + g;


                    var normal = VectorMath.GetNormal(GlobalVertices[i4], GlobalVertices[i5], GlobalVertices[i6]);

                    Normals[i * height + g] = normal;

                    NormalIndexes[(i * height + g) * 6]                         =
                        NormalIndexes[(i * height + g) * 6 + 1]                 =
                            NormalIndexes[(i * height + g) * 6 + 2]             =
                                NormalIndexes[(i * height + g) * 6 + 3]         =
                                    NormalIndexes[(i * height + g) * 6 + 4]     =
                                        NormalIndexes[(i * height + g) * 6 + 5] = i * height + 1;
                }
            }
        }
Esempio n. 4
0
 public Model(Vector3[] vertices, Vector2[] texCoords, Vector3[] normals, int[] indexes, int[] texCoordsIndexes, int[] normalIndexes, FastBitmap texture)
 {
     Pivot                = Pivot.BasePivot(Vector3.Zero);
     LocalVertices        = vertices;
     GlobalVertices       = vertices.Select(v => Pivot.ToGlobalCoords(v)).ToArray();
     TextureCoords        = texCoords;
     Normals              = normals;
     Indexes              = indexes;
     TextureCoordsIndexes = texCoordsIndexes;
     NormalIndexes        = normalIndexes;
     Texture              = texture;
 }
Esempio n. 5
0
 public Primitive(Vector3[] lv, Vector3[] gv, Vector3[] n, Vector2[] t, int[] i, int[] ni, int[] ti, IShader[] s, Pivot p)
 {
     Indexes              = i;
     NormalIndexes        = ni;
     TextureCoordsIndexes = ti;
     TextureCoords        = t;
     Normals              = n;
     LocalVertices        = lv;
     GlobalVertices       = gv;
     Shaders              = s;
     Pivot = p;
 }
Esempio n. 6
0
 public Primitive Clone()
 {
     return(new Primitive(LocalVertices.ToArray(),
                          GlobalVertices.ToArray(),
                          Normals.ToArray(),
                          TextureCoords.ToArray(),
                          Indexes.ToArray(),
                          NormalIndexes.ToArray(),
                          TextureCoordsIndexes.ToArray(),
                          Shaders.ToArray(),
                          Pivot.Clone()));
 }
Esempio n. 7
0
        public void RotateAt(Vector3 point, float angle, Axis axis)
        {
            //creating basis with center in point
            var rotationBasis = Pivot.BasePivot(point);
            //transforming to basis coords 4 points : , Center , Center + XAxis , Center + YAxis , Center + ZAxis
            var center = Center - point;
            var xaxis  = center + XAxis;
            var yaxis  = center + YAxis;
            var zaxis  = center + ZAxis;
            //rotating this points in local basis and tranforming to global
            var newCenter = rotationBasis.ToGlobalCoords(center.Rotate(angle, axis));
            var newx      = rotationBasis.ToGlobalCoords(xaxis.Rotate(angle, axis));
            var newy      = rotationBasis.ToGlobalCoords(yaxis.Rotate(angle, axis));
            var newz      = rotationBasis.ToGlobalCoords(zaxis.Rotate(angle, axis));

            //creating new basis from this points
            Center = newCenter;
            XAxis  = newx - Center;
            YAxis  = newy - Center;
            ZAxis  = newz - Center;
        }
Esempio n. 8
0
 public void RotateAt(Vector3 point, float angle, Axis axis)
 {
     Pivot.RotateAt(point, angle, axis);
     GlobalVertices = LocalVertices.Select(v => Pivot.ToGlobalCoords(v)).ToArray();
 }
Esempio n. 9
0
 public void Scale(float k)
 {
     LocalVertices  = LocalVertices.Select(v => v * k).ToArray();
     GlobalVertices = LocalVertices.Select(v => Pivot.ToGlobalCoords(v)).ToArray();
 }
Esempio n. 10
0
 public override void Rotate(float angle, Axis axis)
 {
     Pivot.Rotate(angle, axis);
     OnRotateEvent(angle, axis);
 }
Esempio n. 11
0
 public override void Move(Vector3 v)
 {
     Pivot.Move(v);
     OnMoveEvent(v);
 }