Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Sun May 19, 2013 3:11 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ] 
Author Message
 Post subject: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 1:24 pm 
Offline
Invisibility
User avatar

Joined: Fri Aug 13, 2004 4:39 pm
Posts: 3654
Location: Right there! Look!
Hey guys,

I have a vector position, let's call it (origin).
For sake of argument, let's say this position is at (100,100,100)
I also have an angle. This angle can be either (0-360) or (-1,-2) for up and down.
I also have a distance, let's say this distance is 1000.

Now I want to calculate the new vector position after applying the angle and the distance.
Is there an easy way to go about this?

I've looked at the following commands, but they seem to need vectors, and all I have is a float for the angle and the distance.

Code:
// Returns a forward vector for the given Euler angles.
scriptEvent   vector   angToForward( vector angles );

// Returns a right vector for the given Euler angles.
scriptEvent   vector   angToRight( vector angles );

// Returns an up vector for the given Euler angles.
scriptEvent   vector   angToUp( vector angles );


Any help is appreciated!

_________________
Check out GRIMM Quest for the Gatherer's Key!
Grimm's Youtube Channel

Follow Grimm Quest on Twitter!


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 3:25 pm 
Offline
missed 400 shots

Joined: Sat Jul 05, 2003 4:08 pm
Posts: 452
Antispam measure: What is larger? The Sun or the Galaxy?: sun
The "vector" class in Doom3 Scripts is really just a collection of float values that gets interpreted differently based on context.
In the case of the angTo* Functions, it would contain three Euler Angles.

http://www.modwiki.net/wiki/AngToForwar ... t_event%29

If you just have one angle, does it mean you just need to rotate around one axis ?

The monster_boss_guardian_seeker::state_Respawn function inside ai_monster_boss_guardian_seeker.script seems to do this too.

Snippet :
Code:
vector ang;
vector dir;

ang_y = sys.random( 360 );
dir = sys.angToForward( ang );
setAngles( ang );

setOrigin( guardian.spawner.getWorldOrigin() - '0 0 48' + dir * 82 );

_________________
( imagine obnoxiously huge Image here )
Doom3 Ambient Light Fix - Thread - Site


Last edited by rebb on Sun Nov 20, 2011 3:40 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 3:38 pm 
Offline
is sad because his cool title went away
User avatar

Joined: Tue Aug 12, 2003 11:38 am
Posts: 701
Location: Underneath it all, waiting to get to the surface.
Code:
        /|
hipo  /  |
    /    | sin angle * hipotenuse
  /      |
A--------|
cos angle * hipotenuse


for every dimension of the vector, but you only need three calcullations in two dimensions. in the third you already have all info needed.
I don't know how do you calc sin and cos with doom3

_________________
-->7318<--


Top
 Profile  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 7:16 pm 
Offline
Very Senior Forum Poster
User avatar

Joined: Sun May 29, 2005 10:02 pm
Posts: 7069
Location: Here, not there.
I'd use use your origin, rotate to the angle you want (angles are three floats by the way, you always have to use three) then you can use the ".move()" script command. According to modwiki, it has a "forward" option so it would be:
Code:
$temp_entity.move(FORWARD, 1000);


*IF* it were me, setup a name & origin for a new temp entity (origin = the location you're using, name is something relevant), spawn it, have the facing angle already set in the spawn arguments, then move it forward.

D3 scripting DOES have trig built in, someone pointed it out to me a year or so ago, I just can't find the thread where he pointed it out & compressed my HUGE script in to a small simple one. Trig would be easier.

_________________
Fuzzy Logic Inc
PAINTBALL DOOM 3!!!!
Check out my Q2 server! q2server.fuzzylogicinc.com :D
Doom 3, Paintball! d3server.fuzzylogicinc.com


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 7:46 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1123
If you're simply moving the entity along the angle it's facing, then you'd want to do what Friar said. If you need the new vector for other things in the script, then do what's in rebb's post.

Code:
vector newOrigin = getWorldOrigin() + sys.angToForward( ang ) * dist );   // 'ang' is your input angle and 'dist' is your input distance


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 8:32 pm 
Offline
Invisibility
User avatar

Joined: Fri Aug 13, 2004 4:39 pm
Posts: 3654
Location: Right there! Look!
Ah but there's the crux, I need to know the position before the mover goes there.

This is for a particle effect that needs to be spawned and triggered at the moment the mover *is* at the end position.
I've found a solution, but it's a hack: I simply wait with spawning the particle effect until the mover is at it's end position and do this only if it hasn't been spawned before, in that case I can spawn it at the origin of the mover.

It was for a 'moving_trap' entity where I could simply set particle effects, say for dust falling of a beam of wood that moves up and down.
The hack works, but it would be better if I could spawn the particle effects at the beginning and ending position before having the mover actually move there.

Regardless, this last solution works. :)

_________________
Check out GRIMM Quest for the Gatherer's Key!
Grimm's Youtube Channel

Follow Grimm Quest on Twitter!


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Nov 20, 2011 9:00 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1123
That's what the code above gives you (minus that extra ")" at the end). If you know the mover's origin and you know the angle and distance it's going to move, then you can get the destination position. Then you can just spawn your particle if the mover's origin equals the destination position.


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Mon Nov 21, 2011 2:05 am 
Offline
is sad because his cool title went away
User avatar

Joined: Tue Aug 12, 2003 11:38 am
Posts: 701
Location: Underneath it all, waiting to get to the surface.
out of curiosity, do you know ho to achieve the trigonometic results with doom? do you happen to know the commands to calculate the sinus cosinus tangents of a give angle or viceversa?

_________________
-->7318<--


Top
 Profile  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Mon Nov 21, 2011 2:24 am 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1123
idMath:: will bring up all of the functions in the math library.


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Mon Nov 21, 2011 3:19 pm 
Offline
Quad Damage!
User avatar

Joined: Tue Jun 22, 2004 6:57 pm
Posts: 4992
Location: Green Bay, WI
gravity gun script :)

_________________
Don't take the swine flu shot!


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Mon Nov 21, 2011 3:57 pm 
Offline
Very Senior Forum Poster
User avatar

Joined: Sun May 29, 2005 10:02 pm
Posts: 7069
Location: Here, not there.
Didn't that script get broken in an engine update though? Something to do with func_beam?

_________________
Fuzzy Logic Inc
PAINTBALL DOOM 3!!!!
Check out my Q2 server! q2server.fuzzylogicinc.com :D
Doom 3, Paintball! d3server.fuzzylogicinc.com


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Fri Jan 13, 2012 4:18 pm 
Online
picked up 200 ammo

Joined: Tue Aug 31, 2004 7:31 pm
Posts: 279
Location: Ireland
Ok, I want to move an object to a new location with setOrigin(). The distance and direction of the movement are defined by a vector (x,y,z), so (5,0.0) will move the object 5 units in x dir.

Now, if the object is facing the +x direction, then it moves 5 units forward.

I always want the object to move 'forward', so if the object is rotated, what operation should I perform on (5,0,0) so that it contains the correct data to move the object 5 units forward, relative to it's new angle?

e,g,. if the object is rotated 90 degrees (pointing +y dir), then the vector should be (0,5,0), but how do I convert (5,0,0) to (0,5,0) dynamically, based on the object's angle?

I hope that makes sense...

_________________
"Leave me alone, I know what I'm doing..." Kimi Raikkonen


Top
 Profile  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Fri Jan 13, 2012 4:53 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1123
Something like this should work:
Code:
vector dir = sys.angToForward( getAngles() );

vector newPos = getOrigin() + dir * 5.0f;


Top
 Profile E-mail  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Fri Jan 13, 2012 5:14 pm 
Online
picked up 200 ammo

Joined: Tue Aug 31, 2004 7:31 pm
Posts: 279
Location: Ireland
Sikkpin wrote:
Something like this should work:
Code:
vector dir = sys.angToForward( getAngles() );

vector newPos = getOrigin() + dir * 5.0f;


Thanks Sikkpin,

So, I can use this?

Code:

vector dir = sys.angToForward( getAngles() );

vector dist = (3,11,0) ;

vector newPos = getOrigin() + (dir * dist);

_________________
"Leave me alone, I know what I'm doing..." Kimi Raikkonen


Top
 Profile  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Sun Jan 15, 2012 11:15 pm 
Offline
Last man standing
User avatar

Joined: Fri Apr 22, 2005 11:55 pm
Posts: 1180
You can only multiply a vector by a scalar.

Btw the correct sintax for declaring a vector is:

vector dist = '3 11 0';

_________________
Fragging Free - a frantic Doom3:ROE single-player modification.


Top
 Profile  
 
 Post subject: Re: Stupid question about vectors and angles
PostPosted: Mon Jan 16, 2012 12:48 am 
Online
picked up 200 ammo

Joined: Tue Aug 31, 2004 7:31 pm
Posts: 279
Location: Ireland
Ivan_the_B wrote:
You can only multiply a vector by a scalar.

Btw the correct sintax for declaring a vector is:

vector dist = '3 11 0';

Thanks Ivan,
I must have been thinking in Python with that syntax :oops:

Anyway, If anyone else has the same problem, this code works:
Code:
void player::translate_player() {
   char_move_dir_x = (sys.cos(pang))*sys.sqrt(movexy_x*movexy_x + movexy_y*movexy_y);
   char_move_dir_y = (sys.sin(pang))*sys.sqrt(movexy_x*movexy_x + movexy_y*movexy_y);
   new_char_pos = char_pos + char_move_dir;
   self.setOrigin(new_char_pos);
}

where:
pang = player Y angle.
vector movexy = the x,y,z data of 'origin' from the current frame of .md5anim.
char_pos = the player origin at the start of the animation.

This lets the player move as dictated by the animation, instead of just slipping on the spot.

_________________
"Leave me alone, I know what I'm doing..." Kimi Raikkonen


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Adsense [Bot], hellstorm27 and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group