Skip to content

Commit 0a24a07

Browse files
MelonSpeedrunsdcvz
authored andcommitted
Free Camera (#337)
* wip free cam * Almost done, needs collision still * Added free cam behind cvar * added WIP collision * Fixed & implemented "Manual mode" from WW & TP * Fixed camera not rotating when Link is moving * fixed initialized camera rotation * Fixed camera getting stuck + made it smoother * reduced deadzone * fixed epona camera height + added WW z-target free camera * Adjusted player camera height & fixed fov * Fixed camera roll * fixed fov when moving the camera while in z-target * Camera resets to Auto when going through doors or changing maps * Fixed building * touch * more touch work * Added WIP mouse support to the free cam * gui stuff * fixed building * fixed building error * ok fixed building for real this time * oops * Fix compilation issues * removed mouse stuff that magically appeared in this branch * smoothed out stick values & removed remains of mouse support * re-added manual camera when pressing Z * reduced minimum Y position of camera * Addressed dcsv's nitpicks * part 2 * oops Co-authored-by: David Chavez <[email protected]>
1 parent 3aa93b9 commit 0a24a07

File tree

12 files changed

+221
-20
lines changed

12 files changed

+221
-20
lines changed

libultraship/libultraship/Controller.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#include "GlobalCtx2.h"
33
#include "stox.h"
44
#include <memory>
5+
#include <string>
6+
#if __APPLE__
7+
#include <SDL_events.h>
8+
#else
9+
#include <SDL2/SDL_events.h>
10+
#endif
511

612
namespace Ship {
713
Controller::Controller(int32_t dwControllerNumber) : dwControllerNumber(dwControllerNumber) {
@@ -16,8 +22,12 @@ namespace Ship {
1622
void Controller::Read(OSContPad* pad) {
1723
ReadFromSource();
1824

25+
SDL_PumpEvents();
26+
27+
// Button Inputs
1928
pad->button |= dwPressedButtons & 0xFFFF;
2029

30+
// Stick Inputs
2131
if (pad->stick_x == 0) {
2232
if (dwPressedButtons & BTN_STICKLEFT) {
2333
pad->stick_x = -128;
@@ -42,8 +52,13 @@ namespace Ship {
4252
}
4353
}
4454

55+
// Gyro
4556
pad->gyro_x = wGyroX;
4657
pad->gyro_y = wGyroY;
58+
59+
// Right Stick
60+
pad->cam_x = wCamX;
61+
pad->cam_y = wCamY;
4762
}
4863

4964
void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) {
@@ -93,4 +108,4 @@ namespace Ship {
93108
std::string Controller::GetBindingConfSection() {
94109
return GetControllerType() + " CONTROLLER BINDING " + std::to_string(GetControllerNumber() + 1);
95110
}
96-
}
111+
}

libultraship/libultraship/Controller.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Ship {
1515
class Controller {
16-
1716
public:
1817
Controller(int32_t dwControllerNumber);
1918

@@ -38,7 +37,9 @@ namespace Ship {
3837
int8_t wStickY;
3938
float wGyroX;
4039
float wGyroY;
41-
40+
float wCamX;
41+
float wCamY;
42+
4243
virtual std::string GetControllerType() = 0;
4344
virtual std::string GetConfSection() = 0;
4445
virtual std::string GetBindingConfSection() = 0;

libultraship/libultraship/ImGuiImpl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,8 @@ namespace SohImGui {
11431143
EnhancementCheckbox("Skip Text", "gSkipText");
11441144
Tooltip("Holding down B skips text\nKnown to cause a cutscene softlock in Water Temple\nSoftlock can be fixed by pressing D-Right in Debug mode");
11451145

1146+
EnhancementCheckbox("Free Camera", "gFreeCamera");
1147+
11461148
ImGui::EndMenu();
11471149
}
11481150

libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/controller.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ typedef struct {
112112
/* 0x02 */ s8 stick_x;
113113
/* 0x03 */ s8 stick_y;
114114
/* 0x04 */ u8 err_no;
115-
/* 0x05 */ f32 gyro_x;
116-
/* 0x09 */ f32 gyro_y;
117-
} OSContPad; // size = 0x0D
115+
/* 0x05 */ f32 gyro_x;
116+
/* 0x09 */ f32 gyro_y;
117+
/* 0x1C */ f32 cam_x;
118+
/* 0x20 */ f32 cam_y;
119+
} OSContPad; // size = 0x24
118120

119121
typedef struct {
120122
/* 0x00 */ u8 rumble;

libultraship/libultraship/SDLController.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace Ship {
132132
}
133133

134134

135-
void SDLController::NormalizeStickAxis(int16_t wAxisValueX, int16_t wAxisValueY, int16_t wAxisThreshold) {
135+
void SDLController::NormalizeStickAxis(int16_t wAxisValueX, int16_t wAxisValueY, int16_t wAxisThreshold, bool isRightStick) {
136136
//scale {-32768 ... +32767} to {-84 ... +84}
137137
auto ax = wAxisValueX * 85.0 / 32767.0;
138138
auto ay = wAxisValueY * 85.0 / 32767.0;
@@ -163,8 +163,15 @@ namespace Ship {
163163
ay *= scale;
164164
}
165165

166-
wStickX = +ax;
167-
wStickY = -ay;
166+
if (!isRightStick) {
167+
wStickX = +ax;
168+
wStickY = -ay;
169+
}
170+
else {
171+
//SOHTODO KIRITO: Camera Sensitivity
172+
wCamX = +ax * 15.0f;
173+
wCamY = -ay * 15.0f;
174+
}
168175
}
169176

170177
void SDLController::ReadFromSource() {
@@ -187,6 +194,10 @@ namespace Ship {
187194
}
188195
}
189196

197+
auto cameraX = SDL_GameControllerGetAxis(Cont, SDL_CONTROLLER_AXIS_RIGHTX);
198+
auto cameraY = SDL_GameControllerGetAxis(Cont, SDL_CONTROLLER_AXIS_RIGHTY);
199+
NormalizeStickAxis(cameraX, cameraY, ThresholdMapping[SDL_CONTROLLER_AXIS_LEFTX], true);
200+
190201
if (SDL_GameControllerHasSensor(Cont, SDL_SENSOR_GYRO))
191202
{
192203
size_t contNumber = GetControllerNumber();
@@ -328,7 +339,7 @@ namespace Ship {
328339
if (StickAxisX != SDL_CONTROLLER_AXIS_INVALID && StickAxisY != SDL_CONTROLLER_AXIS_INVALID) {
329340
auto AxisValueX = SDL_GameControllerGetAxis(Cont, StickAxisX);
330341
auto AxisValueY = SDL_GameControllerGetAxis(Cont, StickAxisY);
331-
NormalizeStickAxis(AxisValueX, AxisValueY, StickDeadzone);
342+
NormalizeStickAxis(AxisValueX, AxisValueY, StickDeadzone, false);
332343
}
333344
}
334345
}
@@ -365,12 +376,13 @@ namespace Ship {
365376
void SDLController::CreateDefaultBinding() {
366377
std::string ConfSection = GetBindingConfSection();
367378
std::shared_ptr<ConfigFile> pConf = GlobalCtx2::GetInstance()->GetConfig();
379+
368380
ConfigFile& Conf = *pConf.get();
369381

370-
Conf[ConfSection][STR(BTN_CRIGHT)] = std::to_string((SDL_CONTROLLER_AXIS_RIGHTX + AXIS_SCANCODE_BIT));
371-
Conf[ConfSection][STR(BTN_CLEFT)] = std::to_string(-(SDL_CONTROLLER_AXIS_RIGHTX + AXIS_SCANCODE_BIT));
372-
Conf[ConfSection][STR(BTN_CDOWN)] = std::to_string((SDL_CONTROLLER_AXIS_RIGHTY + AXIS_SCANCODE_BIT));
373-
Conf[ConfSection][STR(BTN_CUP)] = std::to_string(-(SDL_CONTROLLER_AXIS_RIGHTY + AXIS_SCANCODE_BIT));
382+
Conf[ConfSection][STR(BTN_CRIGHT)] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
383+
Conf[ConfSection][STR(BTN_CLEFT)] = std::to_string(SDL_CONTROLLER_BUTTON_Y);
384+
Conf[ConfSection][STR(BTN_CDOWN)] = std::to_string(SDL_CONTROLLER_BUTTON_X);
385+
Conf[ConfSection][STR(BTN_CUP)] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSTICK);
374386
//Conf[ConfSection][STR(BTN_CRIGHT + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_X);
375387
//Conf[ConfSection][STR(BTN_CLEFT + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_Y);
376388
//Conf[ConfSection][STR(BTN_CDOWN + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);

libultraship/libultraship/SDLController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace Ship {
4444
std::map<int32_t, int16_t> ThresholdMapping;
4545

4646
void LoadAxisThresholds();
47-
void NormalizeStickAxis(int16_t wAxisValueX, int16_t wAxisValueY, int16_t wAxisThreshold);
47+
void NormalizeStickAxis(int16_t wAxisValueX, int16_t wAxisValueY, int16_t wAxisThreshold, bool isRightStick);
4848
bool Open();
4949
bool Close();
5050
};

libultraship/libultraship/UltraController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ typedef struct {
120120
/* 0x04 */ uint8_t err_no;
121121
/* 0x05 */ float gyro_x;
122122
/* 0x09 */ float gyro_y;
123-
} OSContPad; // size = 0x0D
123+
/* 0x1C */ float cam_x;
124+
/* 0x20 */ float cam_y;
125+
} OSContPad; // size = 0x24
124126

125127
typedef struct {
126128
/* 0x00 */ uint8_t rumble;

soh/include/z64.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,9 @@ typedef struct GlobalContext {
12031203
/* 0x00790 */ Camera* cameraPtrs[NUM_CAMS];
12041204
/* 0x007A0 */ s16 activeCamera;
12051205
/* 0x007A2 */ s16 nextCamera;
1206+
/* 0x007A2 */ bool manualCamera;
1207+
/* 0x007A2 */ f32 camX;
1208+
/* 0x007A2 */ f32 camY;
12061209
/* 0x007A4 */ SequenceContext sequenceCtx;
12071210
/* 0x007A8 */ LightContext lightCtx;
12081211
/* 0x007B8 */ FrameAdvanceContext frameAdvCtx;

0 commit comments

Comments
 (0)