简体   繁体   English

按顶点数 3D 对象排序 C++

[英]Sort 3D objects by their number of vertices C++

"Create an application that visually sorts the *Static Meshes presented on the screen, by their number of vertices ." “创建一个应用程序,按顶点数对屏幕上呈现的 *Static Meshes 进行可视化排序。”

*Static mesh is just a 3D model (in Unreal Engine 4) *静态网格只是 3D model(在虚幻引擎 4 中)

Here's a visual "guide" on it, that was sent along with the challenge:这是与挑战一起发送的视觉“指南”:

https://drive.google.com/file/d/1v0-3zEoDugelGWK-U9t4GEHkA0hAuLfk/view?usp=sharing https://drive.google.com/file/d/1v0-3zEoDugelGWK-U9t4GEHkA0hAuLfk/view?usp=sharing

I know I should use a sorting algorithm, but how would the number of vertices fit in it for example ?我知道我应该使用排序算法,但是例如顶点数如何适合它

What I don't understand is how would I sort an object's location (3D Vector, XYZ) based on its Static Mesh's number of vertices (an integer), and how are the translation of both chairs so different (check video) if they have the same number of vertices, since they're the same exact Static Mesh.我不明白的是,我将如何根据其 Static 网格的顶点数(整数)对对象的位置(3D 矢量,XYZ)进行排序,以及两把椅子的翻译如何如此不同(查看视频)如果他们有相同数量的顶点,因为它们是完全相同的 Static 网格。 Does that mean their target locations aren't set but rather chosen, meaning their values are constant and exist prior sorting?这是否意味着它们的目标位置不是设置而是选择的,这意味着它们的值是恒定的并且在排序之前存在?

Am I approaching this all wrong?我接近这一切都错了吗?

Choose a starting point near the camera (let's call it cameraPos with coords x1, y1, z1 for example).选择相机附近的起点(例如,我们将其称为 cameraPos,坐标为 x1、y1、z1)。 Choose some point towards the direction the camera is looking at(lookAt with coords x2, y2, z2).选择朝向相机正在看的方向的某个点(lookAt with coords x2, y2, z2)。 The direction vector(let's call it dirVec) is lookAt - cameraPos(x2-x1, y2 - y1, z2 - z1).方向向量(我们称之为 dirVec)是 lookAt - cameraPos(x2-x1, y2 - y1, z2 - z1)。 This is a vector, which represents the general direction of the camera.这是一个向量,表示相机的大致方向。 You sort your 3d objects and now they are ranked - for example the one with the most vertices is with rank 1, the second - 2 and so on.您对 3d 对象进行排序,现在它们被排名 - 例如,具有最多顶点的对象排名为 1,第二个对象排名为 2,依此类推。 Now calculate the position of every object like this: pos = cameraPos + dirVec * rank.现在计算每个 object 的 position,如下所示:pos = cameraPos + dirVec * rank。 Here, your objects are now sorted visually.在这里,您的对象现在可以直观地排序。 If you don't know how to add/subtract vectors or multiply vector by number or the meaning of these operations, you should first get familiar with it.如果您不知道如何添加/减去向量或将向量乘以数字或这些操作的含义,您应该先熟悉它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM