Forum

RotatePointAroundVector Broken?

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

RotatePointAroundVector Broken?

Postby jitspoe » Fri Nov 15, 2013 4:15 am

I wanted to tweak the angle of the stars a bit for the skybox I'm working on, so RotatePointAroundVector seemed to be the appropriate function to use, however, instead of just rotating, it seems I've managed to collapse the universe!

I'm rotating around 0,1,0 (y axis), and here are the results from 0 to -100 degrees:

Image
Image
Image
Image
Image
Image

Does anybody have a fixed version of the function, or is this how it's expected to work? Doesn't seem right...
jitspoe
 
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: RotatePointAroundVector Broken?

Postby Spike » Fri Nov 15, 2013 4:56 am

AngleVectors('0 1 0' * time, forward,left,up);
neworg_x = dot(forward,origorg);
neworg_y = dot(left,origorg);
neworg_z = dot(up,origorg);

or in other words, use a matrix.
and rotate the matrix a little so that you're not standing at the north pole.

if you're just making a skybox image, you could just swizzle+negate accordingly without bothering with complex rotations.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: RotatePointAroundVector Broken?

Postby jitspoe » Fri Nov 15, 2013 5:05 am

I'm just doing the rotation on load.

I ended up rewriting the function like this, and it appears to work:

Code: Select all
void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
{
   float u = dir[0], v = dir[1], w = dir[2];
   float x = point[0], y = point[1], z = point[2];
   float ux = u * x, uy = u * y, uz = u * z, vx = v * x, vy = v * y, vz = v * z, wx = w * x, wy = w * y, wz = w * z;
   float uu = u * u, ww = w * w, vv = v * v;
   float s = (float)sin(DEG2RAD(degrees));
   float c = (float)cos(DEG2RAD(degrees));

   dst[0] = u * (ux + vy + wz) + (x * (vv + ww) - u * (vy + wz)) * c + (vz - wy) * s;
   dst[1] = v * (ux + vy + wz) + (y * (uu + ww) - v * (ux + wz)) * c + (wx - uz) * s;
   dst[2] = w * (ux + vy + wz) + (z * (uu + vv) - w * (ux + vy)) * c + (uy - vx) * s;
}



Edit: Wonder if model culling was buggy because of this? Or maybe this fix will create new bugs?
jitspoe
 
Posts: 217
Joined: Mon Jan 17, 2005 5:27 am

Re: RotatePointAroundVector Broken?

Postby Jay Dolan » Fri Nov 15, 2013 12:06 pm

You might want to look at LordHavoc's matrix lib to replace or at least augment the sparse / incomplete / seemingly arbitrary / questionably buggy transform functions included in Quake2:

https://github.com/jdolan/quake2world/b ... r_matrix.c

It works very well; I've never had to touch it.
User avatar
Jay Dolan
 
Posts: 59
Joined: Tue Jan 22, 2008 7:16 pm
Location: Naples, FL


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest