Problem with width and height of quads

Started by
13 comments, last by Dev_NightDreamer 11 years, 7 months ago
Hello dudes,

I've got a little problem, but maybe I am only too silly to solve it. unsure.pngbiggrin.png

I've got a window (1280x720) and a perspective from 0.01f till 1000.0f.
So, when I will render a normal quad with the width and height of the whole screen, I don't know where the vertices of the quad must be.
I try with (-1/-1), (-1/1), (1/-1), (1/1) and for each z-Axis coordinate 1 (I'm rendering with trianglestrips!), but then it is way too big! dry.png

So my question is, how I could know the true coordinates of each vertex for rendering a quad which is as big as the screen? wacko.png
Are there any mathematical tricks or something like that? mellow.png
Advertisement
We are missing a lot of context here...
I'm so sorry. I thought, it was enough information.

My plan is to make a little 3D Game like Little Big Planet.
I'm coding in C++ and DirectX 9 with Vertex- and Pixelshader 3.0
This is a part of my Initialisationcode:

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
d3dpp.hDeviceWindow = hWnd;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = windowed;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.BackBufferFormat = D3DFMT_R5G6B5;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferWidth = width;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3d9Device);
D3DXMATRIXA16 projection;
D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI/4, (float)width / (float)height, 0.01f, 100.0f);
d3d9Device->SetTransform(D3DTS_PROJECTION,&projection);


If you miss other things, please tell me and I will edit this post. smile.png
Also I excuse me for my terrible english... I'm from Germany and my english mark isn't so good... >.<
Is there a specific reason you have to do this with a perspective projection? It becomes much easier to determine the necessary coordinates if you use an orthographic projection instead since you can directly construct a coordinate system that matches exactly what you expect and want.
I'm not really sure, but I think I could remember from Blender, that perspective means, that you can see a wall, which is lightly inclined to the back, but in orthographic mode you couldn't see it. Or am I wrong? mellow.png
If so, could you explain me the difference between perspective and orthographic projection?
Because in Little Big Planet you also could see three dimensional objects through perspective projection, could you? wacko.png
Perspective projection has perspective, orthographic projection does not. Perspective is how you see reality yourself; objects appear smaller by distance. Since you're probably quite familiar with perspective, you should look for orthographic projection specifically and see how they behave and are different from what you would expect reality to look like. I know this is for OpenGL, but you can have a look at the Red Book, chapter 3. The theory is universal and the functions maps pretty much directly to Direct3D equivalents. It discusses projections a bit along with general viewpoint transforms.

Since it appears that you have problems getting the coordinates correct due to the perspective effect, my question was basically; why not eliminate that factor in the first place and use a projection that doesn't have perspective?
Thank you.
This is what I meant, I know it from the 3D modelling programm Blender. smile.png
Maybe my question wasn't very explicit , so I try it once more:
How can I get the correct position of a vertex in perspective projection?

(Btw: Why I don't really want to use orthographic projection is the fact, that my "camera" will allways look from the front of the scene to the back. So you don't really see any 3D effect, due to the orthographic "viewmode". E.g. a crate where you have to jump over, isn't really a crate anymore but a simple quad. )
Perhaps I'm not understanding what it is you want then. I thought from your first post that you were trying to display a quad the size of the screen, which to me suggested that you were trying to fit the quad perfectly onto the screen, and you were having problems getting the coordinates that corresponded to the corners of the screen.

Can you explain better what it is you're trying to do? What is the 3D effect you want from the quad? Why do you need screen-specific placement of objects that exists in a 3D world? The two spaces are typically used independently, but sometimes you have to go from 3D coordinates to screen coordinates, but rarely the other way around.
Yeah, you're right. smile.png
That the quad fits the screen perfectly was just an example to understand what I mean (because my english skill is so limited as you probably see...).

The 3D effect that I want is something like in this video (from 4:03 mins to 4:13 mins as example).
In orthographic projection it doesn't work very well to do so, so I must use perspective projection, or am I wrong? unsure.png
My specific problem is, when I will set up e.g. a crate (e.g for the beginning of the level), I must define, where it has to be. But without any coordinates, it doesn't work.
So I will learn, how to "find" the correct coordinates.

I hope, this time, you can understand what I mean... sad.png
I excuse me for my bad english, again.
I don't see why you would need screen coordinate for that and why you don't know where the crate is. Isn't the crate located somewhere within the scene, and isn't the crate just like any other 3D object in the 3D scene?

This topic is closed to new replies.

Advertisement