23 July 2020, 17:10 | #1 |
Registered User
Join Date: Feb 2020
Location: Germany
Posts: 178
|
What is the easiest way to calculate hidden faces of an cube
Hello,
What is the easiest or fastest way to calculate which faces are covered by a cube. If the cube rotates only around one axis, you can determine this simply by the angle, for example a>180° face 1,2,3,4 are not visible. How does the whole thing look like if you rotate the cube on several axes. As far as I understood you have to determine the vector of the face. Then you have to calculate the angle of the vector to the observer. If this angle is greater than 90° the face is not visible. But this kind of calculation correct? This is how my cube looks like until now. Thanks JoeJoe |
23 July 2020, 18:30 | #2 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,216
|
Quote:
Depending on how you normalize your view vector, it is thus sufficient to check whether this coordinate is positive (pointing towards the observer) or negative (pointing into the opposide direction). However, this works only if the surface has no holes. In general, you sort the surfaces from front to back, i.e. by the Z coordinate of its center, and then draw them from back to front. This always works. |
|
23 July 2020, 22:00 | #3 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
|
|
24 July 2020, 08:03 | #4 |
Registered User
Join Date: Feb 2020
Location: Germany
Posts: 178
|
Thanks for the information. I will implement it and then report when i have success.
|
24 July 2020, 09:33 | #5 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
If you plan on more complex objects than cubes (i.e. anything not a single purely convex object) then you may want to look at Binary Space Partitioning (BSP) trees next. This uses the surface normal work that you're about to do, but also gives you the order in which to draw the surfaces, rather than just using the painters algorithm (drawing from back to front) which only works in simple cases.
Last edited by deimos; 24 July 2020 at 09:42. |
24 July 2020, 13:58 | #6 |
Registered User
Join Date: Feb 2020
Location: Germany
Posts: 178
|
It´s work now
|
26 July 2020, 09:27 | #7 |
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
|
JoeJoe, which method did you end up using? My code has always used the 2D way but I recently added multi-point light sources so had to dig into all the normal/dot product math. No matter which way I tried to code it the 2D method was always faster for me.
My notes from the time were concerned with doing visibility check, followed by calculating normal for the visible face for lighting. Code:
Rotate a point 3-axis: 9 muls Working out surface normal: 6 muls Working out normal magnitude: 3 muls, 1 sqrt Normalizing (dont have magnitude): 3 muls, 1 sqrt, 3 divs Normalizing (already have magnitude): 3 divs Working out dot product of unit vectors 3 muls Face visibility check/2d method: 2 muls Face visibility check/3d method: 9 muls (surface non-unit normal + dot product (sign only)) muls = 70 cycles divs = 158 sqrt = 500 2D vs 3D Face Visibility ======================== As in all methods we end up doing the surface normal for visible faces is it quicker to do the 2D check first and then only do the surface normal? Again assuming 20 faces, with 8 being visible on average. Face 2D: 2d visibility check (20 faces) 2 * 20 muls get surface normal for lighting visible faces (8 faces) 6 * 8 muls 88 muls, 6160? cycles Face 3D: get surface normal (20 faces) 6 * 20 muls 3d visibility check,dot product with first vertex (20 faces) 3 * 20 muls Get surface normal for lighting visible faces FREE 180 muls, 12600? cycles No contest. Use 2D method. Last edited by Antiriad_UK; 26 July 2020 at 09:58. |
13 August 2020, 11:35 | #8 |
Registered User
Join Date: Feb 2020
Location: Germany
Posts: 178
|
Sorry for the delay. I use the "old 2D" way from post 3 to do this.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to calculate possible blit times? | Tigerskunk | Coders. Asm / Hardware | 32 | 11 January 2022 08:24 |
Games with hidden/un-hidden symbolism? | markpjd | Retrogaming General Discussion | 8 | 06 December 2017 16:56 |
Demo name? - Talking fish/human faces in tank & rotating Coke can | Higgy | request.Demos | 0 | 08 May 2017 09:54 |
Calculate a color gradient. | AGS | Coders. Asm / Hardware | 13 | 11 February 2015 11:20 |
Faces which defined the Amiga | Tolls | Nostalgia & memories | 25 | 02 June 2011 22:02 |
|
|