⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base_types.c.svn-base

📁 A Flash Player with ActionScript support. Write in C and C++. It have two part, one is Player and an
💻 SVN-BASE
字号:
#include <glib.h>#include "base_types.h"long mat_getx(struct Matrix *matrix_p,long x,long y) {    return (long) (x * matrix_p->ScaleX + y * matrix_p->RotateSkew0 + matrix_p->TranslateX);}long mat_gety(struct Matrix *matrix_p, long x, long y) {    return (long) (x*matrix_p->RotateSkew1+y*matrix_p->ScaleY+matrix_p->TranslateY);}void mat_new(struct Matrix *matrix_p) {    matrix_p->ScaleX = 1.0;    matrix_p->ScaleY = 1.0;    matrix_p->RotateSkew0 = matrix_p->RotateSkew1 = 0.0;    matrix_p->TranslateX = matrix_p->TranslateY = 0;}struct Matrix mat_multi(struct Matrix *n, struct Matrix *m) {    struct Matrix mat;    mat.ScaleX = n->ScaleX * m->ScaleX + n->RotateSkew0 * m->RotateSkew1;    mat.RotateSkew0 = n->ScaleX * m->RotateSkew0 + n->RotateSkew0 * m->ScaleY;    mat.RotateSkew1 = n->RotateSkew1 * m->ScaleX + n->ScaleY * m->RotateSkew1;    mat.ScaleY = n->RotateSkew1 * m->RotateSkew0 + n->ScaleY * m->ScaleY;    mat.TranslateX = mat_getx(n,m->TranslateX,m->TranslateY);    mat.TranslateY = mat_gety(n,m->TranslateX,m->TranslateY);    return mat;}struct Matrix mat_invert(struct Matrix *matrix_p) {    struct Matrix mat;    float det;    det = matrix_p->ScaleX*matrix_p->ScaleY-matrix_p->RotateSkew0*matrix_p->RotateSkew1;    mat.ScaleX  = matrix_p->ScaleY/det;    mat.RotateSkew0  = -matrix_p->RotateSkew0/det;    mat.RotateSkew1  = -matrix_p->RotateSkew1/det;    mat.ScaleY  = matrix_p->ScaleX/det;    mat.TranslateX = - (long)(mat.ScaleX * matrix_p->TranslateX + mat.RotateSkew0 * matrix_p->TranslateY);    mat.TranslateY = - (long)(mat.RotateSkew1 * matrix_p->TranslateX + mat.ScaleY * matrix_p->TranslateY);    return mat;}static void mat_bbox(struct RECT *rect, struct Matrix *m, long x1, long y1) {    long x,y;    x = mat_getx(m,x1,y1);    y = mat_gety(m,x1,y1);    if (x < rect->Xmin)        rect->Xmin = x;    if (x > rect->Xmax)        rect->Xmax = x;    if (y < rect->Ymin)        rect->Ymin = y;    if (y > rect->Ymax)        rect->Ymax = y;}void rect_new(struct RECT *r_p) {    r_p->Xmin = LONG_MAX;    r_p->Xmax = LONG_MIN;    r_p->Ymin = LONG_MAX;    r_p->Ymax = LONG_MIN;};struct RECT mat_multi_rect(struct Matrix *m_p, struct RECT *r_p) {    struct RECT bb;    rect_new(&bb);    mat_bbox(&bb,m_p,r_p->Xmin,r_p->Ymin);    mat_bbox(&bb,m_p,r_p->Xmax,r_p->Ymin);    mat_bbox(&bb,m_p,r_p->Xmin,r_p->Ymax);    mat_bbox(&bb,m_p,r_p->Xmax,r_p->Ymax);    return bb;}struct RECT rect_add(struct RECT *r1_p, struct RECT *r2_p) {    struct RECT bb;    bb = *r1_p;    if (r1_p->Xmin > r2_p->Xmin) {        bb.Xmin = r2_p->Xmin ;    };    if (r1_p->Xmax < r2_p->Xmax) {        bb.Xmax = r2_p->Xmax ;    };    if (r1_p->Ymin > r2_p->Ymin) {        bb.Ymin = r2_p->Ymin ;    };    if (r1_p->Ymax < r2_p->Ymax) {        bb.Ymax = r2_p->Ymax ;    };    return bb;};gboolean rect_is_point_in(struct RECT *r_p, long x, long y) {    if ((x < r_p->Xmin) || (x > r_p->Xmax) || (y < r_p->Ymin) || (y > r_p->Ymax))        return FALSE;    return TRUE;};// 先求两方型中心点(cp1,cp2).再求两中心点连线的中心点(cp3),判断求出的中心点是否在方形内.gboolean rect_is_rect_cross(struct RECT *r1_p, struct RECT *r2_p) {    long cp1_x, cp1_y, cp2_x, cp2_y;    long cp3_x, cp3_y;    if (r1_p->Xmin == LONG_MAX            && r1_p->Xmax == LONG_MIN            && r1_p->Ymin == LONG_MAX            && r1_p->Ymax == LONG_MIN) {        return FALSE;    };    if (r2_p->Xmin == LONG_MAX            && r2_p->Xmax == LONG_MIN            && r2_p->Ymin == LONG_MAX            && r2_p->Ymax == LONG_MIN) {        return FALSE;    };    cp1_x = r1_p->Xmin + (r1_p->Xmax - r1_p->Xmin)/2;    cp1_y = r1_p->Ymin + (r1_p->Ymax - r1_p->Ymin)/2;    cp2_x = r2_p->Xmin + (r2_p->Xmax - r2_p->Xmin)/2;    cp2_y = r2_p->Ymin + (r2_p->Ymax - r2_p->Ymin)/2;    if (cp1_x < cp2_x) {        cp3_x = cp1_x + (cp2_x - cp1_x) / 2;    } else {        cp3_x = cp2_x + (cp1_x - cp2_x) / 2;    };    if (cp1_y < cp2_y) {        cp3_y = cp1_y + (cp2_y - cp1_y) / 2;    } else {        cp3_y = cp2_y + (cp1_y - cp2_y) / 2;    };    return ((rect_is_point_in(r1_p, cp3_x, cp3_y) || rect_is_point_in(r2_p, cp3_x, cp3_y)));};void cxform_new(struct CxFormWithAlpha* cx_p) {    cx_p->RedAddTerm = 0;    cx_p->BlueAddTerm = 0;    cx_p->GreenAddTerm = 0;    cx_p->AlphaAddTerm = 0;    cx_p->RedMultTerm = 1;    cx_p->BlueMultTerm = 1;    cx_p->GreenMultTerm = 1;    cx_p->AlphaMultTerm = 1;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -