Ejemplo n.º 1
0
 public static void FillUvs(TpSpriteMeta *self, float *uvs)
 {
                 #if FDB
     Should.NotNull("self", self);
     Should.NotNull("uvs", uvs);
     Should.TypeEqual("self", self->type, Type);
     Should.NotNull("self->atlas", self->atlas);
     Should.TypeEqual("self->atlas->type", self->atlas->type, TpAtlasMeta.Type);
                 #endif
     float *size = self->atlas->size;
     float  invSizeX = 1 / size[0], invSizeY = 1 / size[1];
     float *uv = self->uv;
     float  uvX = uv[0], uvY = uv[1], uvW = uv[2], uvH = uv[3];
     if (self->rotated)
     {
         Vec2.Set(uvs, (uvX + uvW) * invSizeX, -uvY * invSizeY);
         Vec2.Set(uvs + 2, (uvX + uvW) * invSizeX, (-uvY - uvH) * invSizeY);
         Vec2.Set(uvs + 4, uvX * invSizeX, (-uvY - uvH) * invSizeY);
         Vec2.Set(uvs + 6, uvX * invSizeX, -uvY * invSizeY);
     }
     else
     {
         Vec2.Set(uvs, uvX * invSizeX, -uvY * invSizeY);
         Vec2.Set(uvs + 2, (uvX + uvW) * invSizeX, -uvY * invSizeY);
         Vec2.Set(uvs + 4, (uvX + uvW) * invSizeX, (-uvY - uvH) * invSizeY);
         Vec2.Set(uvs + 6, uvX * invSizeX, (-uvY - uvH) * invSizeY);
     }
 }
Ejemplo n.º 2
0
        public static void Init(TpSprite *self, TpSpriteMeta *spriteMeta)
        {
                        #if FDB
            Should.NotNull("self", self);
            Should.NotNull("spriteMeta", spriteMeta);
            self->type = Type;
                        #endif
            self->tag = Tag.TpSprite;

            Vec3.Zero(self->pos);
            Vec2.One(self->scl);
            self->rot = 0;
            self->isTransformDirty = true;              // delay regen verts to first Draw

            Vec4.Set(self->color, 1, 1, 1, 0);
            TpSpriteMeta.FillUvs(spriteMeta, self->uvs);

            self->spriteMeta = spriteMeta;
        }
Ejemplo n.º 3
0
 // v0 - v1
 // |  \ |
 // v3 - v2
 public static void FillQuad(TpSpriteMeta *self, float *mat, float *verts)
 {
                 #if FDB
     Should.NotNull("self", self);
     Should.NotNull("verts", verts);
     Should.NotNull("mat", mat);
     Should.TypeEqual("self", self->type, Type);
     Should.NotNull("self->atlas", self->atlas);
     Should.TypeEqual("self->atlas->type", self->atlas->type, TpAtlasMeta.Type);
                 #endif
     float *pivot = self->pivot;
     float  pivotX = pivot[0], pivotY = pivot[1];
     float *quad = self->quad;
     float  quadX = quad[0], quadY = quad[1], quadW = quad[2], quadH = quad[3];
     Vec2.TransformMat2D(verts, mat, -pivotX + quadX, pivotY - quadY);
     Vec2.TransformMat2D(verts + 2, mat, -pivotX + quadX + quadW, pivotY - quadY);
     Vec2.TransformMat2D(verts + 4, mat, -pivotX + quadX + quadW, pivotY - quadY - quadH);
     Vec2.TransformMat2D(verts + 6, mat, -pivotX + quadX, pivotY - quadY - quadH);
 }
Ejemplo n.º 4
0
 public static void SetMeta(TpSprite *self, TpSpriteMeta *meta)
 {
     self->isTransformDirty = true;
     TpSpriteMeta.FillUvs(meta, self->uvs);
     self->spriteMeta = meta;
 }