Converting projectile "pitch" to World object angles

Post » Tue Dec 29, 2009 6:32 pm

The coordinate system for projectiles is different from the one used to place objects. Projectiles use angles relative to the projectile, where as objects placed in the world use angles that have a fixed position relative to the world.

So the angle x on a projectile (how far it points up or down or AKA the "PITCH") becomes partly angle x and partly angle y for objects placed in the world depending on which Z direction (the "YAW" ) they face.

I am doing "getangle x" (Pitch) on a arrow in flight and applying this to another arrow that is placed in the game manually (not shot by the player). I am at a lost as to how to convert the numbers to get the placed arrow Pitch to match the Pitch of the player shot arrow.

Unless some math genius can point me to some existing script that is written to solve this conversion issue I am going to have to do something crazy like forcing both arrows into the "north" direction first, then angleing the Pitch, THEN forcing them back again to the original Yaw position once again.

Actually now that I say it out loud I guess this is not so crazy a solution, but I would prefer a mathematical one if one exists?

Help please?
User avatar
Mari martnez Martinez
 
Posts: 3500
Joined: Sat Aug 11, 2007 9:39 am

Post » Tue Dec 29, 2009 8:21 am

I suppose the easier solution is to get the XYZ angles from one arrow and apply them on the other arrow. They would be parallel.

But to position the second arrow relative to the first (like side by side, above or below) you may use the following OBSE user function I created based on math provided by SkyRanger-1 some time ago.

The usage is as follows:
RefToBePositioned.call zuRefPositionRelative AnchorRef deltaX deltaY deltaZ deltaAngleZ

Where:
RefToBePositioned is the arrow to be positioned
AnchorRef is the 'anchor' arrow
deltaX deltaY deltaZ are the relative positions of the second arrow relative to the first, when the first is at angles XYZ = 0.
deltaAngleZ = 0 - not applicable to arrows

E.g. if you want the second arrow 5 units above the first, the call would be:
MySecondArrowRef.call zuRefPositionRelative MyFirstArrowRef 0 0 5 0

scn zuRefPositionRelative;---------------------------------------;	Positions the calling ref relative to the anchor position and angle;---------------------------------------;	Must be called on a ref;---------------------------------------float angXanchor float angYanchor float angZfloat angZanchor float angZanchor float dangX float dangZfloat dDistfloat dposXfloat dposYfloat dposZfloat posXfloat posXanchor float posYfloat posYanchor float posZfloat posZanchor Float xtoxFloat xtox2Float xtoy Float xtoy2 Float xtozFloat xtoz2Float ytox Float ytox2Float ytoy Float ytoy2 Float ytozFloat ytoz2Float ztoxFloat ztox2Float ztoyFloat ztoy2Float ztozFloat ztoz2ref refAnchor string_var xxsSelfbegin Function {refAnchor dposX dposY dposZ dangZ} 	let posXanchor := refAnchor.getpos x	let posYanchor := refAnchor.getpos y	let posZanchor := refAnchor.getpos z 	let angXanchor := refAnchor.getangle x  	let angYanchor := refAnchor.getangle y	let angZanchor := refAnchor.getangle z	;============================================================	;	Modder's resource code by SkyRanger-1	;============================================================	; APPLY Z angle (simplified/optimized slightly since we know where the zeroes and ones were)	Set xtox to cos angZanchor	Set xtoy to -1 * sin angZanchor	Set xtoz to 0	Set ytox to sin angZanchor 	Set ytoy to cos angZanchor 	Set ytoz to 0	Set ztox to 0	Set ztoy to 0	Set ztoz to 1	; APPLY Y angle (not simplified/optimized, even though we know where a few zeros and ones were)	Set xtox2 to ( xtox * COS angYanchor ) + ( -1 * xtoz * SIN angYanchor )	Set xtoy2 to xtoy	Set xtoz2 to ( 1 * xtox * SIN angYanchor ) + ( xtoz * COS angYanchor )	Set ytox2 to ( ytox * COS angYanchor ) + (  -1 * ytoz * SIN angYanchor )	Set ytoy2 to ytoy	Set ytoz2 to ( 1 * ytox * SIN angYanchor ) + ( ytoz * COS angYanchor )	Set ztox2 to ( ztox * COS angYanchor ) + (  -1 * ztoz * SIN angYanchor )	Set ztoy2 to ztoy	Set ztoz2 to ( 1 * ztox * SIN angYanchor ) + ( ztoz * COS angYanchor )	; APPLY X angle (cannot be simplified/optimized)	Set xtox to xtox2	Set xtoy to ( xtoy2 * COS angXanchor ) + ( xtoz2 * SIN angXanchor )	Set xtoz to ( -1 * xtoy2 * SIN angXanchor ) + ( 1 * xtoz2 * COS angXanchor )	Set ytox to ytox2	Set ytoy to ( ytoy2 * COS angXanchor ) + ( ytoz2 * SIN angXanchor )	Set ytoz to ( -1 * ytoy2 * SIN angXanchor ) + ( 1 * ytoz2 * COS angXanchor )	Set ztox to ztox2	Set ztoy to ( ztoy2 * COS angXanchor ) + ( ztoz2 * SIN angXanchor )	Set ztoz to ( -1 * ztoy2 * SIN angXanchor ) + ( 1 * ztoz2 * COS angXanchor )	; NEW COORDINATES AFTER ROTATION	Set posX to posXanchor +  dposX * xtox + dposY * ytox + dposZ * ztox	Set posY to posYanchor +  dposX * xtoy + dposY * ytoy + dposZ * ztoy	Set posZ to posZanchor +  dposX * xtoz + dposY * ytoz + dposZ * ztoz	setpos X posX	setpos Y posY	setpos Z posZ	setangle X angXanchor 	setangle Y angYanchor 	let  angZ := angZanchor + dangZ 	setangle Z angZ End

User avatar
Judy Lynch
 
Posts: 3504
Joined: Fri Oct 20, 2006 8:31 am


Return to IV - Oblivion