Move a 2D texture in 3D

BlitzMax Forums/BlitzMax Programming/Move a 2D texture in 3D

Grey Alien(Posted 2007) [#1]
Hi. How easy it is in native Bmax to get a 2D texture that's part of a TImage and draw it in 3D e.g. slightly angled back with perspective, using DX or OpenGL calls? I assume all the fancy 3D engines that people are making do that, but is there like a really easy way to do it for a single texture?

OK I'm a bit out of touch, but in 3D games the CPU does all the maths and rotations etc of the shapes in 3D and then sends the coords to the 3D card to render right. The 3D card doesn't do any fancy maths does it? Or am I wrong here?

Thanks!


Gabriel(Posted 2007) [#2]
OK I'm a bit out of touch, but in 3D games the CPU does all the maths and rotations etc of the shapes in 3D and then sends the coords to the 3D card to render right. The 3D card doesn't do any fancy maths does it? Or am I wrong here?

It depends. You used to be right here, because IIRC Max2D did not enable TNL ( hardware transform and lighting ) by default, but I think it does now. Or if it doesn't, it's available with a third party module. Pretty much any 3d card sold in the past decade can do it, so there's no sense not using it.

As for the 3d thingy, can't you calculate the projection manually and use Tim's textured poly module to do the drawing? Basic 3d projection is very simple, so it won't take any time. I'm guessing that both GL and DX modules lock you into 2d drawing with a 2d projection matrix so switching to a 3d projection matrix, drawing a quad and then switching back to the 2d projection matrix again would be slow because of the time it takes to reset the PM. Might as well stick with 2d and calculate the projection yourself, I'd say.

EDIT: Just to be clear, I've not used Tim's module, so I'm not sure how it works. It may not be suitable, so if I sound wrong here, I probably am.


ImaginaryHuman(Posted 2007) [#3]
"Using native Bmax" ???? You can't. You have to introduce rotation commands applied to the modelview or projection matrix.

Also you can't use the orthographic projection that 2D uses, you have to switch to a perspective projection, which means defining like glFrustum() or gluPerspective(). Then you have to position the objects in 3d space where the camera can see them. Then you have to add rotation to the projection/modelview matrix with glRotatef(), presumably in the Y axis.


H&K(Posted 2007) [#4]
Its quite easy to draw a texture to a draw/poly command. One of the very early GL Tuts tells you how. And Indies Textured poly if the same.

Now ok this is just a textureed poly and not a 2d texture in 3d. So you have all the problems Angel said. But it really depends on wha tyou are doing.
Iso none projected 3d is just rotated 2d textures.
But simply to make it look "angeled" just means moveing two oposite corners of a quad closer together.


ImaginaryHuman(Posted 2007) [#5]
Moving the top corners closer together will not give you the impression of perspective because there is no vertical adjustment to represent distance. You could draw it in segments perhaps, each a little thinner than the last into the distance.


H&K(Posted 2007) [#6]
Yep, but the TOP corners are not oposite corners.
But Anyway I was talking about (though I didnt say) when you have ONE top corner, two corners horizontal to eash other, and a bottom corner. (Basicly Iso). I agree it get complicated if you want to be able to "do everything".


Grey Alien(Posted 2007) [#7]
I can do all the math to rotate a poly in 3D with perspective (since like about uh 18 years ago) but that will be an untextured poly. Are you lot saying that if I used Tim's texture mod that it won't be suitable for say a photo as the photo of course would be drawn with perspective, it would be normal 2D within a weird shaped poly is all.

OK forget native BMax but can it be done easily with a few DX/GL calls from within Max and without having to change 3D graphics mode or whatever. i.e. leave my game in 2D mode but have a 3D rotated texture with perspective spin around on top or something?


Jake L.(Posted 2007) [#8]
If it's possible to change the projection matrix between drawing commands, this would be possible. As far as I know you can change the projection matrix as you like (at least under GL), so this should work:

<Set Ortho-Projection>
<Draw 2D-Stuff>
<Set 3D-Perspective-Projection>
<Draw 3D>
<Flip>

Have a look at the NeHe-Tutorials (in the BMax-Tutorials-Forum) for the 3D-Matrix and other stuff, should be easy to create a testapp.

You can manually set a 2D-Matrix by:

glMatrixMode GL_PROJECTION
glLoadIdentity
glOrtho 0,screenwidth%,screenheight%,0,-1,1

Don't know about the DirectX side, but should be possible, too.


H&K(Posted 2007) [#9]
Well, what I was saying was if you just moved the corners about, it would "look" like 3D when useing textured quads.

You only need to mess with the projection if you want a lot of things to look 3d next to each other. (The others are right if you need to do specific things). but if you just want a "Picture" to spin about and "look" 3d, then textured poly just moving the corner points about will probably be enough.

It comes down to how much 3d you want. If its just a graphical gimic, then what Ive just said works. If its more (or obviously if you want an expandable solution), then either follow the NeHe tuts or just use minib3d or one of the other 3d solutions


anawiki(Posted 2007) [#10]
Grey, give MiniB3D a try. We mix 2d with 3d and it works pretty well.


Grey Alien(Posted 2007) [#11]
interesting. Yeah I don't need a whole 3D system, just to spin a texture in 3D. In fact I don't even need that I was just wondering if it was possible easily.