Project

General

Profile

Revision 207

maybe working

View differences:

sprite.c
44 44
struct sprite{
45 45
    const basic_sprite_t *bsp;
46 46
    int16_t x, y; //position in screen
47
    double theta;
47
    double theta, s, c;
48 48
    double scale;
49 49
};
50 50

  
......
54 54
    ret->bsp = bsp;
55 55
    ret->x = 0;
56 56
    ret->y = 0;
57
    ret->theta = 0.0;
57
    sprite_set_angle(ret, 0.0);
58 58
    ret->scale = 1.0;
59 59
    return ret;
60 60
}
......
64 64
}
65 65

  
66 66
void (sprite_set_pos)   (sprite_t *p, int16_t x , int16_t y ){ p->x = x; p->y = y; }
67
void (sprite_set_angle) (sprite_t *p, double angle          ){ p->theta = angle; }
67
void (sprite_set_angle) (sprite_t *p, double angle          ){ p->theta = angle; p->c = fm_cos(p->theta); p->s = fm_sin(p->theta); }
68 68
void (sprite_set_scale) (sprite_t *p, double scale          ){ p->scale = scale; }
69 69
int16_t  (sprite_get_x)(const sprite_t *p){ return p->x; }
70 70
int16_t  (sprite_get_y)(const sprite_t *p){ return p->y; }
71 71

  
72 72
void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){
73
    double s = fm_sin(p->theta);
74
    double c = fm_cos(p->theta);
75 73
    double dx = (x - p->x)/p->scale;
76 74
    double dy = (y - p->y)/p->scale;
77
    int16_t du = dx*c - dy*s + 0.5;
78
    int16_t dv = dx*s + dy*c + 0.5;
75
    int16_t du = dx*p->c - dy*p->s + 0.5;
76
    int16_t dv = dx*p->s + dy*p->c + 0.5;
79 77
    *u = du + basic_sprite_get_u0(p->bsp);
80 78
    *v = dv + basic_sprite_get_v0(p->bsp);
81 79
}
82 80

  
83 81
void (sprite_pic2src)(const sprite_t *p, int16_t u, int16_t v, int16_t *x, int16_t *y){
84
    double s = fm_sin(p->theta);
85
    double c = fm_cos(p->theta);
86 82
    int16_t du = u - basic_sprite_get_u0(p->bsp);
87 83
    int16_t dv = v - basic_sprite_get_v0(p->bsp);
88
    double dx =  du*c + dv*s;
89
    double dy = -du*s + dv*c;
84
    double dx =  du*p->c + dv*p->s;
85
    double dy = -du*p->s + dv*p->c;
90 86
    *x = dx*p->scale + 0.5 + p->x;
91 87
    *y = dy*p->scale + 0.5 + p->y;
92 88
}
......
114 110
            sprite_src2pic(p, x, y, &u, &v);
115 111
            if(0 <= u && u < w && 0 <= v && v < h){
116 112
                uint32_t c = *(uint32_t*)(map + (v*w + u)*4);
117
                graph_set_pixel_alpha(x, y, GET_COLOR(c), GET_ALP(c));
113
                if(GET_ALP(c) < 0x7F)
114
                    graph_set_pixel(x, y, GET_COLOR(c));
118 115
            }
119 116
        }
120 117
    }

Also available in: Unified diff