Page 1 of 2

Real 3D Engine to show object

Posted: Sat Nov 27, 2010 2:08 pm
by ArtBlink
Hello,

This is a real 3D programm, have fun... Sorry it is in french ;-)

Code: Select all

@SCREEN {Mode = "ask", Width = 640, Height = 400}
SetFormStyle(#ANTIALIAS) ; Antialiasing sur le cube
FC=200
CX=160
CY=100
CZ=200
Function Controle()
	If IsKeyDown("Left")=True Then Gauche() ; Vers la gauche
	If IsKeyDown("Right")=True Then Droite() ; Vers la droite
	If IsKeyDown("Up")=True Then Haut() ; Vers le Haut
	If IsKeyDown("Down")=True Then Bas() ; Vers le bas
	If IsKeyDown("RSHIFT")=True Then Zoomin() ; Zoom in
	If IsKeyDown("RCONTROL")=True Then Zoomout() ; Zoom Out
EndFunction

Function Gauche()
	AY=AY+1
	If AY>359 Then AY=0
EndFunction

Function Droite()
	AY=AY-1
	If AY<0 Then AY=359
EndFunction

Function Haut()
	AX=AX+1
	If AX>359 Then AX=0
EndFunction
        
Function Bas()
	AX=AX-1
	If AX<0 Then AX=359
EndFunction

Function Zoomin()
	CZ=CZ+10
	If CZ>500 Then CZ=500
EndFunction

Function Zoomout()
	CZ=CZ-10
	If CZ<80 Then CZ=80)
EndFunction

Function PRG()
	
	Controle() ; Exécution de la fonction Controle
	; Réservation mémoire et création des tableaux
	Dim CO[360] ; 360 cases réservé car une rotation c'est 360° pour le Cosinus
	Dim SI[360] ; 360 cases réservé car une rotation c'est 360° pour le Sinus
	Dim X[8] ; Un cube, c'est 8 points en X
	Dim Y[8] ; Un cube, c'est 8 points en Y
	Dim Z[8] ; Un cube, c'est 8 points en Z
	Dim XE[8] ; Point final du cube a dessiner en X
	Dim YE[8] ; Point final du cube a dessiner en Y
	Dim ZZ[8] ; Point final du cube a dessiner en Z
	Dim P1[12] ; Un cube, c'est 12 lignes (point de départ de la ligne)
	Dim P2[12] ; Un cube, c'est 12 lignes (point final de la ligne)
	
Flip ; Flip d'écran pour le double buffer
Cls ; Effacement de l'écran sinon on verrait des cube partout lol

For I=0 To 359
	CO[I]=Cos(I*0.1)*256 ; Mise en mémoire de 360 calcule du Cosinus des angles sur 360°
	SI[I]=Sin(I*0.1)*256 ; Mise en mémoire de 360 calcule du Sinus des angles sur 360°
Next 

	For I=0 To 7
		X = {-50,50,50,-50,-50,50,50,-50} ; Coordonnées des points dans l'espace en X
		Y = {-50,-50,50,50,-50,-50,50,50} ; Coordonnées des points dans l'espace en Y
		Z = {-50,-50,-50,-50,50,50,50,50} ; Coordonnées des points dans l'espace en Z
		P1 = {0,1,2,3,4,5,6,7,0,1,2,3} ; Point de départ pour tracer la ligne
		P2 = {1,2,3,0,5,6,7,4,4,5,6,7} ; Point d'arrivée pour tracer la ligne
		;Calcule 3D grâce au magazine Dream N°27 de Mars 1996
		Y1=(Y[I]*CO[AX]+Z[I]*SI[AX])/256
		Z1=(-Y[I]*SI[AX]+Z[I]*CO[AX])/256
		X1=(X[I]*CO[AY]+Z1*SI[AY])/256
		ZZ[I]=(-X[I]*SI[AY]+Z1*CO[AY])/256
		X=(X1*CO[AZ]+Y1*SI[AZ])/256
		Y=(-X1*SI[AZ]+Y1*CO[AZ])/256
		D=FC/(Sqrt(X^2+Y^2+(CZ+ZZ[I])^2))
		XE[I]=320+X*D
		YE[I]=200+Y*D
	Next
	; Calcule final
	For I=0 To 11
		GP1=P1[I]
		GP2=P2[I]
		X=XE[GP1]
		Y=YE[GP1]
		X1=XE[GP2]
		Y1=YE[GP2]
		Line (X,Y,X1,Y1,#WHITE) ; Traçage des lignes
	Next
EndFunction

BeginDoubleBuffer

SetInterval(1,PRG,1000/50)

Repeat
WaitEvent
Forever
Respect

Re: Real 3D Engine to show object

Posted: Sat Nov 27, 2010 7:46 pm
by ArtBlink
@Andreas:

Hihi... you see we can make 3D with hollywood... (3 month to make that lol)

When you add 3D command in hollywood my god?
;)

Respect

Re: Real 3D Engine to show object

Posted: Sat Nov 27, 2010 9:57 pm
by airsoftsoftwair
ArtBlink wrote: When you add 3D command in hollywood my god?
That's not going to come... I'm an oldskool 2D guy :)

Re: Real 3D Engine to show object

Posted: Sun Nov 28, 2010 9:01 am
by ArtBlink
Tsss.. test this, i think you like that. This code is perfectible (really).

lol

Good fun

Code: Select all

@SCREEN {Mode = "ask", Width = 640, Height = 400}
FC=200
CZ=200
Function Controle()
	If IsKeyDown("Left")=True Then Gauche() ; Vers la gauche
	If IsKeyDown("Right")=True Then Droite() ; Vers la droite
	If IsKeyDown("Up")=True Then Haut() ; Vers le Haut
	If IsKeyDown("Down")=True Then Bas() ; Vers le bas
	If IsKeyDown("a")=True Then Zoomin() ; Zoom in
	If IsKeyDown("z")=True Then Zoomout() ; Zoom Out
	If IsKeyDown("p")=True Then SetFillStyle(#FILLCOLOR) ; Zoom Out
	If IsKeyDown("o")=True Then SetFillStyle(#FILLNONE)   
	If IsKeyDown("i")=True Then SetFillStyle(#FILLGRADIENT, #LINEAR, $888888, $FFFFFF)
	If IsKeyDown("u")= True Then SetFormStyle(#ANTIALIAS) 
	If IsKeyDown("y")= True Then SetFormStyle(#NORMAL) 
EndFunction

Function Gauche()
	AY=AY+1
	If AY>359 Then AY=0
EndFunction

Function Droite()
	AY=AY-1
	If AY<0 Then AY=359
EndFunction

Function Haut()
	AX=AX+1
	If AX>359 Then AX=0
EndFunction
	
Function Bas()
	AX=AX-1
	If AX<0 Then AX=359
EndFunction

Function Zoomin()
	CZ=CZ+10
	If CZ>600 Then CZ=600
EndFunction

Function Zoomout()
	CZ=CZ-10
	If CZ<150 Then CZ=150
EndFunction

Function PRG()
	
	Controle() ; Exécution de la fonction Controle
	; Réservation mémoire et création des tableaux
	Dim CO[360] ; 360 cases réservé car une rotation c'est 360° pour le Cosinus
	Dim SI[360] ; 360 cases réservé car une rotation c'est 360° pour le Sinus
	Dim X[8] ; Un cube, c'est 8 points en X
	Dim Y[8] ; Un cube, c'est 8 points en Y
	Dim Z[8] ; Un cube, c'est 8 points en Z
	Dim XE[8] ; Point final du cube a dessiner en X
	Dim YE[8] ; Point final du cube a dessiner en Y
	Dim ZZ[8] ; Point final du cube a dessiner en Z
	Dim P1[10] ; Polygone 1
	Dim P2[10] ; Polygone 2
	Dim P3[10] ; Polygone 3
	Dim P4[10] ; Polygone 4
	Dim P5[10] ; Polygone 5
	Dim P6[10] ; Polygone 6
	
Flip ; Flip d'écran pour le double buffer
Cls ; Effacement de l'écran sinon on verrait des cube partout lol

For I=0 To 359
	CO[I]=Cos(I*0.1)*360 ; Mise en mémoire de 360 calcule du Cosinus des angles sur 360°
	SI[I]=Sin(I*0.1)*360 ; Mise en mémoire de 360 calcule du Sinus des angles sur 360°
Next 

	For I=0 To 7
		X = {-50,50,50,-50,-50,50,50,-50} ; Coordonnées des points dans l'espace en X
		Y = {-50,-50,50,50,-50,-50,50,50} ; Coordonnées des points dans l'espace en Y
		Z = {-50,-50,-50,-50,50,50,50,50} ; Coordonnées des points dans l'espace en Z
		
		;P={0,1,2,3,1,5,6,2,4,5,1,0,4,5,6,7,4,0,3,7,3,2,6,7}
		;Calcule 3D grâce au magazine Dream N°27 de Mars 1996
		Y1=(Y[I]*CO[AX]+Z[I]*SI[AX])/360
		Z1=(-Y[I]*SI[AX]+Z[I]*CO[AX])/360
		X1=(X[I]*CO[AY]+Z1*SI[AY])/360
		ZZ[I]=(-X[I]*SI[AY]+Z1*CO[AY])/360
		X=(X1*CO[AZ]+Y1*SI[AZ])/360
		Y=(-X1*SI[AZ]+Y1*CO[AZ])/360
		D=FC/(Sqrt(X^2+Y^2+(CZ+ZZ[I])^2))
		XE[I]=320+X*D
		YE[I]=200+Y*D
	
	Next
	 ; Calcule final
		P1 = {XE[0],YE[0],XE[1],YE[1],XE[2],YE[2],XE[3],YE[3],XE[0],YE[0]} ; Polygon 1
		P2 = {XE[1],YE[1],XE[5],YE[5],XE[6],YE[6],XE[2],YE[2],XE[1],YE[1]} ; Polygon 2
		P3 = {XE[4],YE[4],XE[5],YE[5],XE[1],YE[1],XE[0],YE[0],XE[4],YE[4]} ; Polygon 3 
		P4 = {XE[4],YE[4],XE[5],YE[5],XE[6],YE[6],XE[7],YE[7],XE[4],YE[4]} ; Polygon 4
		P5 = {XE[4],YE[4],XE[0],YE[0],XE[3],YE[3],XE[7],YE[7],XE[4],YE[4]} ; Polygon 5
		P6 = {XE[3],YE[3],XE[2],YE[2],XE[6],YE[6],XE[7],YE[7],XE[3],YE[3]} ; Polygon 6

		Box (0,0,640,200,$3333EE)
		Locate (0,0)
		Print ("Flèche => Rotation cube")
		Locate (0,12)
		Print ("Touche a => Zoom OUT")
		Locate (0,24)
		Print ("Touche b => Zoom IN")
		Locate (0,36)
		Print ("Touche p => coloration de Garnier")
		Locate (0,48)
		Print ("Touche o => annuler la coloration")
		Locate (0,60)
		Print ("Touche i => Un monde d'acier ;-)")
		Locate (0,72)
		Print ("Touche u => Antialiasing")
		Locate (0,84)
		Print ("Touche y => enlever l'Antialiasing")
		Locate (0,96)
		Print ("Ctrl+c => Quitter")

		; Traçage des polygones avec tests
		; les tests se font sur la coordonnées en Z
		; en gros si le polygone passe derrière les autres alors il s'affiche pas
		; je crois que normalement sa fais gagner du temp CPU... Non?
		If ZZ[1]+ZZ[5]+ZZ[6]+ZZ[2]<-40 Then Polygon (0,0,P2,5,#BLUE) 
		If ZZ[4]+ZZ[5]+ZZ[1]+ZZ[0]<-40 Then Polygon (0,0,P3,5,#RED) 
		If ZZ[0]+ZZ[1]+ZZ[2]+ZZ[3]>40 Then Polygon (0,0,P4,5,#YELLOW) 
		If ZZ[1]+ZZ[5]+ZZ[6]+ZZ[2]>40 Then Polygon (0,0,P5,5,#WHITE) 
		If ZZ[4]+ZZ[5]+ZZ[1]+ZZ[0]>40 Then Polygon (0,0,P6,5,#GREEN)
		If ZZ[0]+ZZ[1]+ZZ[2]+ZZ[3]<-40 Then Polygon (0,0,P1,5,#PURPLE) 
EndFunction

BeginDoubleBuffer

SetInterval(1,PRG,1000/50)

Repeat
WaitEvent
Forever
Respect

Re: Real 3D Engine to show object

Posted: Tue Nov 30, 2010 6:49 am
by PEB
@ArtBlink

Nice job. I had fun playing with your examples.

Re: Real 3D Engine to show object

Posted: Fri Dec 03, 2010 9:35 pm
by HelmutH
A nice 3D program ArtBlink.
May I published the source code in the German-Hollywood Forum? :)

Re: Real 3D Engine to show object

Posted: Sat Dec 04, 2010 8:18 am
by ArtBlink
Thanks Peb and Helmuth...

And YES, you can post my hollywood Prg on german forum, but, be careful, 3D equation isn't perfect, 1 error appear, i work on this, but if you find the solution, contact me ;-)

Respect

Re: Real 3D Engine to show object

Posted: Mon Dec 06, 2010 11:55 pm
by HelmutH
@ArtBlink
Thanks for your permission that i can the source code from your Real 3D Engine to provide on the german Hollywood forum.
When i find an error or solution to a error i contact you. ;)

On the subject on German Hollywood Forum

Re: Real 3D Engine to show object

Posted: Tue Dec 07, 2010 2:09 pm
by ArtBlink
Hello helmuth,

I have find the 3D error equation and i have find light effect, i post code (the object is Cube) i think this evening ;-)

Respect

Re: Real 3D Engine to show object

Posted: Thu Dec 09, 2010 10:38 pm
by HelmutH
Hello ArtBlink
Super :!:
I have saw it and tested. Runs as far good, processor load on my A1 is by 60%. ;)