Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Pinball/PBL_Camera.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PBL_Camera Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
#if MANIA_USE_PLUS
11
ObjectPBL_Camera *PBL_Camera;
12
13
void PBL_Camera_Update(void) {}
14
15
void PBL_Camera_LateUpdate(void)
16
{
17
RSDK_THIS(PBL_Camera);
18
19
StateMachine_Run(self->state);
20
21
PBL_Camera_HandleScreenPos();
22
23
self->targetPos = self->position;
24
self->targetPos.y -= (0x100 << 16);
25
}
26
27
void PBL_Camera_StaticUpdate(void) {}
28
29
void PBL_Camera_Draw(void) {}
30
31
void PBL_Camera_Create(void *data)
32
{
33
RSDK_THIS(PBL_Camera);
34
35
self->active = ACTIVE_NORMAL;
36
self->state = PBL_Camera_State_Normal;
37
38
self->angle = 0x200;
39
self->rotationY = -0x60;
40
41
self->position.x = 0x400 << 16;
42
self->worldY = 0x100 << 16;
43
self->position.y = self->cameraStartOffset + (0x700 << 16);
44
45
self->curCamBoundaryT = 0x100 << 16;
46
self->curCamBoundaryB = 0x700 << 16;
47
self->newCamBoundaryT = 0x100 << 16;
48
self->newCamBoundaryB = 0x700 << 16;
49
}
50
51
void PBL_Camera_StageLoad(void)
52
{
53
RSDK.ResetEntitySlot(SLOT_PBL_CAMERA, PBL_Camera->classID, NULL);
54
55
RSDK.ClearCameras();
56
57
EntityPBL_Camera *entity = RSDK_GET_ENTITY(SLOT_PBL_CAMERA, PBL_Camera);
58
RSDK.AddCamera(&entity->targetPos, 0x100 << 16, 0x100 << 16, true);
59
60
PBL_Camera->useAltMatNormal = false;
61
}
62
63
void PBL_Camera_HandleScreenPos(void)
64
{
65
RSDK_THIS(PBL_Camera);
66
67
int32 angle = RSDK.Cos1024(-self->rotationY) << 12;
68
if (angle < 0x3C0000)
69
angle = 0x3C0000;
70
71
int32 ang = self->angle - self->prevAngle;
72
int32 ang2 = ang - 0x400;
73
if (self->angle <= 0x200)
74
ang2 = ang + 0x400;
75
76
if (abs(ang) >= abs(ang2))
77
ScreenInfo->position.x -= 2 * ang2;
78
else
79
ScreenInfo->position.x -= 2 * ang;
80
81
int32 height = ((RSDK.Sin1024(-self->rotationY) << 12) << 8) / angle;
82
ScreenInfo->position.y = height - ScreenInfo->center.y + 512;
83
self->prevAngle = self->angle;
84
self->centerY = CLAMP(ScreenInfo->center.y - height + 8, -64, ScreenInfo->size.y);
85
}
86
87
void PBL_Camera_State_Normal(void)
88
{
89
RSDK_THIS(PBL_Camera);
90
91
Entity *target = self->target;
92
if (target) {
93
if (target->position.y < self->position.y - 0x1500000) {
94
self->position.y += MAX(target->position.y - self->position.y + 0x1500000, -0x100000);
95
}
96
else if (target->position.y > self->position.y - 0xF00000) {
97
self->position.y += MIN(target->position.y - self->position.y + 0xF00000, 0x100000);
98
}
99
100
if (self->position.y < self->curCamBoundaryT + 0x2000000)
101
self->position.y = self->curCamBoundaryT + 0x2000000;
102
103
if (self->curCamBoundaryT != self->newCamBoundaryT)
104
self->curCamBoundaryT += CLAMP(self->newCamBoundaryT - self->curCamBoundaryT, -0x100000, 0x100000);
105
106
if (self->position.y > self->curCamBoundaryB + 0x900000)
107
self->position.y = self->curCamBoundaryB + 0x900000;
108
109
if (self->curCamBoundaryB != self->newCamBoundaryB)
110
self->curCamBoundaryB += CLAMP(self->newCamBoundaryB - self->curCamBoundaryB, -0x100000, 0x100000);
111
}
112
113
RSDK.MatrixTranslateXYZ(&self->matTransform, -self->position.x, -self->worldY, -self->position.y, true);
114
RSDK.MatrixRotateXYZ(&PBL_Camera->matNormalItem, self->rotationY, self->angle, 0);
115
RSDK.MatrixMultiply(&PBL_Camera->matWorld, &self->matTransform, &PBL_Camera->matNormalItem);
116
117
RSDK.MatrixScaleXYZ(&self->matTransform, -0x100, 0x100, 0x100);
118
RSDK.MatrixMultiply(&PBL_Camera->matNormalItem, &PBL_Camera->matNormalItem, &self->matTransform);
119
120
RSDK.MatrixRotateXYZ(&PBL_Camera->matNormal, self->rotationY + 8 * PBL_Setup->timer, self->angle, 0);
121
RSDK.MatrixMultiply(&PBL_Camera->matNormal, &PBL_Camera->matNormal, &self->matTransform);
122
RSDK.MatrixMultiply(&PBL_Camera->matWorld, &PBL_Camera->matWorld, &self->matTransform);
123
}
124
125
#if GAME_INCLUDE_EDITOR
126
void PBL_Camera_EditorDraw(void) {}
127
128
void PBL_Camera_EditorLoad(void) {}
129
#endif
130
131
void PBL_Camera_Serialize(void) {}
132
#endif
133
134