drawleaf.c
4.16 KB
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
/********************************************************************************
NINTENDO64 DIsk Drive IPL4
Leaf drawing module
December 6, 1996
********************************************************************************/
#include <ultra64.h>
#include "ipl4.h"
#include "graphics.h"
#include "static.h"
#define NUMLEAVES 16
CtrlLeaf leafTable[NUMLEAVES]; /* leaf control works */
/********************************************************************************/
/* */
/* Make display list. */
/* */
/********************************************************************************/
static void
MakeDisplayList(CtrlLeaf *leaf, int drawmode)
{
FVector radian;
FVector position = leaf->position;
FVector scaling = leaf->scaling;
Mtx * modeling = (Mtx *)AllocDynamic(sizeof(Mtx));
if (drawmode == LEAF_DRAW_MIRROR) {
position.y *= -1.0f;
scaling.y *= -1.0f;
}
AngvecToRadvec(&radian, &leaf->angle);
CreateModelMatrix(modeling, &position, &radian, &scaling);
gSPMatrix(graphicp++, K0_TO_PHYS(modeling), G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);
gSPDisplayList(graphicp++, Gfx_Leaf);
}
/********************************************************************************/
/* */
/* Initilaize leaf works. */
/* */
/********************************************************************************/
extern void
InitLeaf(void)
{
int index;
for (index = 0; index < NUMLEAVES; index++) {
leafTable[index].flag = 0;
}
}
/********************************************************************************/
/* */
/* Draw leaves. */
/* */
/********************************************************************************/
extern void
DrawLeaf(void)
{
int count;
CtrlLeaf *leaf;
for (leaf = leafTable, count = 0; count < NUMLEAVES; leaf++, count++) {
if (leaf->flag != 0) {
leaf->angle.x += leaf->angvelo.x;
leaf->angle.z += leaf->angvelo.z;
leaf->shake += leaf->angvelo.y;
if ((leaf->falling -= 6.0f) < -16.0f) leaf->falling = -16.0f;
if ((leaf->moving -= 1.2f) < 0.0f) leaf->moving = 0.0f;
leaf->position.x += sin(leaf->angle.y) * (16.0f * sin(leaf->shake) + leaf->moving);
leaf->position.z += cos(leaf->angle.y) * (16.0f * sin(leaf->shake) + leaf->moving);
leaf->position.y += leaf->falling;
if (leaf->flag = (leaf->position.y > 20.0f)) {
MakeDisplayList(leaf, LEAF_DRAW_NORMAL);
MakeDisplayList(leaf, LEAF_DRAW_MIRROR);
}
}
}
}
/********************************************************************************/
/* */
/* Make a leaf. */
/* */
/********************************************************************************/
extern void
MakeLeaf(FVector *position)
{
int count;
CtrlLeaf *leaf;
for (leaf = leafTable, count = 0; count < NUMLEAVES; leaf++, count++) {
if (leaf->flag == 0) break;
}
if (count < NUMLEAVES) {
float scale = Randomf() * 0.5f + 0.5f;
leaf->flag = 1;
leaf->shake = 0;
leaf->position = *position;
leaf->position.y += 50.0f;
leaf->moving = Randomf() * 20.0f + 20.0f;
leaf->falling = Randomf() * 15.0f + 10.0f;
leaf->angvelo.y = Randomf() * 0x400 + 0x600; /* shake angle velocity */
leaf->angvelo.x = (Randomf() - 0.5f) * 0x1000;
leaf->angvelo.z = (Randomf() - 0.5f) * 0x1000;
SetFVector(&leaf->scaling, scale , scale , scale );
SetSVector(&leaf->angle , Randomi(), Randomi(), Randomi());
}
}
/********************************************************************************/
/* */
/* Blow leaves. */
/* */
/********************************************************************************/
extern void
BlowLeaf(FVector *center)
{
int count;
FVector position;
for (count = 0; count < NUMLEAVES; count++) {
position.x = center->x + (Randomf() - 0.5f) * 100.0f;
position.z = center->z + (Randomf() - 0.5f) * 100.0f;
position.y = center->y;
MakeLeaf(&position);
}
for (count = 0; count < NUMLEAVES; count++) {
leafTable[count].falling += Randomf() * 30.0f + 60.0f;
}
}