Я пытаюсь имитировать закон универсальной гравитации Ньютона. Я уже создал частицы и добавил функции чертежа. Я не могу найти, почему я вижу только белое окно. < /P>
#include
#include
#include /* srand, rand */
#include /* time */
#include
#include
#include
#include
using namespace std;
GLfloat xRotated, yRotated, zRotated;
#define WIDTH 800
#define HEIGHT 1200
#define RAD 2000
// 6.67259(30)*10^-11 N(m/kg)^2
// mi escala sera la proporcion de 1 a 1 millón de toneladas.
#define GE 6.67259
void init(void)
{
glClearColor(0,1,0,0);
}
typedef struct particulas{
float x,y,z; // se va a comenza
float factor;
void Drawparticulas();
particulas(float px,float py,float pz,float pfactor){
x=px;
y=py;
z=pz;
factor=pfactor;
}
};
void particulas::Drawparticulas()
{
// clear the drawing buffer.
glPushMatrix();
//glLoadIdentity();
glTranslatef(x,y,z);
//escala al tamaño pedido
glScalef(factor,factor,factor);
glBegin(GL_QUADS); // Draw The Cube Using quads
glColor3f(0.0f,1.0f,0.0f); // Color Blue
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f); // Color Orange
glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f); // Color Red
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f); // Color Yellow
glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
glColor3f(0.0f,0.0f,1.0f); // Color Blue
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f); // Color Violet
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
glEnd(); // End Drawing The Cube
glPopMatrix();
}
vector mundo;
void Muevelos()
{
//Dibujo las lineas del inicio
glBegin(GL_LINES);
glVertex3f(-RAD, -RAD, 0.0f);
glVertex3f(RAD, -RAD, 0.0f);
glVertex3f(RAD, -RAD, 0.0f);
glVertex3f(RAD, RAD, 0.0f);
glVertex3f(RAD, RAD, 0.0f);
glVertex3f(-RAD, RAD, 0.0f);
glVertex3f(-RAD, RAD, 0.0f);
glVertex3f(-RAD, -RAD, 0.0f);
glEnd();
for(int i=0;iDrawparticulas();
}
}
// Not using this yet
void animation(void)
{
for(int i=1;ix-mundo->x;
float yd = mundo[0]->y-mundo->y;
float zd = mundo[0]->x-mundo->x;
float Distance = sqrt(xd*xd + yd*yd + zd*zd);
// Ill apply the newtons law.
//(mi*m2/D)g
float F=(mundo[0]->factor*mundo[0]->factor/Distance)*GE;
//Normalized Vector
float nx,ny,nz;
nx=mundo->x/Distance;
ny=mundo->y/Distance;
nz=mundo->z/Distance;
mundo->x+=F*nx;
mundo->y+=F*ny;
mundo->z+=F*nz;
}
}
void reshape(int x, int y)
{
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(100.0,(GLdouble)x/(GLdouble)y,0,1000);
glMatrixMode(GL_MODELVIEW);
gluLookAt(-600,-600 , -600,
0, 0, 0,
0, 1, 0
);
glViewport(0,0,x,y); //Use the whole window for rendering
}
int main(int argc, char** argv){
mundo.resize(20);
mundo[0]=new particulas(0,0,0,2); // centro
for(int i=1;i
Подробнее здесь: https://stackoverflow.com/questions/232 ... draw-on-it
OpenGL/GLUT не может нарисовать на нем ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение