Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D using D3DFVF_XYZRHW

Started by Bretttido Oct 17, 2002 at 8:51 PM 7 replies 3.8k views
Original Post
Bretttido
Bretttido
This may seem like a silly question, but here goes. I'm using pretransformed verticies (D3DFVF_XYZRHW) for many GUI elements of my program. Let's say I have a Button element whose verticies in a vertex buffer are at (0, 0), (100, 0), (100, 20), and (0, 20). What I'd like to be able to do is transform these verticies to the location of the button on the screen at (x, y). As opposed to locking the vertex buffer and updating the verticies for each button that exists. Is there any way to accomplish this idea of very basically "transforming" D3DFVF_XYZRHW verticies? I had previously simply used untransformed verticies (D3DFVF_XYZ) and an Ortho view matrix to handle GUI elements. So I'm aware of that approach, along with its advantages and disadvantages. Brett [edited by - Bretttido on October 17, 2002 9:54:17 PM]
DrunkenHyena
DrunkenHyena
You cannot transform Transformed vertices (D3DFVF_XYZRHW). There is no way. The only way to move them around is locking the VB.

Why did you stop using untransformed vertices? I find they work pretty well. Though they can get a little inefficient if you''re drawing a million little elements, but that''s not too common for a GUI.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON
Bretttido
Bretttido
I tried moving to pretransformed verticies because I preferred the coordinate system for GUI objects where (0,0) is at the top left with positive y pointing down. Happen to know a way to get this same coordinate system using an ortho matrix?

Brett
Ximmer
Ximmer
you can use D3DXMatrixOrthoOffCenter to put 0,0 in the top left corner...

D3DXMatrixOrthoOffCenter(&Mat, 0, 640, 0, 480, -1, 1);

-Ximmer
Bretttido
Bretttido
Unfortunately, that''s the same ortho matrix I''m currently using. It seems to create a projection matrix where the origin is indeed at the top left... but positive y is point UP. So the center of the screen in that coordinate system ends up being (width/2, -height/2): Which is what I''ve been dealing with so far. It''s not too bad, but certainly not ideal.

Brett
Ximmer
Ximmer
Hmmm I''m not really sure... but perhaps if you flip the handedness of your Ortho projection and invert the top and bottom components of the ortho call?

cause it really doesn''t make sense to me that you put 0 in the Top parameter and some Screen height in the bottom parameter that the Y value would not go from top to bottom, 0 to Height

perhaps showing some code can help us out?
Bretttido
Bretttido
I''m not sure about that one either Ximmer. Though in the docs, it never really states that t stands for top and b stands for bottom in:

D3DXMATRIX* D3DXMatrixOrthoOffCenterLH(
D3DXMATRIX* pOut,
FLOAT l,
FLOAT r,
FLOAT t,
FLOAT b,
FLOAT zn,
FLOAT zf
);

All that it says is t is the minimum y-value and b is the maximum y-value. And it seems to like having the minimum y-value be at the bottom. I''ll try messing around with what you suggested.
Bretttido
Bretttido
Okay, I believe I got it by swapping the t and b values... though how this works does not seem at all intuitive to me.

D3DXMatrixOrthoOffCenterLH(D3DXMATRIX, l, r, t, b, zn, zf);
D3DXMatrixOrthoOffCenterLH(&mat, 0.0f, width, height, 0.0f , -1.0f, 1.0f);

So the t value (which suggests top) has a value of height, and the b value (which suggests bottom) is 0.0f. And THIS results in a projection where the origin (0,0) is at the top left. Can anyone explain how this is working? I'm guessing its simply due to a poor choice of variable names, hehe.

By the way, I've verified my view and world matrix are identity; so no problem there.

Brett

[edited by - Bretttido on October 18, 2002 7:17:18 PM]
DrunkenHyena
DrunkenHyena
Actually the variable names are right, 2D computer graphics are wrong.

I you think back to graphing in school, when you draw your graph on paper, x increased to the right, and y increased to the top of the page.

So the decision to have (0,0) at the top left was really wrong, but very convenient since you would get a pointer to the beginning of the framebuffer and then do your plotting.

Prolly drove mathematicians nuts...

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.