{"id":3,"date":"2007-03-08T18:17:55","date_gmt":"2007-03-08T18:17:55","guid":{"rendered":"http:\/\/www.pyrofersprojects.com\/blog\/?page_id=3"},"modified":"2009-04-15T12:54:05","modified_gmt":"2009-04-15T12:54:05","slug":"3dpic","status":"publish","type":"page","link":"https:\/\/www.pyrofersprojects.com\/blog\/3dpic\/","title":{"rendered":"3D Vector objects in C using the PIC micro"},"content":{"rendered":"<p><a href=\"http:\/\/www.pyrofersprojects.com\/images\/3dcube.jpg\"> <img decoding=\"async\" alt=\"3dcube.jpg\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/3dcube.thumbnail.jpg\" \/> <\/a> <a href=\"http:\/\/www.pyrofersprojects.com\/images\/3dpic.jpg\"><img decoding=\"async\" alt=\"noklcd3d.jpg\" id=\"image5\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/noklcd3d.thumbnail.jpg\" \/><\/a>  <a href=\"http:\/\/www.pyrofersprojects.com\/images\/3dcube.jpg\"><img decoding=\"async\" alt=\"3dpic.jpg\" id=\"image7\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/3dpic.thumbnail.jpg\" \/><\/a><br \/>\n<a href=\"http:\/\/www.pyrofersprojects.com\/images\/new3d.jpg\"><img decoding=\"async\" alt=\"new3d.jpg\" id=\"image8\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/new3d.thumbnail.jpg\" \/><\/a>  <a href=\"http:\/\/www.pyrofersprojects.com\/images\/new3dpic.jpg\"><img decoding=\"async\" alt=\"new3dpic.jpg\" id=\"image9\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/new3dpic.thumbnail.jpg\" \/><\/a>  <a href=\"http:\/\/www.pyrofersprojects.com\/images\/3dground.jpg\"><img decoding=\"async\" alt=\"3dground.jpg\" id=\"image10\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/3dground.thumbnail.jpg\" \/><\/a><br \/>\nThis is my first attempt at 3D graphics on a uP (microprocessor). I started out with some simple vector graphics, the end goal is a full filled 3D object that can move offscreen in some sort of Elite style dogfight. Id love to write a whole elite game, this LCD isnt fast enough though because it uses a serial interface (rs232) to send commands. I have a new Nokia LCD with SPI bus but havent written the drivers yet.<\/p>\n<p>HARDWARE<br \/>\nPic18LF2620<br \/>\n\u2013 40mghz<br \/>\n128\u00d7160 x 65k colour LCD<br \/>\n\u2013 Full Parallel interface (not nokia 6100 spi anymore!)<br \/>\n\u2013 Write directly to LCDRAM buffer and READ back now too!<br \/>\n\u2013 256 colour mode (also 4096 and 65k modes available but unused)<br \/>\nUSB<br \/>\n\u2013 Interface to PC for power RS232 Serial port<br \/>\n\u2013 Bootloader interface to PC<\/p>\n<p>FEATURES<br \/>\nVector object\t   [DONE]<br \/>\nMovement\t   [DONE]<br \/>\nRotation\t   [DONE]<br \/>\nOffscreen clipping [In progress]<br \/>\nHidden line Rem    [N\/A]<br \/>\nBackface Culling   [DONE]<br \/>\nSolid Fill\t   [DONE]<br \/>\nColour Shading\t   [TBC]<br \/>\nNew 3.3v PIC       [DONE]<br \/>\nNew faster LCD\t   [DONE]<br \/>\nNew parallel LCD   [DONE]<br \/>\nGFX routines       [DONE]<br \/>\nDouble buffer      [CANCELLED]<br \/>\nNew 3D routine\t   [DONE]<br \/>\n20 to 40mghz       [DONE]<br \/>\nAnalogue input\t   [DONE]<\/p>\n<p><script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"pub-4526948230635423\";\n\/* 300x250, created 4\/15\/09 *\/\ngoogle_ad_slot = \"4264399593\";\ngoogle_ad_width = 300;\ngoogle_ad_height = 250;\n\/\/-->\n<\/script><br \/>\n<script type=\"text\/javascript\"\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><br \/>\nGet the source <a href=\"http:\/\/www.pyrofersprojects.com\/code\/3dcube.txt\">code<\/a> here. This is the basic vector code only however!<br \/>\nThe analogue input (2 axis) allows me to move or rotate the object as required by hand and will form the basis of the end game controls. A fire button is needed!<\/p>\n<p>UPDATE 16\\07\\2007<\/p>\n<p>Ive made a complete new system using the same pic, but a new LCD. The 128\u00d7160 LCD is better in every way. I am now going to optimise things even further.<\/p>\n<p>Ive converted the sin\/cos to a lookup table rather than live math (big speed increase) and am looking at ways to make the redraw look smoother.<\/p>\n<p>UPDATE 24\\09\\2006<br \/>\nNew display turned up today, an <a href=\"http:\/\/www.dontronics-shop.com\/product.php?productid=16535&cat=263&page=1\">OLED<\/a> screen. Its amazing, such a great clear display. I will post some pictures as soon as I get the 3D running on it, if you want to buy one they are available with controler and RS232 (ttl) interface from <a href=\"http:\/\/www.dontronics-shop.com\">Dontronics<\/a> where I got my first uLCD display. You can also get other stuff like the <a href=\"http:\/\/www.dontronics-shop.com\/product.php?productid=16497&cat=0&page=1\">usb<\/a> driver module from them.<\/p>\n<p>UPDATE \u2013 10\\09\\2006<br \/>\nWow, Look at this one. A landscape! Ive written a second routine that draws a 3d landscape, with the intention of being able to scroll around it so the ship can fly over solid ground.<\/p>\n<p>UPDATE \u2013 9\\09\\2006<br \/>\nFinally got backface culling to work perfectly. I can now render any 3d object built from 3point polygons (triangles) with quite a good speed. All hidden faces (facing away from you) are not drawn so no z buffer\/sort is needed. The Flicker is due to the extra power drain from changing the background to black on the LCD, I need to fix that with a seperate power supply for LCD drive.<\/p>\n<p>UPDATE \u2013 26\\08\\2006<br \/>\nLots of improvement in the code, but no breakthrough in speed. I have an idea to speed it up a lot, but require some more ICs. A simple logic chip will help, ill update if there is any new on that.<\/p>\n<p>UPDATE \u2013 18\\08\\2006<br \/>\nBIG NEWS! Look at the latest picture, I now have SOLID faces to the object. Its back to a cube because its really hard working out the shape! I re-wrote the whole 3D routine from scratch, previously I had a points array, and an array of points to join with lines. This was great for making shapes, but HARD for doing solid. Now the new routine is based entirely on Triangles. This basic polygon can make up any other shape and is a great basis for 3D. Each cube face is 2 triangles, I could make a round object if I put enough polygons in.<br \/>\nI also re-wrote the drawing routines for the LCD, its much more efficient now, and thats why I can manage to do the solid shape at all. Sorry there is no video but my Wife is on holiday with the good camera, hence the crappy picture. I will update with video and good quality pics when I have a good camera (and my wife) back.<\/p>\n<p>UPDATE \u2013 16\\08\\2006<br \/>\nOk, got the board running at 40Mghz, the Pic uses a 10.24 Mghz Crystal with *4 Pll internaly. This was the easiest way to do this. Maybe a 40Mghz Oscilator would be better, but I didnt have one handy!<br \/>\nNow the board runs at 3.3v I needed a new way to power it. Ive put a USB connector on the board to supply 5v and a 3.3v regulator so I have 5v and 3.3v both onboard. The serial output is still via a normal RS232 interface using a Max232, but I will fit a usb to serial on the board next to remove the extra serial connection, that way the USB port will allow downloading of code via bootloader as well as providing power.<\/p>\n<p>UPDATE \u2013 08\\08\\2006<br \/>\nManaged to get the new Nokia 6100 colour LCD working, and ported most of the 3D code over to a new board. Whole project has moved from 5v to a 3.3v board. The new LCD uses an SPI bus instead of rs232 and can transfer data a lot quicker, on the downside it has no graphics routines built in and I need to write them. This means clearscreen consists of writing 18000 pixels or so in sequence to the LCD to blank it out. My pic is only running at 20mghz and that still takes ages with a visible redraw.<br \/>\nIm going to double the PIC clock speed to increase the framerate, this means changing the board design again though as I need to move from a 20mghz crystal to 40mghz Oscillator.<\/p>\n<p>Here is the new Larger LCD with old code running. Ive ported things to work with the new LCD in parallel but have done nothing to the 3d code yet.<\/p>\n<p><a href=\"http:\/\/www.youtube.com\/v\/UIUa3bFyVJc\"> <img decoding=\"async\" alt=\"3D on new LCD\" id=\"image80\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/07\/newlcd.thumbnail.jpg\" \/><\/a><br \/>\nFinal 3D routine with backface culling, on black background.<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/jlesuvBgyrQ\">  <img loading=\"lazy\" decoding=\"async\" width=\"127\" height=\"96\" alt=\"jlesuvbgyrq.jpg\" id=\"image12\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/jlesuvbgyrq.thumbnail.jpg\" \/><\/a><br \/>\nBetter video of the solid cube. Ish.<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/-W8cvSNXozk\">  <img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/w8cvsnxozk.thumbnail.jpg\" \/><\/a><br \/>\nFirst video of solid 3D objects, the flicker is because the screen turns off during redraw<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/sZ1lw3jfBWY\">  <img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/sz1lw3jfbwy.thumbnail.jpg\" \/><\/a><br \/>\nNEW! All new board, new pic, new LCD and new input.<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/Ky1tvE2hEtk\">  <img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/ky1tve2hetk.thumbnail.jpg\" \/><\/a><br \/>\nOk, Was bored with a cube, so made an Elite Spaceship!<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/_S7mjUZVw60\"><img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/s7mjuzvw60.thumbnail.jpg\" \/><\/a><br \/>\nHere is the video of the controller doing rotation instead of location. Its pretty trippy watching the cube mirror your control of the physical object!<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/z2LescrWzAs\"><img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/z2lescrwzas.thumbnail.jpg\" \/><\/a><br \/>\nHere is the video of me controlling the cube with a 3axis (z not used yet) accelerometer. Tilting it in either x or y axis makes the cube move that way. Next is the z axis, but its kinda hard to \u201ctilt\u201d the thing in the z axis!<br \/>\n<a href=\"http:\/\/www.youtube.com\/v\/ImKOZp5PN4Q\"><img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/imkozp5pn4q.thumbnail.jpg\" \/><\/a><br \/>\nHere is the original Video as I first got the 3D working. No control yet, it just drifted around.<\/p>\n<p><a href=\"http:\/\/www.youtube.com\/v\/3tsyNusH0bE\">  <img decoding=\"async\" alt=\"Video\" id=\"image6\" src=\"http:\/\/www.pyrofersprojects.com\/blog\/wp-content\/uploads\/2007\/03\/3tsynush0be.thumbnail.jpg\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is my first attempt at 3D graphics on a uP (microprocessor). I started out with some simple vector graphics, the end goal is a full filled 3D object that can move offscreen in some sort of Elite style dogfight. Id love to write a whole elite game, this LCD isnt fast enough though because [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/pages\/3","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/comments?post=3"}],"version-history":[{"count":3,"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/pages\/3\/revisions"}],"predecessor-version":[{"id":220,"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/pages\/3\/revisions\/220"}],"wp:attachment":[{"href":"https:\/\/www.pyrofersprojects.com\/blog\/wp-json\/wp\/v2\/media?parent=3"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}