Conforming to terrain only on one axis.

Started by
0 comments, last by PlutoWarrior 18 years ago
I am trying to make my horse conform to terrain only along its X axis (using Torque). Conceptually I decided to take the normal under my horse, rotate it around the Z by the inverse of the horse’s Z rotation (face the normal to the direction the horse is facing), and then the resulting normal’s X would be the amount forward and back my horse should tilt to conform to the terrain. Unfortunately I do not know matrix math and can not actually perform this simple operation. This is the code I got from a resource on GarageGames’ site that makes a tank conform to the terrain: // ============ Point3F x,y,z; z = surfaceInfo.normal; z.normalize(); mat.getColumn(1,&y); mCross(y,z,&x); x.normalize(); mCross(z,x,&y); mat.setColumn(0,x); mat.setColumn(1,y); mat.setColumn(2,z); // ============ The problem is it conforms on all axes and I want my horse to tilt only forward and back (X axis). When I try to modify it my horse only ends up skewed and disproportional (this is the rendering transform). Assuming “mat” is the matrix rotation of my horse (only the Z rotation is valid here), “surfaceInfo.normal” is the normal under my horse, and the axes are: X (across), Y (into the distance), and Z (vertical), how can I get this to work? What does cross multiplication (mCross()) do? I could do this on my own with my conceptual method if I knew how to rotate the normal around my player’s Z and how to use the other various matrix functions… Thank you.

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement
I can't really help you with any actual code since I've never tried anything like this. I would start by looking up the cross product, and rotation matricies. They're not that bad. Also look up how to multiply matricies first if you don't know how to do that. Sorry this is really vauge. I'm tired and I need to get some sleep before my 8:00am tomorrow. If you still need help with the math after everyone else has posted, PM me.

Edit: Here are some good links.
http://mathworld.wolfram.com/RotationMatrix.html
http://mathworld.wolfram.com/CrossProduct.html
---------------------------------------------Warning: This post may contain traces of Q-Basic

This topic is closed to new replies.

Advertisement