Jump to content

Simple 3D Graphics with GDI+


Starg
 Share

Recommended Posts

How would I make the movement in this script camera relative?

So if the WASD keys are pressed the camera moves forward based on AngleX and AngleY.

#include "S3d.au3"
#include <GUIConstantsEx.au3>
#include <Misc.au3>

Global $sTitle = "Test", $iWidth = 650, $iHeight = 550
Global $hGUI = GUICreate($sTitle, $iWidth, $iHeight)
GUICtrlCreateInput("", -100, -100, 10, 10)
GUISetState()
_GDIPlus_Startup()

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Global $hPen = _GDIPlus_PenCreate(0xFF0080FF, 2)
_S3d_SelectPen($hPen)

; Select a Graphic object
; width = 650, height = 550
_S3d_SelectGraphic($hGraphic, $iWidth, $iHeight, 2)

Global $hUserDll = DllOpen("user32.dll")
Global $anCamPos[3] = [-90, 210, 120], $anAngle[2] = [0.65, 0.4]
Global $anAddCamPos[3] = [3, 3, 3]
Global $anAddAngle[2] = [0.05, 0.05]
Global $iFPS = 0, $hTimer = TimerInit()

AdlibRegister("_Draw", 30)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
AdlibUnRegister()

DllClose($hUserDll)
_GDIPlus_PenDispose($hPen)

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

Func _Draw()
    If WinGetHandle("[active]") = $hGUI Then
        If _IsPressed("57", $hUserDll) Then ;W
            $anCamPos[0] += $anAddCamPos[0]
        ElseIf _IsPressed("53", $hUserDll) Then ;S
            $anCamPos[0] -= $anAddCamPos[0]
        EndIf

        If _IsPressed("41", $hUserDll) Then ;A
            $anCamPos[1] += $anAddCamPos[1]
        ElseIf _IsPressed("44", $hUserDll) Then ;D
            $anCamPos[1] -= $anAddCamPos[1]
        EndIf

        If _IsPressed("10", $hUserDll) Then ;SHIFT
            $anCamPos[2] += $anAddCamPos[2]
        ElseIf _IsPressed("11", $hUserDll) Then ;CTRL
            $anCamPos[2] -= $anAddCamPos[2]
        EndIf

        If _IsPressed("28", $hUserDll) Then ;DOWN
            $anAngle[1] += $anAddAngle[1]
            If $anAngle[1] > 1.4 Then
                $anAngle[1] = 1.4
            EndIf
        ElseIf _IsPressed("26", $hUserDll) Then ;UP
            $anAngle[1] -= $anAddAngle[1]
            If $anAngle[1] < -1.4 Then
                $anAngle[1] = -1.4
            EndIf
        EndIf

        If _IsPressed("27", $hUserDll) Then ;RIGHT
            $anAngle[0] += $anAddAngle[0]
            If $anAngle[0] > 6.28 Then
                $anAngle[0] = 0
            EndIf
        ElseIf _IsPressed("25", $hUserDll) Then ;LEFT
            $anAngle[0] -= $anAddAngle[0]
            If $anAngle[0] < 0 Then
                $anAngle[0] = 6.28
            EndIf
        EndIf
    EndIf

    _S3d_Clear(0xFFFFFFFF)
    _S3d_SetCameraEx($anCamPos[0], $anCamPos[1], $anCamPos[2], $anAngle[0], $anAngle[1])
    _S3d_Box(0, 0, 0, 80, 80, 80)
    _S3d_Box(0, 120, 0, 80, 200, 80)

    Local $sString = "Camera: "
    For $i = 0 To 2
        $sString &= $anCamPos[$i] & ", "
    Next
    $sString = StringTrimRight($sString, 2) & @CRLF & "Angle: "
    For $i = 0 To 1
        $sString &= $anAngle[$i] & ", "
    Next
    $sString = StringTrimRight($sString, 2)
    _GDIPlus_GraphicsDrawString($hGraphic, $sString, 0, 0)

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    $iFPS += 1
    If TimerDiff($hTimer) >= 1000 Then
        WinSetTitle($hGUI, "", $sTitle & " | " & $iFPS & " FPS")
        $iFPS = 0
        $hTimer = TimerInit()
    EndIf
EndFunc   ;==>_Draw

I'm a math noob.

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

Like this?

#include "S3d.au3"
#include <GUIConstantsEx.au3>
#include <Misc.au3>

Global $sTitle = "Test", $iWidth = 650, $iHeight = 550
Global $hGUI = GUICreate($sTitle, $iWidth, $iHeight)
GUICtrlCreateInput("", -100, -100, 10, 10)
GUISetState()
_GDIPlus_Startup()

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Global $hPen = _GDIPlus_PenCreate(0xFF0080FF, 2)
_S3d_SelectPen($hPen)

; Select a Graphic object
; width = 650, height = 550
_S3d_SelectGraphic($hGraphic, $iWidth, $iHeight, 2)

Global $hUserDll = DllOpen("user32.dll")
Global $anCamPos[3] = [-90, 210, 120], $anAngle[2] = [0.65, 0.4]
Global $anAddCamPos[3] = [3, 3, 3]
Global $anAddAngle[2] = [0.05, 0.05]
Global $iFPS = 0, $hTimer = TimerInit()

AdlibRegister("_Draw", 30)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
AdlibUnRegister()

DllClose($hUserDll)
_GDIPlus_PenDispose($hPen)

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

Func _Draw()
    If WinGetHandle("[active]") = $hGUI Then
        If _IsPressed("57", $hUserDll) Then ;W
            ; $anCamPos[0] += $anAddCamPos[0]
            
            $anCamPos[0] += $anAddCamPos[0] * Cos($anAngle[1]) * Cos($anAngle[0])
            $anCamPos[1] += $anAddCamPos[1] * Cos($anAngle[1]) * Sin($anAngle[0])
            $anCamPos[2] += $anAddCamPos[2] * Sin($anAngle[1])
            
            
        ElseIf _IsPressed("53", $hUserDll) Then ;S
            ; $anCamPos[0] -= $anAddCamPos[0]
            
            $anCamPos[0] -= $anAddCamPos[0] * Cos($anAngle[1]) * Cos($anAngle[0])
            $anCamPos[1] -= $anAddCamPos[1] * Cos($anAngle[1]) * Sin($anAngle[0])
            $anCamPos[2] -= $anAddCamPos[2] * Sin($anAngle[1])
            
        EndIf

        If _IsPressed("41", $hUserDll) Then ;A
            ; $anCamPos[1] += $anAddCamPos[1]
            
            $anCamPos[0] += $anAddCamPos[0] * -Sin($anAngle[0])
            $anCamPos[1] += $anAddCamPos[1] * Cos($anAngle[0])
            
        ElseIf _IsPressed("44", $hUserDll) Then ;D
            ; $anCamPos[1] -= $anAddCamPos[1]
            
            $anCamPos[0] -= $anAddCamPos[0] * -Sin($anAngle[0])
            $anCamPos[1] -= $anAddCamPos[1] * Cos($anAngle[0])
            
        EndIf

        If _IsPressed("10", $hUserDll) Then ;SHIFT
            $anCamPos[2] += $anAddCamPos[2]
        ElseIf _IsPressed("11", $hUserDll) Then ;CTRL
            $anCamPos[2] -= $anAddCamPos[2]
        EndIf

        If _IsPressed("28", $hUserDll) Then ;DOWN
            $anAngle[1] += $anAddAngle[1]
            If $anAngle[1] > 1.4 Then
                $anAngle[1] = 1.4
            EndIf
        ElseIf _IsPressed("26", $hUserDll) Then ;UP
            $anAngle[1] -= $anAddAngle[1]
            If $anAngle[1] < -1.4 Then
                $anAngle[1] = -1.4
            EndIf
        EndIf

        If _IsPressed("27", $hUserDll) Then ;RIGHT
            $anAngle[0] += $anAddAngle[0]
            If $anAngle[0] > 6.28 Then
                $anAngle[0] = 0
            EndIf
        ElseIf _IsPressed("25", $hUserDll) Then ;LEFT
            $anAngle[0] -= $anAddAngle[0]
            If $anAngle[0] < 0 Then
                $anAngle[0] = 6.28
            EndIf
        EndIf
    EndIf

    _S3d_Clear(0xFFFFFFFF)
    _S3d_SetCameraEx($anCamPos[0], $anCamPos[1], $anCamPos[2], $anAngle[0], $anAngle[1])
    _S3d_Box(0, 0, 0, 80, 80, 80)
    _S3d_Box(0, 120, 0, 80, 200, 80)

    Local $sString = "Camera: "
    For $i = 0 To 2
        $sString &= $anCamPos[$i] & ", "
    Next
    $sString = StringTrimRight($sString, 2) & @CRLF & "Angle: "
    For $i = 0 To 1
        $sString &= $anAngle[$i] & ", "
    Next
    $sString = StringTrimRight($sString, 2)
    _GDIPlus_GraphicsDrawString($hGraphic, $sString, 0, 0)

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    $iFPS += 1
    If TimerDiff($hTimer) >= 1000 Then
        WinSetTitle($hGUI, "", $sTitle & " | " & $iFPS & " FPS")
        $iFPS = 0
        $hTimer = TimerInit()
    EndIf
EndFunc   ;==>_Draw
Link to comment
Share on other sites

Like that, but with mouse look and a few improvements:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include "S3d.au3"
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

Global $iWidth = 800, $iHeight = 600
Global $iHalfHeight = $iHeight / 2, $iHalfWidth = $iWidth / 2
Global $iHalfScreenW = @DesktopWidth / 2, $iScreenH = @DesktopHeight, $iScreenW = @DesktopWidth
Global $hUserDll = DllOpen("user32.dll")
Global $anCamPos[3] = [-90, 210, 120], $anAngle[2] = [0, 0]
Global $anAddCamPos[3] = [3, 3, 3]
Global $anAngleCosSin[2][2] = [[0, 0],[0, 0]]
Global $nVertAng = 0, $nFAng = 0.8, $nFAngTarget = 0.8
Global $iFPS = 0

Global $hGUI = GUICreate("S3D Test", $iWidth, $iHeight, -1, -1)
GUICtrlCreateInput("", -100, -100, 10, 10)

GUIRegisterMsg($WM_RBUTTONDOWN, "_HandleRButton")
GUIRegisterMsg($WM_RBUTTONUP, "_HandleRButton")

_GDIPlus_Startup()

Global $hImage = _GDIPlus_ImageLoadFromFile("Textures\Face1.jpg")
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Global $hPen = _GDIPlus_PenCreate(0xFF0080FF, 2)
_S3d_SelectPen($hPen)
Global $hBrush = _GDIPlus_BrushCreateSolid(0x7F00FF00)
_S3d_SelectBrush($hBrush)

_S3d_SelectGraphic($hGraphic, $iWidth, $iHeight, 2)

Global $iTempFPS = 0, $hTimer = TimerInit(), $hKeyCheckTimer = TimerInit()
GUISetState()

; Loop until user exits
Do
    _Draw()
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
AdlibUnRegister()

DllClose($hUserDll)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hImage)

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

Func _Draw()
    If TimerDiff($hKeyCheckTimer) >= 20 And BitAND(WinGetState($hGUI), 8) Then
        Local $aiMousePos = MouseGetPos()
        If $aiMousePos[0] = $iScreenW - 1 Then
            MouseMove(1, $aiMousePos[1], 0)
        ElseIf $aiMousePos[0] = 0 Then
            MouseMove($iScreenW - 2, $aiMousePos[1], 0)
        EndIf

        If $aiMousePos[0] <= $iHalfScreenW Then
            $anAngle[0] = $aiMousePos[0] / $iHalfScreenW * 3.14 + 3.14
        Else
            $anAngle[0] = $aiMousePos[0] / $iHalfScreenW * 3.14 - 3.14
        EndIf
        $anAngle[1] = $aiMousePos[1] / $iScreenH * 3 - 1.5
        ; Only calculate once, should improve performance.
        $anAngleCosSin[0][0] = Cos($anAngle[0])
        $anAngleCosSin[0][1] = Sin($anAngle[0])
        $anAngleCosSin[1][0] = Cos($anAngle[1])
        $anAngleCosSin[1][1] = Sin($anAngle[1])

        If _IsPressed("57", $hUserDll) Then ;W
            ; $anAddCamPos[0] * Cos($anAngle[1]) * Cos($anAngle[0])
            $anCamPos[0] += $anAddCamPos[0] * $anAngleCosSin[1][0] * $anAngleCosSin[0][0]

            ; $anAddCamPos[1] * Cos($anAngle[1]) * Sin($anAngle[0])
            $anCamPos[1] -= $anAddCamPos[1] * $anAngleCosSin[1][0] * $anAngleCosSin[0][1]

            ; $anAddCamPos[2] * Sin($anAngle[1])
            $anCamPos[2] -= $anAddCamPos[2] * $anAngleCosSin[1][1]

        ElseIf _IsPressed("53", $hUserDll) Then ;S

            ; $anAddCamPos[0] * Cos($anAngle[1]) * Cos($anAngle[0])
            $anCamPos[0] -= $anAddCamPos[0] * $anAngleCosSin[1][0] * $anAngleCosSin[0][0]

            ; $anAddCamPos[1] * Cos($anAngle[1]) * Sin($anAngle[0])
            $anCamPos[1] += $anAddCamPos[1] * $anAngleCosSin[1][0] * $anAngleCosSin[0][1]

            ; $anAddCamPos[2] * Sin($anAngle[1])
            $anCamPos[2] += $anAddCamPos[2] * $anAngleCosSin[1][1]
        EndIf

        If _IsPressed("41", $hUserDll) Then ;A
            ; $anAddCamPos[1] * Sin($anAngle[0])
            $anCamPos[0] += $anAddCamPos[1] * $anAngleCosSin[0][1]

            ; $anAddCamPos[0] * Cos($anAngle[0])
            $anCamPos[1] += $anAddCamPos[0] * $anAngleCosSin[0][0]

        ElseIf _IsPressed("44", $hUserDll) Then ;D

            ; $anAddCamPos[1] * Sin($anAngle[0])
            $anCamPos[0] -= $anAddCamPos[1] * $anAngleCosSin[0][1]

            ; $anAddCamPos[0] * Cos($anAngle[0])
            $anCamPos[1] -= $anAddCamPos[0] * $anAngleCosSin[0][0]
        EndIf

        If _IsPressed("10", $hUserDll) Then ;SHIFT
            $anCamPos[2] += $anAddCamPos[2]
        ElseIf _IsPressed("11", $hUserDll) Then ;CTRL
            $anCamPos[2] -= $anAddCamPos[2]
        EndIf

        If $nFAng <> $nFAngTarget Then
            If $nFAng < $nFAngTarget Then
                $nFAng += 0.1
                If $nFAng > $nFAngTarget Then
                    $nFAng = $nFAngTarget
                EndIf
            Else
                $nFAng -= 0.1
                If $nFAng < $nFAngTarget Then
                    $nFAng = $nFAngTarget
                EndIf
            EndIf
            $nFAng = Round($nFAng, 1)
        EndIf

        $hKeyCheckTimer = TimerInit()
    EndIf

    _S3d_Clear(0xFFFFFFFF)
    _S3d_SetCameraEx($anCamPos[0], $anCamPos[1], $anCamPos[2], $anAngle[0], $anAngle[1], $nVertAng, $nFAng)

    _S3d_Box(0, 0, 0, 80, 80, 80)

    _GDIPlus_GraphicsDrawLine($hGraphic, $iHalfWidth, $iHalfHeight + 2, $iHalfWidth, $iHalfHeight + 7)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iHalfWidth, $iHalfHeight - 2, $iHalfWidth, $iHalfHeight - 7)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iHalfWidth + 2, $iHalfHeight, $iHalfWidth + 7, $iHalfHeight)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iHalfWidth - 2, $iHalfHeight, $iHalfWidth - 7, $iHalfHeight)

    Local $sString = "Camera: " & $anCamPos[0] & ", " & $anCamPos[1] & ", " & $anCamPos[2] & @CRLF & _
            "Angle: " & $anAngle[0] & ", " & $anAngle[1] & @CRLF & _
            "FPS: " & $iFPS
    _GDIPlus_GraphicsDrawString($hGraphic, $sString, 0, 0)

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    $iTempFPS += 1
    If TimerDiff($hTimer) >= 1000 Then
        $iFPS = $iTempFPS
        $iTempFPS = 0
        $hTimer = TimerInit()
    EndIf
EndFunc   ;==>_Draw

Func _HandleRButton($hWnd, $Msg, $wParam, $lParam)
    If $Msg = 516 Then
        $nFAngTarget = 0.3
    ElseIf $Msg = 517 Then
        $nFAngTarget = 0.8
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_HandleRButton

What do you say about spawning another process to do the calculations that S3d.au3 does?

Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

  • 3 months later...

Nice work. If you set smoothing for the gfx handle it looks much better ;)

 

Func _S3d_SelectGraphic($hGraphic, $iWidth, $iHeight)
    $__S3d_hGraphic = $hGraphic
    $__S3d_iWidth = $iWidth
    $__S3d_iHeight = $iHeight
    _GDIPlus_GraphicsSetSmoothingMode($__S3d_hGraphic, 2)
EndFunc ;==>_S3d_SelectGraphic

Using matrices to rotate the object is cool.  :thumbsup: 

 

Br,

UEZ

 

Matrices are neat, you can express the rotation of any n-dimension object with them :D

I agree though! Awesome udf.

Link to comment
Share on other sites

I was thinking of writing this in C++ and compiling it to a .dll (the GDI+ stuff too)

Who supports this post?

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

  • 3 months later...
  • 2 weeks later...

Is there any way to rotate a circle?

I tried this way:

#include <GUIConstantsEx.au3>
#include '..\include\S3d.au3'

Local $GUI = GUICreate("S3d Example", 650, 550)
_GDIPlus_Startup()

Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(650, 550, $hGraphics)
Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

_S3d_SelectGraphic($hGraphic, 650, 550)

Global $hPenB = _GDIPlus_PenCreate(0xAA0044FF, 2)
Global $hPenR = _GDIPlus_PenCreate(0xAAFF6633, 3)
Local $nBgColor = 0xFFFFFFFF

Local $i = 0
Local $frame = 0
Local $t = TimerInit()
GUISetState()

Do
    _S3d_Clear($nBgColor)
    Draw($i)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)

    $i += 1
    $frame += 1
    If TimerDiff($t) > 1000 Then
        $t = TimerInit()
        WinSetTitle($GUI, '', '      ' & $frame & ' FPS')
        $frame = 0
    EndIf
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

End()

_GDIPlus_Shutdown()
GUIDelete($GUI)


Func Draw($i)
    _S3d_SetCamera(350 * Cos($i * 0.01), 350 * Sin($i * 0.01), 150, 0, 0, 0)

    _S3d_SelectPen($hPenB)
    _S3d_Box(-100, -100, -100, 100, 100, 100)

    _S3d_SelectPen($hPenR)
    _S3d_LocalRotateX($i, True)
    _S3d_LocalRotateZ(-120, True)

    $tmp = 60
    _S3d_Box(-$tmp, -$tmp, -$tmp, $tmp, $tmp, $tmp)

    _S3d_LocalRotateX($i*2, True)
    _S3d_SelectPen($hPenB)
    $tmp = 30
    _S3d_Circle(0, 0, 0, 30)
EndFunc ;==>Draw

Func End()
    _GDIPlus_PenDispose($hPenB)
    _GDIPlus_PenDispose($hPenR)
EndFunc ;==>End

and boxes rotate, but circle doesn't :/

circle3.gif

EDIT:
why does black square in my script sometimes shows as triangle? o.O
floor1.gif

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include '..\include\S3d.au3'

Global $dll = DllOpen('user32.dll')

Local $GUI = GUICreate('', 650, 550)
_GDIPlus_Startup()

Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(650, 550, $hGraphics)
Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)

_S3d_SelectGraphic($hGraphic, 650, 550)

Global $hPenB = _GDIPlus_PenCreate(0xAA0044FF, 2)
Global $hPenR = _GDIPlus_PenCreate(0xAAFF6633, 3)
Global $hBrushBlack = _GDIPlus_BrushCreateSolid(0xFF000000)
Global $camA = 305
Global $camH = 1
Local $nBgColor = 0xFFAAFFAA

Local $i = 0
Local $frame = 0
Local $t = TimerInit()
GUISetState()
;~ $folderName = 'circle3'
;~ DirCreate('H:\autoit\GDI\3d\' & $folderName)
Do
    _S3d_Clear($nBgColor)
    Draw($i)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
;~  _GDIPlus_ImageSaveToFile($hBitmap, 'H:\autoit\GDI\3d\' & $folderName & '\' & $i & '.png')
    keys()
    $i += 1
    $frame += 1
    If TimerDiff($t) > 1000 Then
        $t = TimerInit()
        WinSetTitle($GUI, '', '      ' & $frame & ' FPS     $camA = ' & $camA & '     $camH = ' & $camH)
        $frame = 0
    EndIf
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

End()

_GDIPlus_Shutdown()
GUIDelete($GUI)

Func Draw($i)
    _S3d_SetCamera(350 * Cos($camA * 0.01), 350 * Sin($camA * 0.01), 150+3.60*$camH, 0, 0, 0)

    $tmp = 500
    $floor_H = 100
    _S3d_SelectBrush($hBrushBlack)
    _S3d_Square(    -$tmp, -$tmp, -$floor_H, _
                    -$tmp,  $tmp, -$floor_H, _
                     $tmp,  $tmp, -$floor_H, _
                     $tmp, -$tmp, -$floor_H, True)

    _S3d_SelectPen($hPenB)
    _S3d_Box(-100, -100, -100, 100, 100, 100)

    _S3d_SelectPen($hPenR)
    _S3d_LocalRotateX($i, True)
    _S3d_LocalRotateZ(-120, True)

    $tmp = 60
    _S3d_Box(-$tmp, -$tmp, -$tmp, $tmp, $tmp, $tmp)

    _S3d_LocalRotateX($i*2, True)
    _S3d_SelectPen($hPenB)
    _S3d_Circle(0, 0, 0, 30)
    Return 350 * Cos($i * 0.01)
EndFunc ;==>Draw

Func End()
    _GDIPlus_PenDispose($hPenB)
    _GDIPlus_PenDispose($hPenR)
    DllClose($dll)
EndFunc ;==>End

Func keys()
    If _IsPressed('25', $dll) Then
        $camA -= 1
    EndIf
    If _IsPressed('27', $dll) Then
        $camA += 1
    EndIf
    If _IsPressed('26', $dll) Then
        $camH *= 1.05
        If $camH > 1000 Then $camH = 1000
    EndIf
    If _IsPressed('28', $dll) Then
        $camH /= 1.05
        If $camH < 1 Then $camH = 1
    EndIf
EndFunc
Edited by ravkr

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...