2024-03-06 17:21:53 +08:00
|
|
|
// Copyright 2024 Bytedance 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
|
|
|
|
|
|
|
|
#include "triangle.h"
|
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
|
|
|
|
class MinusRenderer {
|
|
|
|
public:
|
|
|
|
MinusRenderer(float near, float far, float fov, float aspect_ratio,
|
|
|
|
std::vector<Triangle> &&primitives);
|
|
|
|
|
|
|
|
public:
|
|
|
|
cv::Mat render(const int resolution_width, const int resolution_height);
|
|
|
|
|
|
|
|
public:
|
2024-03-06 22:23:48 +08:00
|
|
|
void model_transform(const TransformMatrix &m);
|
2024-03-07 14:29:24 +08:00
|
|
|
void view_transform(const TransformMatrix &m);
|
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-07 11:11:04 +08:00
|
|
|
static TransformMatrix view_port_transform(const float width,
|
|
|
|
const float height);
|
2024-03-06 22:23:48 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
TransformMatrix squish_tranform();
|
|
|
|
TransformMatrix orthographic_tranform();
|
2024-03-06 17:21:53 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
float near_;
|
|
|
|
float far_;
|
|
|
|
float fov_; // In radian
|
|
|
|
float aspect_ratio_;
|
|
|
|
|
|
|
|
std::vector<Triangle> primitives_;
|
|
|
|
};
|