Skip to content

Commit

Permalink
feat: add camera offset for aspect ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
Solant committed May 15, 2024
1 parent cc0ecf9 commit 994f696
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions MechoSoma/RUNTIME/aspect_ratio.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "aspect_ratio.h"

AspectRatioInfo createAspectRatio(int sc_width, int sc_height) {
AspectRatioInfo createAspectRatio(int sc_width, int sc_height, int cameraOffset) {
int width = 480 / sc_height * sc_width;

return AspectRatioInfo {
.width = width,
.offset = width - 640,
.cameraOffset = cameraOffset,
};
}

AspectRatioInfo aspectRatios[] = {
createAspectRatio(4, 3),
createAspectRatio(16, 9),
createAspectRatio(16, 10),
createAspectRatio(21, 9),
createAspectRatio(4, 3, 0),
createAspectRatio(16, 9, 100),
createAspectRatio(16, 10, 100),
createAspectRatio(21, 9, 100),
};

AspectRatioInfo *AR_CURRENT = &aspectRatios[0];
Expand Down
2 changes: 2 additions & 0 deletions MechoSoma/RUNTIME/aspect_ratio.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct AspectRatioInfo {
int width;
// offset for right-aligned elements
int offset;
// camera offset
int cameraOffset;
};

extern AspectRatioInfo *AR_CURRENT;
Expand Down
3 changes: 2 additions & 1 deletion MechoSoma/Xreal/CameraDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Statistics.h"
#include "MultibodyContact.h"
#include "DebugPrm.h"
#include <aspect_ratio.h>

/* ----------------------------- EXTERN SECTION ----------------------------- */
extern cInterfaceVisGeneric *gb_IVisGeneric;
Expand Down Expand Up @@ -1128,7 +1129,7 @@ void CameraDispatcher::setIvsCamera(const CameraCoords& coords)
#ifdef GPX
auto zOffset = (aspect - 1.33f) / (2.22f - 1.33f) * 100;
#else
auto zOffset = 0;
auto zOffset = AR_CURRENT->cameraOffset;
#endif
Vect3f camera_position = R*vg + Vect3f(0, -coords.CenteringDelta*coords.cameraDistance, coords.cameraDistance + zOffset);
camera_position.negate();
Expand Down

0 comments on commit 994f696

Please sign in to comment.