Im doing some ray casting and picking from a book that is Open GL. I Get perfect movement on the x and y(I rotated the grid 90 so it would match the x and y. Buy when I try to put it on the the z axis, it is not right

How can I get this to work in a left handed coordinate system in directx 11?

Here is my code, maybe somneone can help out.

GetPickRay( float sx, float sy, float fov, float width, float height )//sx-sy window coordinates, fov fieldofview, width height size of window
    //view cords from NDC,SCREEN
   float vx = (+2.0f*(float)sx/(float) mClientWidth - 1.0f)/P(0,0); //P is projection matrix
    float vy = (-2.0f*(float)sy/(float) mClientHeight + 1.0f)/P(1,1);

    XMFLOAT3 viewPoint2(vx,vy,1.0f);
    XMVECTOR viewPoint = XMLoadFloat3(&viewPoint2);
    XMMATRIX invView = XMMatrixInverse(&XMMatrixDeterminant(V), V);
    XMVECTOR T = XMVector3Transform(viewPoint,invView);

    return T - EYEPOINT;

    OnMouseDown(WPARAM btnState, int x, int y)
    mLastMousePos.x = x;
    mLastMousePos.y = y;

    XMVECTOR ray = GetPickRay( (float) x, (float) y, 45.0f,(float) mClientWidth,(float)mClientHeight );

    XMFLOAT3 ra;
    XMFLOAT3 EyePoint;
        // compute intersection with z=0 plane
        float t = -EyePoint.z/ra.z;
        XMVECTOR tt = EYEPOINT + t*ray;
        XMFLOAT3 d;
        moveIT = XMMatrixTranslation(d.x,d.y,d.z);

My up vector for the view matrix is 0,1,0

Thx if someone could point me in the right direction

  • \$\begingroup\$ Just noting that Direct3D 11 does not require a LH coordinate system; it's perfectly possible to use RH coords in Direct3D (and has been since at least 8, if not earlier). \$\endgroup\$ – Maximus Minimus Jul 18 '17 at 10:40
  • \$\begingroup\$ Got it to work. just changed value t to .y. \$\endgroup\$ – Terry Jul 18 '17 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.