begin process at 2012 05 27 14:37:17
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > CLOCK 3D GLUT

CLOCK 3D GLUT


 Information sur la source

Note :
7 / 10 - par 2 personnes
7,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :OpenGL Niveau :Débutant Date de création :07/05/2004 Vu / téléchargé :4 837 / 388

Auteur : aerith

Ecrire un message privé
Site perso
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
petite horloge en 3D avec camera tournante utilisant glut

Source

  • /*****************************************************************************/
  • /* */
  • /* fichier : main.c version : V1.0 */
  • /* projet : clock date : 05/05/2004 */
  • /* par : aerith */
  • /* */
  • /* clock 3D */
  • /* */
  • /*****************************************************************************/
  • #include <stdio.h>
  • #include <string.h>
  • #include <stdlib.h>
  • #include <math.h>
  • #include <time.h>
  • #include "glut.h"
  • #define PI 3.14159265358979323846
  • void Draw(void);
  • GLvoid Reshape(GLsizei w, GLsizei h);
  • void InitGL();
  • void GestionSpecial(int key, int x, int y) ;
  • int Win;
  • float AngX = 0, AngY = 0;
  • int main(int argc, char *argv[], char *envp[])
  • {
  • glutInit(&argc,argv);
  • glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  • Win = glutCreateWindow("Clock 3D");
  • glutReshapeFunc(Reshape);
  • glutDisplayFunc(Draw);
  • glutSpecialFunc(GestionSpecial);
  • InitGL();
  • glutMainLoop();
  • return 0;
  • }
  • void GestionSpecial(int key, int x, int y)
  • {
  • float p = 0.1;
  • switch (key)
  • {
  • case GLUT_KEY_UP :
  • AngX -= p;
  • break;
  • case GLUT_KEY_DOWN :
  • AngX += p;
  • break;
  • case GLUT_KEY_RIGHT :
  • AngY -= p;
  • break;
  • case GLUT_KEY_LEFT :
  • AngY += p;
  • break;
  • }
  • }
  • void InitGL()
  • {
  • glEnable(GL_DEPTH_TEST);
  • glEnable(GL_LIGHTING);
  • glEnable(GL_LIGHT0);
  • glMatrixMode(GL_MODELVIEW);
  • }
  • GLvoid Reshape(GLsizei w, GLsizei h)
  • {
  • if (h==0)
  • h=1;
  • glViewport(0,0,w,h);
  • glMatrixMode(GL_PROJECTION);
  • glLoadIdentity();
  • gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,1.0f,200.0f);
  • glMatrixMode(GL_MODELVIEW);
  • }
  • void Draw(void)
  • {
  • time_t Time;
  • char StrTime[24], Nom[4], Moi[4];
  • int Jou, Heu, Min, Sec, Ann, i, CamDist = 50;
  • int LightPos[4] = {0, 0, CamDist, 0};
  • GLfloat LightDif[4] = {1.0, 1.0, 0.0, 1.0};
  • GLfloat LightSpec[4] = {0.0, 0.0, 1.0, 1.0};
  • float z = CamDist*cos(AngY)*cos(AngX);
  • float x = CamDist*sin(AngY)*cos(AngX);
  • float y = CamDist*sin(AngX);
  • time(&Time);
  • strcpy(StrTime, ctime(&Time));
  • strcpy(Nom, strtok(StrTime, " :"));
  • strcpy(Moi, strtok(NULL, " :"));
  • Jou = atoi(strtok(NULL, " :"));
  • Heu = atoi(strtok(NULL, " :"));
  • Min = atoi(strtok(NULL, " :"));
  • Sec = atoi(strtok(NULL, " :"));
  • Ann = atoi(strtok(NULL, " :"));
  • glMatrixMode(GL_MODELVIEW);
  • glLoadIdentity();
  • LightPos[0] = x;
  • LightPos[1] = y;
  • LightPos[2] = z;
  • gluLookAt(x, y, z,
  • 0, 0, 0,
  • 0, 1, 0);
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • glLightiv(GL_LIGHT0,GL_POSITION,LightPos);
  • glLightfv(GL_LIGHT0,GL_DIFFUSE,LightDif);
  • glLightfv(GL_LIGHT0,GL_SPECULAR,LightSpec);
  • //horloge
  • glPushMatrix();
  • glutSolidSphere(0.5,24,24);
  • glPopMatrix();
  • for(i = 0; i < 12; i++)
  • {
  • glPushMatrix();
  • glTranslated(17*sin(2*PI/12*i),17*cos(2*PI/12*i),0);
  • glutSolidSphere(0.5,12,12);
  • glPopMatrix();
  • }
  • for(i = 0; i < 60; i++)
  • {
  • glPushMatrix();
  • glTranslated(17*sin(2*PI/60*i),17*cos(2*PI/60*i),0);
  • glutSolidSphere(0.25,12,12);
  • glPopMatrix();
  • }
  • // heures
  • glPushMatrix();
  • glTranslated(10*sin(2*PI/12*Heu+2*PI/60*Min/12+2*PI/60*Sec/60/12),10*cos(2*PI/12*Heu+2*PI/60*Min/12+2*PI/60*Sec/60/12),0);
  • glutSolidSphere(1,12,12);
  • glPopMatrix();
  • // minutes
  • glPushMatrix();
  • glTranslated(13*sin(2*PI/60*Min+2*PI/60*Sec/60),13*cos(2*PI/60*Min+2*PI/60*Sec/60),0);
  • glutSolidSphere(0.75,12,12);
  • glPopMatrix();
  • // secondes
  • glPushMatrix();
  • glTranslated(15*sin(2*PI/60*Sec),15*cos(2*PI/60*Sec),0);
  • glutSolidSphere(0.5,12,12);
  • glPopMatrix();
  • glutSwapBuffers();
  • glutPostRedisplay();
  • }
/*****************************************************************************/
/*																			 */
/* fichier	: main.c									version : V1.0		 */
/* projet	: clock										date :	05/05/2004	 */
/* par		: aerith														 */
/*																			 */
/* clock 3D																	 */
/*																			 */
/*****************************************************************************/

#include	<stdio.h>
#include	<string.h>
#include	<stdlib.h>
#include	<math.h>
#include	<time.h>
#include	"glut.h"

#define		PI		3.14159265358979323846

void	Draw(void);
GLvoid	Reshape(GLsizei w, GLsizei h);
void	InitGL();
void	GestionSpecial(int key, int x, int y) ;

int		Win;
float	AngX = 0, AngY = 0;


int		main(int argc, char *argv[], char *envp[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	Win = glutCreateWindow("Clock 3D");
	
	glutReshapeFunc(Reshape);
	glutDisplayFunc(Draw);
	glutSpecialFunc(GestionSpecial);
	InitGL();
	glutMainLoop();

	return 0;
}

void GestionSpecial(int key, int x, int y) 
{ 
	float	p = 0.1;

	switch (key) 
	{ 
	case	GLUT_KEY_UP		:
		AngX -= p;
		break;
	case	GLUT_KEY_DOWN	:
		AngX += p;
		break;
	case	GLUT_KEY_RIGHT	:
		AngY -= p;
		break;
	case	GLUT_KEY_LEFT	:
		AngY += p;
		break;
	}
}

void	InitGL()
{
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glMatrixMode(GL_MODELVIEW);
}

GLvoid Reshape(GLsizei w, GLsizei h)
{
	if (h==0)
		h=1;
	glViewport(0,0,w,h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,1.0f,200.0f);
	glMatrixMode(GL_MODELVIEW);
}


void	Draw(void)
{
	time_t	Time;
	char	StrTime[24], Nom[4], Moi[4];
	int		Jou, Heu, Min, Sec, Ann, i, CamDist = 50;

	int		LightPos[4]		= {0, 0, CamDist, 0};
	GLfloat	LightDif[4]		= {1.0, 1.0, 0.0, 1.0};
	GLfloat	LightSpec[4]	= {0.0, 0.0, 1.0, 1.0};

	float z = CamDist*cos(AngY)*cos(AngX);
	float x = CamDist*sin(AngY)*cos(AngX);
	float y = CamDist*sin(AngX);

	time(&Time);
    strcpy(StrTime, ctime(&Time));
	strcpy(Nom, strtok(StrTime, " :"));
	strcpy(Moi, strtok(NULL, " :"));
	Jou = atoi(strtok(NULL, " :"));
	Heu = atoi(strtok(NULL, " :"));
	Min = atoi(strtok(NULL, " :"));
	Sec = atoi(strtok(NULL, " :"));
	Ann = atoi(strtok(NULL, " :"));

	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

	LightPos[0]	= x;
	LightPos[1]	= y;
	LightPos[2]	= z;
	gluLookAt(x, y, z,
		0, 0, 0,
		0, 1, 0);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLightiv(GL_LIGHT0,GL_POSITION,LightPos);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,LightDif);
	glLightfv(GL_LIGHT0,GL_SPECULAR,LightSpec);
	
	//horloge
	glPushMatrix();
	glutSolidSphere(0.5,24,24);
	glPopMatrix();
	for(i = 0; i < 12; i++)
	{
		glPushMatrix();
		glTranslated(17*sin(2*PI/12*i),17*cos(2*PI/12*i),0);
		glutSolidSphere(0.5,12,12);
		glPopMatrix();
	}
	for(i = 0; i < 60; i++)
	{
		glPushMatrix();
		glTranslated(17*sin(2*PI/60*i),17*cos(2*PI/60*i),0);
		glutSolidSphere(0.25,12,12);
		glPopMatrix();
	}
	// heures
	glPushMatrix();
	glTranslated(10*sin(2*PI/12*Heu+2*PI/60*Min/12+2*PI/60*Sec/60/12),10*cos(2*PI/12*Heu+2*PI/60*Min/12+2*PI/60*Sec/60/12),0);
	glutSolidSphere(1,12,12);
	glPopMatrix();
	// minutes 
	glPushMatrix();
	glTranslated(13*sin(2*PI/60*Min+2*PI/60*Sec/60),13*cos(2*PI/60*Min+2*PI/60*Sec/60),0);
	glutSolidSphere(0.75,12,12);
	glPopMatrix();
	// secondes
	glPushMatrix();
	glTranslated(15*sin(2*PI/60*Sec),15*cos(2*PI/60*Sec),0);
	glutSolidSphere(0.5,12,12);
	glPopMatrix();

	glutSwapBuffers();
	glutPostRedisplay();
}

 Conclusion

aucun bug connu
code portable en theorie

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   clock
    •   Debug
      • clock.exeTélécharger ce fichier [Réservé aux membres club]204 858 octets
      • glut.defTélécharger ce fichier [Réservé aux membres club]2 290 octets
      • glut32.dllTélécharger ce fichier [Réservé aux membres club]237 568 octets
      • glut32.libTélécharger ce fichier [Réservé aux membres club]28 728 octets
    • clock.dspTélécharger ce fichier [Réservé aux membres club]Voir ce fichier4 555 octets
    • clock.dswTélécharger ce fichier [Réservé aux membres club]Voir ce fichier535 octets
    • glut.hTélécharger ce fichier [Réservé aux membres club]Voir ce fichier27 670 octets
    • main.cTélécharger ce fichier [Réservé aux membres club]Voir ce fichier3 666 octets

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture PROPA [SDL]
Source avec Zip Source avec une capture TEXT SDL
Source avec Zip Source avec une capture SERVEUR METEO, IHM EVOLUEE (VC6, CONSOLE WINDOWS, SOCK, THRE...
SUITE LOGIQUE (PORTABLE)
Source avec Zip Source avec une capture FIBO, CALCULE DE LA SUITE DE FIBONACCI AVEC SUPORT DES GRAND...

 Sources de la même categorie

Source avec Zip Source avec une capture AFFICHER DES COURBES DE BEZIER par shorzy
Source avec Zip Source avec une capture BASE/MOTEUR 3D EN QT/OPENGL (COMPLET ET FONCTIONNEL!) POUR U... par envi33
Source avec Zip Source avec une capture CLASSE AVEC OPENGL - OBJETS 3D ET ANIMATIONS par rasta63
Source avec Zip Source avec une capture LETTRES 3D AVEC OPENGL ET QT par opossum_farceur
Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03

Commentaires et avis

Commentaire de Pamaury le 07/05/2004 17:48:39

j'aime bien ton prog mais il y a deux trucs qui ne vont pas je trouve:
-au lieu de dessiner des boules, dessine un cylindre(le corp de  
l'aiguille) puis la boule(l'extrémité), ca ne te demandera pas  
beaucoup de modifications;
-met des chiffres sur à coté des point principaux(3,6,9,12) parce que quand on tourne l'horloge, on sait plus quelle heure il est !(utilise glutBitmapCharacter ou glutStrokeCharacter) .
Voila, sinon c'est très bien.

Commentaire de Funto66 le 07/05/2004 18:31:55

Personnellement je déconseille glutBitmapCharacter(), mais bon pour un cas comme celui-là c'est acceptable.
Chez moi les routines d'affichage de texte de GLUT bouffent beaucoup de FPS :(
J'ai découvert y'a pas longtemps une librairie, FTGL, qui s'appuie sur FreeType2 pour écrire du texte sous OpenGL, lequel texte peut être en 3D, de n'importe quelle font....bref ça a l'air intéressant ^^

Commentaire de LordBob le 07/05/2004 20:52:36

j'aime bien ton prog, mais je lui reproche certaines choses !!! déjà quand on fait tourné la camera c'est tout plat lol !!! moi j'aurrais bien aimé un peu de relief, et sinon autre truc c'est quand on fait tourné la camera dans tous les sens, bah on pert nos repere, on ne sait plus qu'elle heure il est !!!
sinon je pense que c'est tes début, en c'est pas mal !!! mais ce que je viens de dire pourrait est le but de tes prochaines mise a jour de cette source ;)

Commentaire de basted le 08/05/2004 14:34:00

simpa, c'est zoli !!

A titre d'info la glut n'a pas ete mis a jour depuis plusieur année.

Par example elle ne gere pas la mouse wheel et le nouveau truc

Je suis en cours de test de sont succeseur: freeglut (disponible sur le site de sourceforge)

Pour le text3D je suis tout a fait d'accors avec Funto66 ... et pour cause apres mainte test, la FTGL est vraiment top !

Bonne continuation, ce genre d'initiative est a souligné ... longue vie a OpenGL !

Commentaire de sim38 le 04/11/2006 18:05:11

Vraiment classe ton horloge ! Ca marche comment la caméra ? Et c'est quoi glut ? un petit commentaire : pourquoi tu a mi #define PI ... alors que PI est défini dans math.h ?

Commentaire de ENSAF le 29/01/2009 16:55:46

joli horloge!!

merci bcp!!!!!

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,515 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales