English
Source / code snippets

rectangle-Zeichenbereich for Liniengraphik by software: "Cohen-Sutherland Clipping"

 

p.specht

Gray hair emerged with the Umsetzung from C++: in the Demoprogramm go The Endpunkte the lines in the Hauptteil each via Zufallsgenerator definiert. lying these spots but very over- or next to each other (or solely 1 pixel Difference), watts in the Innenschleife The Abbruchbedingung ("Geclippte line lying now complete inside the Sichtfenster-Rechtecks") never More access. the C++ paragon supplied with the Division two Integervariablen namely automatically a Integer-worth back. XProfan-11.2a free attempts with Using the conventional Division but, very To his and supply a Floatwert - The cause for the strange Fehlerverhalten. After substitute the / Operators by the antiquated function @div&(a&,b&) or. by the \ - Integerdivisionszeichen functions now everything. interestingly would a Beschleunigung through Inline-Assemblercode. so remaining it only a demonstration.
greeting

P.s.: there's in the meantime plenty faster, hardwareunterstützte take action, The undertow. "Saturation-Arithmetik"!
' Cohen-Sutherland Clipping demonstration
' No Liability, usage on Own menace!
' P. woodpecker 2011-01 for Paule´s PC Forum
' Note: there's meanwhile already plenty faster Algorithms!
Def %CLIPLEFT  1'  binary   0001
Def %CLIPRIGHT 2'          0010
Def %CLIPLOWER 4'          0100
Def %CLIPUPPER 8'          1000
Def %TRUE 1
Def %FALSE 0

Proc ClipLine

    var k1%=0
    var k2%=0
    declare dx&,dy&
    dx&=x2&-x1&
    dy&=y2&-y1&
    y1Test
    y2Test
    '  Loop to Cohen/Sutherland, The maximum 2 times through becomes

    while k1% OR k2%

        rtn% = %TRUE

        if k1% & k2% : rtn% = %FALSE : BREAK : endif

            if k1%

                if k1% & %CLIPLEFT

                    y1& = y1& + (XMin&-x1&)*dy&\dx&
                    x1& = XMin&

                elseif k1% & %CLIPRIGHT

                    y1& = y1& + (XMax&-x1&)*dy&\dx&
                    x1& = XMax&

                endif

                if k1% & %CLIPLOWER

                    x1& = x1& + (YMin&-y1&)*dx&\dy&
                    y1& = YMin&

                elseif k1% & %CLIPUPPER

                    x1& = x1& + (YMax&-y1&)*dx&\dy&
                    y1& = YMax&

                endif

                k1% = 0
                y1Test

            endif

            if k1% & k2% : rtn% = %FALSE : BREAK : endif

                if k2%

                    if k2% & %CLIPLEFT

                        y2& = y2& + (XMin&-x2&)*dy&\dx&
                        x2& = XMin&

                    elseif k2% & %CLIPRIGHT

                        y2& = y2& + (XMax&-x2&)*dy&\dx&
                        x2& = XMax&

                    endif

                    if k2% & %CLIPLOWER

                        x2& = x2& + (YMin&-y2&)*dx&\dy&
                        y2& = YMin&

                    elseif k2% & %CLIPUPPER

                        x2& = x2& + (YMax&-y2&)*dx&\dy&
                        y2& = YMax&

                    endif

                    k2% = 0
                    y2Test

                endif

            EndWhile

            return rtn%

        ENDPROC

        proc y1Test

            if y1&<YMin&

                k1% = %CLIPLOWER

            elseif y1& > YMax&

                k1% = %CLIPUPPER

            endif

            if x1& < XMin&

                k1% = k1% | %CLIPLEFT

            elseif x1&>XMax&

                k1% = k1% | %CLIPRIGHT

            endif

        endproc

        proc y2Test

            if y2&<YMin&

                k2% = %CLIPLOWER

            elseif y2&>YMax&

                k2% = %CLIPUPPER

            endif

            if x2&<XMin&

                k2% = k2% | %CLIPLEFT

            elseif (x2&>XMax&)

                k2% = k2% | %CLIPRIGHT

            endif

        endproc

        'INIT
        Declare XMax&,YMax&,XMin&,YMin&,rtn%
        Declare x1&,y1&,x2&,y2&,colo&
        RANDOMIZE
        Window Title "Cohen/Sutherland Clipping Demo"
        Window Style  4 | 8 | 16
        'MAIN

        WHILE 1

            XMin& = Rnd(300)
            YMin& = Rnd(200)
            XMax& = XMin& + Rnd(500)
            YMax& = YMin& + Rnd(250)
            CLS
            colo&=rgb(rnd(256),rnd(256),rnd(256))
            USEP 0,3,colo&
            rectangle XMin&,YMin& - XMax&,YMax&
            'print XMin&,YMin&,XMax&,YMax&

            WhileLoop 1000

                x1& = rnd(Width( %HWnd))
                y1& = rnd(Height(%Hwnd))
                x2& = rnd(Width( %HWnd))
                y2& = rnd(Height(%Hwnd))
                colo&=rgb(rnd(256),rnd(256),rnd(256))
                USEP 3,1,colo&
                Line x1&,y1& - x2&,y2&

                if ClipLine()

                    USEP 0,3,colo&
                    Line x1&,y1& - x2&,y2&

                endif

            EndWhile

        ENDWHILE

        END
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
04/11/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

618 Views

Untitledvor 0 min.
p.specht11/24/21
N.Art07/23/21
Glubbfan06/19/21
Uwe ''Pascal'' Niemeier06/13/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie