Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

120 Neutral

About PhoenixGames

  • Rank

Personal Information

  • Interests
  1. Hello, Thank you very much for your reply, your solution worked great! I had gotten myself confused there I think, but I had been working on this problem for some time. Is there some way for me to give you "reputation" or something for that solution? Thanks again!
  2. Hello, I posted this a few months ago. I was trying to rotate a set of points around a sphere, Based on the replies that I got, I made some progress, but I am still not quite there. My current situation can be described best with the aid of THIS graphic (https://postimg.org/image/jkg1hs2fn/).   I tried to embed it, but wasn't able.    Basically, the coloured polygons are a set of vertices that I am trying to move and rotate.  In short, I would like to take the GREEN vertices (testgroup2) and rotate then so that they are in exactly the same position as the pink vertices (testgroup1). I am working on a spherical terrain implementation, and all of these vertices are on the surface of the same sphere, so I should be able to rotate them around the origin of that sphere. What I am trying to do is use Rodrigues rotation formula to handle the rotation. This is the relevant section of code: F32 x = renderlist[i].point.x; F32 y = renderlist[i].point.y; F32 z = renderlist[i].point.z; Point3F v = Point3F(x, y, z); //get the point to be rotated Point3F vec1 = v - Point3F(0, -10, 0); //get a vector from v to a new center point (0,-10,0) v -= vec1; //subtract this vector from v Point3F k = Point3F(1, 0, 0); //all rotation along x F32 theta = -0.785398; //Rotation angle, 45 degrees //Rodrigues' rotation formula: Point3F vRot = v*mCos(theta) + mCross(k, v)*mSin(theta) + k*mDot(k, v)*(1 - mCos(theta)); //Rodrigues Formula, Important! vRot += vec1; //add vec1 back to vRot The above code produces the blue vertices in the image, or "testgroup4".   I am capable of performing the rotation, by any angle, however the issue is that the point of rotation for each of the testgroups is the "local" origin, ie, the center position of the purple vertices. Rotating around this origin gives me THIS result. What I believe I need to do is to translate the nodes to the world space center of the planet, rotate them there, and then translate back. This is what I was trying to do in the above code, but it didn't seem to work. I realise I am not explaining this very well, but can anyone offer any advice? To summarise, I am trying to change the point around which rotation occurs when using Rodriques' rotation formula.  
  3. PhoenixGames

    Moving a point around a Sphere

    Thank you very much for your help, I seem to have rotation working now! I did exactly what you said, I didn't need to convert to spherical coordinates at all, or add the 1.  The only issue that I have now is that that rotation doesn't seem to be solving the problem that I was having. I'm not sure if I should post a new topic or not, but what I am really trying to do, at a high level, is implement a floating-origin type system for a spherical terrain implementation. The terrain is basically working, as the player moves, the terrain is paged in and out.  However, what I now need to do is reset the player and the currently rendering terrain nodes back to the origin when the player exceeds a certain distance. Moving the player and other objects is simple, I just move them back by changing their transform, so move them 10,000 meters on the x axis, for example. The problem is that doing this with the nodes on the spherical terrain doesn't work. The x position is correct, the y position seems correct too, but the z position is above where it should be, and every time the player moves, the terrain moves further and further up the z axis. All I am doing is moving the terrain on the x axis, so I am not sure why it's not aligned correctly on Z. I assumed the issue was caused by the curvature of the terrain itself, but I am not so sure now.  What I need to do, really, is take a series of points and move them along a sphere of known radius along a vector. Is what I am doing the correct way to do this?
  4. PhoenixGames

    Moving a point around a Sphere

    Ahh, I see, it would certainly make things a lot easier if I could stick to the same coordinate system throughout the process. I'll try it with the cartesian coordinates, and see what happens, thanks!   The adding 1 was more of an experiment which seemed to work, I can remove it.
  5. PhoenixGames

    Moving a point around a Sphere

    Hi, Thanks for your reply. I was under the impression that in order to rotate on a sphere (IE, for the point to be rotated along the curve of the sphere, to another point on the same sphere) I needed to convert to spherical coordinates? I am adding 1 because the conversion to spherical coordinates didnt seem to work at all when the cartesian coordinate were in their initial range of -1 to +1. I intended to subtract it before converting back to cartesian. So, vRot *IS* the actual rotated point then, I don't need to apply it to anything? I will try that, thank you!
  6. PhoenixGames

    Moving a point around a Sphere

    Hello,   I am currently working on a problem which I can't seem to solve.   I am trying to move a set of point around a sphere by a certain angle (or, preferably, by a distance, but most of the math examples I have found use angles).   What I am currently doing is as follows: Convert the set of points from Cartesian (XYZ) coordinates to Spherical Coordinates, Use Rodrigues Rotation formula to get "vRot", the rotation vector, Multiply vRot with the original Spherical coordinates to get the new position.   According to Gnuplot, I can successfully convert the points to Spherical Coordinates, but I am having problems with the next two steps. The equation for Rodrigues formula that I am using is this one:   Which I got from here:   http://stackoverflow.com/questions/26453951/rotateing-vector-on-plane-in-3d This is the relevant section of code:   F32 x = renderlist[i].point.x; F32 y = renderlist[i].point.y; F32 z = renderlist[i].point.z; //Values are between -1 and +1, this ensures all values are positive, since negative values seem to cause issues: F32 xscaled = x+1; F32 yscaled = y+1; F32 zscaled = z+1; //convert to spherical coordinates: F32 radialdistance_r = sqrt(xscaled*xscaled + yscaled*yscaled + zscaled*zscaled); F32 polarangle_theta = mAcos(zscaled / radialdistance_r);//0-PI F32 azimuthalangle_phi = mAtan2(yscaled, xscaled); //0-2PI //Using Rodrigues rotation forumula, as given here: //http://stackoverflow.com/questions/26453951/rotateing-vector-on-plane-in-3d Point3F v = Point3F(radialdistance_r, polarangle_theta, azimuthalangle_phi); Point3F k = Point3F(0, 1, 0); //rotate on y axix F32 theta = 0.0174533;// rotate by 1 degree only for now Point3F vRot = v*mCos(theta) + mCross(k, v)*mSin(theta) + k*mDot(k, v)*(1 - mCos(theta)); Point3F newpos = v * vRot; Con::printf("%f %f %f", newpos.x, newpos.y, newpos.z); Is there anything obviously wrong here? Thanks!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!