Показать сообщение отдельно
Старый 17.03.2011, 12:19   #17
ІГРОГРАЙКО
ПроЭктировщик
 
Аватар для ІГРОГРАЙКО
 
Регистрация: 20.06.2009
Адрес: Україна
Сообщений: 152
Написано 10 полезных сообщений
(для 24 пользователей)
Радость Ответ: Volume Rendering на XNA (Texture3D)

Сделал я то что думал.
И вот как оно виглядит:

Нажмите на изображение для увеличения
Название: capture1.jpg
Просмотров: 1384
Размер:	32.1 Кб
ID:	12993

У клас Volume.cs дописал:
VertexBuffer vertexBufferNX;
VertexBuffer vertexBufferNY;
VertexBuffer vertexBufferNZ;

VertexPositionColor[] pointListNX;
VertexPositionColor[] pointListNY;
VertexPositionColor[] pointListNZ;

int pointsNX;
int pointsNY;
int pointsNZ;

short[] triangleStripIndicesNX, triangleStripIndicesNY, triangleStripIndicesNZ;

...

protected 
override void LoadContent()
{
            
base.LoadContent();

            
pointsNX = 4 * mHeight;
            
pointsNY = 4 * mWidth;
            
pointsNZ = 4 * mDepth;

            
pointListNX = new VertexPositionColor[pointsNX];
            
pointListNY = new VertexPositionColor[pointsNY];
            
pointListNZ = new VertexPositionColor[pointsNZ];

            for (
int ny = 0; ny < mHeight; ny++)
            {
                for (
int nx = 0; nx < 2; nx++)
                {
                    for (
int nz = 0; nz < 2; nz++)
                    {
                        
pointListNX[(ny * 4) + (nx * 2) + nz] = new VertexPositionColor(new Vector3((float)nx, (float)(1.0f / mHeight) * ny, (float)nz),Color.White);
                    }
                }
            }

            for (
int nx = 0; nx < mWidth; nx++)
            {
                for (
int ny = 0; ny < 2; ny++)
                {
                    for (
int nz = 0; nz < 2; nz++)
                    {
                        
pointListNY[(nx * 4) + (ny * 2) + nz] = new VertexPositionColor(new Vector3((float)(1.0f / mWidth) * nx, (float)ny, (float)nz),Color.White);
                    }
                }
            }

            for (
int nz = 0; nz < mDepth; nz++)
            {
                for (
int nx = 0; nx < 2; nx++)
                {
                    for (
int ny = 0; ny < 2; ny++)
                    {
                        
pointListNZ[(nz * 4) + (nx * 2) + ny] = new VertexPositionColor(new Vector3((float)nx, (float)ny, (float)(1.0f / mDepth) * nz),Color.White);
                    }
                }
            }

            
vertexBufferNX = new VertexBuffer(Game.GraphicsDevice, VertexPositionTexture.SizeInBytes * pointListNX.Length, BufferUsage.None);
            
vertexBufferNX.SetData<VertexPositionColor>(pointListNX);

            
vertexBufferNY = new VertexBuffer(Game.GraphicsDevice, VertexPositionTexture.SizeInBytes * pointListNY.Length, BufferUsage.None);
            
vertexBufferNY.SetData<VertexPositionColor>(pointListNY);

            
vertexBufferNZ = new VertexBuffer(Game.GraphicsDevice, VertexPositionTexture.SizeInBytes * pointListNZ.Length, BufferUsage.None);
            
vertexBufferNZ.SetData<VertexPositionColor>(pointListNZ);

            
triangleStripIndicesNX = new short[pointsNX];
            
triangleStripIndicesNY = new short[pointsNY];
            
triangleStripIndicesNZ = new short[pointsNZ];

            for (
int y = 0; y < mHeight; y++)
            {
                for (
int i = 0; i < 4; i++)
                {
                    
triangleStripIndicesNX[(y * 4) + i] = (short)((y * 4) + i);
                }
            }

            for (
int x = 0; x < mWidth; x++)
            {
                for (
int i = 0; i < 4; i++)
                {
                    
triangleStripIndicesNY[(x * 4) + i] = (short)((x * 4) + i);
                }
            }

            for (
int z = 0; z < mDepth; z++)
            {
                for (
int i = 0; i < 4; i++)
                {
                    
triangleStripIndicesNZ[(z * 4) + i] = (short)((z * 4) + i);
                }
            }
} 
И метод отрисовки полигонов:
private void DrawTriangleStrip()
        {
            for (
int i = 0; i < pointListNX.Length; i++)pointListNX[i].Color = new Color(1f,1f,1f,0.01f);

            for (
int nx = 0; nx < mHeight; nx++)
            {
                
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                    
PrimitiveType.TriangleStrip,
                    
pointListNX,
                    
nx*4,  // vertex buffer offset to add to each element of the index buffer
                    
4,  // number of vertices to draw
                    
triangleStripIndicesNX,
                    
nx*4,  // first index element to read
                    
2   // number of primitives to draw
                
);
            }

            for (
int i = 0; i < pointListNY.Length; i++)pointListNY[i].Color = new Color(1f, 1f, 1f, 0.01f);
            for (
int ny = 0; ny < mWidth; ny++)
            {
                
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                    
PrimitiveType.TriangleStrip,
                    
pointListNY,
                    
ny*4,  // vertex buffer offset to add to each element of the index buffer
                    
4,  // number of vertices to draw
                    
triangleStripIndicesNY,
                    
ny*4,  // first index element to read
                    
2   // number of primitives to draw
                
);
            }

            for (
int i = 0; i < pointListNZ.Length; i++)pointListNZ[i].Color = new Color(1f, 1f, 1f, 0.01f);
            for (
int nz = 0; nz < mDepth; nz++)
            {
                
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                    
PrimitiveType.TriangleStrip,
                    
pointListNZ,
                    
nz*4,  // vertex buffer offset to add to each element of the index buffer
                    
4,  // number of vertices to draw
                    
triangleStripIndicesNZ,
                    
nz*4,  // first index element to read
                    
2   // number of primitives to draw
                
);
            }
        } 
Подскажите только как убрать ети светла (R,G,B )???

VolumeRayCasting_101.rar
__________________
Blitz3D, XNA, WebGL, OpenGL, Unity3D
PC: ASUS A55VM Core i3 (2.4Ghz), 6 Gb RAM, Nvidia GF 630M GT 2Gb
(Offline)
 
Ответить с цитированием