Jump to content
  • Advertisement
Sign in to follow this  
markypooch

Platform On A Pedastle Rotation

This topic is 729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Guys,

 

While I find myself pretty versed in basic rendering concepts, and having picked up a little bit of vector, and matrice algebra in my studies, I still find my Mathematics skills haven't completely caught up.

 

So I have a few questions for something I wanted to implement. Say I have a platform sitting atop a invisible pedastle over something hazardous (Say lava). And depending on where players stand on this platform affects the tilting, or rotation of said platform. Would my thought process I have in place (Haven't coded it yet) be on par, or in need of total revision, or a little of both?

 

Say the diameter of my platform is 10 (It's a cylinder). Making the radius 5. If I took the players position relative to the distance of the center of the cylinder (Them both being in world space), and normalized it, than used it for a scalar for the axis of rotation would it work well? 

normalization

playerPositionX -= cylinderTopCenter

playerPositionX = (positionX + (-5.0f)) / (5.0f+(-5.0f)) //Diameter is 10

xRotation = 0.8 * playerPositionX   //Use the normalized value as a scalar for the max 
                                    //rotation on any given axis, say, in radians, 0.8

Rinse, and repeat for the Y Axis.

 

I'm pretty sure this should work, and I feel this is pretty simple. But, I could be very much off track as well. Let me know what you guys think.

 

Thanks!

 

Marcus Hansen

Share this post


Link to post
Share on other sites
Advertisement

Not entirely sure what you want to achieve, do you want the platform to lean over as the player reaches the edge as though they are balancing? For example, if the player is in the centre then there is no tilt, if they are at the north edge then the platform tilts downwards to the north side? I'm not sure if what you suggest will do that.

 

Do you have access to some kind of axis-angle rotation? If so then this should be relatively easy. First get a vector from the centre of the platform to the player:

dir = player.pos - platform.pos;
//You're going to need it normalised so get the length and also check it isn't 0 (if it is you don't need to do anything)
length = dir.length();
if(length == 0)
   return;
dir /= length;
// Also, the centre of the player might be above the centre of the platform depending how you define things
// So you should check that too
if(DotProduct(dir, up) == 0)
   return;
// Now you can find your axis of rotation which is just a vector at right angle to your direction
// You can get that with a cross product
axis = CrossProduct(dir, up); // Might have to swap dir/up around
// Now you just need to decide how much of an angle to rotate by
// You could use the length and the platform radius to decide it, tilting maximum as the length reaches radius
angle = length*maxAngle/radius;

How you actually turn that axis-angle into your desired rotation will depend on what you are using. Is it only euler angles you have access too?

Edited by Nanoha

Share this post


Link to post
Share on other sites

Your right on the Money! I did some follow up notebook paper math, and if my memory/skill serves me, this will work perfectly.

The axis would be a vector from my players up vector, and his current direction (As gauged by his position in the world, relative/subtracted by the center of the "platform").

 

length would scale my maximum allowable angle, and be divided by the radius.

 

 

Is it only euler angles you have access too?

 

It's what i'm using due to familiarity. (I had to google what you meant tbh, to realize you were referring to what I refer to as (perhaps incorrectly) 3d Cartesian rotation) What would be the other option quaternions?

 

Not trying to sound like a layman. It's been awhile since I have done anything outside of subnet math. Heck, my vector algebra may be slipping again :P

 

Marcus Hansen

Share this post


Link to post
Share on other sites

Quaternions would certainly be an option but so would matrices, as long as they have the option to be built from axis-angle. I only ask as you might be using a maths lib which would offer a lot of this stuff or if you are doing your own thing. Having only x/y/z angles are great from an intuitive point of view (something a designer would like to use) but not so much for actually doing math with. 

 

It really depends how you are passing all this stuff on when it gets rendered, presumably you are building a transform matrix from it all? In that case you can happily build a rotation matrix from and axis and an angle.

 

I did some more searching on Euler angles/Cartesian etc and I just ended up more confused myself.

Edited by Nanoha

Share this post


Link to post
Share on other sites

I'm using D3D11 for the Rendering API, and more relevant the DirectXMath header. Which i'm almost certain provides the helper functions for building, and manipulating quaternions for the sake of rotations.

 

 

presumably you are building a transform matrix from it all?

 

Yep, I have a simple setup so far. WorldMatrix is passed directly to the shader (simplifies for me at least a lot of calculations that require a worldspace transformation without having to undo a cpu side concatenation) and the view, and projection matrix I concatenate together, and send in separately.

 

I knew of quaternions, however, only in the realm of skeletal animation as using very little space, and being very efficient. The only reason I've never used them is due to me finding other means of mesh animation (vertex interpolation), and just not ever tackling them. But, i'll change that. Once I get the euler angle version working, i'll tackle the quanternion version.

 

Marcus Hansen

Share this post


Link to post
Share on other sites

I think this is easier to solve using quaternions than it is with 3 separate angles.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!