Regarde mieux le code:
ClearList(StarsRendering())
la liste StarsRendering() ne contient que les points à afficher.
sa taille est variable en fonction du nombre de point visible. , on l'efface car on repart avec une liste vierge.
matrix4_identity(*MATRIX_MODELVIEW)
matrix4_translate(*MATRIX_MODELVIEW,CamX,CamY,CamZ)
matrix4_rotate(*MATRIX_MODELVIEW,CamPitch,1,0,0)
matrix4_rotate(*MATRIX_MODELVIEW,CamYaw ,0,1,0)
matrix4_rotate(*MATRIX_MODELVIEW,CamRoll ,0,0,1)
*MATRICE_PROJVIEW.matrix4 = matrix4(*MATRICE_PROJECTION)
matrix4_multiply(*MATRICE_PROJVIEW,*MATRIX_MODELVIEW)
On met à jour les matrices de rotation , la seule allocation est l'avant dernière ligne ( 16 floats )
C'est ici qu'il faut optimisé , car là on parcours toute les étoiles , il faudrais mettre en place un octree
pour ne pas à avoir à parcourir toute les étoiles.
For i = 0 To #NB_STAR-1
matrix4_identity(@Star(i)\mat_view)
matrix4_translate(@Star(i)\mat_view,Star(i)\position\x,Star(i)\position\y,Star(i)\position\z)
*MATRIX_MODELPROJ.matrix4 = matrix4(@Star(i)\mat_view)
Encore une allocation de 16 floats. puis projection à l'écran , le résultat part dans *ScreenCoordinate ( 3 floats)
matrix4_multiply(*MATRICE_PROJVIEW,*MATRIX_MODELPROJ)
;On projette :
*ScreenCoordinate.vector3 = matrix4_coordinate(*MATRICE_PROJVIEW,@Star(i)\position)
*ScreenCoordinate\x * 0.5 / *ScreenCoordinate\z + 0.5
*ScreenCoordinate\y * 0.5 / *ScreenCoordinate\z + 0.5
*ScreenCoordinate\x * ScreenW
*ScreenCoordinate\y * ScreenH
Si le point est visible , on l'ajoute à la liste d'étoiles à rendre.
nous ne somme pas encore dans la boucle de rendu
If *ScreenCoordinate\z>1
If *ScreenCoordinate\x>0 And *ScreenCoordinate\x<ScreenW-1 And *ScreenCoordinate\y>0 And *ScreenCoordinate\y<ScreenH-1
AddElement(StarsRendering())
StarsRendering()\ScreenCoordinate\x = *ScreenCoordinate\x
StarsRendering()\ScreenCoordinate\y = *ScreenCoordinate\y
StarsRendering()\ScreenCoordinate\z = *ScreenCoordinate\z
EndIf
EndIf
free_vector3(*ScreenCoordinate)
Next
on efface se dont l'on a plus besoin , et on commence à mettre des plots
(Remplace avec des sprites 3D , tu verras que c'est plus rapide )
et on parcours la liste d'étoile à rendre , pas besoin de testé si plot() est dans l'écran
on l'a déjà fait plus haut.
free_matrix4(*MATRICE_PROJVIEW)
StartDrawing(ScreenOutput())
ForEach StarsRendering()
Plot(StarsRendering()\ScreenCoordinate\x,StarsRendering()\ScreenCoordinate\y,$FFFFFF)
Next
StopDrawing()
Regarde mieux, tu verras qu'aucun moteur digne de ce nom ne ferait une allocation par point
Tu te mélanges les pinceaux , ici , il n'est pas question de vertex , mais considère l'étoile comme un objet à part entière.
donc , chaque objet à son propre espace , et oui je suis au courant qu'un moteur3D n'alloue pas une/des matrice(s) par vertex...
j'ai pas commencer la 3D hier

je rappelle encore une fois qu'il est question de projection. pas de technique d'occlusion.