Change font display position based on point coordinates

Source: Internet
Author: User

StackOverflow method Found: http://stackoverflow.com/questions/11714298/ d3dxvec3project-requiring-half-the-object-position/11762956#11762956

Yesterday tried several methods, all ineffective, maybe I am stupid ...

In a nutshell, use the D3dxvec3project function to find the projection position of the point in the screen based on the position of the midpoint of the world coordinate system, and then draw the font at that location.

  

1 D3dxvector3 cmfc_d3dview::toscreenspace (d3dxvector3 position)2 {   3D3dxvector3 out;4 D3dviewport9 view;5 D3dxmatrix Matview;6 D3dxmatrix Matworld;7 D3dxmatrix matproj;8 D3dxmatrix Worldpos;9 D3dxmatrix Worldrotx;Ten D3dxmatrix Worldroty; One D3dxmatrix Worldrotz; A D3dxmatrix WORLDSCL; -  -_device->getviewport (&view);//view in debug are showing all the correct values. the_device->gettransform (D3dts_view, &matview);//view is set each frame from the camera -_device->gettransform (D3dts_projection, &matproj);//This was set once in the scene manager -D3DXMatrixIdentity (&matworld); -     //d3dxmatrixtranslation (&matworld, position.x, POSITION.Y, position.z);//uses the given position for the world matrix +  -D3dxvec3project (& out, &position, &view, &matproj, &matview, &matworld); +  A     return  out; at}

The problem with Stacoverflow is that the position of the display font is not the same as expected, because he changed the world Matrix Matworld because the second parameter of the D3dvec3project function has already specified the position of the point, So the input of the world coordinate matrix should be the unit matrix will not appear error, so I will matworld unit a bit, and then in the draw point of the loop to add

  

1         D3dxvector3 POut; 2         D3dxvector3 pIn = D3dxvector3 (m_pointlist[i].x,m_pointlist[i].y,m_pointlist[i].z); 3         POut = toscreenspace (pIn); 4         SetRect (&RC, Pout.x,pout.y, pout.x+, pout.y+  ); 5         M_pfont->drawtexta (0"HelloWorld",-10, White);

The complete code is like this.

  

1 voidCmfc_d3dview::D rawpointusingsphere ()2 {3     4_device->BeginScene ();5      for(inti =0; I<m_pointlist.size (); i++)6     {7_device->setmaterial (&Red_mtrl);8_device->settransform (d3dts_world,&m_matrixofpoint[i]);9M_objectofpoint[i]->drawsubset (0)///Draw the ball (I am the point of the ball instead)Ten          One  A D3dxvector3 POut; -D3dxvector3 pIn =D3dxvector3 (m_pointlist[i].x,m_pointlist[i].y,m_pointlist[i].z); -POut =Toscreenspace (pIn); theSetRect (&AMP;RC, Pout.x,pout.y, pout.x+ Max, pout.y+ - ); -M_pfont->drawtexta (0,"Hello World", -1, &AMP;RC,0, white);//Display text -  -  +          -          +     } A_device->EndScene (); at  -      -}

  

  

Change font display position based on point coordinates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.