Jump to content
  • Advertisement
Sign in to follow this  
edwardfmo

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!