• Advertisement

Archived

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

User-defined clipping planes

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to emulate the glScissor function in OpenGL with Direct3D 8. After doing some searching for information about clip planes and looking at the sdk sample called clip mirror I''ve managed to set up a clipping rectangle about the origin. Since it''s supposed to be a 2D clipping rectangle I set an orthogonal projection as well as set the planes in screen space, but that is incorrect and nothing is rendered. From what the sample has shown (which is very little) the clip planes must be defined in world space about the origin. Is there a way to translate these planes to a different position? Like instead of the planes being about the origin is it possible to move them to an arbitrary point like (5, 5)?

Share this post


Link to post
Share on other sites
Advertisement
I'm still trying to solve this problem.

So far I've been trying to transform my clip planes using D3DXPlaneTransform. I managed to glean most of this straight from the SDK:

D3DXVECTOR3 eye(0.0, 0.0, 1.0);

D3DXVECTOR3 points[4];
v[0] = D3DXVECTOR3(-1.0, -1.0, 0.0);
v[1] = D3DXVECTOR3( 1.0, -1.0, 0.0);
v[2] = D3DXVECTOR3(-1.0, 1.0, 0.0);
v[3] = D3DXVECTOR3( 1.0, 1.0, 0.0);

D3DXPLANE planes[4];
D3DXPlaneFromPoints(planes[0], &v[1], &v[0], &eye);
D3DXPlaneFromPoints(planes[1], &v[2], &v[1], &eye);
D3DXPlaneFromPoints(planes[2], &v[3], &v[1], &eye);
D3DXPlaneFromPoints(planes[3], &v[2], &v[3], &eye);

// Correct setup a translating matrix to move the planes

D3DXMATRIX translate;
D3DXMatrixTranslation(&translate, x, y, z);

D3DXMatrixInverse(&translate, NULL, &translate);
D3DXMatrixTranspose(&translate, &translate);

// Translate the planes to the correct position

for(int i = 0; i < 4; ++i)
{
D3DXPlaneTransform(&planes[i], &planes[i], &translate);
device->SetClipPlane(i, &planes[i]);
}

device->SetRenderState(D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 |
D3DCLIPPLANE1 | D3DCLIPPLANE2 | D3DCLIPPLANE3);



I must be doing something incorrectly because nothing is renderered. If I place the scissor rectangle at (5, 5, 1) and the rectangle is 20 x 20 in dimension, if I place a point primitive at (5, 5, 1) I do not see it rendered.

Any help would be appreciated.


EDIT
fixed the snippet

[edited by - Zorbfish on June 13, 2004 9:40:08 AM]

Share this post


Link to post
Share on other sites
what graphics card do you have, some geforce MXs don''t suport clipping planes in there drivers (stupidest thing evar!)

ATI fully suports the clipping planes though.

Bobboau, bringing you products that work... in theory

Share this post


Link to post
Share on other sites
Well the thing is that I know my card supports it for three reasons.

One, I''m able to run the clipmirror sample in the DirectX8 SDK.
Secondly I can get the planes to work correctly about the origin. For instance when I place the points I build my planes from at (-1, -1, 1), (1, -1, 1), (-1, 1, 1), (1, 1, 1) and place a point primitive at (0, 0, 1) it renders. And last I have check the device caps and I can support 4 planes.

My video card is a Radeon Mobility 7500.

Share this post


Link to post
Share on other sites
1. Something is wrong with your code because D3DXPlaneFromPoints has four parameters, not three.
2. What does it mean to define a plane "about the origin"? With D3DXPlaneFromPoints, you can define any plane.


John Bolton
Page 44 Studios
Current project: NHL Faceoff 2005 PS2

Share this post


Link to post
Share on other sites
Ah yes, that was my mistake. The last parameter in D3DXPlaneFromPoints would be eye. "About the origin" means in model coordinates. For instance if I build the planes from points like (5, 5, 1), (10, 5, 1), (5, 10, 1), (10, 10, 1) nothing will render.

Share this post


Link to post
Share on other sites

  • Advertisement