.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
Looking to trace out at 45 degrees off the players center...
Old
  (#1)
Maleficus
Member
 
Maleficus's Avatar
 
Status: Offline
Posts: 1,054
Join Date: May 2004
Location: Planet Earth
Default Looking to trace out at 45 degrees off the players center... - 18-06-2004

Trying to find a better and cheaper way to find what the 45 degree angles are of a player.

EX:



\*******/*
*\*****/**
**\***/***
***\*/****
****P****

P = The player.

The two 45 degree lines represent the tracelines I would like to make - but how do I find those angles cheaply?? I have one way to do it, but its VERY expensive. I keep thinking I'm missing something, and theres a faster way to find out this info.

Help?


Dum Spiro Spero


  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#2)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

*edit* what I wrote applies as much to HL as to any other engine (such as RTCW)

Use the player's angles, flatten them if needed
Code:
Vector v_myangles = pPlayerEdict->v.angles;
v_myangles.z = 0;
Add 45° on one side (horizontal plane), make sure it stays in bounds
Code:
v_myangles.y += 45;
if (v_myangles.y > 180)
   v_myangles.y -= 360;
Build a referential out of it
Code:
MAKE_VECTORS (v_myangles);
then use the forward, right and upwards vectors generated to fire your traceline
Code:
TraceResult tr;
TRACE_LINE (pPlayerEdict->v.origin,
			pPlayerEdict->v.origin + (gpGlobals->v_forward * 9999),
			ignore_monsters,
			pPlayerEdict,
			&tr);
Do the same for the other side.

That's it.

If you want something faster than MAKE_VECTORS(), or if MAKE_VECTORS() is not available for your engine, well it can look like this:
Code:
void BuildReferential (const Vector &v_angles)
{
   // this function builds a 3D referential from a view angle, that is to say, the relative
   // "forward", "right" and "upwards" direction that a player would have if he were facing this
   // view angle. World angles are stored in Vector structs too, the "x" component corresponding
   // to the X angle (horizontal angle), and the "y" component corresponding to the Y angle
   // (vertical angle). Beware, heavy math here.
 
   static float degrees_to_radians = 2 * MATH_PI / 360;
   float angle;
   float sin_pitch;
   float sin_yaw;
   float sin_roll;
   float cos_pitch;
   float cos_yaw;
   float cos_roll;
 
   // compute the sin and cosine of the pitch component
   angle = v_angles.x * degrees_to_radians;
   sin_pitch = sinf (angle);
   cos_pitch = cosf (angle);
 
   // compute the sin and cosine of the yaw component
   angle = v_angles.y * degrees_to_radians;
   sin_yaw = sinf (angle);
   cos_yaw = cosf (angle);
 
   // compute the sin and cosine of the roll component
   angle = v_angles.z * degrees_to_radians;
   sin_roll = sinf (angle);
   cos_roll = cosf (angle);
 
   // build the FORWARD vector
   referential.v_forward.x = cos_pitch * cos_yaw;
   referential.v_forward.y = cos_pitch * sin_yaw;
   referential.v_forward.z = -sin_pitch;
 
   // build the RIGHT vector
   referential.v_right.x = (-(sin_roll * sin_pitch * cos_yaw) - (cos_roll * -sin_yaw));
   referential.v_right.y = (-(sin_roll * sin_pitch * sin_yaw) - (cos_roll * cos_yaw));
   referential.v_right.z = -(sin_roll * cos_pitch);
 
   // build the UPWARDS vector
   referential.v_up.x = ((cos_roll * sin_pitch * cos_yaw) - (sin_roll * -sin_yaw));
   referential.v_up.y = ((cos_roll * sin_pitch * sin_yaw) - (sin_roll * cos_yaw));
   referential.v_up.z = cos_roll * cos_pitch;
 
   return;
}
Comes straight from RACC
If you're using only the forward vector you can get rid of 60% of this function
Code:
Vector BuildForwardVector (const Vector &v_angles)
{
   // this function builds a "forward" vector from a view angle
 
   static float degrees_to_radians = 2 * MATH_PI / 360;
   float angle;
   float sin_pitch;
   float sin_yaw;
   float cos_pitch;
   float cos_yaw;
   Vector v_forward;
 
   // compute the sin and cosine of the pitch component
   angle = v_angles.x * degrees_to_radians;
   sin_pitch = sinf (angle);
   cos_pitch = cosf (angle);
 
   // compute the sin and cosine of the yaw component
   angle = v_angles.y * degrees_to_radians;
   sin_yaw = sinf (angle);
   cos_yaw = cosf (angle);
 
   // build the FORWARD vector
   v_forward.x = cos_pitch * cos_yaw;
   v_forward.y = cos_pitch * sin_yaw;
   v_forward.z = -sin_pitch;
 
   return (v_forward);
}
Nothing faster - AFAIK.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."

Last edited by Pierre-Marie Baty; 18-06-2004 at 09:45..
  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#3)
sPlOrYgOn
<-- He did it.
 
sPlOrYgOn's Avatar
 
Status: Offline
Posts: 1,558
Join Date: Jan 2004
Location: Los Angeles, California, USA, North America, Earth, Solar System, Milky Way.
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

I thought he was making a bot for RTCW..
  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#4)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

as far as I know, the current fpus support sin and cos support, therefore it's not taking to long to calculate them. Another possibility is using lookup tables for them, but since the fpu normally runs faster than your mem, I guess this is the way to go.

@pierre : why should your code be faster than those of the engine ? don't you think they just do the same ? and in terms of cache usage using the engines one might even be better ... just a thought


  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#5)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

because engine facilities usually compute ALL THREE vectors... the last function I posted computes only the one we want



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#6)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

that's true ...


  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#7)
Maleficus
Member
 
Maleficus's Avatar
 
Status: Offline
Posts: 1,054
Join Date: May 2004
Location: Planet Earth
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

Thx for the info!

I'll give it a try later today when I have the time.



btw: yes, RTCW does have a "make_vectors" function, but its called "AngleVectors", which works exactly the same way (finds the forward, right, up vectors of a client).


Dum Spiro Spero


  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#8)
Maleficus
Member
 
Maleficus's Avatar
 
Status: Offline
Posts: 1,054
Join Date: May 2004
Location: Planet Earth
Default Re: Looking to trace out at 45 degrees off the players center... - 18-06-2004

Hmm. gave it a quick try, but it created a traceline facing upwards at 45 degrees, instead of outward (forward). I'll play with it some more when I have time (should be leaving for work already!).

btw: heres what the code looks like in RTCW:

Code:
  vec3_t angles, forward, start;
  trace_t tr;
  
  VectorCopy(ent->s.angles, angles);
  AngleVectors (angles, forward, NULL, NULL);
  start[2] += ent->client->ps.viewheight;
  forward[2] = 0;
  forward[1] += 45;
  if (forward[1] > 180)
   forward[1] -= 360;
  
  vectoangles(forward, right);
  VectorMA(start, 100, right, end);
  trap_Trace(&tr, start, NULL, NULL, end, ent->s.number, MASK_SHOT);


Dum Spiro Spero


  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#9)
Maleficus
Member
 
Maleficus's Avatar
 
Status: Offline
Posts: 1,054
Join Date: May 2004
Location: Planet Earth
Default Re: Looking to trace out at 45 degrees off the players center... - 19-06-2004

Ugh - nevermind the above post or the posted code, in my hurray to leave for work, I made a TON of mistakes. I've got it working now just fine, thx for the help!

BTW: here is the correct code.

Code:
  VectorCopy(ent->s.angles, angles);
  angles[YAW] += 45;
  AngleVectors (angles, forward, NULL, NULL);
  VectorCopy(ent->r.currentOrigin, start);
  VectorMA(start, 100, forward, end);
  trap_Trace(&tr, start, NULL, NULL, end, ent->s.number, MASK_SHOT);


Dum Spiro Spero


  
Reply With Quote
Re: Looking to trace out at 45 degrees off the players center...
Old
  (#10)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Looking to trace out at 45 degrees off the players center... - 19-06-2004

that looks very similar to HL code in fact... because our MAKE_VECTORS is actually a macro that calls AngleVectors()...

And Vector is a class to handle better the engine's vec3_t structure

VERY similar. Very interesting for the United Bot...



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com