Skip to content

Commit

Permalink
Add readOnly parameters to GetVirtualCamera*Mat()
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeokkim committed Nov 21, 2024
1 parent e4f4776 commit c1f0777
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions include/mvp-demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void DeinitClipSpace(void);
/* ========================================================================= */

/* 가상 카메라로 만들어지는 "투영 행렬"을 반환하는 함수 */
Matrix GetVirtualCameraProjMat(void);
Matrix GetVirtualCameraProjMat(bool readOnly);

/* ===================================================== (from src/local.c) */

Expand Down Expand Up @@ -241,10 +241,10 @@ void DeinitWorldSpace(void);
Camera *GetVirtualCamera(void);

/* 가상 카메라의 "모델 행렬"을 반환하는 함수 */
Matrix GetVirtualCameraModelMat(void);
Matrix GetVirtualCameraModelMat(bool readOnly);

/* 가상 카메라에 대한 "뷰 행렬"을 반환하는 함수 */
Matrix GetVirtualCameraViewMat(void);
Matrix GetVirtualCameraViewMat(bool readOnly);

/* 가상 카메라에 대한 "뷰 행렬"의 U축을 반환하는 함수 */
Vector3 GetVirtualCameraUAxis(void);
Expand Down
6 changes: 3 additions & 3 deletions src/clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void UpdateClipSpace(RenderTexture renderTexture) {
if (shouldUpdateProjMat) {
UpdateProjMatrix(false);

shouldUpdateProjMat = !shouldUpdateProjMat;
shouldUpdateProjMat = false;
}

DrawAxes();
Expand Down Expand Up @@ -98,9 +98,9 @@ void DeinitClipSpace(void) {
/* ========================================================================= */

/* 가상 카메라로 만들어지는 "투영 행렬"을 반환하는 함수 */
Matrix GetVirtualCameraProjMat(void) {
Matrix GetVirtualCameraProjMat(bool readOnly) {
// GUI에서 FOV 값을 업데이트할 때마다 "투영 행렬"도 같이 업데이트
shouldUpdateProjMat = true;
if (!readOnly) shouldUpdateProjMat = true;

return projMat;
}
9 changes: 5 additions & 4 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ void UpdateViewMatrix(bool fromGUI) {
virtualCamera->up = up;
}

gameObjects[OBJ_TYPE_CAMERA].model.transform = GetVirtualCameraModelMat();
gameObjects[OBJ_TYPE_CAMERA].model.transform = GetVirtualCameraModelMat(true);

UpdateMatrixEntryText(guiViewMatEntryText, GetVirtualCameraViewMat());
UpdateMatrixEntryText(guiViewMatEntryText, GetVirtualCameraViewMat(false));

for (int i = 0; i < 3; i++) {
strncpy(guiViewMatEyeValueText[i],
Expand All @@ -576,7 +576,7 @@ void UpdateProjMatrix(bool fromGUI) {
/ (float) mvpArea.height;
}

UpdateMatrixEntryText(guiProjMatEntryText, GetVirtualCameraProjMat());
UpdateMatrixEntryText(guiProjMatEntryText, GetVirtualCameraProjMat(false));

strncpy(guiProjMatFovValueText[0],
TextFormat("%.2f", guiProjMatFovValues[0]),
Expand Down Expand Up @@ -748,7 +748,8 @@ static void DrawGuiArea(void) {
if (guiProjMatFovValues[i] > CAMERA_FOV_MAX_VALUE)
guiProjMatFovValues[i] = CAMERA_FOV_MAX_VALUE;

if (guiProjMatFovValueBoxEnabled[i]) UpdateProjMatrix(true);
if (guiProjMatFovValueBoxEnabled[i])
UpdateProjMatrix(true);

guiProjMatFovValueBoxEnabled[i] =
!guiProjMatFovValueBoxEnabled[i];
Expand Down
6 changes: 3 additions & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void DrawGameObject(GameObject *gameObject, MvpRenderMode renderMode) {
Vector3 virtualCameraEye = GetVirtualCamera()->position;
Vector3 virtualCameraAt = GetVirtualCamera()->target;

Matrix virtualCameraViewMat = GetVirtualCameraViewMat();
Matrix virtualCameraViewMat = GetVirtualCameraViewMat(true);

if (renderMode == MVP_RENDER_LOCAL) {
// "물체 공간"에서는 모든 물체의 "모델 행렬"을 초기화
Expand Down Expand Up @@ -212,8 +212,8 @@ void DrawViewFrustum(MvpRenderMode renderMode, Color color) {

Camera virtualCamera = *(GetVirtualCamera());

Matrix virtualCameraViewMat = GetVirtualCameraViewMat();
Matrix virtualCameraProjMat = GetVirtualCameraProjMat();
Matrix virtualCameraViewMat = GetVirtualCameraViewMat(true);
Matrix virtualCameraProjMat = GetVirtualCameraProjMat(true);

Vector3 virtualCameraEye = Vector3Transform(virtualCamera.position,
virtualCameraViewMat);
Expand Down
10 changes: 5 additions & 5 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Camera *GetVirtualCamera(void) {
}

/* 가상 카메라의 모델 행렬을 반환하는 함수 */
Matrix GetVirtualCameraModelMat(void) {
Matrix GetVirtualCameraModelMat(bool readOnly) {
// 가상 카메라 "뷰 행렬"의 U축을 기준으로 가상 카메라의 모델 회전
Vector3 axis = GetVirtualCameraUAxis();

Expand All @@ -146,15 +146,15 @@ Matrix GetVirtualCameraModelMat(void) {
}

/* 가상 카메라에 대한 "뷰 행렬"을 반환하는 함수 */
Matrix GetVirtualCameraViewMat(void) {
Matrix GetVirtualCameraViewMat(bool readOnly) {
return MatrixLookAt(virtualCamera.position,
virtualCamera.target,
virtualCamera.up);
}

/* 가상 카메라에 대한 "뷰 행렬"의 U축을 반환하는 함수 */
Vector3 GetVirtualCameraUAxis(void) {
Matrix virtualCameraViewMat = GetVirtualCameraViewMat();
Matrix virtualCameraViewMat = GetVirtualCameraViewMat(true);

return (Vector3) { .x = virtualCameraViewMat.m0,
.y = virtualCameraViewMat.m4,
Expand All @@ -163,7 +163,7 @@ Vector3 GetVirtualCameraUAxis(void) {

/* 가상 카메라에 대한 "뷰 행렬"의 V축을 반환하는 함수 */
Vector3 GetVirtualCameraVAxis(void) {
Matrix virtualCameraViewMat = GetVirtualCameraViewMat();
Matrix virtualCameraViewMat = GetVirtualCameraViewMat(true);

return (Vector3) { .x = virtualCameraViewMat.m1,
.y = virtualCameraViewMat.m5,
Expand All @@ -172,7 +172,7 @@ Vector3 GetVirtualCameraVAxis(void) {

/* 가상 카메라에 대한 "뷰 행렬"의 N축을 반환하는 함수 */
Vector3 GetVirtualCameraNAxis(void) {
Matrix virtualCameraViewMat = GetVirtualCameraViewMat();
Matrix virtualCameraViewMat = GetVirtualCameraViewMat(true);

return (Vector3) { .x = virtualCameraViewMat.m2,
.y = virtualCameraViewMat.m6,
Expand Down

0 comments on commit c1f0777

Please sign in to comment.