# pitching an object

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

## Recommended Posts

Hallo! i have a question: i have an object to draw, and it's modelview matrix. It is a tank, so its Y vector is always (0,1,0). Now, i want to implement a terrain under the tank, but the terain at a specifis point has different normal, than (0,1,0). my question is, how do i create a T matrix, so that: Modelview(tank on plain ground)*T=Modelview(tank on a slope). note that, i only know the normal of the terrain, so i have to build the T from only this vector. thanks! p.s: with your help i've finally implemented a stencil shadow algorithm, so thanks for that, additionally here's a screenshot of my precious tank, i hope i don't break frum rules by posting this... http://img30.imageshack.us/img30/5549/mytank.jpg

##### Share on other sites
There are a couple of different ways you can do this. I haven't tried this method, but it seems like it should work (pseudocode, assumes +z is up):
vector3 direction(cos(tank.angle), sin(tank.angle), 0);vector3 side = cross(current_polygon.normal, direction);side.normalize();vector3 up = cross(direction, side);// Now load side, up, direction, and the tank's position into a matrix and upload to OpenGL.
Another option would be to track the tank's orientation yourself, and apply an incremental rotation each update that aligns the tank's up vector with the current normal. If you apply the adjustment incrementally, this'll have the added benefit that the tank will 'glide' from orientation to orientation rather than just 'snapping' immediately to the new orientation every time it reaches a new polygon. (You could probably accomplish the same thing with the other method as well by interpolating between the last normal and the current normal.)

##### Share on other sites
it's not good like this, because the direction (which I call X vector) of the tank won't be perpendicular to the up vector.
what i need is 3 vectors, perpendicular to each other, and one of them is the terrain's normal, and the other two is basically the original X and Z vectors, but not the same, because they will be slighly transformed.

anyone any idea?

ps: i'm not native English speaker, so i hope perpendicular means that the angle between them is 90 degree...

##### Share on other sites
Quote:
 what i need is 3 vectors, perpendicular to each other, and one of them is the terrain's normal, and the other two is basically the original X and Z vectors, but not the same, because they will be slighly transformed.
That's exactly what I told you how to do :)

It's ok if the original direction vector isn't perpendicular to the up vector. As long as the two vectors are not colinear or nearly colinear (which they shouldn't be in this case), the generated basis will be valid.

Did you try it?

##### Share on other sites
thanks, i've tried something similar, and it worked fine.
sorry for the misunderstanding...

thanks again!

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633303
• Total Posts
3011277
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!