Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define IN_BOUNDS(_x,_y, _w,_h) (_x>=0 && _x<_w && _y>=0 && _y<_h)
- void bresenhamAll(KIT_Color* pixels,int w,int h, int x0,int y0, int x1,int y1){
- int dx=abs(x1-x0), dy=-abs(y1-y0);
- int sx,sy, psy;
- if(x0<x1){ sx=1; } else { sx=-1; }
- if(y0<y1){ sy=1; psy=w; } else { sy=-1; psy=-w; }
- int err=dx+dy, err2;
- int pos=x0 + y0*w;
- do {
- if(IN_BOUNDS(x0,y0, w,h)) pixels[pos].value=0xffffff00; //cyan
- if(x0==x1 && y0==y1) break;
- err2=err<<1;
- if(err2>=dy){
- if(x0==x1) break;
- err+=dy;
- x0+=sx;
- pos+=sx;
- }
- if(err2<=dx){
- if(y0==y1) break;
- err+=dx;
- y0+=sy;
- pos+=psy;
- }
- } while(1);
- }
- //draws wireframe triangle
- int notAShader2(KIT_TTM_Canvas3D* canvas, KIT_TTM* ttms,int ttms_len, void* data){
- if(!canvas){ return 1; } if(!ttms){ return 2; } if(!ttms_len){ return 3; }
- float v_w=canvas->v_w, v_h=canvas->v_h; int w=canvas->w, h=canvas->h;
- KIT_TTM_LockCanvas3D(canvas);
- KIT_Color* pixels=canvas->pixels; int w_half=w/2, h_half=h/2;
- for(uint32_t ttm_i=0; ttm_i<ttms_len; ++ttm_i){//for every ttm
- uint32_t objects_len=ttms[ttm_i].objects_len;
- for(uint32_t obj_i=0; obj_i<objects_len; ++obj_i){//for every object
- KIT_TTM_Object* object=&ttms[ttm_i].objects[obj_i];
- uint32_t numWorkTris=object->numWorkTris;
- if(numWorkTris==0) continue;
- KIT_TTM_Triangle* render=object->render;
- memcpy(render,object->work,sizeof(KIT_TTM_Triangle)*numWorkTris);
- for(uint32_t tri_i=0; tri_i<numWorkTris; ++tri_i){//for every triangle
- KIT_TTM_Triangle tri=render[tri_i];
- tri=KIT_TTM_ProjectTriangle(tri, w_half,h_half, v_w,v_h);
- bresenhamAll(pixels,w,h, tri.a.pos.x,tri.a.pos.y, tri.b.pos.x,tri.b.pos.y);
- bresenhamAll(pixels,w,h, tri.b.pos.x,tri.b.pos.y, tri.c.pos.x,tri.c.pos.y);
- bresenhamAll(pixels,w,h, tri.c.pos.x,tri.c.pos.y, tri.a.pos.x,tri.a.pos.y);
- }
- }}
- if(canvas->autoUnlock) KIT_TTM_UnlockCanvas3D(canvas);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement