Author Topic: [AXE] cohen sutherland algorithm... with a little bug  (Read 2305 times)

0 Members and 1 Guest are viewing this topic.

Offline TheMachine02

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 452
  • Rating: +105/-0
  • me = EF99+F41A
    • View Profile
[AXE] cohen sutherland algorithm... with a little bug
« on: June 26, 2013, 12:27:06 pm »
As I need a fast cliping line algorithm, I use this one.   ;D
So I program it, and he looks to be fine. But, in some cases the line is completly false (it draws another line that I need)
I simply can't find why he does that.
If someone has an idea ... ?

The code : (unoptimized, I know  :P )

Code: [Select]
.TE

ExprOn
pi0000->^^oINSIDE
pi0001->^^oLEFT
pi0010->^^oRIGHT
pi0100->^^oBOTTOM
pi1000->^^oTOP
.Code

L1->^^oXMAX+2->^^oYMAX+2->^^oYMIN+2->^^oXMIN+2->^^oGCode

0->XMIN->YMIN
95->XMAX
63->YMAX
0->F->G
Fix 5

Repeat getKey(15)
GCLine(F,G,48,32)
HLine(YMAX)
HLine(YMIN)
VLine(XMIN)
VLine(XMAX)
!If getKey(48)
getKey(3)-getKey(2)+F->F
getKey(1)-getKey(4)+G->G
Else
getKey(3)-getKey(2)+XMAX->XMAX
getKey(1)-getKey(4)+YMAX->YMAX
End
Text(1,1,F>Dec
Text G>Dec

DispGraphClrDraw
End
Fix 4
Return

Lbl GOutCode
^^oINSIDE->GCode
If r1-XMIN//32768
^^oLEFT->GCode
ElseIf XMAX-r1//32768
^^oRIGHT->GCode
End

If r2-YMIN//32768
GCode+^^oTOP->GCode  //or
ElseIf YMAX-r2//32768
GCode+^^oBOTTOM->GCode //or (16bit)
End
Return GCode

Lbl GCLine
GOutCode()->r5
sub(GOutCode^^r,r3,r4)->r6
Text(50,1,r5>Dec

While 1
!If r5+r6  //16-bit  or
Line(r1,r2,r3,r4
Return
End
ReturnIf r5.r6

If r5
r5->B
Else
r6->B
End

If B.^^oBOTTOM
r3-r1*(YMAX-r2)//(r4-r2)+r1->X
YMAX->Y
ElseIf B.^^oTOP
r3-r1*(YMIN-r2)//(r4-r2)+r1->X
YMIN->Y
ElseIf B.^^oRIGHT
r4-r2*(XMAX-r1)//(r3-r1)+r2->Y
XMAX->X
ElseIf B.^^oLEFT
r4-r2*(XMIN-r1)//(r3-r1)+r2->Y
XMIN->X
End

!If B-r5
GOutCode(X,Y)->r5
Else
X->r3
Y->r4
sub(GOutCode^^r,X,Y)->r6
End

ReturnIf getKey(15)
End
#ExprOff

A screenshot to show the bug :
AXE/asm programmer - unleash the power of z80 //C++//C

epic 3D things http://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html