Accueil > > > CUBE EN 3D FILAIRE (C++ SOUS DOS)
CUBE EN 3D FILAIRE (C++ SOUS DOS)
Information sur la source
Description
petit code que je m'etais amusé à faire au debut de mon apprentissage du c++ il y a aussi un peu d'assembler pour des routines optimisées ce code peut s'apparenté à une trés petite ebauche de moteur 3d Pour compiler utiliser turbo c++ de borland
Source
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
-
- #define DISTANCE 256
- #define UINT unsigned int
- #define PI 3.141592654
- typedef struct point
- {
- int x,y,z;
- UINT x2d,y2d;
- }tPoint;
-
- typedef struct tangle
- {
- short x,y,z;
- }tAngle;
-
- tPoint t[8],tp[8];
- double sintab[360],costab[360];
- short lien[10][3];
- int i,j;
- tAngle angle;
-
- void TestLigne();
-
- void PutPixel(UINT x,UINT y,short c)
- {
- asm mov ax,0a000h
- asm mov es,ax
- asm mov ax,320
- asm mul y
- asm add ax,x
- asm mov di,ax
- asm mov al,byte ptr c
- asm mov es:[di],al
- }
-
- void Efface()
- {
- asm mov ax,0a000h
- asm mov es,ax
- asm mov di,0
- asm mov ax,0
- asm mov cx,32000
- asm rep stosw
- }
-
- void Vbl()
- {
- while(!(inp(0x03da) & 0x8));
-
- while(inp(0x03da) & 0x8);
- }
-
- void Invers( UINT* a,UINT* b,UINT* c,UINT* d)
- {
- UINT inter;
-
- inter = *a;
- *a = *c;
- *c = inter;
- inter = *b;
- *b = *d;
- *d = inter;
- }
-
- void Ligne(UINT x1,UINT y1,UINT x2,UINT y2,short couleur)
- {
- int diffx,diffy,dim;
- UINT x,y,i;
- if(x1 == x2)
- {
- if(y1 > y2) Invers(&x1,&y1,&x2,&y2);
- for(i=y1;i<=y2;i++)
- PutPixel(x1,i,couleur);
- }
- else if(y1 == y2)
- {
- if(x1 > x2) Invers(&x1,&y1,&x2,&y2);
- for(i=x1;i<=x2;i++)
- PutPixel(i,y1,couleur);
- }
- else
- {
- diffx = x2-x1;
- diffy = y2-y1;
- if(abs(diffx) > abs(diffy))
- {
- if(diffx < 0)
- {
- Invers(&x1,&y1,&x2,&y2);
- diffy = -diffy;
- diffx = -diffx;
- }
- x = x1;
- y = y1;
- dim = diffx;
- if(diffy > 0)
- do
- {
- do
- {
- PutPixel(x,y,couleur);
- dim = dim-diffy;
- x++;
- }
- while(dim >= 0);
- dim += diffx;
- y++;
- }
- while(y != y2);
- else
- do
- {
- do
- {
- PutPixel(x,y,couleur);
- dim += diffy;
- x++;
- }
- while(dim >= 0);
- dim += diffx;
- y--;
- }
- while(y != y2);
- }
- else
- {
- if(diffy < 0)
- {
- Invers(&x1,&y1,&x2,&y2);
- diffx = -diffx;
- diffy = -diffy;
- }
- x = x1;
- y = y1;
- dim = diffy;
- if(diffx > 0)
- do
- {
- do
- {
- PutPixel(x,y,couleur);
- dim -= diffx;
- y++;
- }
- while(dim >= 0);
- dim += diffy;
- x++;
- }
- while(x != x2);
- else
- do
- {
- do
- {
- PutPixel(x,y,couleur);
- dim += diffx;
- y++;
- }
- while(dim >= 0);
- dim += diffy;
- x--;
- }
- while(x != x2);
- }
- }
- }
-
- void Projeter(tPoint* p)
- {
- p->x2d = (UINT)((DISTANCE*p->x)/(DISTANCE+p->z))+160;
- p->y2d = (UINT)((DISTANCE*p->y)/(DISTANCE+p->z))+100;
- }
-
- void Tourner( tAngle move,tPoint ori, tPoint* p)
- {
- double temp1,temp2;
- p->x = ori.x;
- p->y = ori.y;
- p->z = ori.z;
- temp1 = p->y*costab[move.x]-p->z*sintab[move.x];
- temp2 = p->z*costab[move.x]+p->y*sintab[move.x];
- p->y = (UINT)temp1;
- p->z = (UINT)temp2;
-
- temp1 = p->z*costab[move.y]-p->x*sintab[move.y];
- temp2 = p->x*costab[move.y]+p->z*sintab[move.y];
- p->z = (UINT)temp1;
- p->x = (UINT)temp2;
-
- temp1 = p->x*costab[move.z]-p->y*sintab[move.z];
- temp2 = p->y*costab[move.z]+p->x*sintab[move.z];
- p->x = (UINT)temp1;
- p->y = (UINT)temp2;
- }
-
- void main()
- {
- for(i=0;i<360;i++)
- {
- sintab[i] = sin(i*PI/180);
- costab[i] = cos(i*PI/180);
- }
- angle.x = 0;
- angle.y = 0;
- angle.z = 0;
- t[0].x = -30; t[0].y = 30; t[0].z = -30;
- t[1].x = 30; t[1].y = 30; t[1].z = -30;
- t[2].x = 30; t[2].y = -30; t[2].z = -30;
- t[3].x = -30; t[3].y = -30; t[3].z = -30;
- t[4].x = -30; t[4].y = 30; t[4].z = 30;
- t[5].x = 30; t[5].y = 30; t[5].z = 30;
- t[6].x = 30; t[6].y = -30; t[6].z = 30;
- t[7].x = -30; t[7].y = -30; t[7].z = 30;
- lien[0][0] = 0; lien[0][1] = 4; lien[0][2] = 3;
- lien[1][0] = 3; lien[1][1] = 4; lien[1][2] = 7;
- lien[2][0] = 0; lien[2][1] = 1; lien[2][2] = 3;
- lien[3][0] = 1; lien[3][1] = 2; lien[3][2] = 3;
- lien[4][0] = 1; lien[4][1] = 2; lien[4][2] = 6;
- lien[5][0] = 1; lien[5][1] = 5; lien[5][2] = 6;
- lien[6][0] = 4; lien[6][1] = 5; lien[6][2] = 7;
- lien[7][0] = 5; lien[7][1] = 6; lien[7][2] = 7;
- lien[8][0] = 0; lien[8][1] = 4; lien[8][2] = 5;
- lien[9][0] = 3; lien[9][1] = 6; lien[9][2] = 7;
-
- asm mov ax,13h
- asm int 10h
-
- do
- {
- angle.x++;
- angle.x %= 360;
- for(i=0;i<8;i++)
- {
- Tourner(angle,t[i],&tp[i]);
- Projeter(&tp[i]);
- }
- for(i=0;i<10;i++)
- {
- for(j=0;j<2;j++)
- Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
- Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
- }
- Vbl();
- Efface();
- }
- while(!kbhit());
- getch();
- angle.x = 0;
- do
- {
- angle.y++;
- angle.y %= 360;
- for(i=0;i<8;i++)
- {
- Tourner(angle,t[i],&tp[i]);
- Projeter(&tp[i]);
- }
- for(i=0;i<10;i++)
- {
- for(j=0;j<2;j++)
- Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
- Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
- }
- Vbl();
- Efface();
- }
- while(!kbhit());
- getch();
- angle.y = 0;
- do
- {
- angle.z++;
- angle.z %= 360;
- for(i=0;i<8;i++)
- {
- Tourner(angle,t[i],&tp[i]);
- Projeter(&tp[i]);
- }
- for(i=0;i<10;i++)
- {
- for(j=0;j<2;j++)
- Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
- Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
- }
- Vbl();
- Efface();
- }
- while(!kbhit());
- getch();
- angle.z = 0;
- do
- {
- angle.x++;
- angle.x %= 360;
- angle.y++;
- angle.y %= 360;
- angle.z++;
- angle.z %= 360;
- for(i=0;i<8;i++)
- {
- Tourner(angle,t[i],&tp[i]);
- Projeter(&tp[i]);
- }
- for(i=0;i<10;i++)
- {
- for(j=0;j<2;j++)
- Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
- Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
- }
- Vbl();
- Efface();
- }
- while(!kbhit());
- asm mov ax,03h
- asm int 10h
- }
-
- void TestLigne()
- {
- do
- {
- Ligne(0,50,319,50,1);
- Ligne(319,150,0,150,2);
- Ligne(120,0,120,200,3);
- Ligne(240,200,240,0,4);
- Ligne(0,0,319,200,5);
- Ligne(319,0,0,200,6);
- Ligne(0,180,300,0,7);
- Ligne(319,180,20,0,8);
- }
- while(!kbhit());
- }
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define DISTANCE 256
#define UINT unsigned int
#define PI 3.141592654
typedef struct point
{
int x,y,z;
UINT x2d,y2d;
}tPoint;
typedef struct tangle
{
short x,y,z;
}tAngle;
tPoint t[8],tp[8];
double sintab[360],costab[360];
short lien[10][3];
int i,j;
tAngle angle;
void TestLigne();
void PutPixel(UINT x,UINT y,short c)
{
asm mov ax,0a000h
asm mov es,ax
asm mov ax,320
asm mul y
asm add ax,x
asm mov di,ax
asm mov al,byte ptr c
asm mov es:[di],al
}
void Efface()
{
asm mov ax,0a000h
asm mov es,ax
asm mov di,0
asm mov ax,0
asm mov cx,32000
asm rep stosw
}
void Vbl()
{
while(!(inp(0x03da) & 0x8));
while(inp(0x03da) & 0x8);
}
void Invers( UINT* a,UINT* b,UINT* c,UINT* d)
{
UINT inter;
inter = *a;
*a = *c;
*c = inter;
inter = *b;
*b = *d;
*d = inter;
}
void Ligne(UINT x1,UINT y1,UINT x2,UINT y2,short couleur)
{
int diffx,diffy,dim;
UINT x,y,i;
if(x1 == x2)
{
if(y1 > y2) Invers(&x1,&y1,&x2,&y2);
for(i=y1;i<=y2;i++)
PutPixel(x1,i,couleur);
}
else if(y1 == y2)
{
if(x1 > x2) Invers(&x1,&y1,&x2,&y2);
for(i=x1;i<=x2;i++)
PutPixel(i,y1,couleur);
}
else
{
diffx = x2-x1;
diffy = y2-y1;
if(abs(diffx) > abs(diffy))
{
if(diffx < 0)
{
Invers(&x1,&y1,&x2,&y2);
diffy = -diffy;
diffx = -diffx;
}
x = x1;
y = y1;
dim = diffx;
if(diffy > 0)
do
{
do
{
PutPixel(x,y,couleur);
dim = dim-diffy;
x++;
}
while(dim >= 0);
dim += diffx;
y++;
}
while(y != y2);
else
do
{
do
{
PutPixel(x,y,couleur);
dim += diffy;
x++;
}
while(dim >= 0);
dim += diffx;
y--;
}
while(y != y2);
}
else
{
if(diffy < 0)
{
Invers(&x1,&y1,&x2,&y2);
diffx = -diffx;
diffy = -diffy;
}
x = x1;
y = y1;
dim = diffy;
if(diffx > 0)
do
{
do
{
PutPixel(x,y,couleur);
dim -= diffx;
y++;
}
while(dim >= 0);
dim += diffy;
x++;
}
while(x != x2);
else
do
{
do
{
PutPixel(x,y,couleur);
dim += diffx;
y++;
}
while(dim >= 0);
dim += diffy;
x--;
}
while(x != x2);
}
}
}
void Projeter(tPoint* p)
{
p->x2d = (UINT)((DISTANCE*p->x)/(DISTANCE+p->z))+160;
p->y2d = (UINT)((DISTANCE*p->y)/(DISTANCE+p->z))+100;
}
void Tourner( tAngle move,tPoint ori, tPoint* p)
{
double temp1,temp2;
p->x = ori.x;
p->y = ori.y;
p->z = ori.z;
temp1 = p->y*costab[move.x]-p->z*sintab[move.x];
temp2 = p->z*costab[move.x]+p->y*sintab[move.x];
p->y = (UINT)temp1;
p->z = (UINT)temp2;
temp1 = p->z*costab[move.y]-p->x*sintab[move.y];
temp2 = p->x*costab[move.y]+p->z*sintab[move.y];
p->z = (UINT)temp1;
p->x = (UINT)temp2;
temp1 = p->x*costab[move.z]-p->y*sintab[move.z];
temp2 = p->y*costab[move.z]+p->x*sintab[move.z];
p->x = (UINT)temp1;
p->y = (UINT)temp2;
}
void main()
{
for(i=0;i<360;i++)
{
sintab[i] = sin(i*PI/180);
costab[i] = cos(i*PI/180);
}
angle.x = 0;
angle.y = 0;
angle.z = 0;
t[0].x = -30; t[0].y = 30; t[0].z = -30;
t[1].x = 30; t[1].y = 30; t[1].z = -30;
t[2].x = 30; t[2].y = -30; t[2].z = -30;
t[3].x = -30; t[3].y = -30; t[3].z = -30;
t[4].x = -30; t[4].y = 30; t[4].z = 30;
t[5].x = 30; t[5].y = 30; t[5].z = 30;
t[6].x = 30; t[6].y = -30; t[6].z = 30;
t[7].x = -30; t[7].y = -30; t[7].z = 30;
lien[0][0] = 0; lien[0][1] = 4; lien[0][2] = 3;
lien[1][0] = 3; lien[1][1] = 4; lien[1][2] = 7;
lien[2][0] = 0; lien[2][1] = 1; lien[2][2] = 3;
lien[3][0] = 1; lien[3][1] = 2; lien[3][2] = 3;
lien[4][0] = 1; lien[4][1] = 2; lien[4][2] = 6;
lien[5][0] = 1; lien[5][1] = 5; lien[5][2] = 6;
lien[6][0] = 4; lien[6][1] = 5; lien[6][2] = 7;
lien[7][0] = 5; lien[7][1] = 6; lien[7][2] = 7;
lien[8][0] = 0; lien[8][1] = 4; lien[8][2] = 5;
lien[9][0] = 3; lien[9][1] = 6; lien[9][2] = 7;
asm mov ax,13h
asm int 10h
do
{
angle.x++;
angle.x %= 360;
for(i=0;i<8;i++)
{
Tourner(angle,t[i],&tp[i]);
Projeter(&tp[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
}
Vbl();
Efface();
}
while(!kbhit());
getch();
angle.x = 0;
do
{
angle.y++;
angle.y %= 360;
for(i=0;i<8;i++)
{
Tourner(angle,t[i],&tp[i]);
Projeter(&tp[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
}
Vbl();
Efface();
}
while(!kbhit());
getch();
angle.y = 0;
do
{
angle.z++;
angle.z %= 360;
for(i=0;i<8;i++)
{
Tourner(angle,t[i],&tp[i]);
Projeter(&tp[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
}
Vbl();
Efface();
}
while(!kbhit());
getch();
angle.z = 0;
do
{
angle.x++;
angle.x %= 360;
angle.y++;
angle.y %= 360;
angle.z++;
angle.z %= 360;
for(i=0;i<8;i++)
{
Tourner(angle,t[i],&tp[i]);
Projeter(&tp[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
Ligne(tp[lien[i][j]].x2d,tp[lien[i][j]].y2d,tp[lien[i][j+1]].x2d,tp[lien[i][j+1]].y2d,64);
Ligne(tp[lien[i][0]].x2d,tp[lien[i][0]].y2d,tp[lien[i][2]].x2d,tp[lien[i][2]].y2d,64);
}
Vbl();
Efface();
}
while(!kbhit());
asm mov ax,03h
asm int 10h
}
void TestLigne()
{
do
{
Ligne(0,50,319,50,1);
Ligne(319,150,0,150,2);
Ligne(120,0,120,200,3);
Ligne(240,200,240,0,4);
Ligne(0,0,319,200,5);
Ligne(319,0,0,200,6);
Ligne(0,180,300,0,7);
Ligne(319,180,20,0,8);
}
while(!kbhit());
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVéTECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVé par ROMELARD Fabrice
Speaker : Guillaume Rochette Cette session est dédiée à fournir le retour sur la mise en place d'un cloud privé (IaaS) par Osiatis pour son compte ou celui de ses clients. Ce projet s'est déroulé sur 4 mois et a permis de faire évoluer...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
AUMLAUML par sassion
Cliquez pour lire la suite par sassion
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|