Page 1 sur 1

Lightwave loader

Publié : ven. 04/nov./2005 14:00
par djes
J'ai décidé de donner quelques codes qui pourront servir à ceux qui font de la 3d. Il y a des trucs que j'ai trouvé à droite à gauche et des codes à moi, et ça ne demande qu'à être amélioré. Si quelqu'un se sent d'attaque pour une lib, avec gestion de directx 9, je suis partant aussi ;)

Mode d'emploi : créer un dossier include et y mettre les codes suivants :

1er : headers.pb

Code : Tout sélectionner

;;**********************
;* by djes
;* http://djes.free.fr
;* 4 nov 2005
;**********************

#PI=3.14159265

Structure matrix
	mat.f[9]
EndStructure

Structure vector
	x.f
	y.f
	z.f
EndStructure

Structure object
	pivot.vector
	rotation.matrix
	parent.l
EndStructure

Structure layer
	object_id.l
	pivot.vector
	rotation.matrix
	parent.l
EndStructure

Structure polygon
	layer_id.l
	points_list.l
	points_nb.l
EndStructure

Structure obj_point
	pos.vector
EndStructure

Structure surface
	polygon_id.l
EndStructure

NewList objects.object()
NewList layers.layer()
NewList polygons.polygon()
NewList polygon_points_index.l()
NewList points.vector()
NewList transformed_points.vector()
2nd : lwo_loader.pb

Code : Tout sélectionner

;**********************
;* by djes
;* http://djes.free.fr
;* 4 nov 2005
;**********************

IncludePath "..\include\"
XIncludeFile "headers.pb"

;*********************************************************************************************************************************************************************

Procedure LWO_Load(filename.s)
;*
;* >= Filename.s : name of lwo file to load
;*

	f.f=0																								;a float var
	w.w=0																								;a word var
	l.l=0																								;a long var
	
	points_index_start.l=0

	;*** Does the file exists?

	If ReadFile(0,filename)

		v.l=ReadLong()																					;read a long
		tag.s="AAAA"
		PokeL(@tag,v)																					;write rode tag in tag string
		Debug "FORM? -> "+tag,2

		filesize.l=ReadLong()																			;read a long
		MOV eax,filesize																				;convert endians and put the int to float
		BSWAP eax 
		MOV filesize,eax		
		Debug "File size = "+Str(filesize),2

		v.l=ReadLong()																					;read a long
		tag2.s="AAAA"
		PokeL(@tag2,v)																					;write rode tag in tag string
		Debug "File type : "+tag2,2

		;*** Regular IFF file ?
	
		If tag="FORM" And Lof()=filesize+8 And tag2="LWO2" And Eof(0) = #Null	

			AddElement(objects())
			object_id.l=ListIndex(objects())
	
			total_points_nb.l=0
			total_layers_nb.l=0
			total_polygons_nb.l=0
	
			;*** Looking for tags
	
			While Eof(0) = #Null																		;loop as long the 'end of file' isn't reached
	
				v.l=ReadLong()																			;read a long
				tag.s="AAAA"
				PokeL(@tag,v)		
				Debug v,2
	
				;*** Proceed tags
	
				Select tag
	
				Case "LAYR"
	
					;*** Layer found
	
					Debug "LAYR found",2
					AddElement(layers())
					total_layers_nb+1
					layers()\object_id=object_id
					layer_id.l=ListIndex(layers())
	
					;*** Pass over the tag
	
					v.l=ReadLong()																		;read a long
					MOV eax,v																			;convert endians and put the int to float
					BSWAP eax 
					MOV v,eax
;					!MOV eax,dword [v_v]																;convert endians and put the int to float
;					!bswap eax 
;					!MOV dword [v_v],eax
					Debug Str(v),3
					FileSeek(Loc()+v)																	;jump over the tag
		
					;*** Process rest of the LAYR tag
	
					While Eof(0) = #Null																;loop as long the 'end of file' isn't reached
	
						v.l=ReadLong()																	;read a long
						tag.s="AAAA"
						PokeL(@tag,v)
						
						;*** Looking for geometry tags
	
						Select tag
	
						Case "PNTS"
	
							;*** Points found
	
							Debug "PNTS found",2
							
							;*** Nb of points
	
							nb.l=ReadLong()																;read a long
							MOV eax,nb																	;convert endians 
							BSWAP eax 
							MOV nb,eax	
;							!MOV eax,dword [v_nb]														;convert endians 
;							!bswap eax 
;							!MOV dword [v_nb],eax	
							Debug "Nb of points : "+Str(nb/12),2
							points_index_start=ListIndex(points())+1

							;*** One point = 12 bytes mini (4 bytes per axis)
	
							If nb>=$C						
	
								;*** Loop over points
	
								While Eof(0) = #Null And nb>0											;read sequentially x, y, z
	
									;*** New point
	
									AddElement(points())
									AddElement(transformed_points())
									total_points_nb+1
	
									l.l=ReadLong()														;read a long
									MOV eax,l															;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]												;convert endians and put the int to float
;									!bswap eax 
;									!MOV dword [v_f],eax	
									points()\x=f													
									Debug "x  "+StrF(f),3
	
									l.l=ReadLong()
									MOV eax,l															;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									points()\y=f
									Debug "y  "+StrF(f),3
	
									l.l=ReadLong()
									MOV eax,l															;convert endians and put the int to float
									BSWAP eax 
									MOV f,eax	
;									!MOV eax,dword [v_l]
;									!bswap eax 
;									!MOV dword [v_f],eax	
									points()\z=f
									Debug "z  "+StrF(f),3
	
									nb-12
	
								Wend
							EndIf
						
						Case "POLS"
						
							;*** Polygons found
	
							Debug "POLS found",2
						
							;*** Get size of this tag to process only this one
	
							pols_tagsize.l=ReadLong()													;read a long
							MOV eax,pols_tagsize														;convert endians 
							BSWAP eax 
							MOV pols_tagsize,eax	
;							!MOV eax,dword [v_pols_tagsize]												;convert endians 
;							!bswap eax 
;							!MOV dword [v_pols_tagsize],eax
	
							If Eof(0) = #Null
	
								;*** Get polygon type
	
								v.l=ReadLong()
								pols_tagsize-4
								tag.s="AAAA"
								PokeL(@tag,v)
								Debug tag,3
		
								Select tag
								Case "FACE"
								
									;*** Regular polygon found (first, nb of points, then index of points)
	
									Debug "FACE found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord()
										pols_tagsize-2
										MOV ax,points_nb												;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]										;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											total_polygons_nb+1
											polygons()\points_nb=points_nb
											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\layer_id=layer_id
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0

												AddElement(polygon_points_index())	

												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte()<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(Loc()-1)									;read a word
													w.w=ReadWord()	
													pols_tagsize-2
													MOV ax,w											;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]									;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax
													polygon_points_index()=w+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(Loc()-1)									;read a long
													l.l=ReadLong()	
													pols_tagsize-4
													MOV eax,l											;convert endians
													BSWAP eax 
													And eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]								;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax
													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1					
	
												EndIf										
											Wend
										EndIf
									Wend
									
								Case "PTCH"
								
									;*** Patch polygon found (first, nb of points, then index of points). Read only the cage polygons
	
									Debug "PTCH found",2
		
									;*** Process tag
	
									While Eof(0) = #Null And pols_tagsize>0							
		
										;*** How many points in this pol
	
										points_nb.w=ReadWord()
										pols_tagsize-2
										MOV ax,points_nb												;convert endians
										XCHG ah,al 
										MOV points_nb,ax
;										!MOV ax,word [v_points_nb]										;convert endians
;										!xchg ah,al 
;										!MOV word [v_points_nb],ax
										Debug "Nb of points in this patch polygon : "+Str(points_nb),2
					
										If points_nb>0							
	
											;*** There's at least one point : new polygon
	
											AddElement(polygons())
											total_polygons_nb+1
											polygons()\points_nb=points_nb
											polygons()\points_list=ListIndex(polygon_points_index())+1	;This polygon first point index position
											polygons()\layer_id=layer_id
	
											;*** Process all points of this poly : store indexes in polygon_points_index(), and first one pos in the polygon structure, with the nb of points
	
											While Eof(0) = #Null And points_nb>0
	
												AddElement(polygon_points_index())
											
												;*** Is this a long index, or a short? (more than 65279 points in this poly:long)
	
												If ReadByte()<>$FF										;read first byte, if $FF, index is a long, else it's a word
	
													;*** New short (word, 2 bytes) size index
	
													FileSeek(Loc()-1)									;read a word
													w.w=ReadWord()	
													pols_tagsize-2
													MOV ax,w											;convert endians
													XCHG ah,al
													MOV w,ax
;													!MOV ax,word [v_w]									;convert endians
;													!xchg ah,al
;													!MOV word [v_w],ax
													polygon_points_index()=w+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug w,3
													points_nb-1

												Else
	
													;*** New long (3 bytes in fact) size index
	
													FileSeek(Loc()-1)									;read a long
													l.l=ReadLong()	
													pols_tagsize-4
													MOV eax,l											;convert endians
													BSWAP eax 
													And eax,$00FFFFFF
													MOV l,eax
;													!MOV eax,dword [v_l]								;convert endians
;													!bswap eax 
;													!AND eax,$00FFFFFF
;													!MOV dword [v_l],eax
													polygon_points_index()=l+points_index_start			;value+start of this object's points list
													Debug "num:"+Str(points_nb),3
													Debug l,3
													points_nb-1
	
												EndIf										
											Wend
										EndIf
									Wend									
								Default

									;*** Pass over the unknown tag
					
									Debug tag+" found",2
									FileSeek(Loc()+pols_tagsize)
					
								EndSelect
							EndIf

						Default

							;*** Pass over the unknown tag
			
							Debug tag+" found",2
							v.l=ReadLong()																;read a long
							MOV eax,v																	;convert endians and put the int to float
							BSWAP eax 
							MOV v,eax
		;					!MOV eax,dword [v_v]														;convert endians and put the int to float
		;					!bswap eax 
		;					!MOV dword [v_v],eax
							Debug Str(v),3
							FileSeek(Loc()+v)
			
						EndSelect
						;**************************
					Wend
					
					current_layer+1																		;next layer (if exists)
				
				;*** Process others tag
	
				Default
	
					Debug tag+" found",2
					l.l=ReadLong()
					MOV eax,l																			;convert endians
					BSWAP eax 
					MOV l,eax
;					!MOV eax,dword [v_l]																;convert endians
;					!bswap eax 
;					!MOV dword [v_l],eax
					Debug l,3
					FileSeek(Loc()+l)																	;jump over the tag
	
				EndSelect
				;**************************
				
			Wend
			
		EndIf
		
		CloseFile(0)              																		; close the previously opened file
	
	Else
	
		MessageRequester("Information","Couldn't open the file!")
	
	EndIf
	
	Debug Str(total_layers_nb)+" layer(s)",1
	Debug Str(total_polygons_nb)+" polygon(s)",1
	Debug Str(total_points_nb)+" point(s)",1

EndProcedure	

;*********************************************************************************************************************************************************************


3ème : matrix.pb

Code : Tout sélectionner

;**********************
;* by djes
;* http://djes.free.fr
;* 4 nov 2005
;**********************

IncludePath "..\include\"
XIncludeFile "headers.pb"

;*************************************************************************************************************************************
Procedure.f pi()
 !FLDPI
EndProcedure

;*************************************************************************************************************************************

Procedure matrix_by_matrix_multiply(*a.matrix, *b.matrix) ;/* Return To a */

  DefType.matrix tmp

  For i.l = 0 To 2
    For j.l = 0 To 2
      tmp\mat[i+j*3] = *a\mat[i+0*3] * *b\mat[0+j*3] + *a\mat[i+1*3] * *b\mat[1+j*3] + *a\mat[i+2*3] * *b\mat[2+j*3]
    Next
  Next
  For i = 0 To 2
    For j = 0 To 2
      *a\mat[i+j*3] = tmp\mat[i+j*3];
    Next j
  Next i
;/* 3dica:
;   ¦ a b c ¦   ¦ k l m ¦   ¦ ak+bn+cq al+bo+cr am+bp+cs ¦
;   ¦ d e f ¦ * ¦ n o p ¦ = ¦ dk+en+fq dl+eo+fr dm+ep+fs ¦
;   ¦ h i j ¦   ¦ q r s ¦   ¦ hk+in+jq hl+io+jr hm+ip+js ¦
;*/
EndProcedure

;*************************************************************************************************************************************

Procedure matrix_copy(*a.matrix, *b.matrix) ;/* Return To a */

 For i=0 To 8
  *a\mat[i]=*b\mat[i]
 Next i

EndProcedure

;*************************************************************************************************************************************

Procedure matrix_by_vector_multiply(*vekto.vector, *result.vector, *mat.matrix)

 vekx.f=*vekto\x
 veky.f=*vekto\y
 vekz.f=*vekto\z

 *result\x = *mat\mat[0] * vekx + *mat\mat[1] * veky + *mat\mat[2] * vekz;
 *result\y = *mat\mat[3] * vekx + *mat\mat[4] * veky + *mat\mat[5] * vekz;
 *result\z = *mat\mat[6] * vekx + *mat\mat[7] * veky + *mat\mat[8] * vekz;

;/*
; 3dica:
;                ¦ a b c 0 ¦
;   (Xi+Yj+Zk) * ¦ e f g 0 ¦ = (aX+eY+iZ+m)i + (bX+fY+jZ+n)j +
;                ¦ i j k 0 ¦   (cX+gY+kZ+o)k
;                ¦ m n o 1 ¦
;*/
EndProcedure

;*************************************************************************************************************************************

Procedure matrix_rotation(*m.matrix, tangage.f, cap.f, roulis.f)

 sx.f=Sin(tangage)
 sy.f=Sin(cap)
 sz.f=Sin(roulis)

 cx.f=Cos(tangage)
 cy.f=Cos(cap)
 cz.f=Cos(roulis)

 *m\mat[0+0*3] = cy * cz;
 *m\mat[0+1*3] = cy * sz;
 *m\mat[0+2*3] = -sy;

 *m\mat[1+0*3] = sx * sy * cz - cx * sz;
 *m\mat[1+1*3] = sx * sy * sz + cx * cz;
 *m\mat[1+2*3] = sx * cy;

 *m\mat[2+0*3] = cx * sy * cz + sx * sz;
 *m\mat[2+1*3] = cx * sy * sz - sx * cz;
 *m\mat[2+2*3] = cx * cy;

;/*3dica:
;                     ¦ cy*cz          cy*sz          -sy    0 ¦
;                     ¦ sx*sy*cz-cx*sz sx*sy*sz+cx*cz  sx*cy 0 ¦
;       [X]*[Y]*[Z] = ¦ cx*sy*cz+sx*sz cx*sy*sz-sx*cz  cx*cy 0 ¦
;                     ¦ 0              0               0     1 ¦
;*/
EndProcedure

;*************************************************************************************************************************************

Procedure matrix_rotation_around_axis(*m.matrix, *axis.vector, angle.f)

 nx.f=*axis\x
 ny.f=*axis\y
 nz.f=*axis\z

 ;normalize axis
 length.f = Sqr(nx*nx + ny*ny + nz*nz);

 ;// too close To 0, can't make a normalized vector
 If (length < 0.000001) 
  length=0.000001
 EndIf

 nx = nx/length
 ny = ny/length
 nz = nz/length

 sina.f=Sin(angle)
 cosa.f=Cos(angle)

 nx2.f=nx*nx
 ny2.f=ny*ny
 nz2.f=nz*nz

 *m\mat[0+0*3] = nx2 + (1-nx2)*cosa
 *m\mat[0+1*3] = nx*ny*(1-cosa)+nz*sina
 *m\mat[0+2*3] = nx*nz*(1-cosa)-ny*sina

 *m\mat[1+0*3] = nx*ny*(1-cosa)-nz*sina
 *m\mat[1+1*3] = ny2+(1-ny2)*cosa
 *m\mat[1+2*3] = ny*nz*(1-cosa)+nx*sina

 *m\mat[2+0*3] = nx*nz*(1-cosa)+ny*sina
 *m\mat[2+1*3] = ny*nz*(1-cosa)-nx*sina
 *m\mat[2+2*3] = nz2+(1-nz2)*cosa

EndProcedure

;*************************************************************************************************************************************

Procedure matrix_identity(*m.matrix)

 *m\mat[0+0*3] = 1: *m\mat[1+0*3] = 0: *m\mat[2+0*3] = 0;
 *m\mat[0+1*3] = 0: *m\mat[1+1*3] = 1: *m\mat[2+1*3] = 0;
 *m\mat[0+2*3] = 0: *m\mat[1+2*3] = 0: *m\mat[2+2*3] = 1;
;/* 3dica:
;     ¦ 1 0 0 0 ¦
;     ¦ 0 1 0 0 ¦
;     ¦ 0 0 1 0 ¦
;     ¦ 0 0 0 1 ¦
;*/
EndProcedure

;*************************************************************************************************************************************

Procedure matrix_rotate_around_object_axis(*obj_rotation_matrix.matrix, tangage.f, cap.f, roulis.f) ;/* Return To obj_rotation_matrix. */

 Protected axis_x.vector, axis_y.vector, axis_z.vector
 Protected axis_x_rotation_matrix.matrix, axis_y_rotation_matrix.matrix, axis_z_rotation_matrix.matrix

 ;rotation autour de l'axe x de l'objet
 axis_x\x=*obj_rotation_matrix\mat[0+0*3]
 axis_x\y=*obj_rotation_matrix\mat[0+1*3]
 axis_x\z=*obj_rotation_matrix\mat[0+2*3]
 matrix_rotation_around_axis(@axis_x_rotation_matrix, @axis_x, tangage)

 ;rotation autour de l'axe y de l'objet
 axis_y\x=*obj_rotation_matrix\mat[1+0*3]
 axis_y\y=*obj_rotation_matrix\mat[1+1*3]
 axis_y\z=*obj_rotation_matrix\mat[1+2*3]
 matrix_rotation_around_axis(@axis_y_rotation_matrix, @axis_y, cap)

 ;rotation autour de l'axe z de l'objet
 axis_z\x=*obj_rotation_matrix\mat[2+0*3]
 axis_z\y=*obj_rotation_matrix\mat[2+1*3]
 axis_z\z=*obj_rotation_matrix\mat[2+2*3]
 matrix_rotation_around_axis(@axis_z_rotation_matrix, @axis_z, roulis)

 matrix_by_matrix_multiply(@axis_x_rotation_matrix,@axis_y_rotation_matrix)
 matrix_by_matrix_multiply(@axis_x_rotation_matrix,@axis_z_rotation_matrix)
 matrix_by_matrix_multiply(*obj_rotation_matrix,@axis_x_rotation_matrix)
EndProcedure

;*************************************************************************************************************************************

Procedure.f radians(angle.f)
!FLDPI

 ProcedureReturn (angle*2.0*#PI)/360.0
EndProcedure

;*************************************************************************************************************************************

Procedure.f degrees(angle.f)
 ProcedureReturn (angle*360.0)/(2.0*#PI)
EndProcedure

;*************************************************************************************************************************************

Procedure vector_define(*vertex.vector, x, y, z)
 *vertex\x=x
 *vertex\y=y
 *vertex\z=z
EndProcedure

;*************************************************************************************************************************************

Procedure vectors_add(*vertex.vector, *vertex2add.vector)
 *vertex\x+*vertex2add\x
 *vertex\y+*vertex2add\y
 *vertex\z+*vertex2add\z
EndProcedure

;*************************************************************************************************************************************

Procedure vectors_sub(*vertex.vector, *vertex2sub.vector)
 *vertex\x-*vertex2sub\x
 *vertex\y-*vertex2sub\y
 *vertex\z-*vertex2sub\z
EndProcedure

;*************************************************************************************************************************************

Procedure vector_copy(*vertexsrc.vector, *vertexdest.vector)
 *vertexdest\x=*vertexsrc\x
 *vertexdest\y=*vertexsrc\y
 *vertexdest\z=*vertexsrc\z
EndProcedure

;*************************************************************************************************************************************

Procedure vector_rotate(*vertex.vector, *pivot.vector, tangage.f, cap.f, roulis.f)

 vectors_sub(*vertex, *pivot)

 If roulis <> 0
     x.f = Cos(roulis) * *vertex\x - Sin(roulis) * *vertex\z
     *vertex\z = Sin(roulis) * *vertex\x + Cos(roulis) * *vertex\z
     *vertex\x = x
 EndIf

 If tangage <> 0
     y.f = Cos(tangage) * *vertex\y - Sin(tangage) * *vertex\z
     *vertex\z = Sin(tangage) * *vertex\y + Cos(tangage) * *vertex\z
     *vertex\y = y
 EndIf

 If cap <> 0
     x.f = Cos(cap) * *vertex\x - Sin(cap) * *vertex\y
     *vertex\y = Sin(cap) * *vertex\x + Cos(cap) * *vertex\y
     *vertex\x = x
 EndIf

 vectors_add(*vertex, *pivot)

EndProcedure

;*************************************************************************************************************************************

Procedure vector_rotate2(*vertex.vector, *pivot.vector, tangage.f, cap.f, roulis.f )

  cr.f = Cos( tangage );
  sr.f = Sin( tangage );
  cp.f = Cos( roulis  );
  sp.f = Sin( roulis  );
  cy.f = Cos( cap );
  sy.f = Sin( cap );

  Dim m.f(12)
  m(0) = ( cp*cy );
  m(1) = ( cp*sy );
  m(2) = ( -sp );

  srsp.f = sr*sp;
  crsp.f = cr*sp;

  m(4) = ( srsp*cy-cr*sy );
  m(5) = ( srsp*sy+cr*cy );
  m(6) = ( sr*cp );

  m(8) = ( crsp*cy+sr*sy );
  m(9) = ( crsp*sy-sr*cy );
  m(10) = ( cr*cp );

  tmpx.f=*vertex\x
  tmpy.f=*vertex\y
  tmpz.f=*vertex\z

  *vertex\x = tmpx*m(0) + tmpy*m(1) + tmpz*m(2);
  *vertex\y = tmpx*m(4) + tmpy*m(5) + tmpz*m(6);
  *vertex\z = tmpx*m(8) + tmpy*m(9) + tmpz*m(10)

EndProcedure
Ensuite, voici un programme d'exemple (il vous faut la lib spritedx9 dispo là http://forums.purebasic.com/english/vie ... =spritedx9)). Vous pouvez aussi adapter le code

Code : Tout sélectionner

;**********************
;* by djes
;* http://djes.free.fr
;* 4 nov 2005
;**********************

EnableDebugger
DebugLevel 2

IncludePath "..\include\"
XIncludeFile "headers.pb"
XIncludeFile "matrix.pb"
XIncludeFile "lwo_loader.pb"

InitSpriteDX9() 
InitKeyboard()
InitMouse()

; **** Run Windowed/FullScreen Mode? 

lResult = MessageRequester("Please select:","Run example in FullScreen mode?",#PB_MessageRequester_YesNo)

If lResult = #PB_MessageRequester_No      ; User pressed NoButton
	lMode = #PB_D3D_Windowed|#PB_D3D_AlphaBlending;|#PB_D3D_CopyBuffer;#PB_D3D_AntiAliasing4
	hScreen = OpenScreenDX9(800,600,32,OpenWindow(0,0,0,800,600,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"SpriteDX9 Example"),lMode)
Else                                      ; User pressed YesButton
	lMode = #PB_D3D_AlphaBlending;|#PB_D3D_AntiAliasing4;|#PB_D3D_CopyBuffer|
	hScreen = OpenScreenDX9(800,600,32,"SpriteDX9 Example",lMode)
EndIf

; *** Open DirectX9 Screen

If hScreen = 0 
	MessageRequester("Error","Cant open DirectX9 Screen",0)
	End
EndIf

; *** Petites variables pour la persp

SetLineWidthDX9(2)

RandomSeed(ElapsedMilliseconds())

D3DBLEND_SRC=#D3DBLEND_SRCCOLOR
D3DBLEND_DEST=#D3DBLEND_ONE

cap.f=0.01
tangage.f=0.015
roulis.f=0.018
d.f=200
ppd.f=-160

Gosub INIT_OBJECTS
Gosub TRANSFORM_OBJECTS

; *** M a i n L o o p
 
Repeat

	ClearScreenDX9(RGBA(0,0,100,0))

	StartDX9(#D3DXSPRITE_ALPHABLEND)
		SetAlphaBlendingDX9(#True,D3DBLEND_SRC,D3DBLEND_DEST)
		Gosub DRAW_OBJECTS
	StopDX9()

	FlipBuffersDX9()

	; -------- Obj movements --------

	Gosub TRANSFORM_OBJECTS

	; -------- Check Window Events --------

	lEvent.l = WindowEvent()
	While lEvent
		If lEvent = #PB_Event_CloseWindow
			wQuit.w = 1
		EndIf
		lEvent = WindowEvent()
	Wend
	
	; -------- Check if ESCAPE pressed --------
	DisableDebugger
	ExamineKeyboard()
	ExamineMouse()
	If KeyboardPushed(#PB_Key_Space)
		d+100
		If d>10000000
			d=0
		EndIf
	EndIf
	
Until KeyboardPushed(#PB_Key_Escape) Or wQuit

EnableDebugger

CloseScreenDX9()
End


;*** New object

INIT_OBJECTS:

	LWO_Load("toile4.lwo")
	matrix_identity(@objects()\rotation)
;	LWO_Load("sphere.lwo")
;	matrix_identity(@objects()\rotation)
;	LWO_Load("cube2.lwo")
;	matrix_identity(@objects()\rotation)
  Return

;*** Draw objects

DRAW_OBJECTS:

	ResetList(objects())
	While NextElement(objects())
		object.l=ListIndex(objects())
		xc.f=objects()\pivot\x
		yc.f=objects()\pivot\y
		zc.f=objects()\pivot\z
		col.l=RGBA(100,100,100,150)
		ResetList(layers())
		While NextElement(layers())	
			If layers()\object_id=object
				layer.l=ListIndex(layers())
				ResetList(polygons())
				While NextElement(polygons())
					If polygons()\layer_id=layer
						SelectElement(polygon_points_index(), polygons()\points_list)				;locate the first point of this polygon in the index
						SelectElement(transformed_points(),polygon_points_index())					;select the point
						x1t.f=400+((xc+transformed_points()\x)*d)/(ppd+(zc+transformed_points()\z))
						y1t.f=300+((yc+transformed_points()\y)*d)/(ppd+(zc+transformed_points()\z))
						NextElement(polygon_points_index())											;next point in the index
						For u=1 To polygons()\points_nb-1
							SelectElement(transformed_points(),polygon_points_index())				;give the point
							x2t.f=400+((xc+transformed_points()\x)*d)/(ppd+(zc+transformed_points()\z))
							y2t.f=300+((yc+transformed_points()\y)*d)/(ppd+(zc+transformed_points()\z))
							LineDX9(x1t,y1t,x2t,y2t,col)
							x1t=x2t
							y1t=y2t
							NextElement(polygon_points_index())
						Next u	
					EndIf
				Wend
			EndIf
		Wend
	Wend		
	Return
	
;*** Transform objects

TRANSFORM_OBJECTS:

	ResetList(objects())
	While NextElement(objects())	
		object.l=ListIndex(objects())
		matrix_rotate_around_object_axis(@objects()\rotation, tangage.f, cap.f, roulis.f)
		ResetList(layers())
		While NextElement(layers())	
			If layers()\object_id=object
				layer.l=ListIndex(layers())
				ResetList(polygons())
				While NextElement(polygons())
					If polygons()\layer_id=layer
						SelectElement(polygon_points_index(), polygons()\points_list)				;locate the first point of this polygon in the index
						For u=1 To polygons()\points_nb
							SelectElement(points(),polygon_points_index())							;select the point
							SelectElement(transformed_points(),polygon_points_index())
							matrix_by_vector_multiply(@points(), @transformed_points(),  @objects()\rotation)
							NextElement(polygon_points_index())
						Next u
					EndIf
				Wend
			EndIf
		Wend
	Wend		
	Return
L'objet lightwave utilisé est dispo ici : http://djes.free.fr/purebasic/toile4.lwo

Je suis ouvert à toute suggestion :D

Have fun!

Publié : sam. 05/nov./2005 16:12
par djes
Comme je n'ai pas beaucoup de réponses, je vous ai mis quelques petits exemples.

L'un en utilisant les codes ci-dessous (un peu lent) : http://djes.free.fr/purebasic/djes_lwo_ ... xample.zip

L'autre, sur des test effectués avant, avec un convertisseur que j'avais fait sur amiga :
http://djes.free.fr/purebasic/djes_spri ... xample.zip

Publié : dim. 06/nov./2005 10:13
par Crystal Noir
joli travail ! hop c'est sur DevMag ^^

Publié : dim. 06/nov./2005 14:00
par djes
Oups!

Publié : dim. 06/nov./2005 19:54
par Crystal Noir
? euh que se passe t'il ?

Publié : lun. 07/nov./2005 10:54
par djes
Non, rien :lol: Juste un peu de timidité!

Merci!