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
|
#include "worldmap.h"
dWorldCamera_c *dWorldCamera_c::instance = 0;
dWorldCamera_c *dWorldCamera_c::build() {
OSReport("Creating WorldCamera\n");
void *buffer = AllocFromGameHeap1(sizeof(dWorldCamera_c));
dWorldCamera_c *c = new(buffer) dWorldCamera_c;
OSReport("Created WorldCamera @ %p\n", c);
instance = c;
return c;
}
int dWorldCamera_c::onCreate() {
this->camPos = (Point3d){0.0f, 500.0f, 1000.0f};
this->camRotate = (Point3d){-40.0f, -30.0f, 0.0f}; // ZXY order
camDist = 740;
camY = 330;
targetDist = 100;
targetY = -220;
return true;
}
int dWorldCamera_c::onDelete() {
return true;
}
int dWorldCamera_c::onExecute() {
int heldButtons = Remocon_GetButtons(GetActiveRemocon());
/*if (heldButtons & WPAD_LEFT)
this->camPos.x -= 5.0f;
if (heldButtons & WPAD_RIGHT)
this->camPos.x += 5.0f;
if (heldButtons & WPAD_UP)
this->camPos.z -= 5.0f;
if (heldButtons & WPAD_DOWN)
this->camPos.z += 5.0f;
if (heldButtons & WPAD_MINUS)
this->camRotate.y -= 2.0f;
if (heldButtons & WPAD_PLUS)
this->camRotate.y += 2.0f;*/
/*bool change = false;
if (heldButtons & WPAD_LEFT) { camDist -= 5.0f; change = true; }
if (heldButtons & WPAD_RIGHT) { camDist += 5.0f; change = true; }
if (heldButtons & WPAD_UP) { camY -= 5.0f; change = true; }
if (heldButtons & WPAD_DOWN) { camY += 5.0f; change = true; }
if (heldButtons & WPAD_MINUS) { targetDist -= 5.0f; change = true; }
if (heldButtons & WPAD_PLUS) { targetDist += 5.0f; change = true; }
if (heldButtons & WPAD_ONE) { targetY -= 5.0f; change = true; }
if (heldButtons & WPAD_TWO) { targetY += 5.0f; change = true; }
if (change)
OSReport("[Cam Dist=%f Y=%f] [Target Dist=%f Y=%f]\n", camDist, camY, targetDist, targetY);*/
return true;
}
int dWorldCamera_c::onDraw() {
// fixup camera shit
GXRenderModeObj *rmode = nw4r::g3d::G3DState::GetRenderModeObj();
// 2D camera
nw4r::g3d::Camera cam2d(GetCameraByID(1));
if (rmode->field_rendering != 0)
cam2d.SetViewportJitter(VIGetNextField());
cam2d.SetOrtho(rmode->efbHeight, 0.0f, 0.0f, rmode->fbWidth * (IsWideScreen() ? 1.3333334f : 1.0f), -100000.0f, 100000.0f);
// 3D camera
nw4r::g3d::Camera cam3d(GetCameraByID(0));
if (rmode->field_rendering != 0)
cam3d.SetViewportJitter(VIGetNextField());
cam3d.SetPerspective(45, (f32)rmode->viWidth / (f32)rmode->viHeight, 0.1f, 2400.0f);
//cam3d.SetOrtho(rmode->efbHeight, 0.0f, 0.0f, rmode->fbWidth * (IsWideScreen() ? 1.3333334f : 1.0f), -100000.0f, 100000.0f);
/*nw4r::g3d::Camera::PostureInfo posture;
posture.tp = nw4r::g3d::Camera::POSTURE_ROTATE;
posture.cameraRotate = this->camRotate;
cam3d.SetPosition(this->camPos);
cam3d.SetPosture(posture);*/
// The map is actually roughly 500x500, but I use a bigger circle in order
// to give leeway for the camera
// TODO: Make these vars tweakable!
float angle = MTXDegToRad(90.0) - atan2(daWMPlayer_c::instance->pos.z, daWMPlayer_c::instance->pos.x);
float camX = sin(angle) * camDist;
float camZ = cos(angle) * camDist;
float targetX = sin(angle) * targetDist;
float targetZ = cos(angle) * targetDist;
nw4r::g3d::Camera::PostureInfo posture;
posture.tp = nw4r::g3d::Camera::POSTURE_LOOKAT;
posture.cameraUp = (Point3d){0,1,0};
posture.cameraTarget = (Point3d){targetX,targetY,targetZ};
cam3d.SetPosition((Point3d){camX,camY,camZ});
cam3d.SetPosture(posture);
return true;
}
|