space transformations

Started by
5 comments, last by Sc4Freak 16 years ago
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?
Advertisement
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).
-----KEXIK - Reversity Studios (www.reversity.org)
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?
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.
NextWar: The Quest for Earth available now for Windows Phone 7.
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?
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.
Quote:Original post by subflood
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?

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.
NextWar: The Quest for Earth available now for Windows Phone 7.

This topic is closed to new replies.

Advertisement