Accueil > > > OPENGL : GALAXIE
OPENGL : GALAXIE
Information sur la source
Description
voila un petit programme qui reprensente une pseudo-galaxie (elle a une forme d'un cube ...) il en plus il existe 3 type de planetes !! (rouge,vert,bleu)
bon elles sont reprensentees par un point (c'est ca le but de la source)
Source
- #include <windows.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <gl/glaux.h>
-
- #include <math.h>
-
- //------------------------------------------------------------
- #define PI 3.1415926535
- //------------------------------------------------------------
- #define MY_MIN_ZOOM 1
- #define MY_MAX_ZOOM 100
-
- #define NBPOINT 5000
-
- #define MY_CUBE_LINE 99
- #define MY_PLANET_1 100
- #define MY_PLANET_2 101
- #define MY_PLANET_3 102
- //------------------------------------------------------------
- double CompiloRandomDouble(double a,double b)
- {
- return a + ((b-a)*(double)rand())/((double)RAND_MAX);
- }
- //------------------------------------------------------------
- void RePaint(HDC DC,double zoom,double theta,double phi)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
-
- // position de l'oeil
- gluLookAt(zoom*cos(theta)*cos(phi),zoom*sin(theta)*cos(phi),zoom*sin(phi),0,0,0,cos(theta-PI)*cos(PI/2.-phi),sin(theta-PI)*cos(PI/2.-phi),sin(PI/2.-phi));
-
- // on trace les lignes du cube
- glCallList(MY_CUBE_LINE);
- glCallList(MY_PLANET_1);
- glCallList(MY_PLANET_2);
- glCallList(MY_PLANET_3);
-
- glPopMatrix();
-
- SwapBuffers(DC);
- }
- //------------------------------------------------------------
- void InitPixelFormat(HDC hdc)
- {
- PIXELFORMATDESCRIPTOR pfd = {sizeof (PIXELFORMATDESCRIPTOR),1,PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,16,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0};
- SetPixelFormat(hdc,ChoosePixelFormat(hdc,&pfd),&pfd);
- }
- //------------------------------------------------------------
- void CreatePlanet(int ID,double r,double g,double b)
- {
- int i;
-
- glNewList(ID,GL_COMPILE);
- glColor3d(r,g,b);
- glBegin(GL_POINTS);
- for(i=0;i<NBPOINT;i++)
- {
- double x,y,z;
- x = CompiloRandomDouble(-10.,+10.);
- y = CompiloRandomDouble(-10.,+10.);
- z = CompiloRandomDouble(-10.,+10.);
- glVertex3d(x,y,z);
- }
- glEnd();
- glEndList();
- }
- //------------------------------------------------------------
- void CreateNewList(void)
- {
-
- glNewList(MY_CUBE_LINE,GL_COMPILE);
- glColor3d(1.,1.,1.);
-
-
- glBegin(GL_LINE_LOOP);
- glVertex3d(-10.,-10.,-10.);
- glVertex3d(-10.,-10.,+10.);
- glVertex3d(-10.,+10.,+10.);
- glVertex3d(-10.,+10.,-10.);
- glEnd();
-
- glBegin(GL_LINE_LOOP);
- glVertex3d(+10.,-10.,-10.);
- glVertex3d(+10.,-10.,+10.);
- glVertex3d(+10.,+10.,+10.);
- glVertex3d(+10.,+10.,-10.);
- glEnd();
-
- glBegin(GL_LINES);
- glVertex3d(+10.,-10.,-10.);
- glVertex3d(-10.,-10.,-10.);
- glVertex3d(+10.,-10.,+10.);
- glVertex3d(-10.,-10.,+10.);
- glVertex3d(+10.,+10.,+10.);
- glVertex3d(-10.,+10.,+10.);
- glVertex3d(+10.,+10.,-10.);
- glVertex3d(-10.,+10.,-10.);
- glEnd();
-
- glEndList();
-
- CreatePlanet(MY_PLANET_1,1.,0.,0.);
- CreatePlanet(MY_PLANET_2,0.,1.,0.);
- CreatePlanet(MY_PLANET_3,0.,0.,1.);
- }
- //------------------------------------------------------------
- LRESULT CALLBACK WindowProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)
- {
- static HDC DC;
- static HGLRC RC;
- static int cxClient,cyClient;
- static double zoom,theta,phi,_theta,_phi;
- static BOOL isMouseDown;
- static int xMouseStart,yMouseStart;
-
- // traitement des messages
- switch (iMsg)
- {
- case WM_CREATE:
- {
- DC = GetDC(hwnd);
- InitPixelFormat(DC);
- RC = wglCreateContext(DC);
- wglMakeCurrent(DC,RC);
- glEnable(GL_DEPTH_TEST);
- glClearColor(0,0,0,0);
-
- zoom = 50.;
- theta = 0.;
- phi = 0.;
-
- CreateNewList();
- break;
- }
- case WM_SIZE:
- {
- cxClient = LOWORD(lParam); cxClient = (cxClient ? cxClient : 1);
- cyClient = HIWORD(lParam); cyClient = (cyClient ? cyClient : 1);
- glViewport(0,0,cxClient,cyClient);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.,(float)(cxClient)/(float)(cyClient),0.1,1000);
- break;
- }
- case WM_CHAR:
- {
- switch((char)wParam)
- {
- case 'a':
- {
- zoom -= 1.;
- if(zoom < MY_MIN_ZOOM) zoom = MY_MIN_ZOOM;
- return 0;
- }
- case 'q':
- {
- zoom += 1.;
- if(zoom > MY_MAX_ZOOM) zoom = MY_MAX_ZOOM;
- return 0;
- }
- case 'w':
- {
- CreateNewList();
- return 0;
- }
- }
- break;
- }
- case WM_LBUTTONDOWN:
- {
- xMouseStart = LOWORD(lParam);
- yMouseStart = HIWORD(lParam);
- // on sauvegarde les angles
- _theta = theta;
- _phi = phi;
- isMouseDown = TRUE;
- SetCapture(hwnd);
- return 0;
- }
- case WM_LBUTTONUP:
- {
- if(isMouseDown)
- {
- ReleaseCapture();
- isMouseDown = FALSE;
- }
- return 0;
- }
- case WM_MOUSEMOVE:
- {
- if(isMouseDown)
- {
- int x,y;
- x = (int) (__int16) LOWORD(lParam);
- y = (int) (__int16) HIWORD(lParam);
-
- // attention, comme les coordonnees en Y
- // client sont inversees (de haut en bas)
- // il faut faire -, et non +
- // comme pout le X
- theta = _theta + ((xMouseStart - x)*2*PI)/(double)cxClient;
- phi = _phi - ((yMouseStart - y)*2*PI)/(double)cyClient;
- }
- return 0;
- }
- case WM_PAINT:
- {
- RePaint(DC,zoom,theta,phi);
- return 0;
- }
- case WM_DESTROY:
- {
- glDeleteLists(MY_CUBE_LINE,1);
-
- wglMakeCurrent(NULL, NULL);
- wglDeleteContext(RC);
- ReleaseDC(hwnd,DC);
- PostQuitMessage(0);
- break;
- }
- }
- return DefWindowProc(hwnd,iMsg,wParam,lParam);
- }
- //------------------------------------------------------------
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
- {
- WNDCLASS wc;
- MSG msg;
- HWND hWnd;
-
- srand((unsigned)GetTickCount());
-
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = WindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "jcd";
-
- RegisterClass(&wc);
-
- hWnd = CreateWindow("jcd","openGl : Une Galaxie ... (JCD)",
- WS_OVERLAPPEDWINDOW | WS_VISIBLE,
- CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
- NULL,NULL,hInstance,NULL
- );
-
- while(GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return 0;
- }
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <math.h>
//------------------------------------------------------------
#define PI 3.1415926535
//------------------------------------------------------------
#define MY_MIN_ZOOM 1
#define MY_MAX_ZOOM 100
#define NBPOINT 5000
#define MY_CUBE_LINE 99
#define MY_PLANET_1 100
#define MY_PLANET_2 101
#define MY_PLANET_3 102
//------------------------------------------------------------
double CompiloRandomDouble(double a,double b)
{
return a + ((b-a)*(double)rand())/((double)RAND_MAX);
}
//------------------------------------------------------------
void RePaint(HDC DC,double zoom,double theta,double phi)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// position de l'oeil
gluLookAt(zoom*cos(theta)*cos(phi),zoom*sin(theta)*cos(phi),zoom*sin(phi),0,0,0,cos(theta-PI)*cos(PI/2.-phi),sin(theta-PI)*cos(PI/2.-phi),sin(PI/2.-phi));
// on trace les lignes du cube
glCallList(MY_CUBE_LINE);
glCallList(MY_PLANET_1);
glCallList(MY_PLANET_2);
glCallList(MY_PLANET_3);
glPopMatrix();
SwapBuffers(DC);
}
//------------------------------------------------------------
void InitPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd = {sizeof (PIXELFORMATDESCRIPTOR),1,PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,16,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0};
SetPixelFormat(hdc,ChoosePixelFormat(hdc,&pfd),&pfd);
}
//------------------------------------------------------------
void CreatePlanet(int ID,double r,double g,double b)
{
int i;
glNewList(ID,GL_COMPILE);
glColor3d(r,g,b);
glBegin(GL_POINTS);
for(i=0;i<NBPOINT;i++)
{
double x,y,z;
x = CompiloRandomDouble(-10.,+10.);
y = CompiloRandomDouble(-10.,+10.);
z = CompiloRandomDouble(-10.,+10.);
glVertex3d(x,y,z);
}
glEnd();
glEndList();
}
//------------------------------------------------------------
void CreateNewList(void)
{
glNewList(MY_CUBE_LINE,GL_COMPILE);
glColor3d(1.,1.,1.);
glBegin(GL_LINE_LOOP);
glVertex3d(-10.,-10.,-10.);
glVertex3d(-10.,-10.,+10.);
glVertex3d(-10.,+10.,+10.);
glVertex3d(-10.,+10.,-10.);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3d(+10.,-10.,-10.);
glVertex3d(+10.,-10.,+10.);
glVertex3d(+10.,+10.,+10.);
glVertex3d(+10.,+10.,-10.);
glEnd();
glBegin(GL_LINES);
glVertex3d(+10.,-10.,-10.);
glVertex3d(-10.,-10.,-10.);
glVertex3d(+10.,-10.,+10.);
glVertex3d(-10.,-10.,+10.);
glVertex3d(+10.,+10.,+10.);
glVertex3d(-10.,+10.,+10.);
glVertex3d(+10.,+10.,-10.);
glVertex3d(-10.,+10.,-10.);
glEnd();
glEndList();
CreatePlanet(MY_PLANET_1,1.,0.,0.);
CreatePlanet(MY_PLANET_2,0.,1.,0.);
CreatePlanet(MY_PLANET_3,0.,0.,1.);
}
//------------------------------------------------------------
LRESULT CALLBACK WindowProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)
{
static HDC DC;
static HGLRC RC;
static int cxClient,cyClient;
static double zoom,theta,phi,_theta,_phi;
static BOOL isMouseDown;
static int xMouseStart,yMouseStart;
// traitement des messages
switch (iMsg)
{
case WM_CREATE:
{
DC = GetDC(hwnd);
InitPixelFormat(DC);
RC = wglCreateContext(DC);
wglMakeCurrent(DC,RC);
glEnable(GL_DEPTH_TEST);
glClearColor(0,0,0,0);
zoom = 50.;
theta = 0.;
phi = 0.;
CreateNewList();
break;
}
case WM_SIZE:
{
cxClient = LOWORD(lParam); cxClient = (cxClient ? cxClient : 1);
cyClient = HIWORD(lParam); cyClient = (cyClient ? cyClient : 1);
glViewport(0,0,cxClient,cyClient);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.,(float)(cxClient)/(float)(cyClient),0.1,1000);
break;
}
case WM_CHAR:
{
switch((char)wParam)
{
case 'a':
{
zoom -= 1.;
if(zoom < MY_MIN_ZOOM) zoom = MY_MIN_ZOOM;
return 0;
}
case 'q':
{
zoom += 1.;
if(zoom > MY_MAX_ZOOM) zoom = MY_MAX_ZOOM;
return 0;
}
case 'w':
{
CreateNewList();
return 0;
}
}
break;
}
case WM_LBUTTONDOWN:
{
xMouseStart = LOWORD(lParam);
yMouseStart = HIWORD(lParam);
// on sauvegarde les angles
_theta = theta;
_phi = phi;
isMouseDown = TRUE;
SetCapture(hwnd);
return 0;
}
case WM_LBUTTONUP:
{
if(isMouseDown)
{
ReleaseCapture();
isMouseDown = FALSE;
}
return 0;
}
case WM_MOUSEMOVE:
{
if(isMouseDown)
{
int x,y;
x = (int) (__int16) LOWORD(lParam);
y = (int) (__int16) HIWORD(lParam);
// attention, comme les coordonnees en Y
// client sont inversees (de haut en bas)
// il faut faire -, et non +
// comme pout le X
theta = _theta + ((xMouseStart - x)*2*PI)/(double)cxClient;
phi = _phi - ((yMouseStart - y)*2*PI)/(double)cyClient;
}
return 0;
}
case WM_PAINT:
{
RePaint(DC,zoom,theta,phi);
return 0;
}
case WM_DESTROY:
{
glDeleteLists(MY_CUBE_LINE,1);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(RC);
ReleaseDC(hwnd,DC);
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
//------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
WNDCLASS wc;
MSG msg;
HWND hWnd;
srand((unsigned)GetTickCount());
wc.style = CS_OWNDC;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "jcd";
RegisterClass(&wc);
hWnd = CreateWindow("jcd","openGl : Une Galaxie ... (JCD)",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL
);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|