Andy Pike - DirectX 8 Programming Tutorial
Здесь есть возможность читать онлайн «Andy Pike - DirectX 8 Programming Tutorial» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:DirectX 8 Programming Tutorial
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:5 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 100
- 1
- 2
- 3
- 4
- 5
DirectX 8 Programming Tutorial: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «DirectX 8 Programming Tutorial»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
DirectX 8 Programming Tutorial — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «DirectX 8 Programming Tutorial», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
m_pCube5->Render();
The full new render method for this tutorial is shown below. One thing to note is that I have moved the code from SetupPerspective() into the SetupCamera() function (just trying to keep the code simple).
void CGame::Render() {
D3DXMATRIX matRotationX, matRotationY, matRotationZ, matRotationUser1;
D3DXMATRIX matMoveRight27, matMoveLeft27, matMoveRight9, matMoveLeft9, matMoveDown15, matMoveUp15;
D3DXMATRIX matTransformation2, matTransformation3, matTransformation4, matTransformation5;
D3DXMATRIX matScaleUp1p5;
if (m_pD3DDevice == NULL) {
return;
}
//Clear the back buffer and depth buffer
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
//Begin the scene
m_pD3DDevice->BeginScene();
//Setup camera and perspective
SetupCamera();
//Create the rotation transformation matrices around the x, y and z axis
D3DXMatrixRotationX(&matRotationX, timeGetTime()/400.0f);
D3DXMatrixRotationY(&matRotationY, timeGetTime()/400.0f);
D3DXMatrixRotationZ(&matRotationZ, timeGetTime()/400.0f);
//Create the rotation transformation matrices around our user defined axis
D3DXMatrixRotationAxis(&matRotationUser1, &D3DXVECTOR3(1.0f, 1.0f, 0.0f), timeGetTime()/400.0f);
//Create the translation (move) matrices
D3DXMatrixTranslation(&matMoveRight27, 27.0, 0.0, 0.0);
D3DXMatrixTranslation(&matMoveLeft27, –27.0, 0.0, 0.0);
D3DXMatrixTranslation(&matMoveRight9, 9.0, 0.0, 0.0);
D3DXMatrixTranslation(&matMoveLeft9, –9.0, 0.0, 0.0);
D3DXMatrixTranslation(&matMoveDown15, 0.0, –15.0, 0.0);
D3DXMatrixTranslation(&matMoveUp15, 0.0, 15.0, 0.0);
//Create a scale transformation
D3DXMatrixScaling(&matScaleUp1p5, 1.5, 1.5, 1.5);
//Combine the matrices to form 4 transformation matrices
D3DXMatrixMultiply(&matTransformation2, &matMoveRight9, &matRotationY);
D3DXMatrixMultiply(&matTransformation2, &matTransformation2, &matMoveLeft9);
D3DXMatrixMultiply(&matTransformation3, &matMoveLeft9, &matRotationZ);
D3DXMatrixMultiply(&matTransformation3, &matTransformation3, &matMoveRight9);
D3DXMatrixMultiply(&matTransformation4, &matMoveLeft27, &matRotationUser1);
D3DXMatrixMultiply(&matTransformation4, &matTransformation4, &matMoveRight27);
D3DXMatrixMultiply(&matTransformation5, &matMoveDown15, &matRotationY);
D3DXMatrixMultiply(&matTransformation5, &matTransformation5, &matRotationX);
D3DXMatrixMultiply(&matTransformation5, &matTransformation5, &matRotationZ);
D3DXMatrixMultiply(&matTransformation5, &matTransformation5, &matMoveUp15);
D3DXMatrixMultiply(&matTransformation5, &matTransformation5, &matScaleUp1p5);
//Apply the transformations and render our objects
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matRotationX);
m_pCube1->Render();
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTransformation2);
m_pCube2->Render();
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTransformation3);
m_pCube3->Render();
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTransformation4);
m_pCube4->Render();
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTransformation5);
m_pCube5->Render();
//End the scene
m_pD3DDevice->EndScene();
//Filp the back and front buffers so that whatever has been rendered on the back buffer
//will now be visible on screen (front buffer).
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
//Count Frames
m_dwFrames++;
}
Once you have made these changes, you should finish up with five rotating cubes (shown below).
In this tutorial we learnt what a matrix is, how matrices work and how to multiply them together. We also saw how to use transformation matrices in our DirectX applications. In the next tutorial we'll take a look a textures.
DirectX Tutorial 6: Textures
In this tutorial we will learn about textures, what they are and how to use them. Textures can be used to add realism to your scenes. From our example from the last tutorial, we will add a different texture to each rotating cube, numbering them from 1 to 5 in different colours. You can download the full source code by clicking the "Download Source" link above.
A texture in 3D graphics is a 2D bitmap that can be applied to a polygon (or a number of polygons) to increase realism. For example, lets say that you want to have a brick wall in your scene. You could create a square object in front of the camera and colour it red. Hmm… that looks more like a red square than a brick wall, what you really want to see are the bricks and maybe a window. You can do this using textures. All you need is an object (your square) and a wall texture. You can create your texture in any art package that will save .bmp files, I use Adobe Photoshop but you can use any software you like, even Microsoft Paint that comes with Windows.
You can create a texture in any size you like. But to improve efficiency you should (where possible) keep your textures small and square and to a power of 2: 16×16, 32×32, 64×64, 128×128, 256×256 etc. 256×256 is the most efficient size, but only use this size of texture if you need to. Remember: the smaller the texture, the better.
What are texture coordinates? Well, texture coordinates are used to specify a point on a texture. Because a texture is 2D we only need two values to specify any point: U and V. U is the number of units across (columns) and V is the number of units down (rows). The values of U and V should be between 0 and 1 (you can specify other values to create special effects, more on this later). The top left corner of the texture is (0, 0) and the bottom right corner is (1, 1) in the form (U, V). Fig 6.1 below shows the texture coordinates of nine points of a texture.
Fig 6.1
Now that we know about texture coordinates, we can apply our texture to an object in our scene, this is called Texture Mapping. The process of texture mapping is to map texture coordinates to vertices in a scene, therefore each vertex will have two extra values, U and V. Fig 6.2 below, shows an example of mapping a texture on to a cube. The example uses one texture placed on each side of a cube. The cubes vertices have been numbered in the same way as our cube structure in http://www.andypike.com/tutorials/directx8/003.htm and our code for this tutorial.
Therefore, the texture coordinates for each vertex are as follows (where vertex number = (U, V)):
0 = (0, 1) 9 = (0, 0)
1 = (0, 0) 10 = (1, 1)
2 = (1, 1) 11 = (1, 0)
3 = (1, 0) 12 = (0, 1)
4 = (0, 1) 13 = (0, 0)
5 = (0, 0) 14 = (0, 1)
6 = (1, 1) 15 = (0, 0)
7 = (1, 0) 16 = (1, 1)
8 = (0, 1) 17 = (1, 0)
Читать дальшеИнтервал:
Закладка:
Похожие книги на «DirectX 8 Programming Tutorial»
Представляем Вашему вниманию похожие книги на «DirectX 8 Programming Tutorial» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «DirectX 8 Programming Tutorial» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.