• Advertisement

Archived

This topic is now archived and is closed to further replies.

Help!!! DX has gone insane!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''ve written a simple program (VB .NET, DX 9) that renders two coloured triangles. They are placed around the origin. The camera position is at (0,0,-1) and it points to (0,0,0). Now, If I want to change the camera position (in the view matrix), DirectX produces funny things. Here''s the code: Public Sub Render() d3dDev.Transform.World = Matrix.Identity() d3dDev.Transform.View = Matrix.LookAtLH(New Vector3(0.0F, 0.0F, -1.0F), New Vector3(0.0F, 0.0F, 1.0F), New Vector3(0, 1, 0)) d3dDev.Transform.Projection.PerspectiveFovLH(PI / 2, 4 / 3, 0.0F, 100.0F) d3dDev.BeginScene() d3dDev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.FromArgb(0), 1.0F, 0.0F) d3dDev.VertexFormat = CustomVertex.PositionColored.Format d3dDev.SetStreamSource(0, vbuffer, 0) d3dDev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2) d3dDev.EndScene() d3dDev.Present() End Sub ... If I for example set the camera position to (0,0,-0.1), nothing will change at all. If I set it to (0,0,-1.1), the triangles disappear. That means they are only visible in a range of 0-1, without any size changes between 0 and 1... As I understand it, the float values I set for position and alignment are treated as Integers, that means changes below 1.0 don'' have any effect. Furthermore, some odd clipping occurs (though my near plane is 0). For some reason, DX calculates extremely inaccurately. Do you know any problems the view and projection matrix can cause so that simple operations don''t work properly anymore? Thanks a lot

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
d3dDev.Transform.Projection.PerspectiveFovLH(PI / 2, 4 / 3, 0.0F, 100.0F)

By setting your near plane to zero you are totally killing your projection matrix. Check out in the documentation how your matrix is constructed to see why.

Share this post


Link to post
Share on other sites
Okay, I have set the near plane to 1.0F, but there is still a problem... The slightest changes in camera position cause that the triangles aren''t visible anymore or that parts are clipped.
Changes in triangles vertex positions have the same effect.
If I leave all matrix intitialisations out, the program works anyway, I don''t understand this...Why are the rendered primitives not shown spacial correctly and what is DX doing with the clipping?

Share this post


Link to post
Share on other sites
Finally, I''ve got it :-)
In deed, something was wrong with the projection matrix. I just copied an initialization from a tutorial, which doesn''t differ much from my call before, and now it works.
Thank you for your help

Share this post


Link to post
Share on other sites
d3dDev.Transform.Projection.PerspectiveFovLH(PI / 2, 4 / 3, 1.0F, 100.0F) 


Just curious, was it the aspect ratio that was screwing everything up?

Up there you have it set as (4/3), when the standard screen aspect is (3/4).

Share this post


Link to post
Share on other sites
quote:
Original post by henrym
Up there you have it set as (4/3), when the standard screen aspect is (3/4).


Eh? Standard screen aspect is (width/height) - take something like (800/600), and that boils down to (4/3)...

Edit: from the DXSDK page on D3DXMatrixPerspectiveFovLH:

quote:
Aspect
[in] Aspect ratio, defined as view space width divided by height.


[edited by - Superpig on April 16, 2004 9:06:56 AM]

Share this post


Link to post
Share on other sites

  • Advertisement