Skip to content

first draft#1

Open
rualss wants to merge 16 commits intomainfrom
dev
Open

first draft#1
rualss wants to merge 16 commits intomainfrom
dev

Conversation

@rualss
Copy link
Copy Markdown
Owner

@rualss rualss commented Feb 2, 2025

No description provided.

@rualss
Copy link
Copy Markdown
Owner Author

rualss commented Feb 2, 2025

Я буду переписывать тут всё, потому что мне не понравился GLM и я хочу на Eigen переписать. В GLM есть всякие штуки, после которых не ощущается, что я from scratch делаю

@rualss rualss requested a review from DimaTrushin February 3, 2025 20:12
Copy link
Copy Markdown
Collaborator

@DimaTrushin DimaTrushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обрати внимание, что я не повторял замечания. Если одна и та же ошибка всречалась несколько раз, я комментировал лишь единожды. Потому я ожидаю, что ты поправишь все аналогичные замечания всюду.

Comment thread CMakeLists.txt
project(3d-renderer)

set(CMAKE_CXX_STANDARD 20)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавь строчку

set(CMAKE_CXX_STANDARD_REQUIRED True)

А то cmake разрешено откатиться на более низкий стандарт.

Comment thread src/renderer.cpp Outdated

namespace renderer {

Vec3 TransformVector(const Mat4& transformation_matrix, const Vec3& vector) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если объявляешь методы внутри cpp файлов (а так же классы и переменные), которых нет в h файле, то обязательно заворачивай их в anonymous namespace. Иначе это черевато ошибками линкера, а с ним лучше не играться.

Comment thread src/renderer.cpp Outdated
#include "glm/ext.hpp"

// I plan to rewrite all of this using Eigen
// Because glm::perspective and glm::translate feels like cheating to me
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можешь их просто не использовать.

Comment thread src/world.h Outdated

class World {
public:
World(const std::vector<Polygon>& polygons) : polygons_(polygons) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Почему имплементация в хедере
  2. Плохая идея принимать конкретные контейнеры в конструкторе. Список инициализации тоже плохая идея, так как из него нельзя мувнуть данные, а у тебя полигоны не легкие объекты. Потому либо два итератора, либо по rvalue ссылке.

Comment thread src/world.h Outdated
World(const std::vector<Polygon>& polygons) : polygons_(polygons) {
}

void AddPolygon(const Polygon& polygon);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как минимум нужен метод позволяющий сделать move полигона внутрь.

void AddPolygon(Polygon&& polygon);

Comment thread src/camera.h
}

Vec3 GetFocalPoint() const;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не делай так много вертикальных пробелов между функциями в h файле.

Comment thread src/camera.h Outdated
Comment on lines +17 to +20
: focal_point_(kDefaultFocalPoint),
near_dist_(kDefaultNearDist),
far_dist_(kDefaultFarDist),
fov_y_(kDefaultFOV) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это делается не так

class Camera {
public:
  Camera() = default;
  ...
private:
  focal_point_ = kDefaultFocalPoint;
  near_dist_ = kDefaultNearDist;
  far_dist_ = kDefaultFarDist;
  fov_y_ = kDefaultFOV;
};

Comment thread src/camera.h Outdated
Comment on lines +10 to +13
static constexpr CoordType kDefaultNearDist = 0.1;
static constexpr CoordType kDefaultFarDist = 10.0;
static constexpr Vec3 kDefaultFocalPoint = {0, 0, 0};
static constexpr CoordType kDefaultFOV = 45.0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Константы можно перенести в конец перед переменными класса.

Comment thread src/camera.h Outdated
far_dist_(kDefaultFarDist),
fov_y_(kDefaultFOV) {
}
Camera(Vec3 focal_point, CoordType near_dist, CoordType far_dist, CoordType fov_y)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень хорошо, что у тебя 2, 3 и 4 аргументы одного типа. Их можно легко перепутать в конструкторе. Тут бы использовать strongly typed aliases, но уже enum-ами ты не обойдешься в случае float или double.

Comment thread src/camera.h Outdated
: focal_point_(focal_point), near_dist_(near_dist), far_dist_(far_dist), fov_y_(fov_y) {
}

Vec3 GetFocalPoint() const;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уверен, что хочешь вектор возвращать by value?

Copy link
Copy Markdown
Collaborator

@DimaTrushin DimaTrushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все очень сырое и недоделанное
Тут придется много копать

Comment thread src/app/application.cpp
void Application::Run() {
while (window_.isOpen()) {
timer_.Tick();
window_.clear();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нарушение уровня абстракции. Это низкоуровневая фигня, которая является частью отрисовки фрейма, непонятно зачем это тут зовется. Это должно быть внутри функции draw frame.

Comment thread src/app/application.cpp Outdated
Comment thread src/app/application.cpp
window_.clear();
HandleEvents();
HandleKeyboard();
RenderFrame();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Слишком специфичное название. У тебя выше две функции общего назначения, которые обслуживают run-time loop. А тут почему-то ты делаешь такую мелкую специфическую работу, как отрендерить фрейм. Это скорее всего должно быть частью какой-то другой общей работы.
  • Название метода врет, ты не просто рендеришь фрейм, ты его сначала создаешь, а потом отрисовываешь на экране. Не ври в названии методов.

Comment thread src/app/application.cpp
Comment on lines +25 to +27
HandleEvents();
HandleKeyboard();
RenderFrame();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну это просто феерия черных ящиков. Прям три закрытые шкатулки, угадайте где лежит миллион рублей. Блять, ты что в Поле Чудес переиграл? Как вообще понять, какой тут поток данных? Ты просто манипулируешь скрыто состоянием объекта Application и все. Не делай так.

Comment thread src/app/application.cpp
void Application::HandleEvents() {
while (const std::optional event = window_.pollEvent()) {
if (event->is<sf::Event::Closed>()) {
window_.close();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Странно, что после этого ты не останавливаешь run-time loop, а делаешь вызовы к двух других функций.

Comment thread src/renderer.cpp Outdated
Comment thread src/renderer.cpp Outdated
Comment thread src/renderer.cpp
Comment on lines +232 to +233
Vec2 point_to_check = {static_cast<CoordType>(x) + 0.5,
static_cast<CoordType>(y) + 0.5};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это должно быть преобразование координат

Comment thread src/renderer.h Outdated
Comment thread src/renderer.h Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants