• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# 3D - Non flat surfaces?

## Recommended Posts

Okay, I''m a newbie to 3D programming, I''ve just managed to create my first app where you can rotate a flat texture and move it, no big deal. Okay what about real 3d then? Say a cube, thats 6 sides = 6 squares = 4*6 vertices + 6 textures, how do I organize something like that? Should I create my object class, create some kind of square class which has 4 vertices and a texture and then have a pointer ot x squares? And when I''ve initialized them I guess I create my vertex buffer and fill it... Now comes the tricky part how do you set the multiple texture? Since I draw the entire buffer? That''s quiz one. My other question is: How do you make an object translate the way it''s facing, something like: newx = oldx + (dirx * speed) I dunno the formula andI whounder if someone could tell me it? Thanks!

##### Share on other sites
Well... If you want to draw an object that has several textures, you would do the following (I am not very good in DirectX, hope I say nothing stupid):
Fill one vertex buffer with all the necessary vertices for the 6 sides. Set the first texture. Render the first 4 vertices of your square (I think there is a way to render a vertex buffer partially. If not, set up several vertex buffers). Set the second texture. Render the next 4 vertices of your square. Set the third texture...
If you want to translate an object the way it´s facing, it is important how the object´s position is stored. If you use a 3x3 matrix for the rotation of your object (if you use a 4x4 matrix, just take the upper left 3x3 matrix), the first row (or column, I don´t know which is correct for DX) of the matrix points into the direction of the object (even though it might also be the 2nd or the 3rd).
Let´s say the direction vector is then (_11, _12, _13). Now you must multiply this with your speed: (speed * _11, speed * _12, speed * _13). And add this to the translation vector of your object (probably the last row or column of your 4x4 transformation matrix). If it moves in a strange way, just try all possible vectors, like (_11, _21, _31) or (_21, _22, _23) or (_12, _22, _32)...
One of them should work.

##### Share on other sites
Okidoki, thanks for your answer think I''ve got it. I use the same matrix I used for the rotation and extract the 3 rotation values. (Why can''t I just use my object''s own rotation vectors? like Object.Angle.x ... y ...z etc ?) And add the new values to the translation vector and translate it. Again thanks

• ### Forum Statistics

• Total Topics
628275
• Total Posts
2981756

• 10
• 11
• 17
• 10
• 9