Page 1 of 1

[ACS] How to make this ""respect"" my pitch?

Posted: Sun Nov 23, 2014 8:48 pm
by Vincent(PDP)
Well I couldn't find a better title.

I've made this thing so that when you're looking at yourself through a camera, a green line should be drawn to indicate where you are currently aiming at.
It works fine with the player's angle, but when it comes to the player's pitch it only goes to 45 degrees instead of straight up or straight down (90 degrees).

Centered view:
[spoiler]Image[/spoiler]


Looking straight up:
[spoiler]Image[/spoiler]


As you see in the second image the "line" won't go further than that.
To create the line I make it spawn things as small as 1x1 pixels in front of you.

Here's ACS my code:

Code: Select all

Bool CouldSpawn = True;
Int increment = -(sin(GetActorPitch(0)));
        
For(Int dist=2; dist<4097 && CouldSpawn == True; dist++)
{
    increment += (increment / dist);
     CouldSpawn = SetActorPosition(1400+PlayerNumber(), GetActorX(0) + cos(GetActorAngle(0)) * dist, GetActorY(0) + sin(GetActorAngle(0)) * dist, (34.0 + GetActorZ(0))+increment, False);
            
    If(CouldSpawn == True)
    {
        Spawn("Pixel", GetActorX(0) + cos(GetActorAngle(0)) * dist, GetActorY(0) + sin(GetActorAngle(0)) * dist, (34.0 + GetActorZ(0))+increment, 1100+PlayerNumber(), GetActorAngle(0) >> 8);
    }
}
DECORATE (in case you want to try this):

Code: Select all

ACTOR Pixel
{
  Height 1
  Radius 1
  +NOGRAVITY
  +NOBLOCKMAP
  +CLIENTSIDEONLY
  +FORCEXYBILLBOARD
  States
  {
  Spawn:
	PIXA A 2 Bright
	Stop
  }
}

ACTOR Checker
{
  Height 1
  Radius 1
  +NOGRAVITY
  +NOBLOCKMAP
  +CLIENTSIDEONLY
  +FORCEXYBILLBOARD
  States
  {
  Spawn:
	NULL A -1
	Stop
  }
}

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Mon Nov 24, 2014 12:38 am
by Watermelon
You should try to debug what the increment is and print the angle of the player as well so we can see what is going on.

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Mon Nov 24, 2014 7:40 am
by Vincent(PDP)
Watermelon wrote: You should try to debug what the increment is and print the angle of the player as well so we can see what is going on.
I did before. I think it went from -65535 to 65536

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Mon Nov 24, 2014 9:05 pm
by Konda
First, you've defined increment as a sine value of the player's pitch:

Code: Select all

Int increment = -(sin(GetActorPitch(0)));
After that comes the problematic statement:

Code: Select all

increment += (increment / dist);
I don't get what increment/dist will give you exactly in the first iteration of the for loop, not to mention the other iterations...

You used the increment variable to get the value of the Z coordinate of the pixel but all you have to do to get the Z coordinate of the pixel you want to spawn is to multiply the sine value by dist:
[spoiler]Image[/spoiler]

Just be careful with the sign of the player's pitch since the sign of the player's pitch is negative when player is facing upwards and vice-versa.

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Tue Nov 25, 2014 8:52 am
by Vincent(PDP)
Konda wrote: First, you've defined increment as a sine value of the player's pitch:

Code: Select all

Int increment = -(sin(GetActorPitch(0)));
After that comes the problematic statement:

Code: Select all

increment += (increment / dist);
I don't get what increment/dist will give you exactly in the first iteration of the for loop, not to mention the other iterations...

You used the increment variable to get the value of the Z coordinate of the pixel but all you have to do to get the Z coordinate of the pixel you want to spawn is to multiply the sine value by dist:
[spoiler]Image[/spoiler]

Just be careful with the sign of the player's pitch since the sign of the player's pitch is negative when player is facing upwards and vice-versa.
I just tried random ways to calculate how much to increment each pixel's Z-height... And (increment / dist) plus the player's Z-height atleast put the pixels in a 45° angle upwards... dist is the incremented distance between each pixel.

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Tue Nov 25, 2014 11:28 am
by Watermelon
This may be a hacky fix, but if you want to get 90 degrees and youre only getting 45, maybe multiply the data going into the limiting function by 2 to attempt to give you the whole range?

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Tue Nov 25, 2014 2:07 pm
by Vincent(PDP)
Watermelon wrote: This may be a hacky fix, but if you want to get 90 degrees and youre only getting 45, maybe multiply the data going into the limiting function by 2 to attempt to give you the whole range?
I don't really get what the limiting function is but I have tried:

Code: Select all

Int increment = -(sin(GetActorPitch(0) * 2));
and
increment = (increment / dist) * 2
and
increment = (increment / (dist * 2))
and
increment = ((increment * 2) / dist)
None of it worked...

But this raised the angle a bit more but still not to 90:
increment = increment * 2
increment = (increment / dist)

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Tue Nov 25, 2014 9:29 pm
by Vincent(PDP)
Konda wrote: First, you've defined increment as a sine value of the player's pitch:

Code: Select all

Int increment = -(sin(GetActorPitch(0)));
After that comes the problematic statement:

Code: Select all

increment += (increment / dist);
I don't get what increment/dist will give you exactly in the first iteration of the for loop, not to mention the other iterations...

You used the increment variable to get the value of the Z coordinate of the pixel but all you have to do to get the Z coordinate of the pixel you want to spawn is to multiply the sine value by dist:
[spoiler]Image[/spoiler]

Just be careful with the sign of the player's pitch since the sign of the player's pitch is negative when player is facing upwards and vice-versa.
Your code almost made it. It misses about 20 degrees, or so... :/

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Tue Nov 25, 2014 9:57 pm
by Combinebobnt
Does that 45 degree thing happen to do with something involving software's limitations involving looking up and down (or somewhere in that domain), because that might have something to do with it. Or I could also not know anything I'm talking about, that's possible too.

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Tue Nov 25, 2014 10:15 pm
by Klofkac
Uh, don't forget that horizontal distance must be limited by the cosine of the pitch...
Let's think with distance = 1...
Because if you keep the "cosine" part always 1, on 90° pitch you will get vector of (1, sin(90°) = 1), whose angle is 45°. With using the cosine of pitch, you will get the vector of (cos(90°) = 0, sin(90°) = 1), which corresponds to 90°.
Another way you can imagine this is that all the points the green line spawn at without cosine, make up lateral surface of a cylinder with radius of 1 and hieght of 2, and with cosine they make up the surface of a sphere with radius of 1.
For analytic geometry, equation of sphere is x²+y²+z² = r². Equation of circle is x²+y²=r². By making z independent on circle equation, but limit it to [-h/2; h/2], we get lateral cylinder surface.

TL;DR for the horizontal distance, you want to multiply it with the cosine of pitch, before using it to calculate horizontal position.

...Yeah, trigonometry in three dimensions becomes bitch.

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Sat Nov 29, 2014 7:23 pm
by Vincent(PDP)
Klofkac wrote: Uh, don't forget that horizontal distance must be limited by the cosine of the pitch...
Let's think with distance = 1...
Because if you keep the "cosine" part always 1, on 90° pitch you will get vector of (1, sin(90°) = 1), whose angle is 45°. With using the cosine of pitch, you will get the vector of (cos(90°) = 0, sin(90°) = 1), which corresponds to 90°.
Another way you can imagine this is that all the points the green line spawn at without cosine, make up lateral surface of a cylinder with radius of 1 and hieght of 2, and with cosine they make up the surface of a sphere with radius of 1.
For analytic geometry, equation of sphere is x²+y²+z² = r². Equation of circle is x²+y²=r². By making z independent on circle equation, but limit it to [-h/2; h/2], we get lateral cylinder surface.

TL;DR for the horizontal distance, you want to multiply it with the cosine of pitch, before using it to calculate horizontal position.

...Yeah, trigonometry in three dimensions becomes bitch.
Okay, I don't understand very much of what you said... :lol: :myam:

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Fri Dec 05, 2014 11:29 am
by Klofkac
Okay...
We want to find the point coordinates on sphere (so we can multiply it later for higher distance).
Image
λ is equivalent for angle and φ is equivalent for pitch.
The angle is pretty much straightforward - x position is cos of radius and y position is sin of radius. But these coordinates apply only for equator.
Because when we use non zero pitch, we will move on smaller circle parallel to equator, as you can notice on the picture. Therefore, we need to multiply the horizontal radius by cos of pitch, the z coordination is straigghforward too, you just multiply the radius with sin of pitch.

So we get something like this:
x = cos(angle)×cos(pitch)×radius
y = sin(angle)×cos(pitch)×radius
z = sin(pitch)×radius

Sorry for being nerdy in prevoius post. I hope you understand this now.

RE: [ACS] How to make this ""respect"" my pitch?

Posted: Fri Dec 05, 2014 1:45 pm
by Vincent(PDP)
Klofkac wrote: Okay...
We want to find the point coordinates on sphere (so we can multiply it later for higher distance).
Image
λ is equivalent for angle and φ is equivalent for pitch.
The angle is pretty much straightforward - x position is cos of radius and y position is sin of radius. But these coordinates apply only for equator.
Because when we use non zero pitch, we will move on smaller circle parallel to equator, as you can notice on the picture. Therefore, we need to multiply the horizontal radius by cos of pitch, the z coordination is straigghforward too, you just multiply the radius with sin of pitch.

So we get something like this:
x = cos(angle)×cos(pitch)×radius
y = sin(angle)×cos(pitch)×radius
z = sin(pitch)×radius
Thanks. I will have a proper look at this when I get the time!
Klofkac wrote: Sorry for being nerdy in prevoius post. I hope you understand this now.
Naaah. You weren't so nerdy. It's just me not knowing anything about sine/cosine. :)