2024-03-22 20:12:09 +08:00
|
|
|
// Copyright 2024 SquareBlock Inc. All Rights Reserved.
|
2024-03-07 14:29:24 +08:00
|
|
|
// Author: tianlei.richard@qq.com (tianlei.richard)
|
2024-03-06 17:21:53 +08:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-21 21:34:29 +08:00
|
|
|
#include "mesh.h"
|
|
|
|
#include "util/math_util.h"
|
2024-03-06 17:21:53 +08:00
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
|
|
|
|
class MinusRenderer {
|
|
|
|
public:
|
2024-03-08 11:54:37 +08:00
|
|
|
MinusRenderer(float near, float far, float fov, float aspect_ratio);
|
2024-03-06 17:21:53 +08:00
|
|
|
|
|
|
|
public:
|
2024-03-27 18:31:10 +08:00
|
|
|
void set_meshes(const std::vector<Mesh> &meshes);
|
|
|
|
|
2024-03-06 17:21:53 +08:00
|
|
|
cv::Mat render(const int resolution_width, const int resolution_height);
|
|
|
|
|
2024-03-08 11:54:37 +08:00
|
|
|
public:
|
|
|
|
void model_transform(const TransformMatrix &mtx);
|
|
|
|
void view_transform(const TransformMatrix &mtx);
|
|
|
|
|
2024-03-06 17:21:53 +08:00
|
|
|
private:
|
2024-03-06 22:23:48 +08:00
|
|
|
static float calculate_height(const float fov, const float near);
|
|
|
|
static float calculate_width(const float height, const float ratio);
|
2024-03-22 20:12:09 +08:00
|
|
|
static std::tuple<double, double, double>
|
|
|
|
calculate_barycentric_coordinate(const Triangle &t, const Point2d &p);
|
2024-03-06 22:23:48 +08:00
|
|
|
|
|
|
|
private:
|
2024-03-28 21:55:30 +08:00
|
|
|
std::pair<TransformMatrix, TransformMatrix>
|
|
|
|
construct_transform(const int resolution_width,
|
|
|
|
const int resolution_height) const;
|
2024-03-06 17:21:53 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
float near_;
|
|
|
|
float far_;
|
|
|
|
float fov_; // In radian
|
|
|
|
float aspect_ratio_;
|
|
|
|
|
2024-03-08 11:54:37 +08:00
|
|
|
std::vector<Mesh> meshes_;
|
2024-03-06 17:21:53 +08:00
|
|
|
};
|