3D Vector objects in C using the PIC micro
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 it uses a serial interface (rs232) to send commands. I have a new Nokia LCD with SPI bus but havent written the drivers yet.
128×160 x 65k colour LCD
- Full Parallel interface (not nokia 6100 spi anymore!)
- Write directly to LCDRAM buffer and READ back now too!
- 256 colour mode (also 4096 and 65k modes available but unused)
- Interface to PC for power RS232 Serial port
- Bootloader interface to PC
Vector object [DONE]
Offscreen clipping [In progress]
Hidden line Rem [N/A]
Backface Culling [DONE]
Solid Fill [DONE]
Colour Shading [TBC]
New 3.3v PIC [DONE]
New faster LCD [DONE]
New parallel LCD [DONE]
GFX routines [DONE]
Double buffer [CANCELLED]
New 3D routine [DONE]
20 to 40mghz [DONE]
Analogue input [DONE]
Get the source code here. This is the basic vector code only however!
The 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!
Ive made a complete new system using the same pic, but a new LCD. The 128×160 LCD is better in every way. I am now going to optimise things even further.
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.
New display turned up today, an OLED 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 Dontronics where I got my first uLCD display. You can also get other stuff like the usb driver module from them.
UPDATE – 10\09\2006
Wow, 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.
UPDATE – 9\09\2006
Finally 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.
UPDATE – 26\08\2006
Lots 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.
UPDATE – 18\08\2006
BIG 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.
I 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.
UPDATE – 16\08\2006
Ok, 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!
Now 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.
UPDATE – 08\08\2006
Managed 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.
Im 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.
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.
Final 3D routine with backface culling, on black background.
Better video of the solid cube. Ish.
First video of solid 3D objects, the flicker is because the screen turns off during redraw
NEW! All new board, new pic, new LCD and new input.
Ok, Was bored with a cube, so made an Elite Spaceship!
Here is the video of the controller doing rotation instead of location. Its pretty trippy watching the cube mirror your control of the physical object!
Here 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 “tilt” the thing in the z axis!
Here is the original Video as I first got the 3D working. No control yet, it just drifted around.