Accueil > > > MOTEUR 3D DIMETRIQUE
MOTEUR 3D DIMETRIQUE
Information sur la source
Description
c'est une application qui affiche un terrain en projection orthogonale dimetrique. une projection dimétrique est une projection gardant les projections de 2 axes (une projection isometrique garde les proportions des 3 axes) . cette projection est faite à l'aide d'une matrice de transformation Opengl
la projection permet de changer l'inclinaison du terrain et de le faire tourner mais je n'ai pas implementer de depth sorting et en regardant le terrain de l'arriere on voit les faces avant .
->click gauche sur l'eau : crée des vagues
-> drag click droit : scroll (translate) le terrain
-> drag click milieu : change l'echelle (scale) le terrain
-> drag click gauche+droite : change l'inclinaison et la rotation du terrain
le programme tourne à 75fps sur mon ordinateur (Geforce 2 MX T_T): je pense qu'il n'est limité que par le nombre de polygones à affiché (128*128)
l'executable est trop gros pour le zip
mais vous pouvez le trouver sur http://matt2000.free.fr/release.rar ainsi que des textures non compressés
Source
- void CTerrainNode::Draw() {
-
- GLdouble model[16], proj[4][4];
- GLint view[4];
- glGetDoublev(GL_PROJECTION_MATRIX, &proj[0][0]);
- glGetIntegerv(GL_VIEWPORT, &view[0]);
- double x,y,z;
- char tmp[32];
- unsigned char white[] = { 255,255,255 },height;
- short mx = WindowMaker->mouse.x;
- short my = WindowMaker->mouse.y;
-
- /**
- Projection setting
- **/
- glPushMatrix();
- float matrix[16]= { sqrt(2)*0.5 , -sqrt(2)*0.5*sin((float)(256-View->camera.ry)/256) , 0 , 0,
- -sqrt(2)*0.5 , -sqrt(2)*0.5*sin((float)(256-View->camera.ry)/256) , 0 , 0,
- 0 , cos((256-View->camera.ry)/256) , 1 , 0,
- View->camera.x , View->camera.y , 0 , 1 };
- glLoadMatrixf(matrix);
- glRotatef((-View->camera.rx+128)/2.8,0,0,1);
- glScalef((float)View->camera.zoom/8,(float)View->camera.zoom/8,(float)View->camera.zoom/16);
-
- /**
- Terrain rendering
- **/
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- glBindTexture( GL_TEXTURE_2D, tilemap->id );
-
- for(int i=0;i<heightmap->height-1;i++) {
- for(int j=0;j<heightmap->width-1;j++) {
-
- glBegin(GL_QUADS);
- glTexCoord2f((float)i/heightmap->width,(float)j/heightmap->height);
- glVertex3f(i ,j ,heightmap->get(i,j,0));
- glTexCoord2f((float)(i+1)/heightmap->width,(float)(j)/heightmap->height);
- glVertex3f(i+1 ,j ,heightmap->get(i+1,j,0));
- glTexCoord2f((float)(i+1)/heightmap->width,(float)(j+1)/heightmap->height);
- glVertex3f(i+1 ,j+1 ,heightmap->get(i+1,j+1,0));
- glTexCoord2f((float)(i)/heightmap->width,(float)(j+1)/heightmap->height);
- glVertex3f(i ,j+1 ,heightmap->get(i,j+1,0));
- glEnd();
- }
- }
-
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
-
- /**
- retrieve the mouse position on the terrain
- **/
- glGetDoublev(GL_MODELVIEW_MATRIX, &model[0]);
- double right[3];
- right[0] = model[0];
- right[1] = model[4];
- right[2] = model[8];
- float w;
- glReadPixels(mx,768-my,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&w); //read pixel (GL_FLOAT) return a float not a double
- z = w;
- gluUnProject( mx,768-my,z,&model[0], &proj[0][0], &view[0], &x, &y,&z);
- ix = x+0;
- iy = y+0;
- if(ix>127) ix = 127; else if(ix<0) ix = 0;
- if(iy>127) iy = 127; else if(iy<0) iy = 0;
-
- glColor4ub(255,0,0,128);
-
- glBegin(GL_QUADS);
- glVertex3f(ix ,iy ,heightmap->get(ix,iy,0));
- glVertex3f(ix+1 ,iy ,heightmap->get(ix+1,iy,0));
- glVertex3f(ix+1 ,iy+1 ,heightmap->get(ix+1,iy+1,0));
- glVertex3f(ix ,iy+1 ,heightmap->get(ix,iy+1,0));
- glEnd();
-
- /**
- Object (tree,building) rendering using point sprite extension
- **/
- glPointSize((float)View->camera.zoom/4);
- glTexEnvf (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
- glEnable (GL_POINT_SPRITE);
- glEnable(GL_TEXTURE_2D);
- glColor3ub(255,255,255);
-
- for(int i=0;i<heightmap->height-1;i++) {
- for(int j=0;j<heightmap->width-1;j++) {
- if( objectmap->get(i,j,0) && objectmap->get(i,j,0) <= nofObject ) {
-
- glBindTexture( GL_TEXTURE_2D, object [ objectmap->get(i,j,0) ].id );
-
- glBegin(GL_POINTS);
- glVertex3f(i+0.5,j+0.5,heightmap->get(i,j,0));
- glEnd();
- }
- }
- }
-
- glPointSize(16);
- glDisable (GL_POINT_SPRITE);
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
- glColor4ub(96,192,255,64);
-
- for(int i=0;i<heightmap->height-1;i++) {
- for(int j=0;j<heightmap->width-1;j++) {
- if(heightmap->get(i,j,0) < 64) {
- glBegin(GL_QUADS);
- //glTexCoord2f((float)i/heightmap->width,(float)j/heightmap->height);
- glVertex3f(i ,j ,64+((float)wavemap[(i+j*128)*2+swap]/32));
- //glTexCoord2f((float)(i+1)/heightmap->width,(float)(j)/heightmap->height);
- glVertex3f(i-1 ,j ,64+((float)wavemap[(i-1+j*128)*2+swap]/32));
- //glTexCoord2f((float)(i+1)/heightmap->width,(float)(j+1)/heightmap->height);
- glVertex3f(i-1 ,j-1 ,64+((float)wavemap[(i-1+(j-1)*128)*2+swap]/32));
- //glTexCoord2f((float)(i)/heightmap->width,(float)(j+1)/heightmap->height);
- glVertex3f(i ,j-1 ,64+((float)wavemap[(i+(j-1)*128)*2+swap]/32));
- glEnd();
- }
- }
- }
-
- glDisable(GL_DEPTH_TEST);
- sprintf(tmp," x %i y %i z %0.0f",ix,iy,z);
- gl.DrawText2D(128,128,white,2.0f,0,tmp);
-
- glPopMatrix();
void CTerrainNode::Draw() {
GLdouble model[16], proj[4][4];
GLint view[4];
glGetDoublev(GL_PROJECTION_MATRIX, &proj[0][0]);
glGetIntegerv(GL_VIEWPORT, &view[0]);
double x,y,z;
char tmp[32];
unsigned char white[] = { 255,255,255 },height;
short mx = WindowMaker->mouse.x;
short my = WindowMaker->mouse.y;
/**
Projection setting
**/
glPushMatrix();
float matrix[16]= { sqrt(2)*0.5 , -sqrt(2)*0.5*sin((float)(256-View->camera.ry)/256) , 0 , 0,
-sqrt(2)*0.5 , -sqrt(2)*0.5*sin((float)(256-View->camera.ry)/256) , 0 , 0,
0 , cos((256-View->camera.ry)/256) , 1 , 0,
View->camera.x , View->camera.y , 0 , 1 };
glLoadMatrixf(matrix);
glRotatef((-View->camera.rx+128)/2.8,0,0,1);
glScalef((float)View->camera.zoom/8,(float)View->camera.zoom/8,(float)View->camera.zoom/16);
/**
Terrain rendering
**/
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, tilemap->id );
for(int i=0;i<heightmap->height-1;i++) {
for(int j=0;j<heightmap->width-1;j++) {
glBegin(GL_QUADS);
glTexCoord2f((float)i/heightmap->width,(float)j/heightmap->height);
glVertex3f(i ,j ,heightmap->get(i,j,0));
glTexCoord2f((float)(i+1)/heightmap->width,(float)(j)/heightmap->height);
glVertex3f(i+1 ,j ,heightmap->get(i+1,j,0));
glTexCoord2f((float)(i+1)/heightmap->width,(float)(j+1)/heightmap->height);
glVertex3f(i+1 ,j+1 ,heightmap->get(i+1,j+1,0));
glTexCoord2f((float)(i)/heightmap->width,(float)(j+1)/heightmap->height);
glVertex3f(i ,j+1 ,heightmap->get(i,j+1,0));
glEnd();
}
}
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
/**
retrieve the mouse position on the terrain
**/
glGetDoublev(GL_MODELVIEW_MATRIX, &model[0]);
double right[3];
right[0] = model[0];
right[1] = model[4];
right[2] = model[8];
float w;
glReadPixels(mx,768-my,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&w); //read pixel (GL_FLOAT) return a float not a double
z = w;
gluUnProject( mx,768-my,z,&model[0], &proj[0][0], &view[0], &x, &y,&z);
ix = x+0;
iy = y+0;
if(ix>127) ix = 127; else if(ix<0) ix = 0;
if(iy>127) iy = 127; else if(iy<0) iy = 0;
glColor4ub(255,0,0,128);
glBegin(GL_QUADS);
glVertex3f(ix ,iy ,heightmap->get(ix,iy,0));
glVertex3f(ix+1 ,iy ,heightmap->get(ix+1,iy,0));
glVertex3f(ix+1 ,iy+1 ,heightmap->get(ix+1,iy+1,0));
glVertex3f(ix ,iy+1 ,heightmap->get(ix,iy+1,0));
glEnd();
/**
Object (tree,building) rendering using point sprite extension
**/
glPointSize((float)View->camera.zoom/4);
glTexEnvf (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glEnable (GL_POINT_SPRITE);
glEnable(GL_TEXTURE_2D);
glColor3ub(255,255,255);
for(int i=0;i<heightmap->height-1;i++) {
for(int j=0;j<heightmap->width-1;j++) {
if( objectmap->get(i,j,0) && objectmap->get(i,j,0) <= nofObject ) {
glBindTexture( GL_TEXTURE_2D, object [ objectmap->get(i,j,0) ].id );
glBegin(GL_POINTS);
glVertex3f(i+0.5,j+0.5,heightmap->get(i,j,0));
glEnd();
}
}
}
glPointSize(16);
glDisable (GL_POINT_SPRITE);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glColor4ub(96,192,255,64);
for(int i=0;i<heightmap->height-1;i++) {
for(int j=0;j<heightmap->width-1;j++) {
if(heightmap->get(i,j,0) < 64) {
glBegin(GL_QUADS);
//glTexCoord2f((float)i/heightmap->width,(float)j/heightmap->height);
glVertex3f(i ,j ,64+((float)wavemap[(i+j*128)*2+swap]/32));
//glTexCoord2f((float)(i+1)/heightmap->width,(float)(j)/heightmap->height);
glVertex3f(i-1 ,j ,64+((float)wavemap[(i-1+j*128)*2+swap]/32));
//glTexCoord2f((float)(i+1)/heightmap->width,(float)(j+1)/heightmap->height);
glVertex3f(i-1 ,j-1 ,64+((float)wavemap[(i-1+(j-1)*128)*2+swap]/32));
//glTexCoord2f((float)(i)/heightmap->width,(float)(j+1)/heightmap->height);
glVertex3f(i ,j-1 ,64+((float)wavemap[(i+(j-1)*128)*2+swap]/32));
glEnd();
}
}
}
glDisable(GL_DEPTH_TEST);
sprintf(tmp," x %i y %i z %0.0f",ix,iy,z);
gl.DrawText2D(128,128,white,2.0f,0,tmp);
glPopMatrix();
Conclusion
Features :
-projection dimétrique d'un terrain heightmappé et texturé
-Loader de texture tga,bmp & jpg
-selection de la case sous la souris
-affichage d'objet(arbres,batiments) (utilise l'extension point_sprite )
-simulation de l'eau ( vague )
Todo :
-lorsque j'aurai un carte graphique correcte, j'utiliserai l'extension frame buffer object pour faire le reflet de l'eau et ne rerendre qu'une partie de l'écran lors des translations
-possibilité de creation de route
-possibilité de creer un batiment -> selection du batiment -> debut d'interface pour créer des bonhommes
-pathfinding
-un vrai jeu ?
Historique
- 10 juillet 2006 18:42:44 :
- terrain texturé - picking - petit changement de structure
- 10 juillet 2006 18:44:19 :
- terrain texturé - picking - petit changement de structure
- 10 juillet 2006 18:44:51 :
- terrain texturé - picking - petit changement de structure
- 11 juillet 2006 13:13:13 :
- simulation de l'eau ( vague ) - affichage d'objet(arbres,batiments)
- 11 juillet 2006 13:13:53 :
- simulation de l'eau ( vague ) - affichage d'objet(arbres,batiments)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
OpenGl et objets 3D [ par mshn ]
bonjour, est ce qu'on peux céer des objets 3D sous OpenGl, et les manipuler (animer et déplacer) par programme en utilisant un environnement de C++ ?
Charger un model 3D en C++ avec opengl [ par smoove5198 ]
Bonjour,j'essaye depuis un moment de charger un model 3D avec opengl en C++, pour ca j'utilise le seul format de fichier que je connaisse et dont j'ai
Création de terrain 3d [ par pitap0 ]
BOnjour a toutes la communauté Voili je cherche des sites, infos traitants Directx 8.1 sous visual C++ (6) plus precisement sur la création de terrain
Moteur 3d OpenGL [ par Stormy ]
Salut. Je recherche des personnes motives pour travailler sur un moteur 3d sous OpenGL. Les bases sont deja etablies (Detection de collisions, sons, m
Objects 3D Opengl [ par mastave ]
Comment inclure dans un fenêtre OpenGl un fichier 3D DXF ou3DS???
Projet OpenGl [ par barraq ]
salut,Voila j'ai un projet a faire pour ma fac, je doit réaliser tout un environement 3d en opengl .Je doit pouvoir me deplacer dans une map donnée et
3d opengl [ par darvil ]
Qui peu m'aider?je cherche de quoi developer sur mac en 3d . Je cherche une adreese ou tlecharger un compilateur des logiciels 3d. comment fair march
Deplacement d'un personnage en OpenGL [ par Clercq ]
Bonjour a tous, J'ai parcourus les sources de ce site mais je n'ai pas concretement trouvé reponse a ma question, en fait j'ai c
OpenGL 3D [ par jojomillenium ]
Bonjour, J'aimerai créer une application qui me permette de charger une liste de cube (coordonnée et taille) et les placer dans un espace 3D et pouvoi
Problème avec OpenGL [ par Xaviou ]
Bonjour, Je suis en train de réaliser un prog permettant de visualiser des fichiers 3D au format STL. Si j'éxécute mon prog depuis Visu
|
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
|