MFC 창에 direct3d 환경이 있으며 3D 소프트웨어와 마찬가지로 화면 모서리에 좌표계 축을 그려야합니다. 나는 이것이 아무런 문제가되지 않을 것이라고 생각했지만 카메라를 움직이기 시작할 때 문제가 발생했습니다. 카메라를 이동, 확대/축소 또는 회전하는 방법과 상관없이 동일한 지점에있는 것처럼 보이는 개체가 필요합니다.direct3d의 화면 구석에 좌표계 축 그리기
하지만 내가 뭔가 잘못하고있는 것 같아요. 누군가 내가 올바른 방향으로 나를 가리킬 수 있기를 바랬습니다. 왜냐하면 내가 그리는 객체가 줌을 할 때 그에 따라 크기가 조정되지 않았기 때문입니다. 그러나 패닝이나 회전. 내가 시도하는 코드를 자세히보고하지 않은
void CDEMView::DrawSomeBox()
{
// Define the needed matrices - object world, view and project
D3DXMATRIX matObjectWorld;
D3DXMatrixIdentity (&matObjectWorld); // object world matrix
D3DXMATRIX matView;
D3DXMatrixIdentity (&matView); // view matrix
D3DXMATRIX matProjection;
D3DXMatrixIdentity (&matProjection); // projection matrix
// Get the needed matrices
_device->GetTransform(D3DTS_VIEW, &matView);
_device->GetTransform(D3DTS_PROJECTION, &matProjection);
// Get the viewport
D3DVIEWPORT9 viewport;
_device->GetViewport(&viewport);
// Get the center point of the object
D3DXVECTOR3* p_centerPoint = BoxCenterVector; // this is from an external variable
// Get the point on the creen that is the screen projection of the object
D3DXVECTOR3 projectPoint;
D3DXVec3Project(&projectPoint, p_centerPoint ,&viewport, &matProjection, &matView, &matObjectWorld);
// choose the screen point where the object is to be drawn, relative to the Viewport's dimensions
D3DXVECTOR3 screenPoint;
screenPoint.x = 0.1*viewport.Width; // x position (horizontal) is 10% of the width of the screen (0% is left, 100% is right)
screenPoint.y = 0.9*viewport.Height; // y position (vertical) is 90% of the height of the screen (0% is top, 100% is bottom)
screenPoint.z = projectPoint.z; // 1-projectPoint.z*60/(-zoom);
//transform the screen position to a world position
D3DXVECTOR3 worldPoint;
D3DXVec3Unproject(&worldPoint, &screenPoint, &viewport, &matProjection, &matView, &matObjectWorld);
// now define how much to translate the box in order to get it to the point we want it to be (WorldPoint)
float transX, transY, transZ;
transX = worldPoint.x;
transY = worldPoint.y;
transZ = worldPoint.z;
// define a mesh to store the object into and create the object
ID3DXMesh* _SomeBox;
float boxSize = 2.0f;
D3DXCreateBox(_device,boxSize,boxSize,boxSize,&_SomeBox,NULL);
// define a material and set its color
D3DMATERIAL9 mat;
// Set the RGBA for diffuse reflection.
mat.Diffuse.r = 255;
mat.Diffuse.g = 0;
mat.Diffuse.b = 0;
mat.Diffuse.a = 0.5;
_device->SetMaterial(&mat);
_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); // D3DFILL_SOLID
// apply the translation matrix
D3DXMatrixTranslation(&matObjectWorld, transX, transY, transZ);
_device->SetTransform(D3DTS_WORLD, &matObjectWorld);
// draw the object
_SomeBox->DrawSubset(0);
// release the mesh
_SomeBox->Release();
}
안녕하세요! 답장을 보내 주셔서 감사합니다. 나는 일반적인 프로그래밍과 directx 프로그래밍에 대한 지식이 거의 없다. 따라서 나는 "가상 장면"이 무엇인지, 그리고 어떻게 그것이 이루어질 수 있는지 이해하지 못합니다. 나는 또 다른 작은 뷰포트를 만들고 거기에 축을 그리는 아이디어를 가지고 있었지만 나는 그것에 많은 어려움을 겪었고 그 아이디어를 버렸다. 아마도 당신이 어디에 내가 같은 창 (나는 MFC를 사용하여)에 여러 viewports 사용법을 공부할 수있는 곳으로 나를 가리킬 수 있습니다. 다시 한 번 감사드립니다! – user2415320
가상 장면은 공식적인 용어가 아니며 설명 된 접근 방식에 대한 나의 용어였습니다. 더 작은 뷰포트를 사용하는 것은 그리 많지 않습니다. 렌더링하고자하는 좌표로 SetViewport를 호출하면 렌더링하기 전에 Clear를 호출하여 z 버퍼를 지우고 싶을 것입니다. 이제 뷰포트가 화면의 해당 하위 영역으로 설정되도록 설정 한 렌더링이 수행됩니다. – mattnewport
좋아요! 나는 그것을 줄 것이다. 나는 또한 며칠 전에 그것을 시도했지만, 나는 이제 무엇이 잘못되었는지 이해한다고 생각한다. 나는 계속 너를 게시 할 것이다. – user2415320