NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
g3d_camera.h
1#ifndef NW4R_G3D_CAMERA_H
2#define NW4R_G3D_CAMERA_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/g3d/res/g3d_rescommon.h>
6
7#include <nw4r/math.h>
8
9#include <revolution/MTX.h>
10
11namespace nw4r {
12namespace g3d {
13
14struct CameraData {
15 enum Flag {
16 FLAG_CAM_LOOKAT = (1 << 0),
17 FLAG_CAM_ROTATE = (1 << 1),
18 FLAG_CAM_AIM = (1 << 2),
19 FLAG_CAM_MTX_READY = (1 << 3),
20
21 FLAG_PROJ_FRUSTUM = (1 << 4),
22 FLAG_PROJ_PERSP = (1 << 5),
23 FLAG_PROJ_ORTHO = (1 << 6),
24 FLAG_PROJ_MTX_READY = (1 << 7),
25
26 FLAG_VI_ODD_FIELD = (1 << 8),
27 };
28
29 math::MTX34 cameraMtx; // at 0x0
30 math::MTX44 projMtx; // at 0x30
31 ulong flags; // at 0x70
32 math::VEC3 cameraPos; // at 0x74
33 math::VEC3 cameraUp; // at 0x80
34 math::VEC3 cameraTarget; // at 0x8C
35 math::VEC3 cameraRotate; // at 0x98
36 f32 cameraTwist; // at 0xA4
37 GXProjectionType projType; // at 0xA8
38 f32 projFovy; // at 0xAC
39 f32 projAspect; // at 0xB0
40 f32 projNear; // at 0xB4
41 f32 projFar; // at 0xB8
42 f32 projTop; // at 0xBC
43 f32 projBottom; // at 0xC0
44 f32 projLeft; // at 0xC4
45 f32 projRight; // at 0xC8
46 f32 lightScaleS; // at 0xCC
47 f32 lightScaleT; // at 0xD0
48 f32 lightTransS; // at 0xD4
49 f32 lightTransT; // at 0xD8
50 math::VEC2 viewportOrigin; // at 0xDC
51 math::VEC2 viewportSize; // at 0xE4
52 f32 viewportNear; // at 0xEC
53 f32 viewportFar; // at 0xF0
54 ulong scissorX; // at 0xF4
55 ulong scissorY; // at 0xF8
56 ulong scissorWidth; // at 0xFC
57 ulong scissorHeight; // at 0x100
58 s32 scissorOffsetX; // at 0x104
59 s32 scissorOffsetY; // at 0x108
60};
61
62class Camera : public ResCommon<CameraData> {
63public:
64 enum PostureType { POSTURE_LOOKAT, POSTURE_ROTATE, POSTURE_AIM };
65
66 struct PostureInfo {
67 PostureType tp; // at 0x0
68 math::VEC3 cameraUp; // at 0x4
69 math::VEC3 cameraTarget; // at 0x10
70 math::VEC3 cameraRotate; // at 0x1C
71 f32 cameraTwist; // at 0x28
72 };
73
74public:
75 explicit Camera(CameraData* pData);
76
77 void Init();
78 void Init(u16 efbWidth, u16 efbHeight, u16 xfbWidth, u16 xfbHeight,
79 u16 viWidth, u16 viHeight);
80
81 void SetPosition(f32 x, f32 y, f32 z);
82 void SetPosition(const math::VEC3& rPos);
83
84 void SetPosture(const PostureInfo& rInfo);
85 void SetCameraMtxDirectly(const math::MTX34& rMtx);
86 void SetPerspective(f32 fovy, f32 aspect, f32 near, f32 far);
87 void SetOrtho(f32 top, f32 bottom, f32 left, f32 right, f32 near, f32 far);
88 void SetProjectionMtxDirectly(const math::MTX44* pMtx);
89
90 void SetScissor(ulong x, ulong y, ulong width, ulong height);
91 void SetScissorBoxOffset(s32 ox, s32 oy);
92
93 void SetViewport(f32 x, f32 y, f32 width, f32 height);
94 void SetViewportZRange(f32 near, f32 far);
95 void GetViewport(f32* pX, f32* pY, f32* pWidth, f32* pHeight, f32* pNear,
96 f32* pFar) const;
97
98 void GetCameraMtx(math::MTX34* pMtx) const;
99 void GetProjectionMtx(math::MTX44* pMtx) const;
100 void GetProjectionTexMtx(math::MTX34* pMtx) const;
101 void GetEnvironmentTexMtx(math::MTX34* pMtx) const;
102
103 void GXSetViewport() const;
104 void GXSetProjection() const;
105 void GXSetScissor() const;
106 void GXSetScissorBoxOffset() const;
107
108 GXProjectionType GetProjectionType() const {
109 return ref().projType;
110 }
111
112private:
113 void UpdateCameraMtx() const;
114 void UpdateProjectionMtx() const;
115};
116
117} // namespace g3d
118} // namespace nw4r
119
120#endif
3D graphics drawing library.
Definition g3d_3dsmax.h:10