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:

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

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