Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ WhitespaceSensitiveMacros:
DECOMP_FORCEACTIVE_DTOR,
DECOMP_FORCEACTIVE,
DECOMP_FORCELITERAL,
OS_ASSERT,
OS_ERROR,
EGG_ASSERT,
EGG_ASSERT_MSG,
RP_ASSERT,
Expand Down
7 changes: 5 additions & 2 deletions config/RSPE01_01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3271,13 +3271,13 @@ Pack/RPGraphics/RPGrpModelAnmImplement.cpp:
.text start:0x801AA99C end:0x801ACB40
.rodata start:0x803836B0 end:0x803836E0
.data start:0x803BA188 end:0x803BA2F0
.sbss start:0x804BF5F0 end:0x804BF5F8
.sdata2 start:0x804C1868 end:0x804C1878

Pack/RPGraphics/RPGrpModelImplement.cpp:
.text start:0x801ACB40 end:0x801ADE70
.data start:0x803BA2F0 end:0x803BA3E8
.bss start:0x804A44C8 end:0x804A44F8
.sbss start:0x804BF5F0 end:0x804BF5F8

Pack/RPGraphics/RPGrpModelMisc.cpp:
.text start:0x801ADE70 end:0x801ADE80
Expand Down Expand Up @@ -3339,9 +3339,12 @@ Pack/RPGraphics/RPGrpModelBoundingInfo.cpp:
.data start:0x803BA708 end:0x803BA718

Pack/RPGraphics/RPGrpDrawPathShadowTexture.cpp:
.text start:0x801B2690 end:0x801B284C
.text start:0x801B2690 end:0x801B273C
.data start:0x803BA718 end:0x803BA730

Pack/RPGraphics/RPGrpShadowTexture.cpp:
.text start:0x801B273C end:0x801B284C

Pack/RPGraphics/RPGrpModelMaterial.cpp:
.text start:0x801B284C end:0x801B3DF0
.rodata start:0x80383768 end:0x80383778
Expand Down
298 changes: 149 additions & 149 deletions config/RSPE01_01/symbols.txt

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,30 +1232,31 @@ def MatchingFor(*versions):
"cflags": cflags_rp,
"progress_category": "graphics", # str | List[str]
"objects": [
Object(NonMatching, "Pack/RPGraphics/RPGrpCamera.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpCamera.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpDrawPathManager.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpLightManager.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModel.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelAnm.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpLightManager.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpModel.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpModelAnm.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelAnmImplement.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelImplement.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelMisc.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelManager.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelResManager.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpRenderer.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpScreen.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpScreen.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpView.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpViewRender2D.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpViewRender3D.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelScene.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpDrawPathLightMap.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelBoundingInfo.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpDrawPathShadowTexture.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpModelBoundingInfo.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpDrawPathShadowTexture.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpShadowTexture.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelMaterial.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelRecord.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpTexture.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpCaptureTexture.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpFogManager.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpCaptureTexture.cpp"),
Object(Matching, "Pack/RPGraphics/RPGrpFogManager.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpProjectionObject.cpp"),
Object(NonMatching, "Pack/RPGraphics/RPGrpModelRfl.cpp"),
],
Expand Down
13 changes: 13 additions & 0 deletions include/Pack/RPGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@
#define RP_PUBLIC_GRAPHICS_H

#include <Pack/RPGraphics/IRPGrpModelCallback.h>
#include <Pack/RPGraphics/RPGrpCamera.h>
#include <Pack/RPGraphics/RPGrpCaptureTexture.h>
#include <Pack/RPGraphics/RPGrpDrawPath.h>
#include <Pack/RPGraphics/RPGrpDrawPathBloom.h>
#include <Pack/RPGraphics/RPGrpDrawPathDOF.h>
#include <Pack/RPGraphics/RPGrpDrawPathHDR.h>
#include <Pack/RPGraphics/RPGrpDrawPathLightMap.h>
#include <Pack/RPGraphics/RPGrpDrawPathManager.h>
#include <Pack/RPGraphics/RPGrpDrawPathSV.h>
#include <Pack/RPGraphics/RPGrpDrawPathShadowTexture.h>
#include <Pack/RPGraphics/RPGrpDrawPathXluSnap.h>
#include <Pack/RPGraphics/RPGrpFogManager.h>
#include <Pack/RPGraphics/RPGrpLightManager.h>
#include <Pack/RPGraphics/RPGrpModel.h>
#include <Pack/RPGraphics/RPGrpModelAnm.h>
#include <Pack/RPGraphics/RPGrpModelAnmImplement.h>
#include <Pack/RPGraphics/RPGrpModelBoundingInfo.h>
#include <Pack/RPGraphics/RPGrpModelG3D.h>
#include <Pack/RPGraphics/RPGrpModelManager.h>
#include <Pack/RPGraphics/RPGrpModelMaterial.h>
#include <Pack/RPGraphics/RPGrpModelMisc.h>
#include <Pack/RPGraphics/RPGrpModelRecord.h>
#include <Pack/RPGraphics/RPGrpModelResManager.h>
#include <Pack/RPGraphics/RPGrpModelRfl.h>
#include <Pack/RPGraphics/RPGrpProjectionObject.h>
#include <Pack/RPGraphics/RPGrpRenderer.h>
#include <Pack/RPGraphics/RPGrpScreen.h>
#include <Pack/RPGraphics/RPGrpShadowTexture.h>
#include <Pack/RPGraphics/RPGrpTexture.h>

#endif
248 changes: 248 additions & 0 deletions include/Pack/RPGraphics/RPGrpCamera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
#ifndef RP_GRAPHICS_CAMERA_H
#define RP_GRAPHICS_CAMERA_H
#include <Pack/types_pack.h>

#include <nw4r/g3d.h>
#include <nw4r/math.h>

//! @addtogroup rp_graphics
//! @{

// Forward declarations
class RPGrpScreen;

/**
* @brief Camera controller
*/
class RPGrpCamera {
public:
/**
* @brief Camera behavior type
*/
enum ECameraType {
//! Use the G3D camera animation result
ECameraType_Anm,
//! World matrix is supplied directly
ECameraType_Direct,
//! Look at the target position
ECameraType_LookAt,
//! Rotate around the target point
ECameraType_Orbit,
//! Camera is placed in the scene
ECameraType_Free,
};

private:
//! Default camera
static RPGrpCamera sDefaultCamera;

//! Camera view matrix (world -> cam)
nw4r::math::MTX34 mViewMtx; // at 0x0
//! Inverse of the view matrix (cam -> world)
nw4r::math::MTX34 mWorldMtx; // at 0x30
//! View matrix controlled by a G3D camera animation
nw4r::math::MTX34 mAnmViewMtx; // at 0x60
//! World matrix supplied for direct type cameras
nw4r::math::MTX34 mDirectWorldMtx; // at 0x90

//! World position of the camera
nw4r::math::VEC3 mPosition; // at 0xC0
//! World position of the camera's target
nw4r::math::VEC3 mTarget; // at 0xCC
//! Rotation of the camera, in degrees
nw4r::math::VEC3 mRotation; // at 0xD8

//! Distance to the camera target
f32 mDistance; // at 0xE4

//! Right vector (+X)
nw4r::math::VEC3 mRight; // at 0xE8
//! Up vector (+Y)
nw4r::math::VEC3 mUp; // at 0xF4
//! Forward vector (+Z)
nw4r::math::VEC3 mForward; // at 0x100

//! Camera behavior type
ECameraType mCameraType; // at 0x10C
//! Camera state flags
u16 mFlags; // at 0x110

//! World matrix during the previous frame
nw4r::math::MTX34 mWorldMtxOld; // at 0x114

//! Saved state of the view matrix
nw4r::math::MTX34 mSavedViewMtx; // at 0x144

public:
/**
* @brief Initializes the camera system
*/
static void Initialize();

/**
* @brief Constructor
*/
RPGrpCamera();

/**
* @brief Destructor
*/
virtual ~RPGrpCamera() {} // at 0x8

/**
* @brief Copies the state from another camera
*
* @param rOther Camera from which to copy
*/
virtual void CopyFromAnother(const RPGrpCamera& rOther); // at 0xC

/**
* @brief Resets the camera transformation
*/
void Identity();

/**
* @brief Updates the camera state based on the camera type
*/
void CalcMatrix();

/**
* @brief Saves the current state of the view matrix
*/
void SaveCameraMatrix();

/**
* @brief Converts a position from world-space to screen-space
*
* @param[out] pScreenPos Position in screen-space
* @param rWorldPos Position in world-space
* @param pScreen Screen
*/
void GetWorldToScreen(nw4r::math::VEC3* pScreenPos,
const nw4r::math::VEC3& rWorldPos,
const RPGrpScreen* pScreen) const;

/**
* @brief Converts a position from screen-space to world-space
*
* @param[out] pWorldPos Position in world-space
* @param rScreenPos Position in screen-space
* @param pScreen Screen
*/
void GetScreenToWorld(nw4r::math::VEC3* pWorldPos,
const nw4r::math::VEC3& rScreenPos,
const RPGrpScreen* pScreen) const;

/**
* @brief Converts a position from screen-space to world-space
*
* @param[out] pWorldPos Position in world-space
* @param rScreenPos Position in screen-space
* @param pScreen Screen
*/
void GetScreenToWorld(nw4r::math::VEC3* pWorldPos,
const nw4r::math::VEC2& rScreenPos,
const RPGrpScreen* pScreen) const;

/**
* @brief Applies camera settings from the specified scene resource
*
* @param scn Scene resource
* @param refNumber Camera reference number
* @param frame Animation frame (defaults to the first frame)
*/
void LoadScnCameraMatrix(const nw4r::g3d::ResAnmScn scn, u8 refNumber,
f32 frame = 0.0f);

/**
* @brief Sets the type of this camera
*
* @param type New camera type
*/
void SetCameraType(ECameraType type) {
mCameraType = type;
}

/**
* @brief Accesses the saved state of the view matrix
*/
const nw4r::math::MTX34& GetSavedCameraMatrix() const {
return mSavedViewMtx;
}

/**
* @brief Accesses the default camera object
*/
static RPGrpCamera& GetDefaultCamera() {
return sDefaultCamera;
}

private:
/**
* @brief Bit flags to control SyncFromMatrix behavior
*/
enum ESyncFlag {
//! Derive position using the world matrix
ESyncFlag_Position = 1 << 0,

//! Derive the up vector using the world matrix
ESyncFlag_Up = 1 << 1,
//! Derive the target position using the world matrix
ESyncFlag_Target = 1 << 2,
//! Derive rotation using the world matrix
ESyncFlag_Rotation = 1 << 3,
//! Calculate distance to the target position
ESyncFlag_Distance = 1 << 4,

//! Derive the view matrix from the world matrix
ESyncFlag_ViewMtx = 1 << 5,
//! Derive the world matrix from the view matrix
ESyncFlag_WorldMtx = 1 << 6,

//! Save the view matrix to the G3D animation matrix
ESyncFlag_AnmViewMtx = 1 << 7,
//! Save the world matrix to the direct world matrix
ESyncFlag_DirectWorldMtx = 1 << 8,

// Sync flag presets
ESyncFlag_ForAnmCamera = ESyncFlag_Position | ESyncFlag_Up |
ESyncFlag_Target | ESyncFlag_Rotation |
ESyncFlag_WorldMtx | ESyncFlag_DirectWorldMtx,

ESyncFlag_ForDirectCamera = ESyncFlag_Position | ESyncFlag_Up |
ESyncFlag_Target | ESyncFlag_Rotation |
ESyncFlag_ViewMtx | ESyncFlag_AnmViewMtx,

ESyncFlag_ForLookAtCamera = ESyncFlag_Rotation | ESyncFlag_Distance |
ESyncFlag_WorldMtx | ESyncFlag_AnmViewMtx |
ESyncFlag_DirectWorldMtx,

ESyncFlag_ForOrbitCamera = ESyncFlag_Position | ESyncFlag_Up |
ESyncFlag_WorldMtx | ESyncFlag_AnmViewMtx |
ESyncFlag_DirectWorldMtx,

ESyncFlag_ForFreeCamera = ESyncFlag_Up | ESyncFlag_Target |
ESyncFlag_ViewMtx | ESyncFlag_AnmViewMtx |
ESyncFlag_DirectWorldMtx,
};

/**
* @brief Camera state flags
*/
enum {
EFlag_5 = 1 << 5,
EFlag_7 = 1 << 7,
};

private:
/**
* @brief Derives components of the camera state from the world matrix
*
* @param flags Flags controlling which components to update
*/
void SyncFromMatrix(u16 flags);
};

//! @}

#endif
Loading
Loading