

	3DRW File Format
			
	© Copyright 1995, 1996 Jose M. Arnesto (Keved / Capsule)
			




Copyright
*********

	The 3DRW file format is copyright 1995, 1996 by Jose M. Arnesto 
 (Keved / Capsule). This format can only be used in Amiga programs and its 
 use on other platforms is prohibited.




Introduction
************



	The idea behind 3DRW was to create a file format to store 3D objects. 
 Many others were available, but all of them were too complicated to use 
 in demos, with features never needed in them. 3DRW is much simpler than 
 all of them, so its use in scene productions is easier.



The author
**********

	Please, if you like TDDD to Raw or the 3DRW format and use any of
 them often, send me a postcard of your hometown. It is nice to hear about
 Amiga mates out there.

	You can contact me at this address:
	
	Jose M. Arnesto
	c/ Pando, 2-2șA
	39300 Torrelavega
	Spain
	
	
	jarnesto@bitmailer.net

 
Description
***********



	A 3DRW file begins with a header. The offset of the points list is
 relative to the beginning of the file, and a value of zero means that the
 object only has points, not faces.


	0000	LONG		'3DRW'
	0004	WORD		file version (currently set to zero)
	0006	LONG		offset of the points list
		

	At present, 3DRW files can only store an object. It is described as
 a list of faces, which is optional, and a list of points. 3DRW describes 
 faces as triangles, composed by three points each.
 	
 	The list of faces, if present,  begins with a word containing the 
 number of faces minus one, as it is prepared to be used as counter in a 
 dbf loop.

 	Each face begins with a word for the color of that face, which will
 currently be set to zero. Six more words contain the numbers of the points
 that compose that face, as 3DRW describes them as triangles, and each vertex 
 has an starting point and an end point. That numbers, if multiplicated by
 four, can be used as offsets in a 2D list of the points coordinates.

	The points in each face are clock-wise ordered, so they can be
 easily used in light source routines.
 	
	0010	WORD		number of faces - 1 (for dbf)
		
	0012	WORD		color of this face (currently set to zero)
	0014	WORD		point number 00
	0016	WORD		point number 01
	0018	WORD		point number 10
	0020	WORD		point number 11
	0022	WORD		point number 20
	0024	WORD		point number 21
	
	The list of points begins at the point described at the file header.
 It has a word containing the number of points minus one, to use it in a
 dbf file. Then, each point has an X, Y, and Z coordinate.

	0000	WORD		number of points - 1 (for dbf)

	0002	WORD		x coordinate
	0004	WORD		y coordinate
	0006	WORD		z coordinate
		
		

Usage
*****


	
	To use an 3DRW file in your demo, first of all, load it or incbin it.
 Then, use the offset of the points list to obtaing the starting address of
 the list of points. 
 	
	Do any operations to the 3D coordinates of the points and store
 the result, projected to 2D, in another buffer (2Dbuf). In that buffer, 
 each point will be composed of four bytes, that is, a word for its x 
 coordinate and another one for its y coordinate.
 	Then, use the list of faces to draw it, using the point numbers of
 each face as offsets to the 2D buffer (2Dbuf).
 
 	A sample of assembly code is provided . Its only purpose is to serve
 as an example. 
 
 
 
 		lea	buffer,a0	points to the file
 		move.l	a0,a1		copies pointer
 		add.l	6(a0),a1	adds the offset to the points list
 		add.l	#10,a0		jumps over the header
 		move.l	a0,facelist	stores pointer to the faces list
 		move.l	a1,pointlist	stores pointer to the points list
 
 		...
 
 		move.l	pointlist,a0	points to the points list
 		lea	2Dbuf,a1	points to the 2D coords buffer
 		move.w	(a0)+,d0	gets the number of points
 		
operate3D	move.w	(a0)+,d1	gets x coordinate
		move.w	(a0)+,d2	gets y coordinate
		move.w	(a0)+,d3	gets z coordinate
 
 		...			operates in 3D and projects to 2D
 		
 		move.w	d4,(a1)+	stores x coordinate
 		move.w	d4,(a1)+	stores y coordinate
 		dbf	d0,operate3D
 
 		...
 
 		move.l	faceslist,a0	points to the faces list
 		lea	2Dbuf,a1	points to the 2D coords buffer
 		move.w	(a0)+,d0	gets number of faces
 		
drawing		move.w	(a0)+,d1	gets color
 		move.w	(a0)+,d2	number of first point, first vertex
 		move.w	(a0)+,d3	number of second point, first vertex
 		asl.w	#2,d2		multiplicates offsets by four
 		asl.w	#2,d3		
 		move.w	(a1,d2),d4	first point, first vertex, x coord
 		move.w	2(a1,d2),d5	first point, first vertex, y coord
 		move.w	(a1,d3),d6	second point, first vertex, x coord
 		move.w	2(a1,d3),d7	second point, first vertex, y coord
 
		...			draw line
 
 		move.w	(a0)+,d2	number of first point, second vertex
 		move.w	(a0)+,d3	number of second point, second vertex
 		asl.w	#2,d2		multiplicates offsets by four
 		asl.w	#2,d3	
		move.w	(a1,d2),d4	first point, second vertex, x coord
 		move.w	2(a1,d2),d5	first point, second vertex, y coord
 		move.w	(a1,d3),d6	second point, second vertex, x coord
 		move.w	2(a1,d3),d7	second point, second vertex, y coord

		...			draw line
 
 		move.w	(a0)+,d2	number of first point, third vertex
 		move.w	(a0)+,d3	number of second point, third vertex
 		asl.w	#2,d2		multiplicates offsets by four
 		asl.w	#2,d3	
 		move.w	(a1,d2),d4	first point, third vertex, x coord
 		move.w	2(a1,d2),d5	first point, third vertex, y coord
 		move.w	(a1,d3),d6	second point, third vertex, x coord
 		move.w	2(a1,d3),d7	second point, third vertex, y coord

		...			draw line
 	
 		dbf	d0,drawing
 
 
file		incbin	'object.raw'

facelist	ds.l	1
pointlist	ds.l	1
2Dbuf		ds.l	???	(its length depends on the number of points)

 