Creating / modifying objects using memblocks. by Rob K31st Aug 2003 10:58
|
---|
Summary Shows the basics of creating and modifying objects at a very low level. Description Using memblocks, you can modify the position / normals of individual verticies (the points which are linked together to form the faces of an object). You can also adjust UV texture co-ordinates (which specify how textures are mapped to the object), and adjust the color and alpha components of individual verticies (useful for making the end of a beam fade out for example). Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on: sync rate 0 rem setting the triangle vars polys=1 x1#=-3.0 : y1#=2.0 : z1#=1.0 x2#=3.0 : y2#=2.0 : z2#=-1.0 x3#=-1.0 : y3#=-1.0 : z3#=0.0 rem make the memblock with the right size (Each poly has 3 vertices with 36 bytes of data each) rem plus another 12 bytes for the header make memblock 1,(polys*3*36)+12 rem write the header rem FVF format (4 bytes, so a dword) this is normally 338 write memblock dword 1,0,338 rem FVF size (in this case 36 bytes) write memblock dword 1,4,36 rem Number of vertices write memblock dword 1,8,polys*3 rem writing data for the first vertex rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point) write memblock float 1,12,x1# write memblock float 1,16,y1# write memblock float 1,20,z1# rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal) write memblock float 1,24,0 write memblock float 1,28,0 write memblock float 1,32,-1.00 rem color (as a dword, or as 4 bytes blue,green,red,alpha) write memblock dword 1,36,rgb(255,0,0) rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture write memblock float 1,40,0.00 write memblock float 1,44,0.00 rem writing data for the second vertex rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point) write memblock float 1,12+36,x2# write memblock float 1,16+36,y2# write memblock float 1,20+36,z2# rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal) write memblock float 1,24+36,0 write memblock float 1,28+36,0 write memblock float 1,32+36,-1.00 rem color (as a dword, or as 4 bytes blue,green,red,alpha) write memblock dword 1,36+36,rgb(0,255,0) rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture write memblock float 1,40+36,1.00 write memblock float 1,44+36,0.00 rem writing data for the third vertex rem position (3 floats(float=4 bytes) for the x,y and z position of the vertex point) write memblock float 1,12+72,x3# write memblock float 1,16+72,y3# write memblock float 1,20+72,z3# rem normal (again 3 floats) we well set it so each vertex point faces the camera (not normal) write memblock float 1,24+72,0 write memblock float 1,28+72,0 write memblock float 1,32+72,-1.00 rem color (as a dword, or as 4 bytes blue,green,red,alpha) write memblock byte 1,36+72,0 write memblock byte 1,36+73,0 write memblock byte 1,36+74,255 write memblock byte 1,36+75,0 rem UV texture coordinates (2 floats) doesn't matter for now, because we don't give it a texture write memblock float 1,40+72,0.50 write memblock float 1,44+72,1.00 rem make a mesh out of this memblock make mesh from memblock 1,1 rem make an object with this mesh make object 1,1,0 position camera 0,0,-10 set object transparency 1,1 do text 20,40,"Screen FPS: " + str$(Screen FPS()) sync loop |