Thread: direct x creating projection matrix

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    direct x creating projection matrix

    I want to create a projection matrix without using D3dx. This is the code I have so far:

    They are both Left Handed matrices.

    Code:
    void Engine::CameraSetProjection(float fov, float aspect, float znear, float zfar)
    {
        float yscale = cos(fov)/sin(fov);
        float xscale = aspect/yscale;
        
        D3DMATRIX mat;
        mat._11 = xscale;
        mat._22 = yscale;
        mat._33 = zfar/(zfar-znear);
        mat._34 = 1;
        mat._43 = -znear*zfar/(zfar-znear);
        
        device->SetTransform(D3DTS_PROJECTION, &mat);
    }
    This is the formula d3dx uses to create a projection matrix:

    Code:
    xScale     0          0               0
    0        yScale       0               0
    0          0       zf/(zf-zn)         1
    0          0       -zn*zf/(zf-zn)     0
    where:
    yScale = cot(fovY/2)
    
    xScale = aspect ratio / yScale
    How ever, that doesn't seem to be working. I am not seeing the triangles that I did when I used d3dx (I don't see any triangles). And the paramters stayed the same.

    I belive my error is in the cot function, I read cot = cos/sin. I also tried cot = 1/tan but neither seem to work.

    Any ideas?

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    your values are wrong..

    Projection Matrix:
    Code:
    //Fill Matrix with 0's
    
    ._11 = (2*NearClip)/ScreenWidth
    ._22 = (2*NearClip)/ScreenHeight
    ._33 = FarClip/(FarClip-NearClip)
    ._43 = (-FarClip*NearClip)/(FarClip-NearClip)
    ._34 = 1;
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Nope, that doesn't work either. Unless do I have to set every value to 0?

    Mine worked, I had to ZeroMemory it first.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  4. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM