summaryrefslogtreecommitdiff
path: root/src/code/m_fbdemo_triforce.c
blob: 48137e63a2acad3d6fad71e4e3ab7c5c1973d612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "m_fbdemo_triforce.h"
#include "gfxalloc.h"
#include "m_rcp.h"
#include "attributes.h"

extern u8 ef_wipe1_modelT[];
extern u8 ef_wipe2_modelT[];
extern u8 ef_wipe3_modelT[];

void fbdemo_triforce_startup(fbDemoTriforce* this) {
    this->finished = 0;
    this->frame = 16;

    if (this->direction != 0) {
        this->txt = 0;
    } else {
        this->txt = 0x224;
    }

    guPerspective(&this->perspMtx, &this->normal, 60.0f, 4.0f / 3.0f, 10.0f, 12800.0f, 1.0f);
    guLookAt(&this->lookAtMtx, 0.0f, 0.0f, 400.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
}

fbDemoTriforce* fbdemo_triforce_init(fbDemoTriforce* this) {
    bzero(this, sizeof(fbDemoTriforce));
    return this;
}

void fbdemo_triforce_setrate(s32* rate, f32 scale) {
    *rate = 548.0f * scale;
}

void fbdemo_triforce_move(fbDemoTriforce* this, s32 rate) {
    s32 moveRate;
    UNUSED s32 txt = this->txt;
    f32 temp = (1.0f - (this->txt / 548.0f));

    moveRate = this->frame + (s32)(12.0f * temp);

    if (this->direction != 0) {

        this->txt += (moveRate << 1) / rate;
        if (this->txt >= 548) {
            this->txt = 548;
            this->finished = TRUE;
        }
    } else {
        this->txt -= (moveRate << 1) / rate;
        if (this->txt <= 0) {
            this->txt = 0;
            this->finished = TRUE;
        }
    }
}

void fbdemo_triforce_draw(fbDemoTriforce* this, Gfx** gfxP) {
    Gfx* gfx = *gfxP;
    Gfx* scroll;
    f32 scale;

    gDPPipeSync(gfx++);
    scroll = gfx_tex_scroll2(&gfx, this->txt, 0, 16, 4);
    gSPSegment(gfx++, G_MWO_SEGMENT_9, scroll);
    gSPMatrix(gfx++, &this->perspMtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
    gSPPerspNormalize(gfx++, this->normal);
    gSPMatrix(gfx++, &this->lookAtMtx, G_MTX_MUL | G_MTX_PROJECTION);

    scale = 0.019f;

    if (1.0f != scale) {
        Mtx* mtxBuf;

        mtxBuf = gfxalloc(&gfx, sizeof(Mtx));

        guScale(mtxBuf, 0.019f, 0.019f, 1.0f);
        gSPMatrix(gfx++, mtxBuf, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
    }

    switch (this->textureNo) {
        case 0:
            gSPDisplayList(gfx++, ef_wipe1_modelT);
            break;
        case 1:
            gSPDisplayList(gfx++, ef_wipe2_modelT);
            break;
        case 2:
            gSPDisplayList(gfx++, ef_wipe3_modelT);
            break;
    }
    gDPPipeSync(gfx++);
    *gfxP = gfx;
}

u8 fbdemo_triforce_is_finish(fbDemoTriforce* this) {
    return this->finished;
}

void fbdemo_triforce_settype(fbDemoTriforce* this, s32 type) {
    this->textureNo = ((type & 0x80) != 0) ? 1 : ((type & 0x40) != 0 ? 2 : 0);

    if ((type & 0xF) == 1) {
        this->direction = 0;
    } else {
        this->direction = 1;
    }
}

void fbdemo_triforce_setcolor_rgba8888(UNUSED fbDemoTriforce* this, UNUSED u32* rgba) {
}