Trying to understand glib, or make a 3D engine myself. Either way, I am stuck at the part with backface culling. I would like just a simple code that someone else had made, just a rotating cube, but I would like to learn for myself too. Anyway.
I can't figure out how to calculate the normal vector when given 4 points on the face of the cube. Here's the code I have now to just display 8 vertices:

Code:
```L1->^^oXCAM+2->^^oYCAM+2->^^oZCAM+2->^^oXANG+2->^^oYANG+2->^^oZANG+2->^^oXSIN+2->^^oYSIN+2->^^oZSIN+2->^^oXCOS+2->^^oYCOS+2->^^oZCOS+2->^^oXXROT+2->^^oYXROT+2->^^oZXROT+2->^^oXYROT+2->^^oYYROT+2->^^oZYROT+2->^^oXZROT+2->^^oYZROT+2->^^oZZROT+2 0->XCAM->YCAM ~48->ZCAM 0->XANG->YANG->ZANG Repeat getKey(15)  sin(XANG)->XSIN  cos(XANG)->XCOS  sin(YANG)->YSIN  cos(YANG)->YCOS  sin(ZANG)->ZSIN  cos(ZANG)->ZCOS  ZCOS*YCOS//128->XXROT  ZCOS*YSIN//128*XSIN-(ZSIN*XCOS)//128->YXROT  ZCOS*YSIN//128*XCOS+(ZSIN*XSIN)//128->ZXROT  ZSIN*YCOS//128->XYROT  ZSIN*YSIN//128*XSIN+(ZCOS*XCOS)//128->YYROT  ZSIN*YSIN//128*XCOS-(ZCOS*XSIN)//128->ZYROT  ~YSIN->XZROT  YCOS*XSIN//128->YZROT  YCOS*XCOS//128->ZZROT .Lbl CODE  For(A,0,7)   A*6+GDB0->[r1]   {[r1]}^^r->S->X   {[r1]+2}^^r->T->Y   {[r1]+4}^^r->U->Z   XXROT*X+(YXROT*Y)+(ZXROT*Z)//128->S   XYROT*X+(YYROT*Y)+(ZYROT*Z)//128->T   XZROT*X+(YZROT*Y)+(ZZROT*Z)//128->U   U-ZCAM->Z   S-XCAM*64//Z+48->X   T-YCAM*64//Z+32->Y   Pt-On(X,Y,[2424240081423C00])  End .Lbl MOVE  getKey(26)-getKey(28)*4+XANG->XANG  getKey(35)-getKey(19)*4+YANG->YANG  getKey(20)-getKey(34)*4+ZANG->ZANG  getKey(3)-getKey(2)*2+XCAM->XCAM  getKey(1)-getKey(4)*2+YCAM->YCAM  getKey(54)-getKey(48)*2+ZCAM->ZCAM  DispGraphClrDraw End Return Data(~10^^r,~10^^r,~10^^r)->GDB0 Data(~10^^r,~10^^r,10^^r) Data(~10^^r,10^^r,~10^^r) Data(~10^^r,10^^r,10^^r) Data(10^^r,~10^^r,~10^^r) Data(10^^r,~10^^r,10^^r) Data(10^^r,10^^r,~10^^r) Data(10^^r,10^^r,10^^r) ```

I'm also not good at optimizing stuff, so if anyone can give some hints for the optimizing too...

Edit: Btw, this is for Axe
You can find a vector normal to a plane by taking the cross product of any two (non-parallel) vectors in that plane. For example....two of the edges that share a corner.
Here's my example of how I tried to do backface culling, which, from looking below, has failed
It has a visual glitch from jstified, but the main problem's still there.

Here's the code for it too

Code:
```... .Loops through the different faces .VERT1 is address for 1st vertex, VERT2 is second, goes in clockwise order {VERT1}^^r-{VERT2}^^r->DELTX1 {VERT1+2}^^r-{VERT2+2}^^r->DELTY\1 {VERT1+4}^^r-{VERT2+4}^^r->DELTZ1 {VERT3}^^r-{VERT2}^^r->DELTX2 {VERT3+2}^^r-{VERT2+2}^^r->DELTY\2 {VERT3+4}^^r-{VERT2+4}^^r->DELTZ2 DELTY\1*DELTZ2-(DELTZ1*DELTY\2)->X DELTZ1*DELTX2-(DELTX1*DELTZ2)->Y DELTX1*DELTY\2-(DELTY\1*DELTX2)->Z .XCAM, YCAM, ZCAM are camera locations {VERT2}^^r-XCAM->S {VERT2+2}^^r-YCAM->T {VERT2+4}^^r-ZCAM->U If S*X+(T*Y)+(U*Z)>>0 .Draws the lines if above is good End ... ```
Wow, that looks amazing, even with the bug! I wish I knew Axe and ASM... I guess I might learn someday.
Sadly, I don't speak Axe, so I can't help anymore here, unless you want to draw up some pseudocode to explain your algorithm in more detail.
Nevermind, I fixed it! Had an overflow error when I was doing the dot product

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum