Forum

rotation around '0 0 0' at fixed distance trouble

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

rotation around '0 0 0' at fixed distance trouble

Postby apolluwn » Tue Aug 23, 2011 9:31 pm

This creates a spiral outward rather than a keeping a fixed distance from '0 0 0' from a starting origin.

There is obviously something being overlooked, but I can't put my finger on it. Any insight into what is being overlooked would be greatly appreciated.

Code: Select all
   local vector vec;
   local float angle;
   
     // x > 0 & y > 0
   // atan(y/x);
        // asin(y/dist);
   
   // x < 0 & y > 0
   // pi+atan(y/x)
        // acos(x/dist);
   
   // x < 0 & y > 0
   // pi+atan(y/x)
        // pi-asin(y/dist)

   // x < 0 y < 0
   // 2pi+atan(y/x)
        // pi-acos(x/dist)
   
   angle = (atan2(self.origin_y, self.origin_x));
   
   if(self.button7)
   {      
      vec_x =   sin(angle);
      vec_y =  -cos(angle);          
   }      
   if(self.button8)
   {
      vec_x =  -sin(angle);
      vec_y =   cos(angle);               
   }   

   if (self.button7 || self.button8 )
   {
      vec_x = vec_x*15;
      vec_y = vec_y*15;   
   }
   
   //convert radians to degrees
   local float degrees;
   
        degrees  = angle * (360/(2*M_PI));
   if(degrees < 0)
             degrees = degrees+360;   
   
   // calculate distance from origin to '0 0 0'
   local float distance, radius;
   distance = vlen(self.origin - '0 0 0');
   // or...
   //   radius = sqrt((self.origin_x*self.origin_x) + (self.origin_y*self.origin_y));   
   
   //calculate difference between vec change and current origin
   local float  diff, diff_x, diff_y;
   
   diff   = vlen((self.origin+vec)-self.origin);
   diff_x = vlen(self.origin+(vec_x*'1 0 0')-self.origin);
   diff_y = vlen(self.origin+(vec_y*'0 1 0')-self.origin);
      
   setorigin(self, self.origin+vec);
apolluwn
 
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Postby Spike » Tue Aug 23, 2011 10:18 pm

if that's a bsp object, you need to compensate for the origin of the bsp object, otherwise you're rotating the object around the center of the map rather than the center of the object.

also, use avelocity if the engine supports that on the movetype you're using.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby apolluwn » Tue Aug 23, 2011 10:40 pm

Spike wrote:if that's a bsp object, you need to compensate for the origin of the bsp object, otherwise you're rotating the object around the center of the map rather than the center of the object.

also, use avelocity if the engine supports that on the movetype you're using.


Thanks for the response, but I think you've misinterpreted what the problem was... I'm not trying to rotate an object on its axis...

I probably should have titled this thread "rotating the player origin around '0 0 0' at a fixed radius", or similar.

The object (of the code) is to rotate the player origin around a spherical object [although the shape of the object is pretty inconsequential] with an origin of '0 0 0'. This does rotate around '0 0 0', but is constantly escaping from its original distance at some arbitrary (and apparently constantly changing/slightly increasing) number.

The distance should be fixed at sqrt(x^2+y^2). The distance from '0 0 0' to the player origin should remain constant, but this is not the case. It constantly escapes per change of the origin (self.origin+vec).

I can't come up with any "regular" offset of the change (although I can "correct it" [for lack of a better description] to a certain degree the change by comparing the radian to pi/4, pi/2, etc[this is not by any means exacting] and adjusting the angle so that it will converge more closely to the original distance at these points), but honestly it shouldn't even be escaping according to the equations...

The math -looks- right (I suppose there is a possibly it is not, but this is pretty basic trig... and when I work out the equations it certainly appears correct). I assume that there must be something that isn't being considered...
apolluwn
 
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest