Sign in to follow this  

Question about ball physical movement

This topic is 4301 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

I am doing a demo to show ball physical movement, i created a plane, and one ball on it, I use keyboard control the plane rotate about x or z axis, and the ball will rotate to the lower side, then how to do the physical movement of this ball, rotate according to the angle of rotate? any hints or sample source code to show the ball movement? Thanks a lot, I am still got problem to deal with the control, how to make a plane rotate about Z, mine one only can rotate about X, and the movement about Z is not that one I want!! Really thanks!!

Share this post


Link to post
Share on other sites
Here are some first ideas how to deal with the problem:

It is assumable that the geometrical center of the ball denotes the center of gravity (COG). The gravity introduces a force on the ball accelerating it towards the ground (more or less). At the contact point the ground reacts so that the ball doesn't sink into the ground.

Now, if the ground becomes tilted, the COG will not be exactly located above the contact point, so that the resulting force from gravity and ground reaction lets the ball "fall" in direction of the lower ground level.

The resulting force will have a component parallel to the ground. This component will be greater for greater angles if tilting, and it accelerates the ball's COG. The current velocity is to be used to compute the way the ball rolls, and that could be used to compute the rotation angle, too.

I assume a simple way to compute the contact point is by resting the ball in a ground local co-ordinate frame first, and then computing the location in the global frame, since the contact point will always be orthogonal below the COG in a ground local frame (as long as the ball doesn't actually fall).

You have to consider moment of intertia, of course, to make the ball not suddenly change direction as soon as the ground becomes tilted another way.

Share this post


Link to post
Share on other sites
Quote:
Original post by koalacui
I am still got problem to deal with the control, how to make a plane rotate about Z, mine one only can rotate about X, and the movement about Z is not that one I want!! Really thanks!!

Give the plane an own co-ordinate frame (i.e. location and orientation of the frame in the global "world" space) and multiply the orientation matrix with "small delta" rotation matrices as long as the belonging keys are pressed (and the angle limitations are not reached). Use the x axis rotation matrix e.g. for left/right keys and the z axis rotation matrix for e.g. up/down keys.

Alternatively increment/decrement the key belonging angle and compute the orientation matrix directly as the product of the both current angles. Perhaps this way matches the limitation of the ground tilting better.

Share this post


Link to post
Share on other sites
When tilting the ground interactively IMHO the user would have best impression of what happens if the rotation doesn't occur around global axes but local ones. I.e. don't use (sorry jollyjeffers, but here comes the Direct3D stuff ;) D3DXMatrixRotationX or D3DXMatrixRotationYawPitchRoll but D3DXMatrixRotationAxis instead.

Think of a cartesian co-ordinate frame of the ground, where 2 axes (say x and z) lie inside the ground, and the 3rd (say y) is perpendicular to the ground. Now, the one key pair (say a and d) should tilt the ground around the x axis, while the other pair (say w and s) should rotate around the z axis. But after performing the initial rotation, IMHO the user expects the next rotation to occur around the already rotated axes.

So my suggestion is to track the orientation state of the ground by a rotation matrix, to use two of the basis vectors of that matrix as rotation pivots for D3DXMatrixRotationAxis with frame time proportional angles, and to multiply the state matrix with that rotation. (Notice that this method will require to re-ortonormalize the state matrix from time to time, of course.)

You should compute the rotation always locally. However, if you think of following the ball with camera, you should try to use a "wandering" rotation origin.

As an extension to the above, you may take into account to also rotate around y. This may be suitable as soon as the user is able to change the camera heading. In such case IMHO the ground rotation pivots should change, too. IMHO the one key pair should always operate on a pivot along the viewing direction, and the other one perpendicular to the viewing direction.


Btw: A mouse based control, on the other hand, allows to choose a single axis pivot, instead of simulating a pivot by rotating around two axes. It furthur allows to drop a time based angle changed but to use a motion based angle.

Share this post


Link to post
Share on other sites

This topic is 4301 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this