PDA

View Full Version : Direct3D and isometric GFX



Harry Hunt
08-04-2003, 04:07 PM
Hi there!
Does anybody have any experience with combining 3D characters and 2D isometric environments?
I've picked up and old project of mine again which used to be entirely 2D, and now I think that a lot of things would be much easier if at least the characters were 3D (don't want to do it entirely in 3D because I want to re-use my old gfx).

I know how to draw 2D sprites in Direct3D, but how do I get the 3D models to look right (= the right perspective/camera angle). Is there something like orthographic projection in Direct3D or do you have to fake it? I know that it's possible because a whole bunch of games use this technique, but I dunnow how to do it.
Any help much appreciated.

Thanks in advance!

Sly
09-04-2003, 12:03 AM
I believe there are some D3DX functions to set an orthographic projection matrix.

Harry Hunt
10-04-2003, 03:28 PM
Thanks...
I came across the D3DXMatrixOrthoLH procedure which looks like it does exactly what I need.

It has the following parameters
function D3DXMatrixOrthoLH(Out : PD3DXMatrix; w, h, zn, zf : Single)

The "out" parameter is obvious of course. But what is the rest?

Here's the explanation given in the DirectX SDK help file

w
[in] Width of the view volume.
h
[in] Height of the view volume.
zn
[in] Minimum z-value of the view volume.
zf
[in] Maximum z-value of the view volume.

I don't get it though. Any ideas?

Alimonster
10-04-2003, 05:05 PM
Disclaimer: I usually use OpenGL, not D3D, so this post may not be entirely correct.

The first thing to note is the fundamental difference between orthographic projection and the standard one. In the standard perspective mode, objects get smaller the further away they are. The z value here controls the relative size of an object as well as which ones get drawn (closest to camera = gets drawn). Ortho graphics will not get smaller the further away they are.

You can imagine an ortho view as a cube and standard perspective as a pyramid. If you take an ortho point, the z value does not change the object's size (imagine the project going straight along one of the edges of the "cube" for ortho projection -- the world position will end up at the same place on the camera, same sized and relative position). In the case of standard projection, you'd be looking at the bottom of the pyramid that's pointing away from you. If you took a point further away, it would be smaller (the objects would end up squished a bit).

Bear in mind that although the z value does not affect an object's size or position, depth testing still takes place. The z value of an object ensures that an object closer to the camera will be drawn in front of another -- so, in effect, the z value for ortho mode is like a standard "z order" a-la every 2d graphics API in existence. Closer z values will be drawn over stuff that's further away. Think of overlapping windows for a 2d analogy.

Anyway, getting back to the point.

Judging by the clear-as-dirty-mud help at MSDN, I think you want to pass in the following parameters:

W, H - the width and height of your screen. The screen's centre point will be (0,0). Your left will be -(width / 2) and right will be (width / 2). The top will be (height / 2) and bottom -(height / 2). The screen width and height will be arbitrary values, since Ortho mode will be resolution independent. You can use 1.0 values if you want, and have a screen that's (-0.5, 0.5) tl to (0.5, -0.5) br, I suppose, or you could do your screen width + height values.

The z near and far values... well, try the classic values of 0 and 1 (or maybe 1 and 0, forgot how D3D handles this, or -1 and 1). The z value here controls the minimum and maximum "z order" value for your objects.

...and that should be it, hopefully.

There's a good chance that I've talked nonsense in this post and have humiliated myself. I await correction and/or clarification from someone with a better memory than me. :pirate:

EDIT: Whoops! Said that you pass in width and height divided by two, but I didn't mean that!

Clootie
11-04-2003, 05:16 AM
It's better to assign Z values with:
Znear = 1
Zfar = 100 (or 1000 or 10000, etc.)

So, you can pass something like this:
D3DXMatrixOrthoLH(Matrix, 2.0, 2.0, 1.0, 1000.0);

Harry Hunt
13-04-2003, 05:43 PM
Cool, I guess I have figured it out :D
Thanks a bunch!