2024-03-06 17:21:53 +08:00
|
|
|
// Copyright 2024 Bytedance Inc. All Rights Reserved.
|
|
|
|
// Author: tianlei.richard@bytedance.com (tianlei.richard)
|
|
|
|
|
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
|
|
|
|
#include "spdlog/spdlog.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "minus_renderer.h"
|
|
|
|
#include "triangle.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
spdlog::set_level(spdlog::level::trace);
|
|
|
|
|
|
|
|
const int resolution_width = 320;
|
|
|
|
const int resolution_height = 180;
|
|
|
|
const int far = -1000;
|
|
|
|
const int near = -10;
|
2024-03-06 22:23:48 +08:00
|
|
|
const float fov = 120. / 180. * M_PI;
|
2024-03-06 17:21:53 +08:00
|
|
|
const float aspect_ratio = static_cast<float>(resolution_width) /
|
|
|
|
static_cast<float>(resolution_height);
|
|
|
|
|
|
|
|
std::vector<Triangle> primitives{
|
2024-03-06 22:23:48 +08:00
|
|
|
{Point3d{10, 5, -20}, Point3d{30, 25, -20}, Point3d{55, 5, -20}}};
|
2024-03-06 17:21:53 +08:00
|
|
|
|
|
|
|
cv::namedWindow("MinusRenderer", cv::WINDOW_AUTOSIZE);
|
|
|
|
const auto start = std::chrono::steady_clock::now();
|
|
|
|
MinusRenderer renderer{near, far, fov, aspect_ratio, std::move(primitives)};
|
|
|
|
do {
|
|
|
|
const auto elapse = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::steady_clock::now() - start)
|
|
|
|
.count();
|
2024-03-06 22:23:48 +08:00
|
|
|
TransformMatrix m{
|
|
|
|
Eigen::Transform<double, 3, Eigen::Affine>(
|
|
|
|
Eigen::AngleAxisd(0.125 * M_PI, Eigen::Vector3d::UnitZ())
|
|
|
|
.toRotationMatrix())
|
|
|
|
.matrix()};
|
|
|
|
renderer.model_transform(m);
|
2024-03-06 17:21:53 +08:00
|
|
|
const auto &color_image =
|
|
|
|
renderer.render(resolution_width, resolution_height);
|
|
|
|
cv::imshow("MinusRenderer", color_image);
|
2024-03-06 22:23:48 +08:00
|
|
|
} while (cv::waitKey(25) == -1);
|
2024-03-06 17:21:53 +08:00
|
|
|
cv::destroyWindow("MinusRenderer");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|