#### Archived

This topic is now archived and is closed to further replies.

# Culling problems when doing custom transforms...

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

## Recommended Posts

Hey, I''m having a problem when orientating objects using custom matrices. What I do is pass the rendering core the up and front vectors of the object, and it''s position. This core then builds a matrix out of this, and does a simple glMultMatrixf to apply the transform. Here''s what I do: 1. Apply camera transformation ( uses gluLookAt ) 2. Calculate side vector as front x up 3. Recalculate up as side x front ( to make sure you have an orthogonal frame ) 4. Setup matrix as: [Fx,Sx,Ux,Px] [Fy,Sy,Uy,Py] [Fz,Sz,Uz,Pz] [0,0,0,1] 5. Apply custom matrix Now, for some reason, this screws up the backface culling on the objects. Any ideas on why? Here''s the exact code for you to take a look at, just incase I made a coding mistake...

camera->ApplyTransformation(); // uses gluLookAt

CVector side = front * up;
up = side * front;
float m[16];
m[0] = front.dx;
m[1] = front.dy;
m[2] = front.dz;
m[3] = 0.0f;
m[4] = side.dx;
m[5] = side.dy;
m[6] = side.dz;
m[7] = 0.0f;
m[8] = up.dx;
m[9] = up.dy;
m[10] = up.dz;
m[11] = 0.0f;
m[12] = pos.dx;
m[13] = pos.dy;
m[14] = pos.dz;
m[15] = 1.0f;

glMultMatrixf( m );

Any help is appreciated. - Phil. Death of one is a tragedy, death of a million is just a statistic.

##### Share on other sites
Forget it, I fixed it now. Sorry for wasting your time.

Death of one is a tragedy, death of a million is just a statistic.

##### Share on other sites
Ah bugger, it's not working in certain situations...

It works when I translate objects, and when I rotate them on the XZ plane. It doesn't work however, when I rotate vertically. The objects get deformed when I try to do this, which makes me think that I haven't actually got an orthogonal set of vectors...

Here's the new code that I use, and some screenshots to show you whats happening:

    camera->ApplyTransformation(); // uses gluLookAtCVector side = front * up;up = side * front;float m[16];m[0] = side.dx;m[1] = side.dy;m[2] = side.dz;m[3] = 0.0f;m[4] = up.dx;m[5] = up.dy;m[6] = up.dz;m[7] = 0.0f;m[8] = front.dx;m[9] = front.dy;m[10] = front.dz;m[11] = 0.0f;m[12] = pos.dx;m[13] = pos.dy;m[14] = pos.dz;m[15] = 1.0f;glMultMatrixf( m );

This picture is of a pyramid, rotated on the XZ axis, this isn't deformed at all.

This one, is as above, but rotated down a bit, so it's facing the floor. This is distorted as you can see.

Normalising the frame vectors didn't make a difference...

Does anyone have any ideas on this?

Cheers.

Death of one is a tragedy, death of a million is just a statistic.

[edited by - python_regious on August 13, 2002 7:35:21 PM]

##### Share on other sites
umm...they may be orthogonal, but may be it isn't normalized... |a*b|=|a||b|sin(angle between them)...so if you calculate one by cross producting other 2, must normalize that one (if the angle between the first two is any thing other than 90 or 270 degrees).

sorry, didnt read the end of your post,I suppose this wont help...[/edit]

[edited by - SporadicFire on August 14, 2002 10:17:04 AM]

##### Share on other sites
Check that the (first three, ignore the translation part) rows columns are orthonormal...
The dot product between any 2 different rows (or columns) should be zero, or thereabouts.
The dot product of any row (or column) with itself should be 1 (or thereabouts).

If that aint the case, I would look at the implementation of the cross product (looks like you are overloading operator* to do that), have you coded it correctly?

I have used the exact same method you describe for building the matrices, worked fine for me.

##### Share on other sites
Yeah, I missed out a minus on the cross product, which screwed it all up. Cheers.

Death of one is a tragedy, death of a million is just a statistic.

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 12
• 12
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632655
• Total Posts
3007670
• ### Who's Online (See full list)

There are no registered users currently online

×