|
dev.gamez.lv Latvian Game Developers Community
|
View previous topic :: View next topic |
Author |
Message |
elvman Indago Uzvarētājs
Joined: 09 Apr 2003 Posts: 1278 Location: Kuldiga
|
Posted: Tue Aug 14, 2007 9:58 am Post subject: Pārvietot near clipping plane |
|
Veidojot ūdeni sastapos ar tādu problēmu, ka, lai renderētu ūdens atspulgu, ir jārenderē tikai tas, kas ir virs ūdens. Tā, kā nevarēju izdomāt, kā pārvietot near clipping plane tā, lai tas atrastos uz ūdens virsmas. Pagaidām renderēju visu scēnu, līdz ar to parādās nelieli artefakti un tas aizņem nedaudz vairāk laika.
Tas saucas Oblique Near Clipping Plane, meklēju googlā pēc tutoriāļiem, bet neatradu nevienu tādu tutorial, kur tas būtu jēdzīgi paskaidrots (visi ir vainu par un ap, vai arī ir specifiski kautkādam enginam).
Te būs attēls, kā tam jāizskatās:
Varbūt kāds var ātri iemest kādu koda gabaliņu, vai arī norādīt linku uz jēdzīgu tutorial. _________________ long time; /* know C */ |
|
Back to top |
|
|
elvman Indago Uzvarētājs
Joined: 09 Apr 2003 Posts: 1278 Location: Kuldiga
|
Posted: Tue Aug 14, 2007 9:59 am Post subject: |
|
Ok, atradu ko tādu:
Code: | void CMyD3DApplication::ClipProjectionMatrix(D3DXMATRIXA16 & matView, D3DXMATRIXA16 & matProj,
D3DXPLANE & clip_plane)
{
D3DXMATRIXA16 matClipProj;
D3DXMATRIXA16 WorldToProjection;
WorldToProjection = matView * matProj;
// m_clip_plane is plane definition (world space)
D3DXPlaneNormalize(&clip_plane, &clip_plane);
D3DXMatrixInverse(&WorldToProjection, NULL, &WorldToProjection);
D3DXMatrixTranspose(&WorldToProjection, &WorldToProjection);
D3DXVECTOR4 clipPlane(clip_plane.a, clip_plane.b, clip_plane.c, clip_plane.d);
D3DXVECTOR4 projClipPlane;
// transform clip plane into projection space
D3DXVec4Transform(&projClipPlane, &clipPlane, &WorldToProjection);
D3DXMatrixIdentity(&matClipProj);
if (projClipPlane.w == 0) // or less than a really small value
{
// plane is perpendicular to the near plane
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj);
return;
}
if (projClipPlane.w > 0)
{
// flip plane to point away from eye
D3DXVECTOR4 clipPlane(-clip_plane.a, -clip_plane.b, -clip_plane.c, -clip_plane.d);
// transform clip plane into projection space
D3DXVec4Transform(&projClipPlane, &clipPlane, &WorldToProjection);
}
// put projection space clip plane in Z column
matClipProj(0, 2) = projClipPlane.x;
matClipProj(1, 2) = projClipPlane.y;
matClipProj(2, 2) = projClipPlane.z;
matClipProj(3, 2) = projClipPlane.w;
// multiply into projection matrix
D3DXMATRIXA16 projClipMatrix = matProj * matClipProj;
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &projClipMatrix);
} |
Tas gan ir DX piemērs, bet derēs. _________________ long time; /* know C */ |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Tue Aug 14, 2007 10:07 am Post subject: |
|
hehe, analītiskā ģeometrija - transformācijas, matricas un vektori :) |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|