Skip to content

Commit

Permalink
apply clang-tidy on gltf code
Browse files Browse the repository at this point in the history
  • Loading branch information
yousifd committed Feb 11, 2025
1 parent 928c994 commit 6fcc13b
Show file tree
Hide file tree
Showing 37 changed files with 520 additions and 566 deletions.
22 changes: 7 additions & 15 deletions platform/darwin/src/gltf/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,35 @@ Camera::Camera() {
_rotationVelocity = 0;
_velocity = 0;
_distance = 4; // 0; // 2;

}

simd_double4x4 Camera::projectionMatrix() {
float fov = M_PI / 3; // original
float fov = M_PI / 3; // original
fov = 0.6435011087932844; // Constant that i found in ML
simd_double4x4 matrix = GLTFPerspectiveProjectionMatrixAspectFovRH(fov, 1.0, 0.01, 250);
return matrix;
}

void Camera::updateWithTimestep(double timestep) {


_rotationAngles += _rotationVelocity * timestep;

static double rot = 0;
// rot += 0.03;
// self.rotationAngles = rot;
// _rotationAngles = simd_make_float3(rot, M_PI/4.0, 0);
// self.rotationAngles = rot;
// _rotationAngles = simd_make_float3(rot, M_PI/4.0, 0);
_rotationAngles = simd_make_float3(rot, 0, 0);


// Clamp pitch
_rotationAngles = (simd_float3){ _rotationAngles.x,
static_cast<float>(fmax(-M_PI_2, fmin(_rotationAngles.y, M_PI_2))),
0 };

_rotationAngles = (simd_float3){
_rotationAngles.x, static_cast<float>(fmax(-M_PI_2, fmin(_rotationAngles.y, M_PI_2))), 0};

_rotationVelocity *= GLTFViewerOrbitCameraRotationDrag;

// _distance += _velocity * timestep;
_velocity *= GLTFViewerOrbitCameraZoomDrag;

simd_double4x4 pitchRotation = GLTFRotationMatrixFromAxisAngleD(GLTFAxisXD, -_rotationAngles.y);
simd_double4x4 yawRotation = GLTFRotationMatrixFromAxisAngleD(GLTFAxisYD, -_rotationAngles.x);
simd_double4x4 translation = GLTFMatrixFromTranslationD((simd_double3){ 0, 0, _distance });
simd_double4x4 translation = GLTFMatrixFromTranslationD((simd_double3){0, 0, _distance});
_viewMatrix = matrix_invert(matrix_multiply(matrix_multiply(yawRotation, pitchRotation), translation));


}
8 changes: 4 additions & 4 deletions platform/darwin/src/gltf/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include <stdio.h>
#include <simd/simd.h>

namespace maplibre { namespace gltf {
namespace maplibre {
namespace gltf {

class Camera {
public:
Expand All @@ -23,10 +24,9 @@ class Camera {
simd_double4x4 projectionMatrix();
simd_double4x4 _viewMatrix;
void updateWithTimestep(double timestep);

};

}}

} // namespace gltf
} // namespace maplibre

#endif /* Camera_hpp */
5 changes: 2 additions & 3 deletions platform/darwin/src/gltf/GLTFMTLRenderItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//

#import <Foundation/Foundation.h>
#import "gltfkit/GLTFNode.h"
#import "gltfkit/GLTFMesh.h"
#import "gltfkit/GLTFNode.h"

NS_ASSUME_NONNULL_BEGIN


@interface GLTFMTLRenderItem: NSObject
@interface GLTFMTLRenderItem : NSObject
@property (nonatomic) NSString *label;
@property (nonatomic) GLTFNode *node;
@property (nonatomic, strong) GLTFSubmesh *submesh;
Expand Down
171 changes: 85 additions & 86 deletions platform/darwin/src/gltf/GLTFManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,91 +17,90 @@
#include "GLTFModel.hpp"
#include "GLTFManagerRenderingEnvironment.hpp"

namespace maplibre { namespace gltf {

// The type of rendering environment we're in
typedef enum {
RenderingEnvironmentUnknown,
RenderingEnvironmentMetal,
RenderingEnvironmentOpenGL,
RenderingEnvironmentVulkan
} RenderingEnvironment;

struct Coordinate2D {
double _lat;
double _lon;
};

struct Cartesian3D {
double _x;
double _y;
double _z;
};


typedef std::function<Cartesian3D(const Coordinate2D &)> ProjectionCallback;

// The GLTF Manager class is the top level entry point
// for all things model based
class GLTFManager {
public:
// Set the callback
void setProjectionCallback(ProjectionCallback projectionCallback);

// Instantiate the manager with the appropriate environment
GLTFManager(RenderingEnvironment renderingEnvironment);

// Load a model
void addModel(std::shared_ptr<GLTFModel> model);

// Remove a model
void removeModel(std::shared_ptr<GLTFModel> model);

// Current meter to screen pixel scale
double _metersPerPixel = 1.0;

// Set the drawable size
void setDrawableSize(int width, int height);

// Set the tilt deg
void setTiltDeg(double tiltDeg);

// Set the rotation deg
void setRotationDeg(double rotationDeg);

// Set the rendering environment variables
void setRenderingEnvironmentVariables(std::shared_ptr<GLTFManagerRenderingEnvironment> environmentVars);

// Update any animations
void updateScene(float timeSinceLastDraw);

// Render
void render();

private:
RenderingEnvironment _renderingEnvironment = RenderingEnvironmentUnknown;

// List of models
std::vector<std::shared_ptr<GLTFModel>> _models;

// Projection callback
ProjectionCallback _projectionCallback;

private:
// Rendering environment
void createRenderingEnvironment();

// The renderer
std::shared_ptr<GLTFRenderer> _renderer = nullptr;


int _drawableWidth = 1;
int _drawableHeight = 1;
double _tiltDeg = 0;
double _rotationDeg = 0;

};

}}
namespace maplibre {
namespace gltf {

// The type of rendering environment we're in
typedef enum {
RenderingEnvironmentUnknown,
RenderingEnvironmentMetal,
RenderingEnvironmentOpenGL,
RenderingEnvironmentVulkan
} RenderingEnvironment;

struct Coordinate2D {
double _lat;
double _lon;
};

struct Cartesian3D {
double _x;
double _y;
double _z;
};

typedef std::function<Cartesian3D(const Coordinate2D &)> ProjectionCallback;

// The GLTF Manager class is the top level entry point
// for all things model based
class GLTFManager {
public:
// Set the callback
void setProjectionCallback(ProjectionCallback projectionCallback);

// Instantiate the manager with the appropriate environment
GLTFManager(RenderingEnvironment renderingEnvironment);

// Load a model
void addModel(std::shared_ptr<GLTFModel> model);

// Remove a model
void removeModel(std::shared_ptr<GLTFModel> model);

// Current meter to screen pixel scale
double _metersPerPixel = 1.0;

// Set the drawable size
void setDrawableSize(int width, int height);

// Set the tilt deg
void setTiltDeg(double tiltDeg);

// Set the rotation deg
void setRotationDeg(double rotationDeg);

// Set the rendering environment variables
void setRenderingEnvironmentVariables(std::shared_ptr<GLTFManagerRenderingEnvironment> environmentVars);

// Update any animations
void updateScene(float timeSinceLastDraw);

// Render
void render();

private:
RenderingEnvironment _renderingEnvironment = RenderingEnvironmentUnknown;

// List of models
std::vector<std::shared_ptr<GLTFModel>> _models;

// Projection callback
ProjectionCallback _projectionCallback;

private:
// Rendering environment
void createRenderingEnvironment();

// The renderer
std::shared_ptr<GLTFRenderer> _renderer = nullptr;

int _drawableWidth = 1;
int _drawableHeight = 1;
double _tiltDeg = 0;
double _rotationDeg = 0;
};

} // namespace gltf
} // namespace maplibre

#endif /* GLTFManager_hpp */
41 changes: 20 additions & 21 deletions platform/darwin/src/gltf/GLTFManagerRenderingEnvironment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@
#include <stdio.h>
#include <simd/simd.h>

namespace maplibre { namespace gltf {
namespace maplibre {
namespace gltf {

// Bsae class does nothing really, just a place holder
class GLTFManagerRenderingEnvironment {
public:
// If the bloom should be used
bool _useBloomPass = false;
// Bsae class does nothing really, just a place holder
class GLTFManagerRenderingEnvironment {
public:
// If the bloom should be used
bool _useBloomPass = false;

// FOV
double _currentFOVDEG = 50;

// Environment projection matrix
simd_double4x4 _currentProjectionMatrix;

// Current zoom level
double _currentZoomLevel = 1;
// FOV
double _currentFOVDEG = 50;

//
simd_float3 _lightDirection;
// Environment projection matrix
simd_double4x4 _currentProjectionMatrix;

GLTFManagerRenderingEnvironment() {
_lightDirection = simd_make_float3(0.0, 10000.0, 10000.0);
}
// Current zoom level
double _currentZoomLevel = 1;

};
//
simd_float3 _lightDirection;

}}
GLTFManagerRenderingEnvironment() { _lightDirection = simd_make_float3(0.0, 10000.0, 10000.0); }
};

} // namespace gltf
} // namespace maplibre
#endif /* GLTFManagerRenderingEnvironment_hpp */
47 changes: 24 additions & 23 deletions platform/darwin/src/gltf/GLTFManagerRenderingEnvironmentMetal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,29 @@
#include <QuartzCore/QuartzCore.h>
#include "GLTFManagerRenderingEnvironment.hpp"

namespace maplibre { namespace gltf {

// Bsae class does nothing really, just a place holder
class GLTFManagerRenderingEnvironmentMetal: public GLTFManagerRenderingEnvironment {
public:
// Allows command buffer and render encoder to be passed in.
// if these are nil, then the renderer will create them
id<MTLRenderCommandEncoder> _currentCommandEncoder = nullptr;
id<MTLCommandBuffer> _currentCommandBuffer = nullptr;

id<CAMetalDrawable> _currentDrawable = nullptr;
MTLRenderPassDescriptor *_currentRenderPassDescriptor = nullptr;
id<MTLDevice> _metalDevice = nullptr;

// TBD: These are placeholders as we noodle how to integrate with ML
// Depth descriptor: If this is null, then use an internal depth
id<MTLTexture> _depthStencilTexture = nullptr;

id<MTLTexture> _colorTexture = nullptr;
};

}}

namespace maplibre {
namespace gltf {

// Bsae class does nothing really, just a place holder
class GLTFManagerRenderingEnvironmentMetal : public GLTFManagerRenderingEnvironment {
public:
// Allows command buffer and render encoder to be passed in.
// if these are nil, then the renderer will create them
id<MTLRenderCommandEncoder> _currentCommandEncoder = nullptr;
id<MTLCommandBuffer> _currentCommandBuffer = nullptr;

id<CAMetalDrawable> _currentDrawable = nullptr;
MTLRenderPassDescriptor *_currentRenderPassDescriptor = nullptr;
id<MTLDevice> _metalDevice = nullptr;

// TBD: These are placeholders as we noodle how to integrate with ML
// Depth descriptor: If this is null, then use an internal depth
id<MTLTexture> _depthStencilTexture = nullptr;

id<MTLTexture> _colorTexture = nullptr;
};

} // namespace gltf
} // namespace maplibre

#endif /* GLTFManagerRenderingEnvironmentMetal_hpp */
Loading

0 comments on commit 6fcc13b

Please sign in to comment.