Why did you not want to get Camera Position in the crosshair deprojection?

Ben, Ben, Ben… you dirty little rapscallion!

When we’re learning to deproject, you tell me that the deprojection returns the camera position, just throw it away, we justwant the unit vector. So i go along my merry way thinking “Oh, we won’t need that!”

Well then we perform the line trace…And come to find out, I need that camera position!!!

Seriously though Ben, I did figure out before watching your solution that I needed the camera position. However, unlike your PlayerCameraManager() approach, I set up a second out parameter from my deprojection method, so that I get both the camera position and unit vector in tha same call… So my question, is there a reason NOT to do this (i.e. speed, efficiency, what-have-you) or is it just your personal preference on avoiding out parameters?

was going to share my solution, but the “formatted text” option seems to be having trouble with that…

Thanks for asking, I think I was just avoiding smelly our parameters.

1 Like

Have to agree to this. I’d rather have the one function with ~15 lines, than 3 functions. I guess this is personal preference, but unless we’d use the other functions somewhere else, there is no need to extract them imo.

Here is my one-function bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const : https://gist.github.com/mBeierl/d110bc0383c191aae39742b5fe80aa72

2 Likes

I don’t mind three functions vs 1 longer one, as this supports abstraction and encapsulation in my opinion. But I’m comfortable enough reading my own code that I prefer the out parameters than adding an extra step.

3 functions ALSO helps later on. Once you’ve left this logic alone for a while and finish, then cone back and decide “oh, I want to add this functionality”, it’s easier to break into a tiny methods to add steps instead of working about without worrying about messing things up wile editting your larger functions

I agree, @ben has kinda overboard with functions in this section IMO. Kinda makes it less readable.

I may have done a little ;-). Those methods will be fleshed-out though, it’s mainly a symptom of the fact I’m working to a prototype. I could do it the other way and only factor-out when needed.

Well you certainly are more organized. When I’m working on a prototype, things get a lot messier :wink:

Privacy & Terms