Jump to content

  • Log In with Google      Sign In   
  • Create Account

WorldToScreen Function help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Anddos   Members   -  Reputation: 515

Like
0Likes
Like

Posted 08 May 2014 - 03:02 AM

I am trying to convert an objects cordinates from 3D Space to 2D Space,but it dosent seem to work at all

 

 void WorldToScreen(IDirect3DDevice9* Device)
 D3DVIEWPORT9 Viewport; 
 D3DXMATRIX ViewMatrix,ProjectionMatrix,ViewProjectionMatrix,LocalToWorld,WorldToLocal; 
 
 Device->GetVertexShaderConstantF(0,ViewMatrix,3);//View
 Device->GetVertexShaderConstantF(3,ProjectionMatrix,4);//Projection
 Device->GetVertexShaderConstantF(43,LocalToWorld,4);//LocalToWorld
 Device->GetViewport(&Viewport);
 D3DXMatrixIdentity(&WorldToLocal);
 
 ViewProjectionMatrix = ViewMatrix * ProjectionMatrix;
 D3DXVec3Project(&Vector2D,
            &Vector3D,
&Viewport,
&ViewProjectionMatrix,
&LocalToWorld,
&WorldToLocal); 
 if(Vector2D.z < 1.0f)
 {
X = static_cast<int>(Vector2D.x);
Y = static_cast<int>(Vector2D.y);
 }
}
 
This is the dissasembled shader
 
// Registers:
//
//   Name                                                  Reg   Size
//   ----------------------------------------------------- ----- ----
//   FogModeA                                              b0       1
//   FogModeB                                              b1       1
//   ShadowReceiverFlag                                    b4       1
//   ShadowReceiverSSSM                                    b7       1
//   VSC_PointLoopCount                                    i0       1
//   VSC_SpotLoopCount                                     i1       1
//   VSC_ViewMatrix                                        c0       3
//   VSC_ProjMatrix                                        c3       4
//   VSC_TexTransform                                      c8      12
//   VSC_InstanceColor                                     c25      1
//   VSC_SpecularPower_Alpha_FogEnd_RCPFogEndMinusFogStart c31      1
//   VSC_MatrixOffset                                      c32      1
//   VSC_Free_ExpFog_AFogEnd_RCPAFogEndMinusAFogStart      c34      1
//   VSC_ShadowmapMatrix                                   c35      3
//   VSC_InstanceLandShadowIntensity                       c38      1
//   VSC_LWSMatrix                                         c43      3
//   view_matrix_56                                        c46    168
//   LPSData                                               c214    20
//

 


:)

Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 6255

Like
1Likes
Like

Posted 08 May 2014 - 03:22 PM


ViewProjectionMatrix = ViewMatrix * ProjectionMatrix; // ??? any reason you're doing this?

 

Take a look at the docs for D3DXVec3Project. A lot of your parameters appear to be inappropriate.

 

For instance, when this code is called, what is Vector3D? It should be the vertex position you're looking to project (from your mesh/model/vertexbuffer?)

 

I don't know if you're retrieving the parameters correctly (have you checked?), but it appears you should be using something like:
 

D3DXVec3Project( &Vector2D, &Vector3D, &viewport, &projectionMatrix, &viewMatrix, &world );

where "world" is whatever you're using to position the object, presumably LocalToWorld. Then, as you have it, the screen pos is (Vector2D.x, Vector2D.y), assuming that Vector2D is really D3DXVECTOR3.

 

Also, just as general practice, you should always check for errors.

 

EDIT: Had the wrong return value for D3DXVec3Project. (Thanks, unbird)


Edited by Buckeye, 09 May 2014 - 06:36 AM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS