Note that there are some explanatory texts on larger screens.

plurals
  1. POfor loop is not working right
    primarykey
    data
    text
    <p>i have this loop that checks two objects. The problem with it, is that it only checks the first one but it doesn't check the others... When my loop check the first object for picking it says if it has been picked or not, but when it loops again to check the second object it says it has not been picked, even when it was picked. So what i did is that i switched the checking process. Like now the second object gets checked than the first object gets checked. So after i did that, i got this result it says that second object got picked or not, it works fine but when it loops again it start checking the first object it says that it is not picked even when it was picked..<br> here is my loop</p> <pre><code>for(int i=0; 1&gt;=i; i++) { matWorld=entity[i]-&gt;s; // Use inverse of matrix D3DXVec3Unproject(&amp;rayPos,&amp;rayPos,&amp;vp,&amp;matProj,&amp;matView,matWorld); D3DXVec3Unproject(&amp;rayDir,&amp;rayDir,&amp;vp,&amp;matProj,&amp;matView,matWorld); rayDir -= rayPos; // make a direction from the 2 positions D3DXVec3Normalize(&amp;rayDir,&amp;rayDir); if(FAILED(D3DXIntersect(entity[i]-&gt;pDrawMesh, &amp;rayPos, &amp;rayDir, &amp;hasHit, NULL, NULL, NULL, &amp;distanceToCollision, NULL, NULL))) { PostQuitMessage(0); }; if(hasHit!=0) { entity[i]-&gt;draw=false; } } </code></pre> <p>any idea?</p> <p><strong>EDIT 2:</strong><br> ok i don't think you guys understood me right. I'm not trying to make my loop check more <code>entity</code>.<br> Ok i'll this is what happening.<br> 1. When it loops for the first time it, checks to see if <code>entity[0]</code> is picked or not, This step works fine.<br> 2. When it loops for the second time, checks to see if <code>entity[1]</code> is picked or not, HERE IS THE PROBLEM.<br> my loop works fine when it loops for the first time, but it doesn't work when it is looping for the second time.<br> When i was debugging i tried this.<br> 1. When it loops for the first time it, checks to see if <code>entity[1]</code> is picked or not, This step works fine.<br> 2. When it loops for the second time, checks to see if <code>entity[2]</code> is picked or not, HERE IS THE PROBLEM. it seems that after the first loop there is something wrong, but i can't see what is it. By the way i don't get any errors. <strong>EDIT 3:</strong> The Entire Function</p> <pre><code>BOOL D3dDevice::Picking(HWND hWnd, LPDIRECT3DDEVICE9 d3ddev, CXFileEntity *entity[4]) { D3DXMATRIX matProj; POINT pt; D3DVIEWPORT9 vp; D3DXMATRIX *matWorld=NULL; D3DXMATRIX matView; GetCursorPos(&amp;pt); ScreenToClient(hWnd, &amp;pt); d3ddev-&gt;GetTransform(D3DTS_PROJECTION, &amp;matProj); d3ddev-&gt;GetViewport(&amp;vp); d3ddev-&gt;GetTransform(D3DTS_VIEW, &amp;matView); D3DXVECTOR3 rayPos((float)pt.x, (float)pt.y,0); // near-plane position D3DXVECTOR3 rayDir((float)pt.x, (float)pt.y,1); // far-plane position BOOL hasHit; float distanceToCollision; for(int i=0; i&lt;=1; i++) { matWorld=entity[i]-&gt;s; // Use inverse of matrix D3DXVec3Unproject(&amp;rayPos,&amp;rayPos,&amp;vp,&amp;matProj,&amp;matView,matWorld); D3DXVec3Unproject(&amp;rayDir,&amp;rayDir,&amp;vp,&amp;matProj,&amp;matView,matWorld); rayDir -= rayPos; // make a direction from the 2 positions D3DXVec3Normalize(&amp;rayDir,&amp;rayDir); if(FAILED(D3DXIntersect(entity[i]-&gt;pDrawMesh, &amp;rayPos, &amp;rayDir, &amp;hasHit, NULL, NULL, NULL, &amp;distanceToCollision, NULL, NULL))) { PostQuitMessage(0); }; if(hasHit!=0) { entity[i]-&gt;draw=false; } } return hasHit; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload