3D Würfel mit Farbänderung hat Fehler

  • Hallo,
    Ich habe gerade mit 3D Programmirung in Autoit angefangen und wollte zu Anfang einen sich Rotirenden Würfel der seine Farben wechselt schreiben.
    Ich lasse die farben durch eine Schleiffe immer erhöhen,erst Rot ($R),dann Grün ($G) und dann Blau ($B). Wenn eine Farbe den Wert "1" angenommen hatt, soll sie stehn bleiben und die nächste Farbe weiter bis "1" laufen, nur genau hier ist mein Problem sobald Grün "1" ereicht hat bleibt es nicht stehn sonder läuft als weiter.
    Wäre schön wenn ihr auch das ganze mal anschaut.
    Ihr müsst auch das Rar archiv laden da ein paar dlls benötigt werden.

    Mfg Kamui
    autoit.de/wcf/attachment/6502/

  • Hi Kamui!

    Erst mal Herzlich Willkommen

    Ich kenne diese udf nicht daher würde ich gerne wissen wie man die farbe setzt dann kann ich dir bestimmt helfen

    gruss Simon

    • Offizieller Beitrag

    Probier es mal so :

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseAnsi=y
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstants.au3>
    #include "GlPluginUtils.au3"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    HotKeySet( "{ESC}", "End" )
    Opt( "GUIOnEventMode", 1 )

    [/autoit] [autoit][/autoit] [autoit]

    Func End( )
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $desktw = @DesktopWidth
    $deskth = @DesktopHeight

    [/autoit] [autoit][/autoit] [autoit]

    If MsgBox( 36, "Screen", "Run this demo in fullscreen mode?" ) = 6 Then
    DefineGlWindow( "würfel!!!" )
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $R = 0
    $G = 0
    $B = 0
    $hGUI = GUICreate( "Au3GlPlugin in a AutoIt GUI", 520, 400 )
    $Label = GUICtrlCreateLabel ( "Rotation: ", 20, 20, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label2 = GUICtrlCreateLabel ( "Rotation: ", 20, 40, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label3 = GUICtrlCreateLabel ( "Color: ", 20, 60, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label4 = GUICtrlCreateLabel ( "R: ", 20, 80, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label5 = GUICtrlCreateLabel ( "G: ", 20, 100, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label6 = GUICtrlCreateLabel ( "B ", 20, 120, 80 )
    GUISetState( @SW_SHOW, $hGUI )

    [/autoit] [autoit][/autoit] [autoit]

    EmbedGlWindow( $hGUI, 400, 300, 100, 20 )

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState( @SW_SHOW, $hGUI )

    [/autoit] [autoit][/autoit] [autoit]

    SetClearColor( 0.2, 0.2, 0.2 )
    CreateLight( 0, 40, 300, 300 )
    SetLightAmbient( 0, 0.2, 0, 0.2 )
    SetLightDiffuse( 0, 0.7, 0.7, 0.7 )
    SetLightSpecular( 0, 1.0, 1.0, 1.0 )

    [/autoit] [autoit][/autoit] [autoit]

    $CubeObj = ObjectCreate( )
    $Box = AddCube( $CubeObj, 70, 70, 70, $R, $G, $B, 1.0 )
    SetPrint( $CubeObj )

    [/autoit] [autoit][/autoit] [autoit]

    SetCamera( 0, 50, 250, 0, 0, 0 )
    GUISetOnEvent( $GUI_EVENT_CLOSE, "End" )

    [/autoit] [autoit][/autoit] [autoit]

    $R = 0
    $G = 0
    $B = 0 ;Zum blocken der Farben
    $block = 1
    $Y_Achse = 0
    $X_Achse = 0
    While 1
    SceneDraw( )
    sleep( 10 )

    [/autoit] [autoit][/autoit] [autoit]

    ;Farbe wechselen

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetData( $Label4, "R: " & $R)
    GUICtrlSetData( $Label5, "G: " & $G)
    GUICtrlSetData( $Label6, "B: " & $B)
    if $block = 1 Then $R += 0.001
    if $R > 1 And $G < 1 Then $block = 2; Wenn $R größer als 1 dann Block = 2

    [/autoit] [autoit][/autoit] [autoit]

    if $block = 2 Then $G += 0.001
    if $G > 1 And $R >1 Then $block = 3;Wenn $R und $G größer als1 dann Bolck = 3
    if $G > 1 then $G += 0.00

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    if $block = 3 then $B += 0.001
    if $B > 1 And $G > 1 And $B > 1 then $block = 1; Wenn $R $G $B größer als 1 dann Block = 1. Die Frage ist was dann geschehen soll

    [/autoit] [autoit][/autoit] [autoit]

    ObjectHide( $CubeObj )
    $CubeObj = ObjectCreate( )
    $Box = AddCube( $CubeObj, 70, 70, 70, $R, $G, $B, 1)
    SetPrint( $CubeObj )

    [/autoit] [autoit][/autoit] [autoit]

    ;Rotation
    ObjectRotate( $CubeObj, $Y_Achse, $X_Achse, 0 )
    GUICtrlSetData( $Label, "Rotation: " & $Y_Achse )
    GUICtrlSetData( $Label2, "Rotation: " & $X_Achse )
    $X_Achse += 1
    $Y_Achse += 1
    If $Y_Achse < 0 Then $Y_Achse += 360
    If $Y_Achse > 360 Then $Y_Achse -= 360
    If $X_Achse < 0 Then $X_Achse += 360
    If $X_Achse > 360 Then $X_Achse -= 360
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit]


    Dein Fehler besteht darin, das bei $G größer als 1 auf $Block =3 geschaltet wird aber beim nächsten Schleifendurchlauf wieder auf $Block =2 geschaltet wird weil $R größer als 1 ist.

  • [code

    $R = 0 ;Rot
    $G = 0 ;Grün
    $B = 0 ;Blau
    ]$CubeObj = ObjectCreate( )
    $Box = AddCube( $CubeObj, 70, 70, 70, $R, $G, $B, 1.0 )
    SetPrint( $CubeObj )[/code]

    Die Farbe wärend der Erstellunng des Objektes eingestellt. Ich habe sie halt durch variablen definiert so das ich sie verändern kann.

  • Hallo,
    Ich habe gerade mit 3D Programmirung in Autoit angefangen und wollte zu Anfang einen sich Rotirenden Würfel der seine Farben wechselt schreiben.
    Ich lasse die farben durch eine Schleiffe immer erhöhen,erst Rot ($R),dann Grün ($G) und dann Blau ($B). Wenn eine Farbe den Wert "1" angenommen hatt, soll sie stehn bleiben und die nächste Farbe weiter bis "1" laufen, nur genau hier ist mein Problem sobald Grün "1" ereicht hat bleibt es nicht stehn sonder läuft als weiter.
    Wäre schön wenn ihr auch das ganze mal anschaut.
    Ihr müsst auch das Rar archiv laden da ein paar dlls benötigt werden.

    Mfg Kamui
    autoit.de/wcf/attachment/6502/

    Hier meine Version:

    Spoiler anzeigen
    [autoit]


    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseAnsi=y
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstants.au3>
    #include "GlPluginUtils.au3"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    HotKeySet( "{ESC}", "End" )
    Opt( "GUIOnEventMode", 1 )

    [/autoit] [autoit][/autoit] [autoit]

    Func End( )
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $desktw = @DesktopWidth
    $deskth = @DesktopHeight

    [/autoit] [autoit][/autoit] [autoit]

    If MsgBox( 36, "Screen", "Run this demo in fullscreen mode?" ) = 6 Then
    DefineGlWindow( "würfel!!!" )
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $R = 0
    $G = 0
    $B = 0
    $hGUI = GUICreate( "Au3GlPlugin in a AutoIt GUI", 520, 400 )
    $Label = GUICtrlCreateLabel ( "Rotation: ", 20, 20, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label2 = GUICtrlCreateLabel ( "Rotation: ", 20, 40, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label3 = GUICtrlCreateLabel ( "Color: ", 20, 60, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label4 = GUICtrlCreateLabel ( "R: ", 20, 80, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label5 = GUICtrlCreateLabel ( "G: ", 20, 100, 80 )
    GUISetState( @SW_SHOW, $hGUI )
    $Label6 = GUICtrlCreateLabel ( "B ", 20, 120, 80 )
    GUISetState( @SW_SHOW, $hGUI )

    [/autoit] [autoit][/autoit] [autoit]

    EmbedGlWindow( $hGUI, 400, 300, 100, 20 )

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState( @SW_SHOW, $hGUI )

    [/autoit] [autoit][/autoit] [autoit]

    SetClearColor( 0.2, 0.2, 0.2 )
    CreateLight( 0, 40, 300, 300 )
    SetLightAmbient( 0, 0.2, 0, 0.2 )
    SetLightDiffuse( 0, 0.7, 0.7, 0.7 )
    SetLightSpecular( 0, 1.0, 1.0, 1.0 )

    [/autoit] [autoit][/autoit] [autoit]

    $CubeObj = ObjectCreate( )
    $Box = AddCube( $CubeObj, 70, 70, 70, $R, $G, $B, 1.0 )
    SetPrint( $CubeObj )

    [/autoit] [autoit][/autoit] [autoit]

    SetCamera( 0, 50, 250, 0, 0, 0 )
    GUISetOnEvent( $GUI_EVENT_CLOSE, "End" )

    [/autoit] [autoit][/autoit] [autoit]

    $R = 0
    $G = 0
    $B = 0 ;Zum blocken der Farben
    $block = 1
    $Y_Achse = 0
    $X_Achse = 0
    While 1
    SceneDraw( )
    sleep( 10 )

    [/autoit] [autoit][/autoit] [autoit]

    ;Farbe wechselen

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetData( $Label4, "R: " & Round($R, 3))
    GUICtrlSetData( $Label5, "G: " & Round($G, 3))
    GUICtrlSetData( $Label6, "B: " & Round($B, 3))
    Select
    Case $block = 1
    $R += 0.001
    If $R >= 1 Then $block += 1
    Case $block = 2
    $G += 0.001
    If $G >= 1 Then $block += 1
    Case $block = 3
    $B += 0.001
    If $B >= 1 Then $block += 1
    EndSelect
    If $block = 4 Then
    $r = 0
    $g = 0
    $b = 0
    $block = 1
    EndIf
    ObjectHide( $CubeObj )
    $CubeObj = ObjectCreate( )
    $Box = AddCube( $CubeObj, 70, 70, 70, $R, $G, $B, 1)
    SetPrint( $CubeObj )

    [/autoit] [autoit][/autoit] [autoit]

    ;Rotation
    ObjectRotate( $CubeObj, $Y_Achse, $X_Achse, 0 )
    GUICtrlSetData( $Label, "Rotation: " & $Y_Achse )
    GUICtrlSetData( $Label2, "Rotation: " & $X_Achse )
    $X_Achse += 1
    $Y_Achse += 1
    If $Y_Achse < 0 Then $Y_Achse += 360
    If $Y_Achse > 360 Then $Y_Achse -= 360
    If $X_Achse < 0 Then $X_Achse += 360
    If $X_Achse > 360 Then $X_Achse -= 360
    WEnd

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    • Offizieller Beitrag

    Die Version von UEZ ist besser als meine. ;)