<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Realistic ball rotation</title>
<description> Hi, I&amp;#039;m trying to rotate a sphere according to the direction in which it moves (x, z), but I can not work properly, I have implemented the physics, but i am unable to make the sphere rotate well XD.

I tried this:

Mtx mX, mY, mZ;
Vector axisX = (1.0, 0.0, 0.0);
Vector axisY = (0.0, 1.0, 0.0);
Vector axisZ = (0.0, 0.0, 1.0);

......
...
guMtxIdentity ....

guMtxRotAxisDeg (mX, &amp; axisX, ball.z);
guMtxRotAxisDeg (mY, &amp; axisY, 0);
guMtxRotAxisDeg (mZ, &amp; axisZ, ball.x);
....
..
But this does not work, because if you rotate on the x axis for example, the z axis going berserk .....
Then I tried with this:

Mtx mR;
Vector axis = (ball.z, 0.0,-ball.x);

where ball.x + = acelx and ball.z + = acelz;

guMtxRotAxisDeg (mR, &amp; axis, ball.z + ball.x);


This works better but is doing weird things: (.
Does anyone have any idea on how to calculate angle of rotation?

Thanks! :)</description><link>http://forum.wiibrew.org/read.php?11,49125,49125#msg-49125</link><lastBuildDate>Mon, 10 Aug 2026 13:20:19 +0200</lastBuildDate>
<generator>Phorum 5.2.23</generator>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49574#msg-49574</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49574#msg-49574</link><description><![CDATA[ XD Ok, I&#039;ll try to do that, he, he, he, I never thought that would be so difficult to rotate a ball XDD]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Thu, 18 Feb 2010 18:11:32 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49568#msg-49568</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49568#msg-49568</link><description><![CDATA[ hmmm...let me think...Ok, I know what happens (I think)<br />The effect of gravity on a rigid body can be represented as an acceleration applied to the center of mass of the body. So we should store in a vector the position of the sphere and in another vector it&#039;s current speed. Every frame we should add the acceleration components (obtained from the wiimote) to the speed of the ball, then use the new speed to compute both the new position and the angular velocity (our rotation variable). All the problems related to inertia etc are likely to be due to the fact that we&#039;re using gravity acceleration as a velocity instead of a force. change that and the simulation will should be physically (and numerically) correct assuming the units are correct. One more thing, the factor to multiply the rotation by should be one over the radius.<br /><br />PD: I&#039;m sure that if we had a paper to write a couple of equations and draw a few things this problem would have been solved in 5 minutes instead of days...xD<br /><br />PD: Congratulations for those cool 3D grafics ;)]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Thu, 18 Feb 2010 15:29:00 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49520#msg-49520</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49520#msg-49520</link><description><![CDATA[ :) Ok, the sphere radius is 2 (in pixels), anyway in video 1 when I change the angle of the wiimote, the rotation changes the direccicion immediately, not gradually as the direction of the ball, or what is the same, the ball has an inertia, against the faster it goes, more difficult to reverse its direction, but whith "rotation = sqrt (...);" the direction of rotation is reversed very quickly. XD]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Wed, 17 Feb 2010 19:12:46 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49502#msg-49502</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49502#msg-49502</link><description><![CDATA[ Ok, you have to use Radians, not degrees, since we&#039;re computing angles from displacement. I had forgotten that rotation speed is also dependent on radius, wich explains why you have to multiply by 20. What is the radius of you sphere?<br />As you can see, when using += sqrt(...) instead of = sqrt(...) there are some weird rotations, so obviously the first option is the correct.]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Wed, 17 Feb 2010 16:16:13 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49439#msg-49439</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49439#msg-49439</link><description><![CDATA[ Ok, then would have to put it that way, does it?<br /><br />guMtxIdentity(ballMtx);<br /><br />guMtxRotAxisRad(Mt_1, &rotationDir, rotation);<br />guMtxTransApply(ballMtx, ballMtx, -x, -y, -z);<br />guMtxConcat(ballMtx, Mt_1, ballMtx);<br /><br />//Here you update x, y, z to their new values and:<br />guMtxTransApply(ballMtx,, ballMtx, x, y, z);<br />guMtxCopy(ballMtx, model);<br /><br />guMtxConcat(view, model, mv);<br />GX_LoadPosMtxImm(mv, GX_PNMTX0);<br /><br />guMtxInverse(mv, mvi);<br />guMtxTranspose(mvi, mv);<br /><br />Anyway, I think there is a problem with my code, because when I set rotation = sqrt (...), the ball does not move, or moves very slowly, I have to, for example, rotation * 800, in guMtxRotAxisDeg, or * 20 on guMtxRotAxisRad, to move ...... I&#039;ll explain better with a video XD:<br /><br />if I put:<br />rotation = sqrt (...);<br />guMtxRotAxisDeg (Mt_1, & rotationDir, rotation * 800); or guMtxRotAxisRad (Mt_1, & rotationDir, rotation * 20)<br /><br />this is what happens: [<a href="http://www.youtube.com/watch?v=WplatvssKkI" rel="nofollow">www.youtube.com</a>]<br /><br /><br />if I put:<br />rotation + = sqrt (...);<br />guMtxRotAxisDeg (Mt_1, & rotationDir, rotation * 20);<br /><br />this is what happens: [<a href="http://www.youtube.com/watch?v=4PM_0gr0Q-U" rel="nofollow">www.youtube.com</a>]]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Tue, 16 Feb 2010 17:45:10 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49424#msg-49424</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49424#msg-49424</link><description><![CDATA[ Ok, this is what you have to do:<br />You must have a matrix that is specific to your ball. You don&#039;t use it for other objects, for example<br />Mtx ballMtx; You have to do guMtxIdentity(ballMtx) just once, when you create the ball, for example. Don&#039;t do it every frame cause it wouldn&#039;t work.<br />then, every frame, BEFORE updating x, y and z variables, you do this<br /><br />guMtxRotAxisRad(Mt_1, &rotationDir, rotation);<br />guMtxTransApply(ballMtx, ballMtx, -x, -y, -z);<br />guMtxConcat(ballMtx, Mt_1, ballMtx);<br /><br />//Here you update x, y, z to their new values and:<br />guMtxTransApply(ballMtx,, ballMtx, x, y, z);<br />guMtxCopy(ballMtx, model);<br /><br />those lines must replace these ones:<br /><br />guMtxRotAxisRad (Mt_1, &rotationDir, rotation*20);<br />guMtxRotAxisDeg(Mt_2, &rotationDir, rotation*20);<br />guMtxConcat(Mt_1, Mt_2, model);<br />guMtxTransApply(model, model, x, y, z);<br /><br />and rotation must equal the square root, not add it. rotation = sqrt(...) instead of rotation += sqrt(...)<br />Because it&#039;s not an angle, it&#039;s an angular speed. and the addition is done in the concat operation.<br />I think that&#039;s all. remember that x, y and z must keep their old values for the first guMtxTransApply, ok?<br /><br />I think that will work]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Tue, 16 Feb 2010 13:06:56 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49370#msg-49370</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49370#msg-49370</link><description><![CDATA[ Ok, it´s true, sorry, to draw the ball i use this:<br /><br />The main mtrix to render the ball and the rest of the scenary is "view"<br />This is how I have it now:<br /><br /><br />Vector dir={-ball.acelx,0,-ball.acelz};<br />Vector normal={0,1,0};<br />Vector rotationDir;<br />guVecCross( &dir, &normal, &rotationDir);<br />rotation +=sqrt(( ball.acelz * ball.acelz + ball.acelx * ball.acelx));<br /><br />guMtxIdentity(model);<br /><br />guMtxRotAxisRad (Mt_1, &rotationDir, rotation*20);<br />guMtxRotAxisDeg(Mt_2, &rotationDir, rotation*20);<br />guMtxConcat(Mt_1, Mt_2, model);<br /><br />guMtxTransApply(model, model, x, y, z);<br />guMtxConcat(view, model, mv);<br />GX_LoadPosMtxImm(mv, GX_PNMTX0);<br /><br />guMtxInverse(mv, mvi);<br />guMtxTranspose(mvi, mv);<br />GX_LoadNrmMtxImm(mv, GX_PNMTX0);<br /><br />GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 960);<br /><br />// draw the ball polygons//<br /><br />I think that&#039;s all :)]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Tue, 16 Feb 2010 01:16:38 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49337#msg-49337</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49337#msg-49337</link><description><![CDATA[ No, it&#039;s not correct, I need a little bit more of information to help you.<br />Which matrix do you use to render your ball, how do you calculate it? and how do you handle position? is it stored as a separated vector or in the same matrix?, do you apply it after rotating?<br /><br />those questions are important because this method is somehow recurrent, it produces correct results when aplied ona alredy correct state.<br /><br />We&#039;re so near to fix this problem, don&#039;t worry.]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Mon, 15 Feb 2010 20:45:38 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49329#msg-49329</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49329#msg-49329</link><description><![CDATA[ I can`t fix the little mistakes of rotation : (, I applied guMtxRotAxisRad in one of the matrix, and I have concatenated, but does not work, probably because I&#039;ve done wrong XD<br /><br />guMtxIdentity (model);<br /><br />guMtxRotAxisDeg (Mt_1, & dir, rotation);<br />guMtxRotAxisRad (Mt_2, & dir, rotation);<br />guMtxConcat (Mt_1, Mt_2, model);<br /><br />Is this correct?]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Mon, 15 Feb 2010 18:37:01 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49326#msg-49326</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49326#msg-49326</link><description><![CDATA[ Ok, just remember that vector will work fine as long as your floor doesn&#039;t get completely vertical.]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Mon, 15 Feb 2010 16:06:57 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49263#msg-49263</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49263#msg-49263</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong></strong><br />By the way, how do you calculate the normal vector?</div></blockquote><br />I have put only Vector normal={0,1,0} (?)]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Sun, 14 Feb 2010 19:43:33 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49259#msg-49259</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49259#msg-49259</link><description><![CDATA[ oh, right, I think I know how to fix that rotation. Intead of applying the guMtxRotAxisRad to your matrix, you have to apply it to a different matrix and then concat those two matrices. Applying directly to your matrix will set your model&#039;s rotation to the rotation angle. Instead, applying to another matrix and concatenating them will ADD the rotation to the old position.<br /><br />There&#039;s something else you have to take into account: if your old matrix is not set to the origin when applying rotations, results will be weird so the steps would be:<br /><br />-Set model matrix to origin (translating functions)<br />-Concat matrices<br />-Set model matrix to the ball&#039;s position again.<br /><br />By the way, how do you calculate the normal vector?]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Sun, 14 Feb 2010 19:19:16 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49256#msg-49256</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49256#msg-49256</link><description><![CDATA[ It&#039;s perfect !! :D, but something must be wrong with my code, because when put<br />sqrt (ball.accelx * ball.accelx + ball.accely * ball.accely),<br /><br />the ball does not rotate, perhaps my acceleration Equation is wrong. ....<br />if I put for example, rotation + = sqrt (ball.accelx * ball.accelx + ball.accely * ball.accely) * 20, the ball rotates fine, but when changing direction, the angles are reversed, and the effect is slightly rare, but it works.<br /><br />I think maybe I&#039;m not using either the acceleration, to create the acceleration I do this:<br /><br />ball.acelx + = sinf ((wiimote0-&gt; orient.pitch) * (2 * 3.1416/360)) * ball.gravity;<br />ball.acelz + = sinf ((wiimote0-&gt; orient.roll) * (2 * 3.1416/360)) * ball.gravity;<br /><br />ball.x + = ball.acelx;<br />ball.z + = ball.acelz;<br />...<br />..<br />In my game, the ball moves according to the inclination of the ground, so I use the gravity XD, to move the command the ground moves as the angle XD<br /><br />Saludos! XD]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Sun, 14 Feb 2010 17:50:17 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49192#msg-49192</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49192#msg-49192</link><description><![CDATA[ Ok, my fault because I didn&#039;t look the function names in libogc.<br />I&#039;ll try to explain:<br />first: Create a vector containing moving direction of your ball.<br />guVector moveDir = {ball.accelx, 0, ball.accely};<br /><br />second: calculate the vector that is normal to the surface tha ball is moving along.<br />I assume the sphere is moving through X and Z axes in a plane surface.<br />guVector planeNormal = {0, 1, 0}<br /><br />third: Calculate the rotation vector<br />guVector rotationDir;<br />guVecCross( &moveDir, &planeNormal, &rotationDir);<br /><br />fourth: Calculate the rotation amount<br />f32 rotation = sqrt( ball.accelx * ball.accelx + ball.accely * ball.accely);<br /><br />fifth: Actually rotate it<br />guMtxRotAxisDeg (mR, &rotationDir, rotation);<br /><br />That should work fine (assuming I didn&#039;t make mistakes). It&#039;s all about Newton&#039;s mechanics. It&#039;s like a wheel in a bike: the axis of rotation (the axis of the wheel) is alwais perpendicular to the move direction (the wheel direction).<br /><br />Tell me about any doubt or things i may have missed.]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Sat, 13 Feb 2010 21:20:50 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49174#msg-49174</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49174#msg-49174</link><description><![CDATA[ Hi Technik , I do not find that function, maybe it guVecCross ()?. anyway I have not understood how to do what you say XD sorry, could you give me more details?.<br /><br />for the direction of the ball I use<br />ball.x + = ball.acelx;<br />ball.z + = ball.acely;<br /><br />acelx and acelz depend on the angle of the wiimote and gravity, perhaps there is the error.<br /><br />I added Daid classes, to use quaternions, but the result is the same, the axis going berserk (?), Maybe I do something wrong.<br /><br />TQuat br;<br />br *= TQuat (TVector (ball.acelx, 0, ball.acelz), (ball.acelz + ball.acelx) / 2);<br />Vector axis = (br.Z, br.Y,-br.X);<br /><br />in the the model transformation :<br />......<br />..<br />guMtxRotAxisDeg (ry, & axis, acosf (br.W) * 360.0f / M_PI);<br />....<br />..<br />but does´t work.]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Sat, 13 Feb 2010 15:56:46 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49166#msg-49166</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49166#msg-49166</link><description><![CDATA[ Actually there&#039;s a simple way to do it physically correct. You just have to calculate a vector that is parallel (is that the correct spelling?) to the displacement plane and perpendicular to the rotation direction. Then rotate around it an angle alpha equal to displacement over radius.<br />for example if the sphere is on a horizontal floor and moving in the direction (1, 0, 0), the vector (the axis of rotation) would be (0, 1, 0). You can calculate these perpendicular vectors using guVecCrossProduct(); Axis = moveDir X surfaceNormal<br />Then rotation would be calculated as rotation = moveDistance/ballRadius<br /><br />You would do guMtxRotAxisRad(mR, &Axis, rotation);<br /><br />It&#039;s quite fast to compute, conceptually easy, flexible and just a few lines of code. Moreover, it&#039;s perfectly physically correct.<br /><br />Hope that helps]]></description>
<dc:creator>technik</dc:creator>
<category>Coding</category><pubDate>Sat, 13 Feb 2010 11:39:04 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49150#msg-49150</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49150#msg-49150</link><description><![CDATA[ :D Thanks for the classes Daid, i try to use it in my project, wow, if that is difficult to rotate a simple ball XD<br /><br />Thanks!]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Sat, 13 Feb 2010 02:50:44 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49128#msg-49128</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49128#msg-49128</link><description><![CDATA[ I think what you are describing is a common Euler angle problem called "Gimbal Lock".<br /><br />[<a href="http://en.wikipedia.org/wiki/Gimbal_lock" rel="nofollow">en.wikipedia.org</a>]<br /><br />If you use a Quaternions based system to rotate objects, you will have better luck.<br /><br />EDIT: Doh... All I hear is "You&#039;re too slow!" in my ears...]]></description>
<dc:creator>Ksmiler</dc:creator>
<category>Coding</category><pubDate>Fri, 12 Feb 2010 16:19:42 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49127#msg-49127</guid>
<title>Re: Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49127#msg-49127</link><description><![CDATA[ Looks like you&#039;re using x/z like yaw/pitch? That will never work right, even if you solve most problems you&#039;ll still run into Gimbal lock at some point: [<a href="http://en.wikipedia.org/wiki/Gimbal_lock" rel="nofollow">en.wikipedia.org</a>]<br />And you&#039;ll create lots of hard math.<br /><br />One way to solve this is with quaternions. Which is some heavy duty math if you google it. But it&#039;s not that hard to use, once you have the code ;)<br />You can use the following classes I created some time ago: [<a href="http://daid.mine.nu/pub/quaternion.zip" rel="nofollow">daid.mine.nu</a>]<br /><pre class="bbcode">TQuat ballRotation;

... in you main loop...
ball.x + = acelx;
ball.z + = acelz;
ballRotation *= TQuat(TVector(acelx, 0, acelz), ballRadius);</pre>You need to tweak the ballRadius, and the acelx, 0, acelz might be in the wrong order.<br /><br />I&#039;m not sure how to modify the guMtx with the final TQuat, but in openGL this works: glRotatef(acosf(Quat.W) * 360.0f / PI, Quat.Z, Quat.Y, Quat.X);]]></description>
<dc:creator>Daid</dc:creator>
<category>Coding</category><pubDate>Fri, 12 Feb 2010 16:19:17 +0100</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,49125,49125#msg-49125</guid>
<title>Realistic ball rotation</title><link>http://forum.wiibrew.org/read.php?11,49125,49125#msg-49125</link><description><![CDATA[ Hi, I&#039;m trying to rotate a sphere according to the direction in which it moves (x, z), but I can not work properly, I have implemented the physics, but i am unable to make the sphere rotate well XD.<br /><br />I tried this:<br /><br />Mtx mX, mY, mZ;<br />Vector axisX = (1.0, 0.0, 0.0);<br />Vector axisY = (0.0, 1.0, 0.0);<br />Vector axisZ = (0.0, 0.0, 1.0);<br /><br />......<br />...<br />guMtxIdentity ....<br /><br />guMtxRotAxisDeg (mX, & axisX, ball.z);<br />guMtxRotAxisDeg (mY, & axisY, 0);<br />guMtxRotAxisDeg (mZ, & axisZ, ball.x);<br />....<br />..<br />But this does not work, because if you rotate on the x axis for example, the z axis going berserk .....<br />Then I tried with this:<br /><br />Mtx mR;<br />Vector axis = (ball.z, 0.0,-ball.x);<br /><br />where ball.x + = acelx and ball.z + = acelz;<br /><br />guMtxRotAxisDeg (mR, & axis, ball.z + ball.x);<br /><br /><br />This works better but is doing weird things: (.<br />Does anyone have any idea on how to calculate angle of rotation?<br /><br />Thanks! :)]]></description>
<dc:creator>copete23</dc:creator>
<category>Coding</category><pubDate>Fri, 12 Feb 2010 15:25:32 +0100</pubDate></item>
</channel>
</rss>