# space transformations

This topic is 3554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I just started learning about Direct3D and 3D graphics in general. I was wondering why when you render something simple, like a triangle, you don't have to go through all the transformations in order to see in on the screen. That is, why don't you have to transform from local space->world space->view space->etc. It seems that direct3D already has a default state?

##### Share on other sites
Which triangle do you mean? If you are talking about simple 2D triangle, you don't need to do any transformations because you enter screen-space coordinates (it is what you get after all transformations from world-space).

##### Share on other sites
Yes I'm talking about a simple 2D triangle. I'm just confused on what happens when you give the coordinates for a triangle to Direct3D. How does Direct3D decide what part of the screen in visible?

##### Share on other sites
If you specify the triangle as being in clip space (eg. D3DFVF_XYZRHW), the you are signalling to DirectX that the triangle has already undergone transformations - and doesn't need to go through local->world->view, etc.

##### Share on other sites
This is from an example and it uses D3DFVF_XYZ. The only transformation the code performs is a projection using D3DXMatrixPerspectiveFovLH. Now since no view transformation was performed, where is "the camera" located, how does direct3d determine this?

##### Share on other sites
As my opinion, use D3DXMatrixLookAtLH can create a matrix which transform the vertex from world space to view space,the D3DXMatrixPerspectiveFovLH will generate the matrix of 3d space to 2d Homogeneous Clip Space ,and the local space to world space matrix is just created by yourself.Last, the following operation will transform your 3d space vertex to 2d screan:

ProjectedVertex = your3Dvertex * ( WorldMatrix * ViewMatrix * ProjectionMatrix);

ScreenX= ProjectedVertex .x * ViewportWidth/2 + ViewportLeft + ViewportWidth / 2
ScreenY= -ProjectedVertex .y * ViewportHeight/2 + ViewportTop+ ViewportHeight/ 2

However ,D3D can handle these operation for you automaticly,you just simply inform d3d which type of matrix you want to specify by calling the "SetTransform" and put the correct parameter to it.

##### Share on other sites
Quote:
 Original post by subfloodThis is from an example and it uses D3DFVF_XYZ. The only transformation the code performs is a projection using D3DXMatrixPerspectiveFovLH. Now since no view transformation was performed, where is "the camera" located, how does direct3d determine this?

The camera is located at (0,0,0), facing down the postive Z axis.

Direct3D doesn't need to know where the camera "is", since the location of the camera has no meaning (the location of the camera, relative to what?). Once everything is transformed to view space, the camera is defined to be at the origin, facing down the positive Z axis. That's what view transform does - moves everything around so that the camera sits at the origin.

##### Share on other sites

This topic is 3554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628658
• Total Posts
2984071

• 10
• 9
• 9
• 10
• 21