Модератор: Mikle
Dim mtrx As D3DMATRIX
With mtrx
.m11 = 0.5
.m12 = 0#
.m13 = 0#
.m14 = 0#
.m21 = 0#
.m22 = -0.5
.m23 = 0#
.m24 = 0#
.m31 = 0#
.m32 = 0#
.m33 = 1#
.m34 = 0#
.m41 = 0.5
.m42 = 0.5
.m43 = 0#
.m44 = 1#
End With
D3DDevice.SetTransform D3DTS_TEXTURE1,mtrx
D3DDevice.SetRenderState D3DRS_CULLMODE,D3DCULL_NONE
D3DDevice.SetTextureStageState 1,D3DTSS_COLOROP,D3DTOP_ADDSMOOTH
D3DDevice.SetTextureStageState 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2
D3DDevice.SetTextureStageState 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
D3DDevice.SetRenderState D3DRS_NORMALIZENORMALS, 1
D3DDevice.SetTexture 1,mSphere_Tex
'//Воспомагательная функция...
Public Function GetCubeMatrix(mFace As Long) As D3DMATRIX
Dim i As Long
Dim vEnvEye As D3DVECTOR, vLookat As D3DVECTOR, vUp As D3DVECTOR
Select Case mFace
Case D3DCUBEMAP_FACE_POSITIVE_X
Case D3DCUBEMAP_FACE_POSITIVE_X:
vLookat.x = 1#: vUp.y = 1#
Case D3DCUBEMAP_FACE_NEGATIVE_X:
vLookat.x = -1#: vUp.y = 1#
Case D3DCUBEMAP_FACE_POSITIVE_Y:
vLookat.y = 1#: vUp.z = -1#
Case D3DCUBEMAP_FACE_NEGATIVE_Y:
vLookat.y = -1#: vUp.z = 1#
Case D3DCUBEMAP_FACE_POSITIVE_Z:
vLookat.z = 1#: vUp.y = 1#
Case D3DCUBEMAP_FACE_NEGATIVE_Z:
vLookat.z = -1#: vUp.y = 1#
End Select
Dim tmpMat As D3DMATRIX
D3DXMatrixLookAtLH tmpMat, vEnvEye, vLookat, vUp
GetCubeMatrix = tmpMat
End Function
'/Рендер в CubeMap
Public Sub RenderToEnvMap()
Dim mView_S As D3DMATRIX, mProj_S As D3DMATRIX
'//Сохраняем трансформации
mView_S = D3DDevice.GetTransform(D3DTS_VIEW)
mProj_S = D3DDevice.GetTransform(D3DTS_PROJECTION)
'//Теперь устанавливаем матрицу проэкции
D3DXMatrixPerspectiveFovLH matProj,Pi/2, 1, 0.5, 1000
D3DDevice.SetTransform D3DTS_PROJECTION,matProj
matView.m41 = 0: matView.m42 = 0: matView.43 = 0
'//Сохраняем буферы
Dim zB as Direct3DSurface8,bB As Direct3DSurface8
Set zB = D3DDevice.GetRenderTarget()
Set bB = D3DDevice.GetDepthStencilSurface()
'//Теперь рендерим изображение в 6 поверхностей:
Dim i As Integer
For i = 0 To 6
Dim mView As D3DMATRIX
'//Применяем ранее обявленую функцию для получения матрицы
mView = GetCubeMatrix(i)
D3DXMatrixMultiply mView,matView,mView
D3DDevice.SetTransform D3DTS_VIEW, mView
'//Теперь устанавливаем нужную поверхность, как цель для рендеринга
Dim mCubeSurf As Direct3DSurface8
Set mCubeSurf = CubeMap.GetCubeMapSurface(i,0)
D3DDevice.SetRenderTarget mCubeSurf, zB, 0
Set mCubeSurf = Nothing
'//Рендерим сцену, без объекта
D3DDevice.BeginScene
Call RenderScene(False)
D3DDevice.EndScene
Next i
End Sub
- Код: Выделить всё
'//Теперь рендерим изображение в 6 поверхностей:
Dim i As Integer
For i = 0 To 6
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2