Inside3D!
     

vector math, combining angles and offsets

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
daemon



Joined: 07 Nov 2007
Posts: 62

PostPosted: Sat Mar 22, 2008 5:18 pm    Post subject: vector math, combining angles and offsets Reply with quote

I'm trying to locate the position of a weapon blade in the world based on a few angles and offsets.

I have:

self - (the player)
wep.targorigin - (the origin the weapon in the player's hand is moving toward)

wep is an attachment on the player, so it's origin is relative.
in order to find it's real origin in the world I do this:

---
ang = self.angles + vectoangles(wep.targorigin); // the angle in the world from the player origin to the weapon origin
ang_x = -ang_x; // negate the pitch
makevectors(ang); // get v_forward
wep_position = self.origin + v_forward*vlen(wep.targorigin); // the weapon origin in the world
---

now I have wep_position to base my next calculation from.
and also:
wep.targangles - (the angles the weapon is turning toward)
wep.damagepoint_ofs - (the offset of the weapon blade)


wep.damagepoint_ofs being shown here as '8.7 0.2 23.23'

so I do the following to find the position of the weapon blade:

---
ang = self.angles + wep.targangles + vectoangles(wep.damagepoint_ofs); // the angle in the world from the weapon position to the weapon blade
ang_x = -ang_x; // negate the pitch again
makevectors(ang); // get v_forward
swing_end = wep_position + v_forward*vlen(wep.damagepoint_ofs); // the position of the blade in the world
---

for some reason this doesn't work out. the position of the blade ends up being calculated way off. I can't figure out what I'm doing wrong or what I need to do to make this work.

I suspect that it has something to do with this line:
ang = self.angles + wep.targangles + vectoangles(wep.damagepoint_ofs);

pitch, yaw, and roll are all tilted in wep.targangles, but self.angles and vectoangles(wep.damagepoint_ofs) only have a pitch and a yaw...

any ideas?
_________________
-daemon [ daemonforge.org ]
Back to top
View user's profile Send private message Visit poster's website
daemon



Joined: 07 Nov 2007
Posts: 62

PostPosted: Sun Mar 23, 2008 12:21 am    Post subject: Reply with quote

ok, ignore that post above. here is the updated code for the weapon position ONLY:

Code:
   pivot_ofs = '0 0 16';
   pivotpoint = self.origin + pivot_ofs;
   wep_targorg = wep.targorigin - pivot_ofs;
   self_ang = self.angles;
   
   ang = self_ang + vectoangles(wep_targorg);
   ang_x = -ang_x;
   makevectors(ang);
   wep_pos = pivotpoint + v_forward*vlen(wep_targorg);


when i look up and down the wep_pos becomes inaccurate...
_________________
-daemon [ daemonforge.org ]
Back to top
View user's profile Send private message Visit poster's website
daemon



Joined: 07 Nov 2007
Posts: 62

PostPosted: Sun Mar 23, 2008 3:04 am    Post subject: Reply with quote

well.. here's the working copy if anyone is interested. Thanks to KrimZon for help with combining angles. I don't understand why I had to subtract v_right, but that's the only way I could get it to work correctly.

Code:
void UpdateDamagePoint(entity wep) =
{
   local vector ang, wep_pos, dmg_ang;

   ang = self.angles;
   ang_x = -ang_x;
   makevectors(ang);
   ang = vectoangles(v_forward*wep.targorigin_x - v_right*wep.targorigin_y + v_up*wep.targorigin_z); // angle from player origin to weapon handle in modelspace
   
   ang_x = -ang_x;
   makevectors(ang);
   wep_pos = self.origin + v_forward*vlen(wep.targorigin); // position of weapon handle in worldspace
   
   dmg_ang = wep.targangles;
   dmg_ang_x = -dmg_ang_x;
   makevectors(dmg_ang);
   dmg_ang = (v_forward*wep.damagepoint_ofs_x - v_right*wep.damagepoint_ofs_y + v_up*wep.damagepoint_ofs_z); // angle from weapon handle to weapon damagepoint in modelspace
   
   ang = self.angles;
   ang_x = -ang_x;
   makevectors(ang);
   ang = vectoangles(v_forward*dmg_ang_x - v_right*dmg_ang_y + v_up*dmg_ang_z); // angle from weapon handle to weapon damagepoint in worldspace
   
   ang_x = -ang_x;
   makevectors(ang);
   wep.damagepoint = wep_pos + v_forward*vlen(wep.damagepoint_ofs);// position of weapon damagepoint in worldspace
}   

_________________
-daemon [ daemonforge.org ]
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2004 phpBB Group