• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Camera Yaw and Pitch

Status
Not open for further replies.
Level 7
Joined
May 3, 2007
Messages
210
I was wondering what exactly the yaw and pitch returns in relation to the camera, obviously it's in degrees, but exactly what angle? See picture for a better understanding of my confusion.

As well, if anyone knows how to calculate the distance between the central target point (the cameras target x,y,z) and the actual cameras location that'd be nice. I assumed it was just "distance" but that doesn't seem to pan out when you formulate a triangle and find the values of the other sides with the law of sines, they seem to pan out to a point, but if you shift away at certain angles the lengths get far beyond any reasonable marign of error.
 

Attachments

  • Camera.jpg
    Camera.jpg
    55.3 KB · Views: 309
Last edited:
Level 7
Joined
Jun 16, 2008
Messages
253
I'm not precisely sure if I know what you're asking exactly, but I'll take a stab and see if it hits anything helpful.

- Yaw = Camera 2D Rotation. Pitch = Angle from ground to Source Camera (Z)
That's probably not what you're asking but just in case.

I'm wondering if you could Create a second camera on the same position that switched its target to point straight down from its position, so you could get the XY of its position. Then get the 2D distance from
Camera Target to Camera Source, use the Pitch with the Adjacent to get the opposite or hypoteneuse.

You'd probably need to do this in two Pythagoras formulas, of getting the 'horizontal plane triangle', and then the 'vertical plane triangle' in order to get an exact X,Y,Z position of Camera Source.

Again, I'm not sure if I'm being helpful or repeating the obvious. I'm about to be poking my head in this area as well so I kinda wanna know too. :D
 
Level 7
Joined
May 3, 2007
Messages
210
Here, maybe this picture will help you. This is how I imagine pitch works, and am looking to find out if its actually true or not.
 

Attachments

  • cam2.jpg
    cam2.jpg
    39.7 KB · Views: 362
Level 7
Joined
Jun 16, 2008
Messages
253
Looks right to me! You can see how the camera behaves in the editor (if you have access at the moment) by changing the appropriate properties.

The angle is taken from the Target Point, to the position of Source Camera.

SO if the target point is on the ground, then the angle is from the Ground to the Camera.

This remains true even if the Target Point is up in the air, or higher than the Source Camera, or whatever the case is. The horizontal axis is taken parallel to the ground, and though the Z might change direction relatively, the angle won't be affected.

In short, yeah, you're right. XD
 
Level 7
Joined
May 3, 2007
Messages
210
I'm guessing distance is the length from the source camera to the focal point then?

I've been doing a lot of calculations and making a lot of stupid assumptions which is why I finally gave up and mad this topic. I'm starting to get a very good understanding of how everything camera related works though. There are still a couple things that I just don't get or know how to do, but we're getting there.
 
Level 7
Joined
Jun 16, 2008
Messages
253
Hahaha, totally know what you mean. I slept through my maths class (cos we NEVER use it in real life), so I had to go find my old math book and learn everything so I could calculate 3D stuff. *brainexplode*

Distance - I really couldn't give you guaranteed answer. I ASSUMED it was from target point to Source Camera point, but your initial post seems to discredit it. Unless perhaps it's just some bizarre angle thing. Perhaps somewhere, somehow, you've got a 0 (this minus that = 0) that's causing havoc. You have to be careful with 0's, they mess everything. Maybe it's some kind of 0 axis thing that's make it spaz out. I really don't know. :(

Only suggestion I could probably offer is to make sure you're compensating for terrain height, and that you're not getting negative values where you shouldn't, and vice versa. I.E. distance is never a negative, cos it's not a direction, just a difference.

'Fraid that's the best I can do, I'm only just learning this stuff meself. XD
 
Level 7
Joined
May 3, 2007
Messages
210
Alright these are my findings based on the assumptions of how yaw and pitch work, I can whip up a three dimensional picture if you want.

Let sx be source camera's x position and sy and sz follow in a similiar fashion, let d be the distance from the source to the target. Let tx, ty, tz be the coordinates for the source cameras target point,

d2 is the two dimensional distance between the two points.
dx is the displacement in the x direction.
dy is the displacement in the y direction.
dz is the displacement in the z direction.


p be the pitch, y be the yaw

d2 = d*cosp
dx = d2*cosy
dy = d2*siny
dz = d2*tanp


sx = tx - dx
sy = ty - dy
sz = tz - dz

Feel free to correct something if you see its obviously wrong.
 
Last edited:
Level 7
Joined
Jun 16, 2008
Messages
253
Heya!

I tested it on my Planetoids bonus map (your math is so much tidier than mine, I hope you don't mind if I use your example. :D) and it's perfect aside from the tiny snag of:

sz = tz - dz

which should be: sz = tz + dz

This is because the current formula produces reflected angles. Instead of getting negative as your dz, you get a positive, and vice versa. Which I'm sure you'll see when you play with it anyway. :D

As a note: On my space map I took away all the terrain, which I believe can be schizo with the Z. I think the Height of Point remains the same (explosions occur at where the terrain used to be), but the Height at Point will be decreased accordingly with the cliff drop. Just a heads up. :D

Tell me if it works out for you! :D
 
Level 7
Joined
May 3, 2007
Messages
210
I think tz + dz only makes sense if the source is above the target, when i formulated it was the other way around, making the target above the source.

That could pose a case issue and i'm guessing you'd just have to guess, see if its negative, and if so, do the other. When they're level it shouldn't matter.

If you imagine in 3d, if the target is above, and you project a parralel to the xy-plane towards the point, and a line perpindicular to that plane down to meet forming a right triangle, then the distance down would be dz and thus the height of the target minus that length would give you the length of the source camera, IF the source is below the target. If it is above the target you have to add. You should always do tz - dz first though, if i'm imaging it correctly.

@AionCannozSC2 Thanks for the tip, that should be pretty easily fixed though, all you'd have to do is check to see if the value of the angle is negative, also I don't think the intervals of the normal trig functions would cause any issues with negative angle values, obviosuly the inverses would.
 
Level 7
Joined
Jun 16, 2008
Messages
253
Actually I think that, through no fault of my own, I hit the right answer by accident.

I tested it out, reversing the pitch angle, and it seemed to pan out fine. I can't remember the reason that I suspected is responsible for it behaving against expectiations. I think it had to do with assumptions with the Z value. Or at least it was in the initial calculations of Z, that influenced the end result.

Maybe it was an assumption with Z displacement being a negative, or not being a negative. Or the Target Z? I can't remember.

Or maybe it's just some weird fluke because of my 'terrainless' map. I don't really like seeing any +'s either, in a difference calculation, but the - is in the pudding.

But it works on my map! :D That's all I can say! XD

EDIT: All I know is that, your initial way worked on my calculator, when I put in some test values. But it works the other way in the Starcraft end result. So I can only assume that
the information is different, and we just didn't spot it. :D
 
Level 7
Joined
May 3, 2007
Messages
210
I imagine it works in your case because in almost all cases the source is always above the target, in fact it's probably limited to being either at level or above the target in most maps, so that would explain why the addition variant is a better choice. I'll have to test it out myself though to see if i'm just missing something, or what have you.
 
Level 7
Joined
Jun 16, 2008
Messages
253
That's probably the best way. XD

But nada, I had the source camera pointing upward, honest! I tried it at 45 degrees and then -45 after, just to see. I SWEAR TO MY FACE!!! O.O But you'll see either way. :D I have faith in the Pikachu's mastery of science.
 
Level 7
Joined
May 3, 2007
Messages
210
After some testing I noticed a pretty significant flaw of assumption on my part. I was having the camera follow a unit and assumed the cameras target would be the poisition of the unit..

That was a silly assumption, and now I realize the target of the camera can in fact not be negative in height unless possibly intentionally set negative, so addition would be the best option in all cases.

Likewise, I made the mistake of projecting a line from the source to the target to get the vector I wanted, though I still need the source point, I need to project it to the position of the unit followed offset by a constant Z, le'sigh. More clicking and scrolling for me.
 
Status
Not open for further replies.
Top