简体   繁体   中英

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 mesh is just a 3D model (in Unreal Engine 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

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. 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). Choose some point towards the direction the camera is looking at(lookAt with coords x2, y2, z2). The direction vector(let's call it dirVec) is 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. Now calculate the position of every object like this: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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