-
Notifications
You must be signed in to change notification settings - Fork 0
/
effect6.c
200 lines (155 loc) · 4.57 KB
/
effect6.c
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// AO Cubes
#include <nds.h>
#include <nds/registers_alt.h>
#include "DS3D/Utils.h"
#include "DS3D/DS3D.h"
#include "VoxelBlock.h"
#include "Hardware.h"
#include "Loader.h"
#include "RainbowTable.h"
VoxelBlock block;
void heart_at(int posx, int posy, int z, u16 col) {
SetVoxelAt(&block,posx-0,posy-2,z,col);
SetVoxelAt(&block,posx-1,posy-3,z,col);
SetVoxelAt(&block,posx-2,posy-4,z,col);
SetVoxelAt(&block,posx-3,posy-3,z,col);
SetVoxelAt(&block,posx-4,posy-2,z,col);
SetVoxelAt(&block,posx-4,posy-1,z,col);
SetVoxelAt(&block,posx-3,posy-0,z,col);
SetVoxelAt(&block,posx-3,posy-0,z,col);
SetVoxelAt(&block,posx-2,posy+1,z,col);
SetVoxelAt(&block,posx-1,posy+2,z,col);
SetVoxelAt(&block,posx-0,posy+3,z,col);
SetVoxelAt(&block,posx+1,posy+2,z,col);
SetVoxelAt(&block,posx+2,posy+1,z,col);
SetVoxelAt(&block,posx+3,posy+0,z,col);
SetVoxelAt(&block,posx+4,posy-1,z,col);
SetVoxelAt(&block,posx+4,posy-2,z,col);
SetVoxelAt(&block,posx+3,posy-3,z,col);
SetVoxelAt(&block,posx+2,posy-4,z,col);
SetVoxelAt(&block,posx+1,posy-3,z,col);
}
void effect6_init() {
DISPCNT_A=DISPCNT_MODE_5|DISPCNT_3D|DISPCNT_BG0_ON|DISPCNT_BG2_ON|DISPCNT_BG3_ON|DISPCNT_ON;
BLDCNT_A = BLDCNT_SRC_A_BG3|BLDCNT_SRC_B_BG0|BLDCNT_EFFECT_ALPHA;
BLDALPHA_A = BLDALPHA_EVA(8)|BLDALPHA_EVB(15);
// BG and frame
VRAMCNT_D = VRAMCNT_D_LCDC;
VRAMCNT_B = VRAMCNT_B_BG_VRAM_A_OFFS_0K;
VRAMCNT_A = VRAMCNT_A_BG_VRAM_A_OFFS_128K;
loadImageVRAMIndirectGreen( "nitro:/gfx/tunnel_frame.img.bin", VRAM_A_OFFS_0K,256*256*2);
loadImageVRAMIndirectGreen( "nitro:/gfx/stripe_bg_hori.img.bin", VRAM_A_OFFS_128K,256*256*2);
BG2CNT_A = BGxCNT_EXTENDED_BITMAP_16 | BGxCNT_OVERFLOW_WRAP | BGxCNT_BITMAP_SIZE_256x256 | BGxCNT_BITMAP_BASE_0K;
BG2CNT_A = (BG2CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_0;
BG2_XDX = (1 << 8);
BG2_XDY = 0;
BG2_YDX = 0;
BG2_YDY = (1 << 8);
BG2_CX = 0;
BG2_CY = 0;
// Init BG0 priority as above BG3
BG0CNT_A = (BG0CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_2;
BG3CNT_A = BGxCNT_EXTENDED_BITMAP_16 | BGxCNT_OVERFLOW_WRAP | BGxCNT_BITMAP_SIZE_256x256 | BGxCNT_BITMAP_BASE_128K;
BG3CNT_A = (BG3CNT_A&~BGxCNT_PRIORITY_MASK)|BGxCNT_PRIORITY_1;
BG3_XDX = (1 << 8);
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = (1 << 8);
BG3_CX = 0;
BG3_CY = 0;
// Set up voxelcubes
VRAMCNT_D=VRAMCNT_D_LCDC;
VRAMCNT_F=VRAMCNT_F_LCDC;
loadVRAMIndirect( "nitro:/textures.pal4", VRAM_LCDC_D,16384);
for(int i=0;i<16;i++) VRAM_LCDC_F[i]=MakeRGB15(i+16,i+16,i+16);
VRAMCNT_D=VRAMCNT_D_TEXTURE_OFFS_0K;
VRAMCNT_F=VRAMCNT_F_TEXTURE_PALETTE_SLOT_0;
DSInit3D();
DSViewport(0,0,255,191);
DSSetControl(DS_TEXTURING|DS_ANTIALIAS|DS_FOG);
DSClearParams(26,26,26,0,63);
DSSetPaletteOffset(0,DS_TEX_FORMAT_PAL4);
DSMatrixMode(DS_PROJECTION);
DSLoadIdentity();
DSPerspectivef(65,256.0/192.0,0.1,16);
DSSetFogLinearf(0,0,0,31,8,16,0.1,16);
InitVoxelBlock(&block,17,17,64,NULL);
}
int offx = 0;
int offy = 0;
void voxelSpiral(int t) {
BG3_CY = t*512*4;
// Kludge
static int lt = 0;
lt++;
t = lt*2;
static uint8_t ri = 0;
DSMatrixMode(DS_POSITION);
DSLoadIdentity();
// Move blocks
if(t%4==0) {
ScrollVoxelBlockByZ(&block);
}
// Spiral rainbows
int posx = 8;
int posy = 8;
float offx_f = ((float)isin((t-4*64)<<4))/250.0;;
float offy_f = ((float)icos((t-4*64)<<4))/250.0;
int new_offx = isin(t<<4)/1500;
int new_offy = icos(t<<4)/1500;
// Clear old heart
if(new_offx != offx || new_offy != offy) {
// SetVoxelAt(&block,posx-offx,posy-offy,0,0);
heart_at(posx-offx, posy-offy, 0, 0);
}
offx = new_offx;
offy = new_offy;
// Heart
if((t/4)%16<=2) {
int bright = abs(((t/4)%16));
u16 col = 0;
if((t/8)%16<=2) {
col = MakeRGB15(27 + 2 * bright, 13 + 2*bright, 13 + 2*bright);
}
else {
col = MakeRGB15(25 + 3 * bright, 25 + 3*bright, 25 + 3*bright);
}
// SetVoxelAt(&block,posx-offx,posy-offy,0,col);
heart_at(posx-offx, posy-offy, 0, col);
}
else {
// SetVoxelAt(&block,posx-offx,posy-offy,0,0);
heart_at(posx-offx, posy-offy, 0, 0);
}
RefreshVoxelBlock(&block);
// Move things
DSRotateZi(-t<<2);
DSTranslatef(offx_f*0.025,offy_f*0.025,0);
DSScalef(0.25,0.25,0.25);
DSTranslatef32(DSf32(0),DSf32(0),((t&3)<<10)-DSf32(33));
DrawVoxelBlock(&block);
DSSwapBuffers(0);
}
void objectShow(int t) {
static uint8_t ri = 0;
DSMatrixMode(DS_POSITION);
DSLoadIdentity();
DSSwapBuffers(0);
}
uint8_t effect6_update( uint32_t t ) {
voxelSpiral(t);
return 0;
}
void effect6_destroy() {
CleanupVoxelBlock(&block);
oamClear(&oamMain,0,128);
oamUpdate(&oamMain);
BG3PA_A=(1<<8);
BG3PB_A=0;
BG3PC_A=0;
BG3PD_A=(1<<8);
BG3X_A=0;
BG3Y_A=0;
BLDCNT_A = 0;
BLDALPHA_A = 0;
}