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

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#1

Post by Vincent(PDP) » Sun Nov 23, 2014 8:48 pm

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
  }
}
Last edited by Vincent(PDP) on Sun Nov 23, 2014 8:52 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#2

Post by Watermelon » Mon Nov 24, 2014 12:38 am

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.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#3

Post by Vincent(PDP) » Mon Nov 24, 2014 7:40 am

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
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Konda
Forum Regular
Posts: 487
Joined: Thu Jun 07, 2012 5:22 pm

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

#4

Post by Konda » Mon Nov 24, 2014 9:05 pm

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.
Last edited by Konda on Tue Nov 25, 2014 12:32 am, edited 1 time in total.

Code: Select all

<Synert> fuck
<Synert> plugged in my memory stick and got a bsod

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#5

Post by Vincent(PDP) » Tue Nov 25, 2014 8:52 am

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.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#6

Post by Watermelon » Tue Nov 25, 2014 11:28 am

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?

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#7

Post by Vincent(PDP) » Tue Nov 25, 2014 2:07 pm

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)
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#8

Post by Vincent(PDP) » Tue Nov 25, 2014 9:29 pm

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... :/
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

User avatar
Combinebobnt
Retired Staff / Community Team Member
Posts: 1907
Joined: Mon Jun 04, 2012 3:37 am
Location: Earth
Contact:

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

#9

Post by Combinebobnt » Tue Nov 25, 2014 9:57 pm

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.

Klofkac
Forum Regular
Posts: 481
Joined: Sat Jun 09, 2012 1:31 pm
Location: Ask Grandvoid servers

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

#10

Post by Klofkac » Tue Nov 25, 2014 10:15 pm

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.
Last edited by Klofkac on Tue Nov 25, 2014 11:19 pm, edited 1 time in total.
𝕂𝕝𝕠𝕗𝕜𝕒𝕔

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#11

Post by Vincent(PDP) » Sat Nov 29, 2014 7:23 pm

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:
Last edited by Vincent(PDP) on Sat Nov 29, 2014 7:27 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Klofkac
Forum Regular
Posts: 481
Joined: Sat Jun 09, 2012 1:31 pm
Location: Ask Grandvoid servers

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

#12

Post by Klofkac » Fri Dec 05, 2014 11:29 am

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.
Last edited by Klofkac on Fri Dec 05, 2014 11:56 am, edited 1 time in total.
𝕂𝕝𝕠𝕗𝕜𝕒𝕔

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

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

#13

Post by Vincent(PDP) » Fri Dec 05, 2014 1:45 pm

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. :)
Last edited by Vincent(PDP) on Fri Dec 05, 2014 1:45 pm, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Post Reply