3d图像的旋转算法(Rotation algorithm of 3D image)
12864 LCD driver simply do not quote out, the function is to draw a straight line and screen. The key part is the rotation algorithm of 3D images. Here is my reference to the source code (add some Chinese notes, copyright to the original author all):
Cube by Jason / / 3D Wright (C) opyright Pyrofer 2006
/ /
Code is / / This free there is no charge for it nor should anybody else charge
The code / / for, its distribution or derivitives of this code. / /
May use this / / You code, modify and change and improve upon it on the following conditions,
/ /
1> You send me the modified / source code and where possible make it public
2> I am credited for the / original work in all derivitives of this code
3> You do not charge for / this code or code derived from this code
4> You comment the code you / / change!
/ /
Use this / / Basically, to learn I couldnt find anything this! Simple when I started so I hope
That this helps others to learn. / You should be able to change the LCD routines to drive almost
Any graphics device. The base resolution / is 128x128 for this display. Simply set the X and Y offset
To half the screen resolution for / each axis.
Then adjust the Z offset to / make the object fit nicely in the screen.
#device PIC18F2520
#include "C:\Dev\PICC\PCW Projects\Dontronics LCD\gfxlcd.h""
#include "math.h" complex math routines / / include
#ORG 0x1E00,0x1FFF{} reserve ROM spce to protect bootloader / / program
#fuses HS, NOWDT, NOPROTECT / / set pic fuses
#use delay (clock=20000000) set Clock speed for time calculations / / 20Mghz
#use RS232 (baud=115200, xmit=PIN_C1, rcv=PIN_C0) up IO for LCD / / set
The following is the definition of the / * center of the image is displayed in the LCD, 12843 can be changed to 64,32,30.
#define OFFSETX 64 for screen wont change unless / / offset
#define OFFSETY 64 use different screen / / I so its kinda fixed!
#define OFFSETZ 30
Void cube (void); / / define the subroutines this one is the actual cube routine
Void clearscreen (void); / / clear the LCD screen
Void (lcdline); / / draw a line on the LCD
Void initlcd (void); / / initialise the LCD
Void proginit (void); / / setup other program stuff
Void shutdown (void); / / shutdown the LCD
Const as they are in / use ROM, saving RAM
The following part / * define a cube.
Const signed int aa[8]={10, -10, -10,10, 10, -10, -10,10} data
for shape vertex; / / X
Const signed int bb[8]={10,10, -10, -10, 10,10, -10, -10} data for shape vertex; / / Y
Const signed int cc[8]={-10, -10, -10, -10, 10,10,10,10} data for shape vertex; / / Z
Const int ff[12]={1,2,3,4, 5,6,7,8 1,2,3,4}, vertex for lines; / / start
Const int gg[12]={2,3,4,1, 6,7,8,5 5,6,7,8}, vertex for lines; / / end
Int SX, sy, ex, ey; define global vars for calling graphics / / subroutines
Void main () / / begin main program.
{
Initlcd (); / / set autobaud and clearscreen
Proginit (); / / call program inits
Cube (); / / call main cube drawing routine
Delay _ MS (9999); / / wait for ages while we look at the pretty picture
Clearscreen (); / / clear the screen
float upShutdown (); / / turn off the LCD ready for power down.
While (1); / / wait forever the program is done.
}
The void cube () / / routine to draw and calc 3D cube
{
Int newx [8]; / / translated screen x co ordinates is vertex
Int newy [8]; / / translated screen y co ordinates is vertex
Int i, loop; / / temp variable for loops:
Float XT, YT, ZT, x, y, Z, sinax, cosax, Sinay, cosay, sinaz, cosaz, vertex; / / lots of work variables
Float XPOS = 0; / / position for object in 3D space, in X
Float YPOS = 0; / / Y
Float zpos = 0; / / and Z values
Float ROTx = 0; / / starting amount of X rotation
Float ROTY = 0; / / starting amount of Y rotation
Float Rotz = 0; / / starting amount of Z rotation
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论