• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Camera Angle Of Attack

Status
Not open for further replies.
Level 16
Joined
Mar 26, 2004
Messages
569
Let's say i have a camera at 500 Z-offset that i want it's angle of attack to change according to a single unit's location.

As shown in this image, when the unit is far away, the angle of attack is less, but when closer it points more downward. How can i trigger this?
attachment.php


*Thumbs up for imba freehand drawing :>*
 

Attachments

  • camera.jpg
    camera.jpg
    20.7 KB · Views: 188
You might want to use trigonometrical functions.

Pay attention to the right triangle formed by the camera (C), the unit (U) and the point right below the camera (where there's a 90º angle). Let's call this point (P). You'll work basically with two sides of it: CP and UP, which are the two catheti. So, the tangent of the angle UCP is UP/CP.

Using the Arctangent function, you can calculate this angle:
atan(UP/CP) = UCP

Now I don't remember which direction is the 0-degree for cameras... :p
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
yeah, i had some problems with it though,, he is right about the Tangent, though i think he means angle PUC/CUP (the AoA is angle between ground and camera-eye with camera-target as mid right?).

I fixed my AoA problems by doing this:
JASS:
set AoA = AoA + 1.5*bj_PI
Where the AoA is in radians. Dunno if it is the right thing to do, but it worked! =D
 
Last edited:
I'll try to explain it better...

@Yixx: yes, thanks xD

Look at the attached triangle.
attachment.php

U = Unit
C = Camera
P = Point

UP = Distance from the unit to the camera position (x/y position only, not z)
CP = Camera Z offset/height (500, right?)

As the camera AoA is determined by the angle formet between the camera and the ground, as Yixx stated, you can use the Tangent relationship:

tan(PUC) = CP/UP

Which you can calculate, as you can have CP and UP :D
So if you use the inverse function atan, you'll get the angle:

atan(CP/UP) = PUC

However this will return in radians. To convert to degrees, multiply it by 180/pi.
 

Attachments

  • Triangle.JPG
    Triangle.JPG
    2.4 KB · Views: 132
Level 16
Joined
Oct 12, 2008
Messages
1,570
But this will return a value like this: (dunno right english word)
0<= angle < 90 (there can be NO 90 degrees (1/2*PI) outcome from Atan, if you wanna know ill explain later)
But AoA has a whole different system of angles. On the ground is 0/360, and it will count UP when going LOWER into the ground, and it will count DOWN (from 360) when going Higher from the ground. Meaning that you will have to add 270 degrees (1.5*PI) to get the value for a good AoA.

"Meaning that you will have to add 270 degrees (1.5*PI)". The statement in my first post must be adjusted, not substract but indeed ADD.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
division by 0 crashes thread so,,

But i hope you now understand the 1.5*PI :p Otherwise, try yourself to set the AoA to an angle that comes freshly out of the Atan lol. It will fuck up,, so i started experimenting with adding values. And when i came to 1.5*PI, i was like "WTF that is SO logical xD"
 
Status
Not open for further replies.
Top