Un cube 3D codé sans l'aide d'un moteur comme Ogre
Publié : ven. 08/déc./2023 16:32
Code : Tout sélectionner
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Code : SPH et Nemerod (2023) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
InitSprite()
InitMouse()
InitKeyboard()
win=OpenWindow(#PB_Any, 0, 0, 0, 0, "Cube 3D", #PB_Window_Maximize | #PB_Window_BorderLess )
scr_w=WindowWidth(win)
scr_h=WindowHeight(win)
OpenWindowedScreen (WindowID(win),0 , 0, scr_w, scr_h,0, 0, 0, #PB_Screen_SmartSynchronization)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Dim imtix.f(7,1)
imtix(0,0) = -1
imtix(1,0) = 01
imtix(2,0) = -1
imtix(3,0) = 01
imtix(4,0) = -1
imtix(5,0) = 01
imtix(6,0) = -1
imtix(7,0) = 01
Dim imtiy.f(7,1)
imtiy(0,0) = -1
imtiy(1,0) = -1
imtiy(2,0) = 01
imtiy(3,0) = 01
imtiy(4,0) = -1
imtiy(5,0) = -1
imtiy(6,0) = 01
imtiy(7,0) = 01
Dim imtiz.f(7)
imtiz(0) = -1
imtiz(1) = -1
imtiz(2) = -1
imtiz(3) = -1
imtiz(4) = 01
imtiz(5) = 01
imtiz(6) = 01
imtiz(7) = 01
Dim g(32,2)
Dim gd(32,2)
a.f=0.0205
b.f=0.0117
c.f=0.0177
zoom=200
dk=500
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
nb_trace=10
trace_la=0
Dim oldx.f(nb_trace,7,1)
Dim oldy.f(nb_trace,7,1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Repeat
Repeat
Event = WindowEvent()
Until Event=0
ClearScreen(0)
; If a.f>0.0050:sx=1:ElseIf a.f<-0.0050:sx=0:EndIf:If sx=0:a.f+0.00004:Else:a.f-0.00002:EndIf
; If b.f>0.0050:sy=1:ElseIf b.f<-0.0050:sy=0:EndIf:If sy=0:b.f+0.00001:Else:b.f-0.00002:EndIf
; If c.f>0.0050:sz=1:ElseIf c.f<-0.0050:sz=0:EndIf:If sz=0:c.f+0.00003:Else:c.f-0.00004:EndIf
For i=0 To 7
x.f=imtix(i,0);point de base X
y.f=imtiy(i,0);point de base Y
z.f=imtiz(i); un peu useless mais point Z
xx.f =(Cos(a.f)*x.f )-(Sin(a.f)*y.f ); axe X
yy.f =(Sin(a.f)*x.f) +(Cos(a.f)*y.f ); profondeur
xxx.f=(Cos(b.f)*xx.f)+(Sin(b.f)*z ); axe Y
zz.f =(Cos(b.f)*z.f) -(Sin(b.f)*xx.f); vertical
yyy.f=(Cos(c.f)*yy.f)-(Sin(c.f)*zz.f); axe Z
zzz.f=(Sin(c.f)*yy.f)+(Cos(c.f)*zz.f); largeur
imtix(i,1)=((xxx.f*2)/(zzz.f+3)); perpestive
imtiy(i,1)=((yyy.f*2)/(zzz.f+3)); peu etre ajusté avec le 2 et le 3
oldx(trace_la,i,1)=imtix(i,1)
oldy(trace_la,i,1)=imtiy(i,1)
imtix(i,0)=xxx.f; valeur de base modifier si besoin
imtiy(i,0)=yyy.f;
imtiz(i)=zzz.f ;
oldx(trace_la,i,0)=xxx
oldy(trace_la,i,0)=yyy
Next
trace_la+1
trace_la%(nb_trace+1)
StartDrawing(ScreenOutput())
;;;;
nb=trace_la
For i=0 To nb_trace-1
LineXY(oldx(nb,0,1)*zoom+dk,oldy(nb,0,1)*zoom+dk,oldx(nb,1,1)*zoom+dk,oldy(nb,1,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,1,1)*zoom+dk,oldy(nb,1,1)*zoom+dk,oldx(nb,3,1)*zoom+dk,oldy(nb,3,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,3,1)*zoom+dk,oldy(nb,3,1)*zoom+dk,oldx(nb,2,1)*zoom+dk,oldy(nb,2,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,2,1)*zoom+dk,oldy(nb,2,1)*zoom+dk,oldx(nb,0,1)*zoom+dk,oldy(nb,0,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,4,1)*zoom+dk,oldy(nb,4,1)*zoom+dk,oldx(nb,5,1)*zoom+dk,oldy(nb,5,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,5,1)*zoom+dk,oldy(nb,5,1)*zoom+dk,oldx(nb,7,1)*zoom+dk,oldy(nb,7,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,7,1)*zoom+dk,oldy(nb,7,1)*zoom+dk,oldx(nb,6,1)*zoom+dk,oldy(nb,6,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,6,1)*zoom+dk,oldy(nb,6,1)*zoom+dk,oldx(nb,4,1)*zoom+dk,oldy(nb,4,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,0,1)*zoom+dk,oldy(nb,0,1)*zoom+dk,oldx(nb,4,1)*zoom+dk,oldy(nb,4,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,1,1)*zoom+dk,oldy(nb,1,1)*zoom+dk,oldx(nb,5,1)*zoom+dk,oldy(nb,5,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,2,1)*zoom+dk,oldy(nb,2,1)*zoom+dk,oldx(nb,6,1)*zoom+dk,oldy(nb,6,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
LineXY(oldx(nb,3,1)*zoom+dk,oldy(nb,3,1)*zoom+dk,oldx(nb,7,1)*zoom+dk,oldy(nb,7,1)*zoom+dk,RGB(8+i*50/nb_trace,8+i*50/nb_trace,8+i*50/nb_trace))
nb+1
nb%(nb_trace+1)
Next
LineXY(imtix(0,1)*zoom+dk,imtiy(0,1)*zoom+dk,imtix(1,1)*zoom+dk,imtiy(1,1)*zoom+dk,$0000ff)
LineXY(imtix(1,1)*zoom+dk,imtiy(1,1)*zoom+dk,imtix(3,1)*zoom+dk,imtiy(3,1)*zoom+dk,$0000ff)
LineXY(imtix(3,1)*zoom+dk,imtiy(3,1)*zoom+dk,imtix(2,1)*zoom+dk,imtiy(2,1)*zoom+dk,$0000ff)
LineXY(imtix(2,1)*zoom+dk,imtiy(2,1)*zoom+dk,imtix(0,1)*zoom+dk,imtiy(0,1)*zoom+dk,$0000ff)
LineXY(imtix(4,1)*zoom+dk,imtiy(4,1)*zoom+dk,imtix(5,1)*zoom+dk,imtiy(5,1)*zoom+dk,$0000ff)
LineXY(imtix(5,1)*zoom+dk,imtiy(5,1)*zoom+dk,imtix(7,1)*zoom+dk,imtiy(7,1)*zoom+dk,$0000ff)
LineXY(imtix(7,1)*zoom+dk,imtiy(7,1)*zoom+dk,imtix(6,1)*zoom+dk,imtiy(6,1)*zoom+dk,$0000ff)
LineXY(imtix(6,1)*zoom+dk,imtiy(6,1)*zoom+dk,imtix(4,1)*zoom+dk,imtiy(4,1)*zoom+dk,$0000ff)
LineXY(imtix(0,1)*zoom+dk,imtiy(0,1)*zoom+dk,imtix(4,1)*zoom+dk,imtiy(4,1)*zoom+dk,$0000ff)
LineXY(imtix(1,1)*zoom+dk,imtiy(1,1)*zoom+dk,imtix(5,1)*zoom+dk,imtiy(5,1)*zoom+dk,$0000ff)
LineXY(imtix(2,1)*zoom+dk,imtiy(2,1)*zoom+dk,imtix(6,1)*zoom+dk,imtiy(6,1)*zoom+dk,$0000ff)
LineXY(imtix(3,1)*zoom+dk,imtiy(3,1)*zoom+dk,imtix(7,1)*zoom+dk,imtiy(7,1)*zoom+dk,$0000ff)
;;;;
;;;;
StopDrawing()
Delay(1)
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
; Delay(400)
; Repeat
; ExamineKeyboard()
; Until KeyboardPushed(#PB_Key_Escape)