|
Author Topic:   Transformations
Cthulhu
Member
posted January 27, 2000 07:53 AM            
If I multiply matrices so that

t = world*camera
t = t*projection

and then transform vertices with matrix t, and pass them to d3d as transformed vertices, shouldn't that be the same as to pass original vertices as untransformed. However, something goes wrong and everything crashes.

IP:

Tim
Member
posted February 21, 2000 03:57 AM            
You still need the perspective divide and viewport transform.


masterMatrix = objectMatrix * eyeMatrix * perspecitveMatrix;


eyespacePoint = vertex * masterMatrix;

rhw= 1.0/eyespacePoint.w;
x = eyeSpacePoint.x*rhw;
y = eyeSpacePoint.x*rhw;
z = eyeSpacePoint.x*rhw;

x = x * viewportWidth/2;
y = y * viewportWidth/2; (yes, width, it keeps things from distoring due to rectangle window sizes)

x += viewportWidth/2;
y += viewportHeight/2;

D3D then gets:
x, y, z, rhw

Note also that for transformed vertices in D3D, you have to clip against w=0. D3D doesn't handle negative rhw's well at all. In fact the entire primitive call may fail to render, even if only one vertex in it had a negative rhw.
You are better off sending untransformed vertices, since D3D can perform CPU specific optimizations to help speed up stuff... and it'll clip things for you.

IP:

Cthulhu
Member
posted February 21, 2000 05:17 AM            
I already got it working but thanks anyway. It was just DrawPrims tutorial that had things made wrong in it.

I'm not currently clipping negative rhw's, that could explain some crashes. When/how does rhw go negative?

I want to transform my own vertices because of some optimizations (which I haven't yet done

IP:

Tim
Member
posted February 22, 2000 05:00 PM            
It's better to do high-level culling, and let the underlying API handle the rest. Since in D3D, you can get the T&L interface and have hardware do transforms faster than you could ever possibly do in software.

One can cull large groups of triangles with the 'cone of normals' technique, and many other schemes.

IP:

Cthulhu
Member
posted February 23, 2000 05:01 AM            
I chose to let D3D handle the transformations since current changes made some optimizations impossible. As you mentioned that also makes T&L support easier to implement.

"One can cull large groups of triangles with the 'cone of normals' technique, and many other schemes."

I'd like to hear more about that. Currently I calculate dot product of camera to triangle vector and triangle normal. It's not very fast.

IP:

Tim
Member
posted February 23, 2000 02:59 PM            

A cone of normals is defined by taking a group of faces (connected or not), that have similar normals within some tolerance. You can then accept reject a whole group of triangles early by doing one dot product and a test.

'coneNormal' is defined as the average normal of all the grouped triangles.

When doing culling, rotate the coneNormal just like you would any point on your object (but without translation)


then compute an angle:
angle = viewDirection dot coneNormal

and compare

if (angle > 0.9659258) (cosine of 15 degrees)
then you can accept it and draw. this means the 'cone' is facing towards the camera enough for some of the triangles to be visible.


IP:

Cthulhu
Member
posted February 23, 2000 04:43 PM            
Never thought of anything like that, I'll have to see if it fits to my engine. Thanks.

IP: