Jeff Molofee - NeHe's OpenGL Tutorials

Здесь есть возможность читать онлайн «Jeff Molofee - NeHe's OpenGL Tutorials» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

NeHe's OpenGL Tutorials: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «NeHe's OpenGL Tutorials»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

NeHe's OpenGL Tutorials — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «NeHe's OpenGL Tutorials», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

glColor3f(0.0f,1.0f,0.0f); // Set Left Point Of Triangle To Green

glVertex3f(-1.0f,-1.0f, 0.0f); // Second Point Of The Triangle

glColor3f(0.0f,0.0f,1.0f); // Set Right Point Of Triangle To Blue

glVertex3f( 1.0f,-1.0f, 0.0f); // Third Point Of The Triangle

glEnd(); // Done Drawing The Triangle

You'll notice in the code below, that we've added another glLoadIdentity(). We do this to reset the view. If we didn't reset the view. If we translated after the object had been rotated, you would get very unexpected results. Because the axis has been rotated, it may not be pointing in the direction you think. So if we translate left on the X axis, we may end up moving up or down instead, depending on how much we've rotated on each axis. Try taking the glLoadIdentity() line out to see what I mean.

Once the scene has been reset, so X is running left to right, Y up and down, and Z in and out, we translate. You'll notice we're only moving 1.5 to the right instead of 3.0 like we did in the last lesson. When we reset the screen, our focus moves to the center of the screen. meaning we're no longer 1.5 units to the left, we're back at 0.0. So to get to 1.5 on the right side of zero we dont have to move 1.5 from left to center then 1.5 to the right (total of 3.0) we only have to move from center to the right which is just 1.5 units.

After we have moved to our new location on the right side of the screen, we rotate the quad, on the X axis. This will cause the square to spin up and down.

glLoadIdentity(); // Reset The Current Modelview Matrix

glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0

glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis ( NEW )

This section of code remains the same. It draws a blue square made from one quad. It will draw the square on the right side of the screen in it's rotated position.

glColor3f(0.5f,0.5f,1.0f); // Set The Color To A Nice Blue Shade

glBegin(GL_QUADS); // Start Drawing A Quad

glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left Of The Quad

glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right Of The Quad

glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right Of The Quad

glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left Of The Quad

glEnd(); // Done Drawing The Quad

The next two lines are new. Think of rtri, and rquad as containers. At the top of our program we made the containers (GLfloat rtri, and GLfloat rquad). When we built the containers they had nothing in them. The first line below ADDS 0.2 to that container. So each time we check the value in the rtri container after this section of code, it will have gone up by 0.2. The rquad container decreases by 0.15. So every time we check the rquad container, it will have gone down by 0.15. Going down will cause the object to spin the opposite direction it would spin if you were going up.

Try chaning the + to a – in the line below see how the object spins the other direction. Try changing the values from 0.2 to 1.0. The higher the number, the faster the object will spin. The lower the number, the slower it will spin.

rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW )

rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW )

return TRUE; // Keep Going

}

Finally change the code to toggle window / fullscreen mode so that the title at the top of the window is proper.

if (keys[VK_F1]) // Is F1 Being Pressed?

{

keys[VK_F1]=FALSE; // If So Make Key FALSE

KillGLWindow(); // Kill Our Current Window

fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode

// Recreate Our OpenGL Window ( Modified )

if (!CreateGLWindow("NeHe's Rotation Tutorial",640,480,16,fullscreen)) {

return 0; // Quit If Window Was Not Created

}

}

In this tutorial I have tried to explain in as much detail as possible, how to rotate objects around an axis. Play around with the code, try spinning the objects, on the Z axis, the X & Y, or all three :) If you have comments or questions please email me. If you feel I have incorrectly commented something or that the code could be done better in some sections, please let me know. I want to make the best OpenGL tutorials I can. I'm interested in hearing your feedback.

Jeff Molofee (NeHe)

* DOWNLOAD Visual C++Code For This Lesson.

* DOWNLOAD ASMCode For This Lesson. (Conversion by Foolman)

* DOWNLOAD Borland C++ Builder 5.0Code For This Lesson. (Conversion by Neil Flynn)

* DOWNLOAD Code Warrior 5Code For This Lesson. (Conversion by Scott Lupton)

* DOWNLOAD CygwinCode For This Lesson. (Conversion by Stephan Ferraro)

* DOWNLOAD DelphiCode For This Lesson. (Conversion by Peter De Jaegher)

* DOWNLOAD Game GLUTCode For This Lesson. (Conversion by Milikas Anastasios)

* DOWNLOAD GenuCode For This Lesson. (Conversion by Louis-Charles Dumais)

* DOWNLOAD GLUTCode For This Lesson. (Conversion by Andy Restad)

* DOWNLOAD IrixCode For This Lesson. (Conversion by Lakmal Gunasekara)

* DOWNLOAD JavaCode For This Lesson. (Conversion by Jeff Kirby)

* DOWNLOAD Jedi-SDLCode For This Lesson. (Conversion by Dominique Louis)

* DOWNLOAD LinuxCode For This Lesson. (Conversion by Richard Campbell)

* DOWNLOAD Linux/GLXCode For This Lesson. (Conversion by Mihael Vrbanec)

* DOWNLOAD Linux/SDLCode For This Lesson. (Conversion by Ti Leggett)

* DOWNLOAD Mac OSCode For This Lesson. (Conversion by Anthony Parker)

* DOWNLOAD Mac OS X/CocoaCode For This Lesson. (Conversion by Bryan Blackburn)

* DOWNLOAD MASMCode For This Lesson. (Conversion by Nico (Scalp))

* DOWNLOAD Power BasicCode For This Lesson. (Conversion by Angus Law)

* DOWNLOAD PythonCode For This Lesson. (Conversion by John)

* DOWNLOAD SolarisCode For This Lesson. (Conversion by Lakmal Gunasekara)

* DOWNLOAD Visual BasicCode For This Lesson. (Conversion by Ross Dawson)

* DOWNLOAD Visual FortranCode For This Lesson. (Conversion by Jean-Philippe Perois)

Lesson 05

Expanding on the last tutorial, we'll now make the object into TRUE 3D object, rather than 2D objects in a 3D world. We will do this by adding a left, back, and right side to the triangle, and a left, right, back, top and bottom to the square. By doing this, we turn the triangle into a pyramid, and the square into a cube.

We'll blend the colors on the pyramid, creating a smoothly colored object, and for the square we'll color each face a different color.

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glLoadIdentity(); // Reset The View

glTranslatef(-1.5f,0.0f,-6.0f); // Move Left And Into The Screen

glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Pyramid On It's Y Axis

glBegin(GL_TRIANGLES); // Start Drawing The Pyramid

A few of you have taken the code from the last tutorial, and made 3D objects of your own. One thing I've been asked quite a bit is "how come my objects are not spinning on their axis? It seems like they are spinning all over the screen". In order for your object to spin around an axis, it has to be designed AROUND that axis. You have to remember that the center of any object should be 0 on the X, 0 on the Y, and 0 on the Z.

The following code will create the pyramid around a central axis. The top of the pyramid is one high from the center, the bottom of the pyramid is one down from the center. The top point is right in the middle (zero), and the bottom points are one left from center, and one right from center.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «NeHe's OpenGL Tutorials»

Представляем Вашему вниманию похожие книги на «NeHe's OpenGL Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Jeff Jacobson - Sleep Tight
Jeff Jacobson
Jeff Salyards - Veil of the Deserters
Jeff Salyards
Jeff LaSala - The Darkwood Mask
Jeff LaSala
Jeff Lindsay - Dexter's Final Cut
Jeff Lindsay
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
libcat.ru: книга без обложки
Неизвестный Автор
Отзывы о книге «NeHe's OpenGL Tutorials»

Обсуждение, отзывы о книге «NeHe's OpenGL Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x