Path: blob/master/SonicMania/Objects/Pinball/PBL_Camera.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PBL_Camera Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectPBL_Camera *PBL_Camera;1112void PBL_Camera_Update(void) {}1314void PBL_Camera_LateUpdate(void)15{16RSDK_THIS(PBL_Camera);1718StateMachine_Run(self->state);1920PBL_Camera_HandleScreenPos();2122self->targetPos = self->position;23self->targetPos.y -= (0x100 << 16);24}2526void PBL_Camera_StaticUpdate(void) {}2728void PBL_Camera_Draw(void) {}2930void PBL_Camera_Create(void *data)31{32RSDK_THIS(PBL_Camera);3334self->active = ACTIVE_NORMAL;35self->state = PBL_Camera_State_Normal;3637self->angle = 0x200;38self->rotationY = -0x60;3940self->position.x = 0x400 << 16;41self->worldY = 0x100 << 16;42self->position.y = self->cameraStartOffset + (0x700 << 16);4344self->curCamBoundaryT = 0x100 << 16;45self->curCamBoundaryB = 0x700 << 16;46self->newCamBoundaryT = 0x100 << 16;47self->newCamBoundaryB = 0x700 << 16;48}4950void PBL_Camera_StageLoad(void)51{52RSDK.ResetEntitySlot(SLOT_PBL_CAMERA, PBL_Camera->classID, NULL);5354RSDK.ClearCameras();5556EntityPBL_Camera *entity = RSDK_GET_ENTITY(SLOT_PBL_CAMERA, PBL_Camera);57RSDK.AddCamera(&entity->targetPos, 0x100 << 16, 0x100 << 16, true);5859PBL_Camera->useAltMatNormal = false;60}6162void PBL_Camera_HandleScreenPos(void)63{64RSDK_THIS(PBL_Camera);6566int32 angle = RSDK.Cos1024(-self->rotationY) << 12;67if (angle < 0x3C0000)68angle = 0x3C0000;6970int32 ang = self->angle - self->prevAngle;71int32 ang2 = ang - 0x400;72if (self->angle <= 0x200)73ang2 = ang + 0x400;7475if (abs(ang) >= abs(ang2))76ScreenInfo->position.x -= 2 * ang2;77else78ScreenInfo->position.x -= 2 * ang;7980int32 height = ((RSDK.Sin1024(-self->rotationY) << 12) << 8) / angle;81ScreenInfo->position.y = height - ScreenInfo->center.y + 512;82self->prevAngle = self->angle;83self->centerY = CLAMP(ScreenInfo->center.y - height + 8, -64, ScreenInfo->size.y);84}8586void PBL_Camera_State_Normal(void)87{88RSDK_THIS(PBL_Camera);8990Entity *target = self->target;91if (target) {92if (target->position.y < self->position.y - 0x1500000) {93self->position.y += MAX(target->position.y - self->position.y + 0x1500000, -0x100000);94}95else if (target->position.y > self->position.y - 0xF00000) {96self->position.y += MIN(target->position.y - self->position.y + 0xF00000, 0x100000);97}9899if (self->position.y < self->curCamBoundaryT + 0x2000000)100self->position.y = self->curCamBoundaryT + 0x2000000;101102if (self->curCamBoundaryT != self->newCamBoundaryT)103self->curCamBoundaryT += CLAMP(self->newCamBoundaryT - self->curCamBoundaryT, -0x100000, 0x100000);104105if (self->position.y > self->curCamBoundaryB + 0x900000)106self->position.y = self->curCamBoundaryB + 0x900000;107108if (self->curCamBoundaryB != self->newCamBoundaryB)109self->curCamBoundaryB += CLAMP(self->newCamBoundaryB - self->curCamBoundaryB, -0x100000, 0x100000);110}111112RSDK.MatrixTranslateXYZ(&self->matTransform, -self->position.x, -self->worldY, -self->position.y, true);113RSDK.MatrixRotateXYZ(&PBL_Camera->matNormalItem, self->rotationY, self->angle, 0);114RSDK.MatrixMultiply(&PBL_Camera->matWorld, &self->matTransform, &PBL_Camera->matNormalItem);115116RSDK.MatrixScaleXYZ(&self->matTransform, -0x100, 0x100, 0x100);117RSDK.MatrixMultiply(&PBL_Camera->matNormalItem, &PBL_Camera->matNormalItem, &self->matTransform);118119RSDK.MatrixRotateXYZ(&PBL_Camera->matNormal, self->rotationY + 8 * PBL_Setup->timer, self->angle, 0);120RSDK.MatrixMultiply(&PBL_Camera->matNormal, &PBL_Camera->matNormal, &self->matTransform);121RSDK.MatrixMultiply(&PBL_Camera->matWorld, &PBL_Camera->matWorld, &self->matTransform);122}123124#if GAME_INCLUDE_EDITOR125void PBL_Camera_EditorDraw(void) {}126127void PBL_Camera_EditorLoad(void) {}128#endif129130void PBL_Camera_Serialize(void) {}131#endif132133134