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
|
#include <game.h>
class daBonePiece_c : public dStageActor_c {
public:
static daBonePiece_c *build();
int onCreate();
int onExecute();
int onDraw();
int onDelete();
StandOnTopCollider collider;
nw4r::g3d::ResFile resFile;
mHeapAllocator_c allocator;
m3d::mdl_c model;
};
/*****************************************************************************/
// Glue Code
daBonePiece_c *daBonePiece_c::build() {
void *buffer = AllocFromGameHeap1(sizeof(daBonePiece_c));
daBonePiece_c *c = new(buffer) daBonePiece_c;
return c;
}
int daBonePiece_c::onCreate() {
// load the model
allocator.link(-1, GameHeaps[0], 0, 0x20);
resFile.data = getResource("lift_torokko", "g3d/t00.brres");
static char thing[] = "lift_torokko?";
thing[0xC] = 'A' + (settings & 3);
nw4r::g3d::ResMdl resmdl = resFile.GetResMdl(thing);
model.setup(resmdl, &allocator, 0, 1, 0);
SetupTextures_MapObj(&model, 0);
allocator.unlink();
// if rotation is off, do nothing else
if ((settings >> 28) & 1) {
// OK, figure out the rotation
u8 sourceRotation = (settings >> 24) & 0xF;
// 0 is up. -0x4000 is right, 0x4000 is left ...
s16 rotation;
// We'll flip it later.
// Thus: 0..7 rotates left (in increments of 0x800),
// 8..15 rotates right (in increments of 0x800 too).
// To specify facing up, well.. just use 0.
if (sourceRotation < 8)
rotation = (sourceRotation * 0x800) - 0x4000;
else
rotation = (sourceRotation * 0x800) - 0x3800;
rotation = -rotation;
rot.z = rotation;
}
collider.init(this,
/*xOffset=*/0.0f, /*yOffset=*/0.0f,
/*topYOffset=*/0,
/*rightSize=*/16.0f, /*leftSize=*/-16.0f,
/*rotation=*/rot.z, /*_45=*/1
);
collider._47 = 0xA;
collider.flags = 0x80180 | 0xC00;
collider.addToList();
return true;
}
int daBonePiece_c::onDelete() {
return true;
}
int daBonePiece_c::onExecute() {
matrix.translation(pos.x, pos.y - 8.0f, pos.z);
matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
model.setDrawMatrix(matrix);
model.setScale(&scale);
model.calcWorld(false);
collider.update();
return true;
}
int daBonePiece_c::onDraw() {
model.scheduleForDrawing();
return true;
}
|