position camera correctly

This commit is contained in:
Skarn
2020-11-14 14:20:35 +03:00
parent d9b5ba58f0
commit f80c542f83
6 changed files with 37 additions and 9 deletions

View File

@@ -77,26 +77,24 @@ void ModelViewer::setModel(std::string const &filename)
void ModelViewer::resetCamera()
{
_camera.reset();
float radius = 0.f;
if (_model_instance.which() == eEntry_WMO)
{
WMOInstance* wmo = boost::get<selected_wmo_type>(_model_instance);
auto bb_center = (wmo->extents[0] + wmo->extents[1]) / 2;
radius = (bb_center - wmo->extents[0]).length();
_camera.position = (wmo->extents[0] + wmo->extents[1]) / 2.0f;
radius = std::max((_camera.position - wmo->extents[0]).length(), (_camera.position - wmo->extents[1]).length());
}
else
{
ModelInstance* model = boost::get<selected_model_type>(_model_instance);
auto extents = model->extents();
auto bb_center = (extents[0] + extents[1]) / 2;
radius = (bb_center - extents[0]).length();
_camera.position = (model->extents()[0] + model->extents()[1]) / 2.0f;
radius = std::max((_camera.position - model->extents()[0]).length(), (_camera.position - model->extents()[1]).length());
}
float distance_factor = abs( aspect_ratio() * radius / sin(_camera.fov()) / 2);
_camera.position = {0.f, 0.f, 0.f};
float distance_factor = abs( aspect_ratio() * radius / sin(_camera.fov()._ / 2.f));
_camera.move_forward_factor(-1.f, distance_factor);
}

View File

@@ -33,6 +33,24 @@ AssetBrowserWidget::AssetBrowserWidget(QWidget *parent)
}
);
// Handle preview rendering
connect(ui->listfileTree, &QTreeView::expanded
,[this] (const QModelIndex& index)
{
for (int i = 0; i != _model->rowCount(index); ++i)
{
auto child = index.child(i, 0);
auto path = child.data(Qt::UserRole).toString();
if (path.endsWith(".wmo") || path.endsWith(".m2"))
{
// do icon rendering here
}
}
}
);
auto start = std::chrono::high_resolution_clock::now();
updateModelData();

View File

@@ -25,6 +25,8 @@ QStandardItem* TreeManager::addItem(QString path)
{
item->appendRow((child = new QStandardItem(elt)));
child->setData(QVariant(path_remainder), Qt::UserRole);
child->setEditable(false);
child->setCheckable(false);
layered_items[path_remainder] = child;
}

View File

@@ -110,4 +110,12 @@ namespace noggit
position += up * sign * move_speed * dt;
}
void camera::reset()
{
position = {0.f, 0.f, 0.f};
_roll = math::degrees(0.0f);
_yaw = math::degrees(0.f);
_pitch = math::degrees(0.f);
}
}

View File

@@ -36,6 +36,8 @@ namespace noggit
void move_forward_factor (float sign, float factor);
void reset();
math::vector_3d position;
float move_speed;

View File

@@ -48,7 +48,7 @@ namespace noggit
LogDebug << key << ": " << _counts.at(pair) << std::endl;
}
);
*/
*/
}
template<typename... Args>