Vectorg 104 Report post Posted July 19, 2005 Does anyone know a way to combine two rotation matrices that are based upon different control axis? To control the orientation of a flying object, such as an airplane, I use a rotation matrix for the control surfaces such as elevator and rudder, and another rotation matrix for gravity. Because, no matter what attitude the plane is in, I want gravity to pull the nose straight toward the ground. Concatenating these two matrices doesn't seem to work. Can someone tell me how this is done? Does anyone know what I'm talking about? Thanks. 1 Share this post Link to post Share on other sites
Ysaneya 1383 Report post Posted July 19, 2005 What do you mean by "doesn't seem to work" ?One thing you can try is to convert your two matrices to two quaternions, do a slerp between these, and convert back to a matrix. It might behave better.Y. 1 Share this post Link to post Share on other sites
Toji 535 Report post Posted July 19, 2005 Well, the big thing to keep in mind is that when dealing with Matricies the order of operations is very VERY important. Rotating on X and then Rotating on Y will give very different results than doing the reverse. It's hard to say the exact order that you should go in, but I would suggest simply toying around with it. Swap the matrix order around and see what you get.Now, I have a question: Why are you storing gravity as a rotation matrix? A simple translation along the gravity vector should do the trick (as long as it's in the right place in the transformation chain) 0 Share this post Link to post Share on other sites
swordfish 276 Report post Posted July 19, 2005 I agree. Use quaternions in the process, but not exclusively unless you want headaches. My camera class use a matrix to store rotations. When I want to pitch/yaw/roll the camera, I convert the matrix to a quaternion, perform the rotation, and convert the quaternion back to matrix.Toji, Vectorg isn't talking about gravity pulling the entire plane downward, he's talking about pulling nose of the plane downward, ie, pitching the entire plane forward. 0 Share this post Link to post Share on other sites
Vectorg 104 Report post Posted July 19, 2005 Thanks for the help.By "doesn't seem to work", I mean that it definitely doesn't work, but maybe I'm just doing it wrong.Here's an example of what should happen. The airplane is flying level, but banked (rolled) at a 45* angle. Gravity will pitch the nose downward toward the ground, but not at a 45* angle.Gravity is causing rotation on an axis different than any of the plane's 3 defined axis, and different than the x,y,z axis defined in the plane's rotation matrix. How can I apply these off-axis rotations to the matrix?Is this what quaternions can do? I have read about, but not used them. How are they different? Where should I start?Thanks. 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted July 19, 2005 Quote:Gravity is causing rotation on an axis different than any of the plane's 3 defined axis, and different than the x,y,z axis defined in the plane's rotation matrix. How can I apply these off-axis rotations to the matrix?Is this what quaternions can do? I have read about, but not used them. How are they different? Where should I start?Short answer on quaternions: forget about them for now. You can do just about anything with a matrix that you can do with a quaternion. Quaternions do have some advantages, but if you introduce quaternions without fully understanding what those advantages are (and, more importantly, are not), you'll just be confusing the issue. All IMHO, but my advice is to just stick with matrices for now.As for your specific question, I don't know how your airplane orientation matrix is set up, but I think the problem you describe will be easiest to solve if you avoid Euler angles (more specifically, avoid constructing your matrix from scratch each frame from an Euler angle triple).Let's say your airplane matrix is maintained from frame to frame using relative rotations about the local axes. Then, to pull the nose toward the ground plane, you need to apply one more axis-angle rotation. I'm just guessing at this point (because I really don't know anything about how airplanes actually behave), but I believe the axis for this rotation should have the properties that a) it lies in the ground plane, and b) it is perpendicular to the airplane's forward vector. You should be able to find such a vector as the normalized cross-product of the plane's forward vector and the world up vector. The angle to rotate is then the angle between the forward vector and the ground plane. Presumably, you will only apply some fraction of this angle so as to drop the nose gradually.That was a little vague - let me know if you'd like a more concrete example. 0 Share this post Link to post Share on other sites
Vectorg 104 Report post Posted July 20, 2005 thanks jyk,Quote:Let's say your airplane matrix is maintained from frame to frame using relative rotations about the local axes.Yes, that's what I'm doing.Quote:Then, to pull the nose toward the ground plane, you need to apply one more axis-angle rotation. I'm just guessing at this point (because I really don't know anything about how airplanes actually behave), but I believe the axis for this rotation should have the properties that a) it lies in the ground plane, and b) it is perpendicular to the airplane's forward vector. You should be able to find such a vector as the normalized cross-product of the plane's forward vector and the world up vector. The angle to rotate is then the angle between the forward vector and the ground plane. Presumably, you will only apply some fraction of this angle so as to drop the nose gradually.I can picture exactly what you're saying, and I will try it. Yes, the nose will drop gradually and I will do that by subtracting a constant (gravity) from the 'y' value of this 4th vector, then normalize.But, because this 4th vector will require its own matrix, I have just used 2 distinct rotation matrices to get the plane into its orientation. How do I then combine these into just one matrix that can be carried to the next frame? --This is the part I don't know how to do.--Any ideas?Thanks. 0 Share this post Link to post Share on other sites
relsoft 255 Report post Posted July 20, 2005 I would suggest you do what jyk was saying. Now let's say you have an orientation of the airplane based on 3 orthogonal axis. An you said you have a roll of 45. You can orient your 3 axes so that the right vector is perpendicular to the vector at 45 degrees (your up) and rotate your nose-point around that vector(axis) using the axis-angle representation of rotation.Unless you represent your rotations with euler angles, I suggest you don't use quats.Oh on second thought. You said gravity will pitch the nose down after a 45 degree roll.Would this work? 1. Rotate your up(0,1,0) vector 45 degrees2. Rotate on that vector n degrees. 0 Share this post Link to post Share on other sites
Ysaneya 1383 Report post Posted July 20, 2005 I must say, i still do not understand what's this "gravity matrix". Gravity is a force that is applied to the center of mass of a rigid body - it does not induce rotations. Can you explain what's your logic behind this ?Y. 0 Share this post Link to post Share on other sites
swordfish 276 Report post Posted July 20, 2005 Yea the gravity stuff is kinda confusing. I'm not 100% on the physics and whatnot, but I'm visualizing the airplane like a stick with a weight at only one end (where the nose of the airplane would be). If you throw that stick into the air, the weighted end will be pulled downwards rotating the entire mass. 0 Share this post Link to post Share on other sites
Monder 993 Report post Posted July 20, 2005 Gravity acts equally on all points regardless of mass with your weight on a stick example there would be no rotation there would also be no rotation for your airplane (caused by gravity anyway). 0 Share this post Link to post Share on other sites
Vectorg 104 Report post Posted July 20, 2005 I'm trying to construct a simple flight dynamics model.Here are the physics I'm applying:Most airplanes are designed so that they will fly straight and level by applying a slight amount of elevator (upward pitch), to offset gravity's desire to pull the nose downward. This pitching is simply due to the presence of air, and would not occur in the vacuum of space.So... when the plane banks left or right, it also turns left or right, because the upward pitch vector is no longer directly opposing the gravity vector.Without a gravity vector, a bank will not result in a turn.I hope this makes it more clear why I need a gravity vector.Quote:You can orient your 3 axes so that the right vector is perpendicular to the vector at 45 degrees (your up) and rotate your nose-point around that vector(axis) using the axis-angle representation of rotation.I'm using a simple 3x3 rotation matrix as per an article by Diana Gruber. What is the "axis-angle representation of rotation?"Thanks again for the help. 0 Share this post Link to post Share on other sites
Vectorg 104 Report post Posted July 20, 2005 I was out watering my lawn and thought of a new way to pose this question.How do I apply a world-space transform to an object-space rotation matrix?I know how to apply a transform to a vertex, but can the transform be done to a 3x3 matrix?Thanks. 0 Share this post Link to post Share on other sites
relsoft 255 Report post Posted July 21, 2005 vectorg:With axis angle, you specify an axis(vector) and an angle. Now with that, the matrix created is a rotation matrix on an arbitrary vector in n-angles.Here's a little demo:Download collide.zipYou can use 3x3 matrices if you want. Translation is independent of rotation anyway.Just translate your vertex manually by adding a translation value to each vertex component.BTW, I use an axis angle rotation in that demo.Pardon the textures and the bad coding style. I just whipped it up to test collisions. :*) 0 Share this post Link to post Share on other sites
Vectorg 104 Report post Posted July 21, 2005 Thanks relsoft, you're very kind to share your demo, but I wasn't able to run it due to a missing SDL.DLL.Let me ask this, when you apply a transformation to an vertex, do you change the value of the vertex, or use a temporary vertex for each frame, thus preserving the original object-space values? 0 Share this post Link to post Share on other sites
relsoft 255 Report post Posted July 22, 2005 Quote:Original post by VectorgThanks relsoft, you're very kind to share your demo, but I wasn't able to run it due to a missing SDL.DLL.Let me ask this, when you apply a transformation to an vertex, do you change the value of the vertex, or use a temporary vertex for each frame, thus preserving the original object-space values?The missing DLL could be found on Libsdl.org.Applying a transformation always changes the value of the vertex(except if it's an identity matrix). In OpenGL, you don't have to store the values on a separate array. The API does the calculations/transforms for you. If you want it on sofware mode and you don't need to cull, etc, You pass the original vertex on the transformation matrix and put the vertex on the fly.I'd say preserve the original vertices. 0 Share this post Link to post Share on other sites