Raised This Month: $ Target: $400
 0% 

[Vectors] Translate point X dist in direction of an angle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 05-07-2015 , 15:59   [Vectors] Translate point X dist in direction of an angle
Reply With Quote #1

I have so many uses for this and yet no idea how to do the math for this.

PHP Code:
stock TranslatePoint(Float:vPos[3], const Float:vAng[3], const Float:flDist) {
    
vPos[0] += 0.0;
    
vPos[1] += 0.0;
    
Vpos[2] += 0.0;

The math is simple in a cartesian plane... but I have no idea in 3D space.

Similarly, I'd like to know how to get the angle from point 1 ---> point 2

For example, let's say I want to make a rocket launcher that shoots 4 rockets. Each rocket should still move towards your cursor and I want to spawn one from the 4 corners of a player's screen, so each rocket appears to fly inward to the same target.

Essentially I'd use TranslatePoint with the player's eye position and eye angles to some arbitrary point flDist away to get the position in the distance that the "cursor" is at.

From the player's eye position, I'd TranslatePoint 4 more times in 4 different angles to make rockets spawn in the four corners of my screen, and I'd set the angle of those rockets from one of the 4 points to the cursor's point in the distance.


However bad that example is, I have plenty of other things this'd be useful for... if anyone can help.

I am not looking for tracerays. I don't necessarily have to care about world collision.
__________________

Last edited by Chdata; 05-07-2015 at 16:18.
Chdata is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-07-2015 , 16:38   Re: [Vectors] Translate point X dist in direction of an angle
Reply With Quote #2

Disclaimer: 3D math isn't my strong suit.

Just an FYI.

On a Cartesian plane, you're only dealing with a single angle in the x-y dimensions.

On a 3D plane, you're dealing with 3 angles:
  • Pitch - y-z (up-down) angle
  • Yaw - x-y (let-right) angle
  • Roll - x-z ("spin") angle

And one last thought here: The player's FOV is going to change where the corners of their screen are.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-09-2015 at 12:36.
Powerlord is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 05-07-2015 , 16:55   Re: [Vectors] Translate point X dist in direction of an angle
Reply With Quote #3

PHP Code:
AnglesToUV(Float:vOut[3], const Float:vAngles[3])
{
    
vOut[0] = Cosine(vAngles[1] * FLOAT_PI 180.0) * Cosine(vAngles[0] * FLOAT_PI 180.0);
    
vOut[1] = Sine(vAngles[1] * FLOAT_PI 180.0) * Cosine(vAngles[0] * FLOAT_PI 180.0);
    
vOut[2] = -Sine(vAngles[0] * FLOAT_PI 180.0);

Once you have the unit vector, a point x units from point p in direction d is p + x * d

Quote:
Originally Posted by Chdata View Post
Similarly, I'd like to know how to get the angle from point 1 ---> point 2
Subtract point 1 from point 2 and normalize it, and you'll have a unit vector in that direction.
Miu is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 05-07-2015 , 16:57   Re: [Vectors] Translate point X dist in direction of an angle
Reply With Quote #4

Yes that's just an example, I just didn't know how else to word "spawn 4 rockets diagonally in NE/SE/NW/NW angles originating from the center of one's view such that they all aim at the same point and appear like a shrinking X shape". See how confusing that is?
__________________
Chdata is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 05-09-2015 , 05:22   Re: [Vectors] Translate point X dist in direction of an angle
Reply With Quote #5

Quote:
Originally Posted by Miu View Post
PHP Code:
AnglesToUV(Float:vOut[3], const Float:vAngles[3])
{
    
vOut[0] = Cosine(vAngles[1] * FLOAT_PI 180.0) * Cosine(vAngles[0] * FLOAT_PI 180.0);
    
vOut[1] = Sine(vAngles[1] * FLOAT_PI 180.0) * Cosine(vAngles[0] * FLOAT_PI 180.0);
    
vOut[2] = -Sine(vAngles[0] * FLOAT_PI 180.0);

Once you have the unit vector, a point x units from point p in direction d is p + x * d



Subtract point 1 from point 2 and normalize it, and you'll have a unit vector in that direction.
Thanks, this seems to have solved it ;O
__________________
Chdata is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 05-09-2015 , 12:19   Re: [Vectors] Translate point X dist in direction of an angle
Reply With Quote #6

3 dimensional is just 2 dimensional with lots more triangles.
thecount is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode