Esta es una pagina de Tecnologia

sábado, 21 de septiembre de 2019

Sistema Solar en OpenGL

Hola aquí les traigo el código del sistema solar en OpenGL  ...espero que les sirva...


#include<windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>
#include<time.h>
#include <math.h>

int rad=100;


void circuloc(int x, int y, int t, int radio)
{
    int angulo=0;
    glPointSize(t);
    glBegin(GL_POINTS);
    glVertex2f(x,y);
    for(angulo=0;angulo<=360;angulo+=1)
    {

        glVertex2f(x+sin(angulo)*radio,y+cos(angulo)*radio);

    }
    glEnd();
}


void dibujar()
{
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glColor3f(1.0,0.0,0.0);
        glColor3f(1.0,1.0,1.0);

        circuloc(0,0,1,310);
        circuloc(0,0,1,280);
        circuloc(0,0,1,250);
        circuloc(0,0,1,220);
        circuloc(0,0,1,190);
        circuloc(0,0,1,160);
        circuloc(0,0,1,130);
        circuloc(0,0,1,100);
        circuloc(0,0,1,70);


}

      // inicializando de variables

      GLfloat rotA=0,rot1=0,rot2=0,rot3=0,rot4=0,rot5=0,rot6=0,rot7=0,rot8=0;
      GLfloat rdS=30,
        rd1=6,
        rd2=12,
        rd3=9,
        rd4=6,
        rd5=18,
        rd6=15,
        rd7=12,
        rd8=12;
      GLfloat posx=0,posz=0;

//Inicializacion de variables para iluminacion

      GLfloat mat_diffuse [] = {0.0, 0.0, 0.0, 1.0};
      GLfloat mat_specular [] = {0.5, 0.5, 0.5, 1.0};
      GLfloat mat_shininess [] = {50};
      GLfloat mat_emission [] = {0.5, 0.2, 0.2, 1.0};

void resize(int width, int height)
{
    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-300,300,-300,300,-300,300);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();//matriz identidad
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

}

        //iluminacion

void iluminacion ()
{
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0,GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);

}

    //CREACION DE LOS PLANETAS

void sol()
{
     glColor3f(1.0,1.0,0.0);
     glutSolidSphere(rdS,60,60);
}
void mercurio()
{
     glColor3f(0.4,0.4,0.4);
     glutSolidSphere(rd1,60,60);
}
void venus()
{
     glColor3f(1.0,0.2,0.0);
     glutSolidSphere(rd2,60,60);
}
void tierra()
{
     glColor3f(0.0,0.4,1.0);
     glutSolidSphere(rd3,60,60);
}
void marte()
{
     glColor3f(0.2,0.4,0.3);
     glutSolidSphere(rd4,60,60);
}
void jupiter()
{
     glColor3f(0.2,0.2,0.2);
     glutSolidSphere(rd5,60,60);
}
void saturno()
{
     glColor3f(1.0,0.4,0.0);
     glutSolidSphere(rd6,60,60);
}
//----------------------------------//
void urano()
{
     glColor3f(0.2,1.0,0.2);
     glutSolidSphere(rd7,60,60);
}
void anillos()
{
     glColor3f(1,0.6,0);
     glRotatef(rotA,1,0,1);
     glutSolidTorus(3, 20, 10,50);
}
//----------------------------------//
void neptuno()
{
     glColor3f(0.0,0.0,1.0);
     glutSolidSphere(rd8,60,60);
}

//-------------------------------------//


    //CREACION DE LA ESCENA

void display()
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glLoadIdentity();
     gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
     iluminacion ();
    dibujar();
     sol();

     glPushMatrix();
     glRotatef(rot1,0,1,0);
     glTranslatef(-40,0,0); //rotacion y traslacion para mercurio
     mercurio();
     glPopMatrix();

     glPushMatrix();
     glRotatef(rot2,0,1,0);
     glTranslatef(60,0,0);//rotacion y traslacion para mercurio
     venus();
     glPopMatrix();

     glPushMatrix();
     glRotatef(rot3,0,1,0);
     glTranslatef(0,0,-80);//rotacion y tralacion para tierra
     tierra();
     glPopMatrix();

     glPushMatrix();
     glRotatef(rot4,0,1,0);
     glTranslatef(100,0,0);//rotacion y traslacion para marte
     marte();
     glPopMatrix();

     glPushMatrix();
     glRotatef(rot5,0,1,0);
     glTranslatef(-120,0,0);//rotacion y traslacion para jupiter
     jupiter();
     glPopMatrix();

     glPushMatrix();
     glRotatef(rot6,0,1,0);
     glTranslatef(0,0,160);//rotacion y traslacion para saturno y anillo
     saturno();
     anillos();
     glPopMatrix();


     glPushMatrix();
     glRotatef(rot7,0,1,0);
     glTranslatef(-170,0,0);//rotacion y traslacion para urano
     urano();
     glPopMatrix();

     glPushMatrix();
     glRotatef(rot8,0,1,0);
     glTranslatef(190,0,0);//rotacion y traslacion para neptuno
     neptuno();
     glPopMatrix();

     rotA=rotA+0.03;
     rot1=rot1+0.1;
     rot2=rot2+0.015;
     rot3=rot3+0.013;
     rot4=rot4+0.05;
     rot5=rot5+0.04;
     rot6=rot6+0.03;
     rot7=rot7+0.02;
     rot8=rot8+0.01;

     glutSwapBuffers();
}

    //MANEJO DE CAMARA

void key(unsigned char key, int x, int y)    //funcion para uso del teclado
{
    switch(key)
    {
          case 27 :
            exit(0);
            break;
        default:
            break;
    }

glutPostRedisplay();    //redibuja el display
}


void idle()
{
    glutPostRedisplay();//redibuja el display
}


int main (int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(950,700);//tamaño de la ventana
    glutInitWindowPosition(0,0);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("SISTEMA PLANETARIO SOLAR");
    glClearColor(0,0,0,0);
    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);

    glutMainLoop();
    return 0;
}

Share:

Cubo de Colores OpenGL

Hola aquí les traigo la animación en OpenGL de cubo en rotacion y que cambie de color según va girando...espero que les ayude ;)















El código aqui...

/*
 * OGL02Animation.cpp: 3D Shapes with animation
 */
#include <windows.h>  // for MS Windows
#include <GL/glut.h>  // GLUT, include glu.h and gl.h

/* Global variables */
char title[] = "3D Shapes with animation";
//GLfloat anglePyramid = 0.0f;  // Rotational angle for pyramid [NEW]
GLfloat angleCube = 0.0f;     // Rotational angle for cube [NEW]
int refreshMills = 15;        // refresh interval in milliseconds [NEW]

/* Initialize OpenGL Graphics */
void initGL() {
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
   glClearDepth(1.0f);                   // Set background depth to farthest
   glEnable(GL_DEPTH_TEST);   // Enable depth testing for z-culling
   glDepthFunc(GL_LEQUAL);    // Set the type of depth-test
   glShadeModel(GL_SMOOTH);   // Enable smooth shading
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Nice perspective corrections
}

/* Handler for window-repaint event. Called back when the window first appears and
   whenever the window needs to be re-painted. */
void display() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers
   glMatrixMode(GL_MODELVIEW);     // To operate on model-view matrix

   // Render a color-cube consisting of 6 quads with different colors
   glLoadIdentity();                 // Reset the model-view matrix
   glTranslatef(0.2f, 0.0f, -7.0f);  // Move right and into the screen
   glRotatef(angleCube, 1.0f, 1.0f, 1.0f);  // Rotate about (1,1,1)-axis [NEW]

   glBegin(GL_QUADS);                // Begin drawing the color cube with 6 quads
      // Top face (y = 1.0f)
      // Define vertices in counter-clockwise (CCW) order with normal pointing out
      glColor3f(0.0f, 1.0f, 0.0f);     // Green
      glVertex3f( 1.0f, 1.0f, -1.0f);
      glVertex3f(-1.0f, 1.0f, -1.0f);
      glVertex3f(-1.0f, 1.0f,  1.0f);
      glVertex3f( 1.0f, 1.0f,  1.0f);

      // Bottom face (y = -1.0f)
      glColor3f(1.0f, 0.5f, 0.0f);     // Orange
      glVertex3f( 1.0f, -1.0f,  1.0f);
      glVertex3f(-1.0f, -1.0f,  1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f( 1.0f, -1.0f, -1.0f);

      // Front face  (z = 1.0f)
      glColor3f(1.0f, 0.0f, 0.0f);     // Red
      glVertex3f( 1.0f,  1.0f, 1.0f);
      glVertex3f(-1.0f,  1.0f, 1.0f);
      glVertex3f(-1.0f, -1.0f, 1.0f);
      glVertex3f( 1.0f, -1.0f, 1.0f);

      // Back face (z = -1.0f)
      glColor3f(1.0f, 1.0f, 0.0f);     // Yellow
      glVertex3f( 1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f,  1.0f, -1.0f);
      glVertex3f( 1.0f,  1.0f, -1.0f);

      // Left face (x = -1.0f)
      glColor3f(0.0f, 0.0f, 1.0f);     // Blue
      glVertex3f(-1.0f,  1.0f,  1.0f);
      glVertex3f(-1.0f,  1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f,  1.0f);

      // Right face (x = 1.0f)
      glColor3f(1.0f, 0.0f, 1.0f);     // Magenta
      glVertex3f(1.0f,  1.0f, -1.0f);
      glVertex3f(1.0f,  1.0f,  1.0f);
      glVertex3f(1.0f, -1.0f,  1.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);
   glEnd();  // End of drawing color-cube

   // Render a pyramid consists of 4 triangles
   glLoadIdentity();                  // Reset the model-view matrix
   glTranslatef(-1.5f, 0.0f, -6.0f);  // Move left and into the screen
//   glRotatef(anglePyramid, 1.0f, 1.0f, 0.0f);  // Rotate about the (1,1,0)-axis [NEW]



   glutSwapBuffers();  // Swap the front and back frame buffers (double buffering)

   // Update the rotational angle after each refresh [NEW]
//   anglePyramid += 0.2f;
   angleCube -= 0.15f;
}

/* Called back when timer expired [NEW] */
void timer(int value) {
   glutPostRedisplay();      // Post re-paint request to activate display()
   glutTimerFunc(refreshMills, timer, 0); // next timer call milliseconds later
}

/* Handler for window re-size event. Called back when the window first appears and
   whenever the window is re-sized with its new width and height */
void reshape(GLsizei width, GLsizei height) {  // GLsizei for non-negative integer
   // Compute aspect ratio of the new window
   if (height == 0) height = 1;                // To prevent divide by 0
   GLfloat aspect = (GLfloat)width / (GLfloat)height;

   // Set the viewport to cover the new window
   glViewport(0, 0, width, height);

   // Set the aspect ratio of the clipping volume to match the viewport
   glMatrixMode(GL_PROJECTION);  // To operate on the Projection matrix
   glLoadIdentity();             // Reset
   // Enable perspective projection with fovy, aspect, zNear and zFar
   gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}

/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
   glutInit(&argc, argv);            // Initialize GLUT
   glutInitDisplayMode(GLUT_DOUBLE); // Enable double buffered mode
   glutInitWindowSize(1040, 580);   // Set the window's initial width & height
   glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
   glutCreateWindow(title);          // Create window with the given title
   glutDisplayFunc(display);       // Register callback handler for window re-paint event
   glutReshapeFunc(reshape);       // Register callback handler for window re-size event
   initGL();                       // Our own OpenGL initialization
   glutTimerFunc(0, timer, 0);     // First timer call immediately [NEW]
   glutMainLoop();                 // Enter the infinite event-processing loop
   return 0;
}
Share:

Filmora Edición Profesional

Hola aquí les traigo un tutorial en el cual les muestro como realizar un vídeo profesional rápidamente en Filmora para todos aquellos que quieran centrar en el mundo de la edición..
Esta es una forma sencilla de realizar un vídeo.

Share:

BTemplates.com

Buscar este blog

Archivo del blog

Con la tecnología de Blogger.