I don't know why this code has the value 176.0 all over it.
It seems a lot of viewport related code has it.
Maybe it's rendering at 640x352 or something and 176 is half of it?
but let me know if you know some secret Wii-176 connection

1/ SQRT(0.0) ?

uhhhh

are you just trying to explode math?

ghidra what kind of type inference is it that you assume the return value of operator_new is an int?

WHEN HAS OPERATOR NEW EVER RETURNED AN INT?

oh nice. I'm retyping it to RenderPass*, then I click away into another function, then click back, and it's an int again.

what is going on, ghidra?

oh it's actually weirder: it's not resetting the decompilation after I switch away.

it's reshuffling the identically named functions, so that when I click on the first one, it's a different one. one I haven't typed yet

I really hope the original source of this engine used heavy use of macros.

because otherwise there are multiple places where they had to copy-paste functions like 70 times

okay it turned out to be only 22 times for this function
but all 22 functions are identical other than which type they take in and which vtable pointer they apply.

Maybe that's getting automatically generated by C++ default compilers? I hope so

and it's not templated, I'd be able to tell from the function names.
currently figuring out which 3D primitives are which by looking at the volume(Primitive*) method and matching up the formulas

4.1887903? that's a sphere!
1.0471976? a cone!

(those constants are π*4/3 and π/3)

I'm not sure what this one is.
it seems to be (pi * h * w²) - (pi*2/3 * w³)

I thought maybe torus but nope, that's not the volume for torus.

the first half is the formula for a cylinder, but it's minus... half a sphere? what?

it's also got a shape_7 which is... weird.
Volume is infinity. when you try to test against if you intersect it, the answer is "yes", no matter what.
It's like... everywhere?

is this primitive shape... god?

okay for that last mystery volume I found some code that interacts with the physics engine and it seems to be allocating a capsule collider
that is NOT the formula for the volume of a capsule, though
maybe someone just made a math mistake here
1.5707964 is another magic number to recognize:
it's 90 degrees in radians, aka half pi
WE SHALL DESTROY GEOMETRY: THERE SHALL BE NO MORE UNIT CIRCLES, CONES, OR SPHERES!
also a couple people have pointed out that (pi * h * w²) - (pi*2/3 * w³) IS the formula for a capsule, if the height includes the spheres on the end.
@foone It’s so much easier to kitbash two spheres on a cylinder than make a “real” capsule primitive, so I am extremely not surprised. I don’t think I’ve ever seen rendering code for physics debug that didn’t do this.

@foone Been told that the sphere is the only classical shape that requires calculus to find it's volume...

Galaxy brain: A capsule's volume requires calculus too :P.

@cr1901 @foone capsules aren't a classical shape though 🧐
@foone
attack and dethrone Euclid
@foone disturb(&standardUnitCircle);

@SonnyBonds @foone

Disturb? As in "introduce rotational eccentricities"?

wobble wobble wobble

@GenghisKen @foone Ask Archimedes :)
@SonnyBonds @foone
Meh. Archimedes will just keep burbling on about how it still moves, ignoring the effect his ranting is having on his neighbours' property values. "Archimedes' screw? Not by 'arf he's not. Poor old bugger!" lamented a sympathetic pensioner from the next street but one, supervising her Great Dane fertilising the astronomer's lawn.
@foone destroy unit cone is a good band name
@foone unit icosahedrons are fine though.
@foone I can't believe you're sending us back to two dimensions

@foone One could make a very challenging puzzle game where you're presented with a random line of legacy FORTRAN source code that contains a floating-point literal, and you have to discover what it means. Hints are subroutine/function name and the name of the application it's from.

This is either a twisted and sad puzzle game or a genius move to modernize old code by duping players into being Mechanical Turks.

Recognizing magic numbers is critical, especially when constants vary throughout a code (9.8, 9.81, 9.805). It also helps to recognize stupid unit conversion factors (459.67).

@arclight @foone

Damn, nerdsniped. I got 9.8 +/- is $g$ but what's the conversion factor one?

@hpcchris @foone 273.15 * 1.8 - 32.0 = 459.65. Add this to degree-F to get degree-Rankine, traditional system absolute temperature.

@arclight @foone

There are two basic mistakes made when coding: 0- or 1-based indexing, inadequate bounds checking, and off-by-one errors.

@foone A cool method I use when seeing weird constants when doing reverse engineering is just to put it in Wolfram Alpha. Here's what it gives your number:
@foone Pretty sure it's the capsule formula if you count the caps towards h (causing you to subtract 6/3πw³ from the other term).

@foone It is - if h is the height _including the end caps_.

The cylinder part is πr²(h-2r), the end caps are 4πr³/3 giving a total volume of πr²(h - 2r + 4r/3) which is πr²(h - 2r/3)