# Centering the View Matrix

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

The following should be a trivial question- I almost apologize for asking it: Below is a snippet of code setting up a projection matrix and a view matrix. My assumption was that based on the matrices that I setup, point <0, 0, 0> should be directly in the center of my application window. This has not been the case as it has been off to the lower right. Is my assumption wrong or did I mess something up: D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 640.0f / 480.0f, 0.1f, 100.0f ); pDevice->SetTransform( D3DTS_PROJECTION, &matProj ); D3DXMATRIX out; D3DXVECTOR3 eye(0,0,-14); D3DXVECTOR3 at(0,0,0); D3DXVECTOR3 up(0,1,0); D3DXMatrixLookAtLH(&out, &eye, &at, &up); pDevice->SetTransform(D3DTS_VIEW, &out);

##### Share on other sites
I don't see problems in your camera code. It's possible that the problem is in the world matrix. Did you set/initialize it before passing? For example:
D3DXMATRIXA16 matWorld;D3DXMatrixIdentity(&matWorld);pDevice->SetTransform( D3DTS_WORLD, &matWorld );

##### Share on other sites
When I used a simple square, the square showed up at the center.

I was trying to place a mesh loaded from a .x file at the center of the screen. I assumed that the .x file only included the geometry of the specific mesh, not empty space. I thought I had checked this before.

I am attempting to implement a menuing system and orientate everything around the origin looking down on the X-Y planes so I can just take the <x,> coords when seeing where the user clicks. This will then get checked against a textured plane using lockRect (I may copy the alpha channel of the texture to a 2x2 matrix which will allow for curvy buttons) to see what button the user may have clicked on from a set of buttons which show themselves by texturing this plane.

I suppose D3DXSprite may be mor efficent for this texture but I figure there won't be a lot of geometry motion when the user is using the menu so I'll have the horsepower available.

Thanks to those who addressed my concern...

##### Share on other sites
Quote:
 When I used a simple square, the square showed up at the center.I was trying to place a mesh loaded from a .x file at the center of the screen. I assumed that the .x file only included the geometry of the specific mesh, not empty space. I thought I had checked this before.

Each vertex from the mesh has a 3D coordinate. This coordinate is defined in the modeling software, when the mesh is created. Although the modeling software and Direct3D may have different coordinate systems, the plugins usually convert the vertex coordinates so that the position of the mesh is maintained (unless you use some special plugin to centralize the mesh before exporting it).

Quote:
 I suppose D3DXSprite may be mor efficent for this texture but I figure there won't be a lot of geometry motion when the user is using the menu so I'll have the horsepower available.

There are many ways to create a nice menu, and sprites could be a good way (see the menus in my MontadorSprites and MagicCube applications. They were made with D3DXSprite).
For circular or elliptic buttons you could use math equations to determine if the cursor position is on the buttons, but for more irregular shapes your method is more flexible [smile]. Most of the time, it is not important to get precision on the button shape detection. A simple rect around the button would be already enough. Usually, people don't notice that.

[Edited by - adriano_usp on June 5, 2005 6:58:58 PM]

##### Share on other sites
I tried creating my menu by creating a texture for a cursor and then doing LoadSurfaceFromSurface calls to move that texture around on another texture whenever the mouse moved. My system isn't breathtakingly fast but it does have some oomph for what I am doing: a 9600 Radeon Pro video car, 3.0 Ghz Pentium 4, 1 gig Ram.

I got burps of action but it seems that this methodology of constantly copying memoery wasn't the way to go with a texture copy operation every render (or time the mouse moved).

I then tried (this is all still new to me) trying to add textures with SetTextureStageState. From what I have seen, adding textures is truly adding textures- I was hoping there was an either or operation in there- I couldn't find it. If I am mistaken, somebody let me know.

My last bit of thinking is to put that cursor texture onto another piece of geometry- I prefer not to do this as it seems to me that I should still be able to mix textures onto one plane without using multiple planes.

• 17
• 10
• 19
• 14
• 19