algiuxas

3D Rendering: Perspective graphics (Make far things look smaller)

11 posts in this topic

Hello,

I need help with perspective graphics, I made orthographic 3D renderer, now I want to make it perspective:
OrtographicsR.thumb.png.bcd30a5d6ea793a1

I have made functions that might help:
- _3DGetPos($PosX,$PosY,$PosZ) (To get 3D position, output is array with X and Y positions)

- _3DGetDistance($PosX,$PosY,$PosZ, [$CameraPosX, $CameraPosY, $CameraPosZ] ) (Gets distance between positions)

- _DrawCubeSolidColor( $Color, $PosX, $PosY, $PosZ, $SizeX, $SizeY, $SizeZ ) (I rendered 4 cubes if you see in the picture)

I tried to make things smaller if they are far with this in _3DGetPos(...):
 $Output[0] = ($Output[0]*(1/_3DGetDistance($PosX,$PosY,$PosZ)(Gets distance between camera and position)) + $PosXReal(This makes everything shown in center of GUI)
 $Output[1] = ($Output[1]*(1/_3DGetDistance($PosX,$PosY,$PosZ))) + $PosXReal

What I get:

Ortographics.thumb.png.1d5bc19e5547f96f9

Weird... What to do?

Thanks :)

(Sorry for my bad English.)


42783.png

Share this post


Link to post
Share on other sites



@algiuxas Give us some code to test :D


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.14.2
    Author:         Algiuxas

    Script Function:
    3D RENDERING

Look(rotate camera) with:
     W
    ASD
Go up and down with: + and -
Move with:
    UP, DOWN, LEFT, RIGHT buttons.



#ce ----------------------------------------------------------------------------

#include <GDIPlus.au3>
#include <Math.au3>
#include <Misc.au3>
#include <Array.au3>
#include <GUIConstants.au3>

Global $Title = "3D Orthographics/Perspective AutoIt (by Algiuxas)"
Global $Display_Width = 600
Global $Display_Height = 400
Global $GUI = GUICreate($Title, $Display_Width, $Display_Height, -1, -1, -1, -1, 0)

Global Const $PI = 3.14159;26535897932384626433832795
Global Const $PI2 = $PI / 2
Global Const $2PI = $PI * 2
Global Const $5PI = $PI * 1.5
Global Const $fDegToRad = $PI / 180

Global $Size = ($Display_Width + $Display_Height) / 10, $CameraPosX = 0, $CameraPosY = 0, $CameraPosZ = 0

#Region# GDIPlus
_GDIPlus_Startup()
Global $Graphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
Global $Bitmap = _GDIPlus_BitmapCreateFromGraphics($Display_Width, $Display_Height, $Graphics)
Global $GfxCtxt = _GDIPlus_ImageGetGraphicsContext($Bitmap)
_GDIPlus_GraphicsSetSmoothingMode($GfxCtxt, 2)
#EndRegion# GDIPlus
#Region# Colors ( 0x AA RR GG BB )
Global Const $Color_DisplayBackground = 0xFF000000
Global Const $Pen_White = _GDIPlus_PenCreate(0xFFFFFFFF, 1)
Global Const $Pen_X = _GDIPlus_PenCreate(0xFFFF0000, 3)
Global Const $Pen_Y = _GDIPlus_PenCreate(0xFF00FF00, 3)
Global Const $Pen_Z = _GDIPlus_PenCreate(0xFF0000FF, 3)
Global Const $Pen_Demo = _GDIPlus_PenCreate(0xFF777700, 2)
Global Const $Brush_White = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
Global Const $Brush_Trans = _GDIPlus_BrushCreateSolid(0x80FFFFFF)
#EndRegion# Colors ( 0x AA RR GG BB )
#Region# Camera
Global $Camera_MinusWatch = 15
Global $CameraPosX = 0
Global $CameraPosY = 0
Global $CameraPosZ = 0
Global $CameraRotationX = Random(0,359,1)
Global $CameraRotationY = Random(180-30,180+30,1)
Global $CameraRotationZ = 0
#EndRegion# Camera

GUISetState(@SW_SHOW)
Do
    _GDIPlus_GraphicsClear($GfxCtxt, $Color_DisplayBackground/3)
    _GDIPlus_GraphicsDrawString( $GfxCtxt, $CameraPosX, 10,10)
    _GDIPlus_GraphicsDrawString( $GfxCtxt, $CameraPosY, 10,30)
    _GDIPlus_GraphicsDrawString( $GfxCtxt, $CameraPosZ, 10,50)
    $Size = ($Display_Width + $Display_Height) / 10
    $CameraRotationX -= 0.05
    If _IsPressed(57) Then $CameraRotationY += 3;W
    If _IsPressed(53) Then $CameraRotationY -= 3;S
    If _IsPressed(41) Then $CameraRotationX += 3;A
    If _IsPressed(44) Then $CameraRotationX -= 3;D

    If _IsPressed("6B") Then $CameraPosY -= 0.05
    If _IsPressed("6D") Then $CameraPosY += 0.05

    $MoveX = 0
    $MoveZ = 0
    If _IsPressed(26) Then $MoveX -= 0.05;<-
    If _IsPressed(28) Then $MoveX += 0.05;->
    If _IsPressed(27) Then $MoveZ -= 0.05;/\
    If _IsPressed(25) Then $MoveZ += 0.05;\/
    If $MoveX <> 0 then
        $CameraPosX += Round(Sin(_Radian($CameraRotationX))*$MoveX,3)
        $CameraPosZ += Round(Cos(_Radian($CameraRotationX))*$MoveX,3)
    EndIf
    If $MoveZ <> 0 then
        $CameraPosX += Round(Sin(_Radian($CameraRotationX-90))*$MoveZ,3)
        $CameraPosZ += Round(Cos(_Radian($CameraRotationX-90))*$MoveZ,3)
    EndIf
    $CameraPosX += 0
    $CameraPosY += 0
    $CameraPosZ += 0
    If $CameraRotationY < 90+$Camera_MinusWatch then $CameraRotationY = 90+$Camera_MinusWatch
    If $CameraRotationY > 270-$Camera_MinusWatch then $CameraRotationY = 270-$Camera_MinusWatch
    _DrawCubeSolidColor(0x7000FF00,0,0,0)
    _DrawCubeSolidColor(0x70FF0000,1,0,0)
    _DrawCubeSolidColor(0x700000FF,0,0,1)
    _DrawCubeSolidColor(0x70FFFFFF,0,1,1)
    _GDIPlus_GraphicsDrawImage($Graphics, $Bitmap, 0, 0)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _DrawCubeSolidColor($Color = 0x70FFFFFF, $PosX = -0.5, $PosY = -0.5, $PosZ = -0.5, $SizeX = 1, $SizeY = 1, $SizeZ = 1)
    $SizeX += $PosX
    $SizeY += $PosY
    $SizeZ += $PosZ
    $Pos000 = _3DGetPos($SizeX, $SizeY, $SizeZ)
    $Pos100 = _3DGetPos($PosX, $SizeY, $SizeZ)
    $Pos010 = _3DGetPos($SizeX, $PosY, $SizeZ)
    $Pos001 = _3DGetPos($SizeX, $SizeY, $PosZ)
    $Pos011 = _3DGetPos($SizeX, $PosY, $PosZ)
    $Pos110 = _3DGetPos($PosX, $PosY, $SizeZ)
    $Pos101 = _3DGetPos($PosX, $SizeY, $PosZ)
    $Pos111 = _3DGetPos($PosX, $PosY, $PosZ)
    Local $Brush_SolidLocal = _GDIPlus_BrushCreateSolid($Color)
    _GDIPlus_GraphicsDrawLine($GfxCtxt, $Pos000[0], $Pos000[1], $Pos001[0], $Pos001[1], $Pen_X)
    _GDIPlus_GraphicsDrawLine($GfxCtxt, $Pos000[0], $Pos000[1], $Pos010[0], $Pos010[1], $Pen_Y)
    _GDIPlus_GraphicsDrawLine($GfxCtxt, $Pos000[0], $Pos000[1], $Pos100[0], $Pos100[1], $Pen_Z)
    _DrawRectSide($Brush_SolidLocal, $SizeX,$SizeY,$SizeZ, $PosX,$SizeY,$SizeZ, $PosX,$PosY,$SizeZ, $SizeX,$PosY,$SizeZ)
    _DrawRectSide($Brush_SolidLocal, $PosX,$SizeY,$PosZ, $SizeX,$SizeY,$PosZ, $SizeX,$PosY,$PosZ, $PosX,$PosY,$PosZ)
;~  _DrawRect($Brush_SolidLocal, $PosX,$SizeY,$PosZ, $SizeX,$SizeY,$PosZ, $SizeX,$PosY,$PosZ, $PosX,$PosY,$PosZ)
;~  _DrawPoint(Color(0,0xFFFFFFFF,1),$PosX,$PosY,$PosZ,16)
;~  _DrawPoint(Color(0,0xFFFFFFFF,3),$PosX,$PosY,$SizeZ,32)
;~  _DrawPoint(Color(0,0xFFFFFFFF,2),$PosX,$SizeY,$PosZ,8)
;~  _DrawPoint(Color(0,0xFFFFFFFF,4),$PosX,$SizeY,$SizeZ,4)
    _DrawRectSide($Brush_SolidLocal, $PosX,$PosY,$SizeZ, $PosX,$PosY,$PosZ, $PosX,$SizeY,$PosZ, $PosX,$SizeY,$SizeZ)
    _DrawRectSide($Brush_SolidLocal, $SizeX,$PosY,$PosZ, $SizeX,$PosY,$SizeZ, $SizeX,$SizeY,$SizeZ, $SizeX,$SizeY,$PosZ)
    _DrawRectTop($Brush_SolidLocal, $PosX,$SizeY,$PosZ, $SizeX,$SizeY,$PosZ, $SizeX,$SizeY,$SizeZ, $PosX,$SizeY,$SizeZ)

EndFunc   ;==>_DrawCubeSolidColor
Func _DrawRectTop($Brush, $PosX0 = 0, $PosY0 = 0, $PosZ0 = 0, $PosX1 = 1, $PosY1 = 0, $PosZ1 = 0, $PosX2 = 1, $PosY2 = 1, $PosZ2 = 0, $PosX3 = 0, $PosY3 = 1, $PosZ3 = 0)
    $RotationDegX = DegreesNormalize(-$CameraRotationX)
    $RotationDegY = DegreesNormalize(-$CameraRotationY)
    $RotationDegZ = DegreesNormalize(-$CameraRotationZ)
;~  If _IsOnDisplay2PointsOneSide($PosX0, $PosY0, $PosZ0, $PosX1, $PosY1, $PosZ1) = True or _IsOnDisplay2PointsOneSide($PosX3, $PosY3, $PosZ3, $PosX2, $PosY2, $PosZ2) = True Then
        $Pos1 = _3DGetPos($PosX0, $PosY0, $PosZ0)
        $Pos2 = _3DGetPos($PosX1, $PosY1, $PosZ1)
        $Pos3 = _3DGetPos($PosX2, $PosY2, $PosZ2)
        $Pos4 = _3DGetPos($PosX3, $PosY3, $PosZ3)
        Local $aPoints[5][2]
        $aPoints[0][0] = 4
        $aPoints[1][0] = $Pos1[0]
        $aPoints[2][0] = $Pos2[0]
        $aPoints[3][0] = $Pos3[0]
        $aPoints[4][0] = $Pos4[0]
        $aPoints[1][1] = $Pos1[1]
        $aPoints[2][1] = $Pos2[1]
        $aPoints[3][1] = $Pos3[1]
        $aPoints[4][1] = $Pos4[1]
        _GDIPlus_GraphicsFillPolygon($GfxCtxt, $aPoints, $Brush)
;~  EndIf
EndFunc   ;==>_DrawRect
Func _DrawRectSide($Brush, $PosX0 = 0, $PosY0 = 0, $PosZ0 = 0, $PosX1 = 1, $PosY1 = 0, $PosZ1 = 0, $PosX2 = 1, $PosY2 = 1, $PosZ2 = 0, $PosX3 = 0, $PosY3 = 1, $PosZ3 = 0)
    $RotationDegX = DegreesNormalize(-$CameraRotationX)
    $RotationDegY = DegreesNormalize(-$CameraRotationY)
    $RotationDegZ = DegreesNormalize(-$CameraRotationZ)
    If _IsOnDisplay2PointsOneSide($PosX0, $PosY0, $PosZ0, $PosX1, $PosY1, $PosZ1) = True or _IsOnDisplay2PointsOneSide($PosX3, $PosY3, $PosZ3, $PosX2, $PosY2, $PosZ2) = True Then
        $Pos1 = _3DGetPos($PosX0, $PosY0, $PosZ0)
        $Pos2 = _3DGetPos($PosX1, $PosY1, $PosZ1)
        $Pos3 = _3DGetPos($PosX2, $PosY2, $PosZ2)
        $Pos4 = _3DGetPos($PosX3, $PosY3, $PosZ3)
        Local $aPoints[5][2]
        $aPoints[0][0] = 4
        $aPoints[1][0] = $Pos1[0]
        $aPoints[2][0] = $Pos2[0]
        $aPoints[3][0] = $Pos3[0]
        $aPoints[4][0] = $Pos4[0]
        $aPoints[1][1] = $Pos1[1]
        $aPoints[2][1] = $Pos2[1]
        $aPoints[3][1] = $Pos3[1]
        $aPoints[4][1] = $Pos4[1]
        _GDIPlus_GraphicsFillPolygon($GfxCtxt, $aPoints, $Brush)
    EndIf
EndFunc   ;==>_DrawRect
Func _DrawPoint($Pen, $PosX0 = 0, $PosY0 = 0, $PosZ0 = 0,$Size=4)
        $Pos = _3DGetPos($PosX0, $PosY0, $PosZ0)
        _GDIPlus_GraphicsDrawEllipse($GfxCtxt,$Pos[0]-$Size/2,$Pos[1]-$Size/2,$Size,$Size,$Pen)
EndFunc   ;==>_DrawRect
Func _DrawLine($Pen, $PosX0 = 0, $PosY0 = 0, $PosZ0 = 0, $PosX1 = 0, $PosY1 = 0, $PosZ1 = 0)
        $Pos0 = _3DGetPos($PosX0, $PosY0, $PosZ0)
        $Pos1 = _3DGetPos($PosX1, $PosY1, $PosZ1)
        _GDIPlus_GraphicsDrawLine($GfxCtxt, $Pos0[0], $Pos0[1], $Pos1[0], $Pos1[1], $Pen)
EndFunc   ;==>_DrawRect
Func _IsOnDisplay2PointsOneSide($PosX0 = 0, $PosY0 = 0, $PosZ0 = 0, $PosX1 = 1, $PosY1 = 0, $PosZ1 = 0)
    $Pos1 = _3DGetPos($PosX0, $PosY0, $PosZ0)
    $Pos2 = _3DGetPos($PosX1, $PosY1, $PosZ1)
    $Rotation = GetAngle($Pos1[0],$Pos1[1],$Pos2[0],$Pos2[1])
    If $Rotation > 90 or $Rotation < -90 then
        Return True
    EndIf
    ;TODO!!!!!!!!!!!!
    Return False
EndFunc   ;==>_IsOnDisplay
Func _IsOnDisplay4PointsOneSide($PosX0 = 0, $PosY0 = 0, $PosZ0 = 0, $PosX1 = 1, $PosY1 = 0, $PosZ1 = 0, $PosX2 = 1, $PosY2 = 1, $PosZ2 = 0, $PosX3 = 0, $PosY3 = 1, $PosZ3 = 0)
    $Pos1 = _3DGetPos($PosX0, $PosY0, $PosZ0)
    $Pos2 = _3DGetPos($PosX1, $PosY1, $PosZ1)
    $Rotation = GetAngle($Pos1[0],$Pos1[1],$Pos2[0],$Pos2[1])
    If $Rotation < 90 and $Rotation > -90 then
        Return True
    EndIf
    ;TODO!!!!!!!!!!!!
    Return False
EndFunc   ;==>_IsOnDisplay
Func _3DGetDistance($PosX0,$PosY0,$PosZ0,$PosX1=$CameraPosX,$PosY1=$CameraPosY,$PosZ1=$CameraPosZ)
    $PosX0 -= $PosX1
    $PosY0 -= $PosY1
    $PosZ0 -= $PosZ1
    Return Sqrt($PosX0^2 + $PosY0^2 + $PosZ0^2)
EndFunc
Func _3DGetPos($PosX = 0, $PosY = 0, $PosZ = 0)
    Local $RotationX = _Radian(-$CameraRotationX)
    Local $RotationY = _Radian(-$CameraRotationY)
    Local $RotationZ = _Radian(-$CameraRotationZ)
    Local $Output[2] = [0, 0]
    Local $CosRotationX_M45 = Cos($RotationX - $PI2)
    Local $SinRotationX_M45 = Sin($RotationX - $PI2)
    Local $CosRotationX = Cos($RotationX)
    Local $SinRotationX = Sin($RotationX)
    Local $CosRotationY = Cos($RotationY)
    Local $SinRotationY = Sin($RotationY)
    Local $PosXReal = $Display_Width / 2
    Local $PosYReal = $Display_Height / 2
    $PosX -= $CameraPosX
    $PosY -= $CameraPosY
    $PosZ -= $CameraPosZ
; LOOK HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    $Output[0] = ( _
            Cos($RotationX) * $Size * $PosX + _ ;X: X
            0 * $PosY + _ ;Y: X
            Cos($RotationX - $PI / 2) * $Size * $PosZ) ;Z: X

    $Output[1] = ( _
            Sin($RotationX) * Sin($RotationY) * $Size * $PosX + _ ;X: Y
            Cos($RotationY) * $Size * $PosY + _ ;Y: Y
            Sin($RotationX - $PI / 2) * Sin($RotationY) * $Size * $PosZ) ;Z: Y
    ;TODO!!!!!!!!
    ;LOOK HERE!!!                       HERE                    HERE                HERE                HERE
    ;Perspective:
    $Output[0] = ($Output[0]*(1/_3DGetDistance($PosX,$PosY,$PosZ))) + $PosXReal
    $Output[1] = ($Output[1]*(1/_3DGetDistance($PosX,$PosY,$PosZ))) + $PosXReal
    ;Orthographics:
;~  $Output[0] = $Output[0] + $PosXReal
;~  $Output[1] = $Output[1] + $PosXReal
    Return $Output

EndFunc   ;==>_3DGetPos

Func DegreesNormalize($Degr)
    ;TODO!!!!!!!!!!!!!!!!!!!!!!!!! Maybe.

    Do
        If $Degr > 360 Then $Degr -= 360
        If $Degr < 0 Then $Degr += 360
    Until $Degr > -0.005 And $Degr < 360.005
    Return $Degr
EndFunc   ;==>DegreesNormalize

Func Color($ColorFunc01,$ColorFunc02,$ColorFunc03=1)
   ;$ColorFunc01 = Pen(0) or Brush(1)
   ;$ColorFunc02 = Color(Black,White,Orange,Yellow,Green,Blue,Red or Hex code)
   ;$ColorFunc03 = Pen width
   ;$ColorFunc04 = Color in Hex
   ;$ColorFuncOP = Pen or Brush OutPut

   ;Error codes:
   ;1001 = $ColorFunc01 invalid.
   ;1002 = $ColorFunc04 invalid lenght.

   ;Check and fix input to prevent errors:
   If $ColorFunc03 = "" then $ColorFunc03 = 1
   If $ColorFunc01 = "" then $ColorFunc01 = 1
   If $ColorFunc01 <> 1 and $ColorFunc01 <> 2 then Exit(1001&$ColorFunc01)
   If $ColorFunc02 = "" then $ColorFunc02 = "White"
   $ColorFunc02Orig = $ColorFunc02
   $ColorFunc02 = StringUpper($ColorFunc02)

   ;Convert $ColorFunc02 to Hex code:
   If       $ColorFunc02 = "BLACK" Then
            $ColorFunc04 = 0xFF000000
   ElseIf   $ColorFunc02 = "WHITE" Then
            $ColorFunc04 = 0xFFFFFFFF
   ElseIf   $ColorFunc02 = "ORANGE" Then
            $ColorFunc04 = 0xFFFF6600
   ElseIf   $ColorFunc02 = "YELLOW" Then
            $ColorFunc04 = 0xFFFFFF00
   ElseIf   $ColorFunc02 = "GREEN" Then
            $ColorFunc04 = 0xFF00FF00
   ElseIf   $ColorFunc02 = "BLUE" Then
            $ColorFunc04 = 0xFF0000FF
   ElseIf   $ColorFunc02 = "RED" Then
            $ColorFunc04 = 0xFFFF0000
   ElseIf   $ColorFunc02 <> "" Then
            $ColorFunc04 = $ColorFunc02orig
   EndIf

   ;Drawing with a Pen:
   If $ColorFunc01 = 1 Then
   Local $ColorFuncOP = _GDIPlus_PenCreate($ColorFunc04, $ColorFunc03)
   Endif

   ;Drawing with a Brush:
   If $ColorFunc01 = 2 Then
   Local $ColorFuncOP = _GDIPlus_BrushCreateSolid($ColorFunc04)
   Endif
   Return $ColorFuncOP
EndFunc

Func ATan2($y, $x)
    Return (2 * ATan($y / ($x + Sqrt($x * $x + $y * $y))))
EndFunc   ;==>ATan2
Func __GetDiagonal($__iDX, $__iDY)
    Return Sqrt($__iDX ^ 2 + $__iDY ^ 2)
EndFunc   ;==>__GetDiagonal
Func __GetDistance($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
;~  ConsoleWrite("__GetDistance( $iX1=" & $iX1 & ", $iY1=" & $iY1 & ", $iX2=" & $iX2 & ", $iY2=" & $iY2 & " )" & @LF)
    $__iDX = Abs($iX2 - $iX1)
    $__iDY = Abs($iY2 - $iY1)

    If Not $__iDX And Not $__iDY Then Return 0
    If Not $__iDX Then Return $__iDY
    If Not $__iDY Then Return $__iDX
    Return Sqrt($__iDX ^ 2 + $__iDY ^ 2)
EndFunc   ;==>__GetDistance
Func __SumAngles($iA1 = 0, $iA2 = 0, $iMode = 0)
    Switch $iMode
        Case 0
            $__iDA = $iA1 + $iA2
            While $__iDA >= $2PI
                $__iDA -= $2PI
            WEnd

            While $__iDA < 0
                $__iDA += $2PI
            WEnd
        Case Else
            $__iDA = $iA1 + $iA2
            While $__iDA >= 360
                $__iDA -= 360
            WEnd

            While $__iDA < 0
                $__iDA += 360
            WEnd
    EndSwitch
    Return $__iDA
EndFunc   ;==>__SumAngles
Func GetAngle($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
    $TempDegr = _Degree(__GetAngle($iX1, $iY1, $iX2, $iY2))
    $TempDegr = _Degree($TempDegr) * $fDegToRad
    Return ($TempDegr - $TempDegr - $TempDegr + 180)
EndFunc   ;==>GetAngle
Func __GetAngle($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
;~  ConsoleWrite(_Degree(__GetAngle(1, 1))-90)
;~  ConsoleWrite("__GetAngle( $iX1=" & $iX1 & ", $iY1=" & $iY1 & ", $iX2=" & $iX2 & ", $iY2=" & $iY2 & " )" & @LF)
    If $iX1 = $iX2 Then
        If $iY1 = $iY2 Then
            Return SetError(1, 0, -1)
        Else
            If $iY1 > $iY2 Then
                Return $PI / 2
            Else
                Return $5PI
            EndIf
        EndIf
    Else
        $__iDX = $iX2 - $iX1
        $__iDY = $iY2 - $iY1
        If $iX1 > $iX2 Then
            If $iY1 = $iY2 Then
                Return $PI
            Else
                If $iY1 > $iY2 Then
                    Return $PI2 + ATan($__iDX / $__iDY)
                Else
                    Return $5PI + ATan($__iDX / $__iDY)
                EndIf
            EndIf
        Else
            If $iY1 = $iY2 Then
                Return 0
            Else
                If $iY1 > $iY2 Then
                    Return $PI2 + ATan($__iDX / $__iDY)
                Else
                    Return $5PI + ATan($__iDX / $__iDY)
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc   ;==>__GetAngle

@TheDcoder It's orthographic view, you will see in line 235 orthographic and perspective codes, remove semicolons(;) from two perspective lines and add to two orthographic lines semicolons

Look with WASD, move with up, down, left, right buttons, go up and down with + and - (- is up, + is down) :)

I forgot to fix one bug that I made... Cube walls are not in the right position... It should work now.

Edited by algiuxas

42783.png

Share this post


Link to post
Share on other sites
1 hour ago, TheDcoder said:

@algiuxas Give us some code to test :D

If you have any questions, ask me.
There are many bugs in script, I will try to fix them :)


42783.png

Share this post


Link to post
Share on other sites

I don't have any questions... because I don't understand your code. I just adviced you to post the code for others to help you :).

 

Although there is a bug (or is it intended behavior?) I noticed... The simulation does not look like 3D :blink:, but some clever image morphing or something :wacko:. My brain hurts! >_<

1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
Just now, TheDcoder said:

I don't have any questions... because I don't understand your code. I just adviced you to post the code for others to help you :).

 

Although there is a bug (or is it intended behavior?) I noticed... The simulation does not look like 3D :blink:, but some clever image morphing or something :wacko:. My brain hurts! >_<

Maybe you should try move back with down button. :) It' 3D, but...well...it's very buggy.


42783.png

Share this post


Link to post
Share on other sites

Į fixed it a long time ago


42783.png

Share this post


Link to post
Share on other sites
46 minutes ago, algiuxas said:

Į fixed it a long time ago

You did? Can I see the final result? :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
On 2016-09-13 at 4:24 PM, TheDcoder said:

You did? Can I see the final result? :)

Oh no... I reinstalled my OS and now it's gone... But it wasn't good enought, I'LL MAKE A BETTER ONE! :D

I made huge mistakes in it, now I know how to make it :)


42783.png

Share this post


Link to post
Share on other sites

Oh, I am sad :(... I will be waiting for a improved version though :D


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
1 minute ago, TheDcoder said:

Oh, I am sad :(... I will be waiting for a improved version though :D

Yeah, it WILL be much better, I have made it in C programming language, but yeah, I reinstalled OS...


42783.png

Share this post


Link to post
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

  • Similar Content

    • Chimp
      By Chimp
      just for further fun Here is a Javascript version of the nice 3D sine wave posted from @UEZ
      This version uses this nice javascript library:(http://visjs.org/graph3d_examples.html).  (All the 'dirty' work is done by the javascript library, so the whole credit goes of course to that library and not to me...) I've simply injected all the html/javascript stuff into a BrowserControl embedded into an AutoIt GUI.
      Have fun
      #include <GUIConstantsEx.au3> Example() Exit Func Example() Local $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl Local $hGUI = GUICreate("3D Sinus wave animation demo", 660, 650, 30, 30) GUICtrlCreateObj($oIE, 0, 0, 660, 650) ; Place BrowserControl on the GUI GUISetState() ;Show GUI $oIE.navigate('about:blank') While Not String($oIE.readyState) = 'complete' ; wait for about:blank Sleep(100) WEnd ; this waits till the document is ready to be used (portion of code from IE.au3) While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4) Sleep(100) WEnd While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4) Sleep(100) WEnd $oIE.document.Write(_GetHTML()) ; inject lising directly to the HTML document: $oIE.document.close() ; close the write stream $oIE.document.execCommand("Refresh") ; ----------------------------- ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; the end $oIE = 0 ; Remove IE from memory. GUIDelete($hGUI) ; Remove GUI EndFunc ;==>Example Func _GetHTML() Local $sHTML = _ "<!doctype html>" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ " <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ " <title></title>" & @CRLF & _ "" & @CRLF & _ " <style type=""text/css"">" & @CRLF & _ " body {" & @CRLF & _ " font: 10pt arial;" & @CRLF & _ " }" & @CRLF & _ " </style>" & @CRLF & _ "" & @CRLF & _ " <script type=""text/javascript"" src=""https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.0/vis.min.js""></script>" & @CRLF & _ "" & @CRLF & _ " <script type=""text/javascript"">" & @CRLF & _ " var data = null;" & @CRLF & _ " var graph = null;" & @CRLF & _ " var x0, x1, x2" & @CRLF & _ " function custom(x, y, t) {" & @CRLF & _ " // change this function to change the graph" & @CRLF & _ " x0 = 20 - t/180;" & @CRLF & _ " x1 = (x/x0)*(x/x0) + t/10;" & @CRLF & _ " y1 = (y/x0)*(y/x0) + t/10;" & @CRLF & _ " return Math.sin(Math.sqrt(x1+y1));" & @CRLF & _ " }" & @CRLF & _ " // Called when the Visualization API is loaded." & @CRLF & _ " function drawVisualization() {" & @CRLF & _ " // Create and populate a data table." & @CRLF & _ " data = new vis.DataSet();" & @CRLF & _ " // create some nice looking data with sin/cos" & @CRLF & _ " var steps = 25;" & @CRLF & _ " var axisMax = 314;" & @CRLF & _ " var tMax = 800;" & @CRLF & _ " var axisStep = axisMax / steps;" & @CRLF & _ " for (var t = 300; t <= tMax; t = t + 50) {" & @CRLF & _ " for (var x = -axisMax; x < axisMax; x+=axisStep) {" & @CRLF & _ " for (var y = -axisMax; y < axisMax; y+=axisStep) {" & @CRLF & _ " var value = custom(x, y, t);" & @CRLF & _ " data.add([" & @CRLF & _ " {x:x,y:y,z:value,filter:t,style:value}" & @CRLF & _ " ]);" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " // specify options" & @CRLF & _ " var options = {" & @CRLF & _ " width: '600px'," & @CRLF & _ " height: '600px'," & @CRLF & _ " style: 'surface'," & @CRLF & _ " showPerspective: true," & @CRLF & _ " showGrid: false," & @CRLF & _ " showShadow: false," & @CRLF & _ " // showAnimationControls: false," & @CRLF & _ " keepAspectRatio: true," & @CRLF & _ " verticalRatio: 0.085, // 0.5," & @CRLF & _ " animationInterval: 100, // milliseconds" & @CRLF & _ " animationPreload: true," & @CRLF & _ " animationAutoStart: true," & @CRLF & _ " filterValue: 'time'" & @CRLF & _ " };" & @CRLF & _ "" & @CRLF & _ " // create our graph" & @CRLF & _ " var container = document.getElementById('mygraph');" & @CRLF & _ " graph = new vis.Graph3d(container, data, options);" & @CRLF & _ " }" & @CRLF & _ " </script>" & @CRLF & _ "</head>" & @CRLF & _ "" & @CRLF & _ "<body onload=""drawVisualization();"">" & @CRLF & _ "<div id=""mygraph""></div>" & @CRLF & _ "" & @CRLF & _ "<div id=""info""></div>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" Return $sHTML EndFunc ;==>_GetHTML  
    • UEZ
      By UEZ
      As requested by @Lakes here:
      GDI and GDI+ versions of 3D Sinus Wave. GDI ≠ GDI+!
       
      GDI:
      ;coded by UEZ build 2017-01-18 #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #include <GuiConstantsEx.au3> #include <WinAPIGdi.au3> #include <WindowsConstants.au3> Global $__f1, $__f2, $__f3, $__fY0, $__fZ0, $__fX1, $__fY1 Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit, $fZoom = 5.0 Global Const $iW = @DesktopWidth * 0.75, $iH = @DesktopHeight * 0.75, $iWh = $iW / 2, $iHh = $iH / 2, $sTitle = "GDI+ 3D Sinus Wave v1.1 coded by UEZ / FPS: " Global Const $fPi = ACos(-1), $fRad = $fPi / 180, $fDeg = 180 / $fPi, $fPi2 = ACos(-1) * 2 AutoItSetOption("GUIOnEventMode", 1) GDIPlus_3DSinusWave() AutoItSetOption("GUIOnEventMode", 0) Func GDIPlus_3DSinusWave() $bExit = False $hGUI = GUICreate($sTitle, $iW, $iH) ;, 0, 0, $WS_POPUP) GUISetState(@SW_SHOW, $hGUI) ;~ GUISetCursor(16, 1) ;create canvas elements Local Const $hDC = _WinAPI_GetDC($hGUI) Local Const $hBitmapGDI = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local Const $hGfxDC = _WinAPI_CreateCompatibleDC($hDC) Local Const $hObjOld = _WinAPI_SelectObject($hGfxDC, $hBitmapGDI) Local Const $hPen = _WinAPI_GetStockObject($DC_PEN) Local Const $hPen_Old = _WinAPI_SelectObject($hGfxDC, $hPen) _WinAPI_SetStretchBltMode($hDC, $HALFTONE) $iFPS = 0 Local Const $fEuler = 2.7182818284 Local $fSpace = 6, $iPoints = 16, $fSpace2 = $fSpace / 2, $iPoints2 = $iPoints / 2 Local $fRotX = Random(-360, 360), $fRotY = Random(-360, 360), $fRotZ = Random(-360, 360), $fPower = 20.0 Local $fRx = Random(-1.5, 1,5), $fRy = Random(-1.5, 1,5), $fRz = Random(-1.5, 1,5) Local $c = 0, $t = 0, $aCoords[$iPoints ^ 2][3] Local $i, $j, $x, $y, $z, $x1, $y1, $z1, $x2, $y2, $z2, $x3, $y3, $z3, $fDistance, $r, $g, $b Local $hDLL_gdi32 = DllOpen("gdi32.dll") Local $tLOGBRUSH = DllStructCreate($tagLOGBRUSH) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") AdlibRegister("CalcFPS", 1000) Do _WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $WHITENESS) ;erase canvas background $c = 0 For $i = 0 To $iPoints - 1 For $j = 0 To $iPoints - 1 $aCoords[$c][0] = $fSpace * $i + $fSpace2 - $fSpace * $iPoints2 $aCoords[$c][1] = $fSpace * $j + $fSpace2 - $fSpace * $iPoints2 $fDistance = Dist(0, 0, $aCoords[$c][0], $aCoords[$c][1]) $aCoords[$c][2] = $fEuler ^ (-$fDistance / 50) * Sin(($fDistance / 10) - $t) * $fPower $c += 1 $t += 0.00075 Next Next For $i = 0 To $iPoints - 2 For $j = 0 To $iPoints - 2 $r = Int(0x80 + $aCoords[$j + $iPoints * $i][0] * 2) $g = Int(0x80 + $aCoords[$j + $iPoints * $i][1] * 2) $b = Int(0x80 + $aCoords[$j + $iPoints * $i][2] * 2) DllCall($hDLL_gdi32, "dword", "SetDCPenColor", "handle", $hGfxDC, "dword", BitShift($b, -16) + BitShift($g, -8) + $r) _3Dto2D($aCoords[$j + $iPoints * $i][0], $aCoords[$j + $iPoints * $i][1], $aCoords[$j + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x1, $y1, $z1) _3Dto2D($aCoords[$j + $iPoints * ($i + 1)][0], $aCoords[$j + $iPoints * ($i + 1)][1], $aCoords[$j + $iPoints * ($i + 1)][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($hDLL_gdi32, "bool", "MoveToEx", "handle", $hGfxDC, "int", $iWh + $x1 * $fZoom, "int", $iHh + $y1 * $fZoom, "ptr", 0) DllCall($hDLL_gdi32, "bool", "LineTo", "handle", $hGfxDC, "int", $iWh + $x2 * $fZoom, "int", $iHh + $y2 * $fZoom) _3Dto2D($aCoords[($j + 1) + $iPoints * $i][0], $aCoords[($j + 1) + $iPoints * $i][1], $aCoords[($j + 1) + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($hDLL_gdi32, "bool", "MoveToEx", "handle", $hGfxDC, "int", $iWh + $x1 * $fZoom, "int", $iHh + $y1 * $fZoom, "ptr", 0) DllCall($hDLL_gdi32, "bool", "LineTo", "handle", $hGfxDC, "int", $iWh + $x2 * $fZoom, "int", $iHh + $y2 * $fZoom) Next Next For $i = 0 To $iPoints - 2 $r = Int(0x80 + $aCoords[$j + $iPoints * $i][0] * 2) $g = Int(0x80 + $aCoords[$j + $iPoints * $i][1] * 2) $b = Int(0x80 + $aCoords[$j + $iPoints * $i][2] * 2) DllCall($hDLL_gdi32, "dword", "SetDCPenColor", "handle", $hGfxDC, "dword", BitShift($b, -16) + BitShift($g, -8) + $r) _3Dto2D($aCoords[$j + $iPoints * $i][0], $aCoords[$j + $iPoints * $i][1], $aCoords[$j + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x1, $y1, $z1) _3Dto2D($aCoords[$j + $iPoints * ($i + 1)][0], $aCoords[$j + $iPoints * ($i + 1)][1], $aCoords[$j + $iPoints * ($i + 1)][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($hDLL_gdi32, "bool", "MoveToEx", "handle", $hGfxDC, "int", $iWh + $x1 * $fZoom, "int", $iHh + $y1 * $fZoom, "ptr", 0) DllCall($hDLL_gdi32, "bool", "LineTo", "handle", $hGfxDC, "int", $iWh + $x2 * $fZoom, "int", $iHh + $y2 * $fZoom) Next For $j = 0 To $iPoints - 2 $r = Int(0x80 + $aCoords[$j + $iPoints * $i][0] * 2) $g = Int(0x80 + $aCoords[$j + $iPoints * $i][1] * 2) $b = Int(0x80 + $aCoords[$j + $iPoints * $i][2] * 2) DllCall($hDLL_gdi32, "dword", "SetDCPenColor", "handle", $hGfxDC, "dword", BitShift($b, -16) + BitShift($g, -8) + $r) _3Dto2D($aCoords[$j + $iPoints * $i][0], $aCoords[$j + $iPoints * $i][1], $aCoords[$j + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x1, $y1, $z1) _3Dto2D($aCoords[($j + 1) + $iPoints * $i][0], $aCoords[($j + 1) + $iPoints * $i][1], $aCoords[($j + 1) + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($hDLL_gdi32, "bool", "MoveToEx", "handle", $hGfxDC, "int", $iWh + $x1 * $fZoom, "int", $iHh + $y1 * $fZoom, "ptr", 0) DllCall($hDLL_gdi32, "bool", "LineTo", "handle", $hGfxDC, "int", $iWh + $x2 * $fZoom, "int", $iHh + $y2 * $fZoom) Next $fRotX += $fRx $fRotY += $fRy $fRotZ += $fRz _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI $iFPS += 1 If $bExit Then ExitLoop Until Not Sleep(10) GUIRegisterMsg($WM_MOUSEWHEEL, "") AdlibUnRegister("CalcFPS") ;release resources _WinAPI_SelectObject($hGfxDC, $hPen_Old) _WinAPI_DeleteObject($hPen) _WinAPI_SelectObject($hGfxDC, $hObjOld) _WinAPI_ReleaseDC($hGUI, $hDC) _WinAPI_DeleteDC($hGfxDC) _WinAPI_DeleteObject($hBitmapGDI) GUIDelete($hGUI) DllClose($hDLL_gdi32) EndFunc ;==>GDIPlus_3DSinusWave Func WM_MOUSEWHEEL($hGUI, $iMsg, $wParam, $lParam) Local $wheel_Dir = _WinAPI_HiWord($wParam) If $wheel_Dir > 0 Then $fZoom += 0.25 $fZoom = $fZoom > 20 ? 20 : $fZoom Else $fZoom -= 0.25 $fZoom = $fZoom < 0.25 ? 0.25 : $fZoom EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>WM_MOUSEWHEEL Func Dist($x1, $y1, $x2, $y2) Return Sqrt(($x1 - $x2) * ($x1 - $x2) + ($y1 - $y2) * ($y1 - $y2)) EndFunc ;==>Dist Func _3Dto2D($fX, $fY, $fZ, $fRotX, $fRotY, $fRotZ, ByRef $__fXPos, ByRef $__fYPos, ByRef $__fZPos) ;apply the x-axis rotation to transform coordinates ($fX, $fY, $fZ) into coordinates ($fX0, $fY0, $fZ0) $__f1 = $fRotX * $fRad $__f2 = Cos($__f1) $__f3 = Sin($__f1) $__fY0 = $fY * $__f2 + $fZ * $__f3 $__fZ0 = $fZ * $__f2 - $fY * $__f3 ;apply the y-axis rotation to ($fX0, $__fY0, $fZ0) to obtain ($__fX1, $__fY1, $fZ1) $__f1 = $fRotY * $fRad $__f2 = Cos($__f1) $__f3 = Sin($__f1) $__fX1 = $fX * $__f2 - $__fZ0 * $__f3 $__fY1 = $__fY0 ;~ $__fZ1 = $__fZ0 * $__f2 + $fX * $__f2 ;finally, apply the z-axis rotation to obtain the point ($fXPos, $fYPos) $__f1 = $fRotZ * $fRad $__f2 = Cos($__f1) $__f3 = Sin($__f1) $__fXPos = $__fX1 * $__f2 + $__fY1 * $__f3 $__fYPos = $__fY1 * $__f2 - $__fX1 * $__f3 $__fZPos = $__fZ0 EndFunc ;==>_3Dto2D Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func CalcFPS() ;display FPS $iShowFPS = $iFPS $iFPS = 0 WinSetTitle($hGUI, "", $sTitle & $iShowFPS) EndFunc ;==>CalcFPS  
      GDI+
      ;coded by UEZ build 2017-01-17 #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $__f1, $__f2, $__f3, $__fY0, $__fZ0, $__fX1, $__fY1 Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit Global Const $iW = @DesktopWidth * 0.75, $iH = @DesktopHeight * 0.75, $iWh = $iW / 2, $iHh = $iH / 2, $sTitle = "GDI+ 3D Sinus Wave v1.0 coded by UEZ" Global Const $fPi = ACos(-1), $fRad = $fPi / 180, $fDeg = 180 / $fPi, $fPi2 = ACos(-1) * 2 AutoItSetOption("GUIOnEventMode", 1) GDIPlus_3DSinusWave() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_3DSinusWave() $bExit = False $hGUI = GUICreate($sTitle, $iW, $iH) ;, 0, 0, $WS_POPUP) GUISetState(@SW_SHOW, $hGUI) ;~ GUISetCursor(16, 1) ;create canvas elements Local Const $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local Const $hBrush_Clr = _GDIPlus_BrushCreateSolid(0xFFFFFFFF), _ $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xF0808080), _ $hFormat_FPS = _GDIPlus_StringFormatCreate(), _ $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _ $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _ $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 60, 16), _ $hPath = _GDIPlus_PathCreate(), _ $hPen = _GDIPlus_PenCreate(0xCF101010, 1.25) _GDIPlus_PenSetLineJoin($hPen, 2) ;~ _GDIPlus_PenSetDashCap($hPen, $GDIP_DASHCAPROUND) ;~ _GDIPlus_PenSetLineCap($hPen, 0x12, 0x12, 2) $iFPS = 0 Local $fEuler = 2.7182818284 Local $fSpace = 6, $iPoints = 16, $fSpace2 = $fSpace / 2, $iPoints2 = $iPoints / 2 Local $fRotX = Random(-360, 360), $fRotY = Random(-360, 360), $fRotZ = Random(-360, 360), $fZoom = 5.0, $fPower = 20.0 Local $fRx = Random(-1.5, 1,5), $fRy = Random(-1.5, 1,5), $fRz = Random(-1.5, 1,5) Local $c = 0, $t = 0, $aCoords[$iPoints ^ 2][3] Local $i, $j, $x, $y, $z, $x1, $y1, $z1, $x2, $y2, $z2, $x3, $y3, $z3, $fDistance, $r, $g, $b GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") AdlibRegister("CalcFPS", 1000) Do ;~ DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush_Clr, "float", 0, "float", 0, _ ;~ "float", $iW, "float", $iH) ;erase canvas background _WinAPI_BitBlt($hDC_backbuffer, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $WHITENESS) $c = 0 For $i = 0 To $iPoints - 1 For $j = 0 To $iPoints - 1 $aCoords[$c][0] = ($fSpace * $i + $fSpace2 - $fSpace * $iPoints2) $aCoords[$c][1] = ($fSpace * $j + $fSpace2 - $fSpace * $iPoints2) $fDistance = Dist(0, 0, $aCoords[$c][0], $aCoords[$c][1]) $aCoords[$c][2] = $fEuler ^ (-$fDistance / 50) * Sin(($fDistance / 10) - $t) * $fPower $c += 1 $t += 0.00075 Next Next For $i = 0 To $iPoints - 2 For $j = 0 To $iPoints - 2 _3Dto2D($aCoords[$j + $iPoints * $i][0], $aCoords[$j + $iPoints * $i][1], $aCoords[$j + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x1, $y1, $z1) _3Dto2D($aCoords[$j + $iPoints * ($i + 1)][0], $aCoords[$j + $iPoints * ($i + 1)][1], $aCoords[$j + $iPoints * ($i + 1)][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($__g_hGDIPDll, "int", "GdipDrawLine", "handle", $hCanvas, "handle", $hPen, _ "float", $iWh + $x1 * $fZoom, "float", $iHh + $y1 * $fZoom, "float", $iWh + $x2 * $fZoom, "float", $iHh + $y2 * $fZoom) _3Dto2D($aCoords[($j + 1) + $iPoints * $i][0], $aCoords[($j + 1) + $iPoints * $i][1], $aCoords[($j + 1) + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($__g_hGDIPDll, "int", "GdipDrawLine", "handle", $hCanvas, "handle", $hPen, _ "float", $iWh + $x1 * $fZoom, "float", $iHh + $y1 * $fZoom, "float", $iWh + $x2 * $fZoom, "float", $iHh + $y2 * $fZoom) Next Next For $i = 0 To $iPoints - 2 _3Dto2D($aCoords[$j + $iPoints * $i][0], $aCoords[$j + $iPoints * $i][1], $aCoords[$j + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x1, $y1, $z1) _3Dto2D($aCoords[$j + $iPoints * ($i + 1)][0], $aCoords[$j + $iPoints * ($i + 1)][1], $aCoords[$j + $iPoints * ($i + 1)][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($__g_hGDIPDll, "int", "GdipDrawLine", "handle", $hCanvas, "handle", $hPen, _ "float", $iWh + $x1 * $fZoom, "float", $iHh + $y1 * $fZoom, "float", $iWh + $x2 * $fZoom, "float", $iHh + $y2 * $fZoom) Next For $j = 0 To $iPoints - 2 _3Dto2D($aCoords[$j + $iPoints * $i][0], $aCoords[$j + $iPoints * $i][1], $aCoords[$j + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x1, $y1, $z1) _3Dto2D($aCoords[($j + 1) + $iPoints * $i][0], $aCoords[($j + 1) + $iPoints * $i][1], $aCoords[($j + 1) + $iPoints * $i][2], $fRotX, $fRotY, $fRotZ, $x2, $y2, $z2) DllCall($__g_hGDIPDll, "int", "GdipDrawLine", "handle", $hCanvas, "handle", $hPen, _ "float", $iWh + $x1 * $fZoom, "float", $iHh + $y1 * $fZoom, "float", $iWh + $x2 * $fZoom, "float", $iHh + $y2 * $fZoom) Next $fRotX += $fRx $fRotY += $fRy $fRotZ += $fRz _GDIPlus_GraphicsDrawStringEx($hCanvas, "FPS: " & $iShowFPS, $hFont_FPS, $tLayout_FPS, $hFormat_FPS, $hBrush_FPS) ;draw background message text _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI $iFPS += 1 If $bExit Then ExitLoop Until Not Sleep(10) AdlibUnRegister("CalcFPS") ;release resources _GDIPlus_PenDispose($hPen) _GDIPlus_PathDispose($hPath) _GDIPlus_FontDispose($hFont_FPS) _GDIPlus_FontFamilyDispose($hFamily_FPS) _GDIPlus_StringFormatDispose($hFormat_FPS) _GDIPlus_BrushDispose($hBrush_Clr) _GDIPlus_BrushDispose($hBrush_FPS) _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hGUI, $hDC) GUIDelete($hGUI) EndFunc ;==>GDIPlus_3DSinusWave Func Dist($x1, $y1, $x2, $y2) Return Sqrt(($x1 - $x2) * ($x1 - $x2) + ($y1 - $y2) * ($y1 - $y2)) EndFunc ;==>Dist Func _3Dto2D($fX, $fY, $fZ, $fRotX, $fRotY, $fRotZ, ByRef $__fXPos, ByRef $__fYPos, ByRef $__fZPos) ;apply the x-axis rotation to transform coordinates ($fX, $fY, $fZ) into coordinates ($fX0, $fY0, $fZ0) $__f1 = $fRotX * $fRad $__f2 = Cos($__f1) $__f3 = Sin($__f1) $__fY0 = $fY * $__f2 + $fZ * $__f3 $__fZ0 = $fZ * $__f2 - $fY * $__f3 ;apply the y-axis rotation to ($fX0, $__fY0, $fZ0) to obtain ($__fX1, $__fY1, $fZ1) $__f1 = $fRotY * $fRad $__f2 = Cos($__f1) $__f3 = Sin($__f1) $__fX1 = $fX * $__f2 - $__fZ0 * $__f3 $__fY1 = $__fY0 ;~ $__fZ1 = $__fZ0 * $__f2 + $fX * $__f2 ;finally, apply the z-axis rotation to obtain the point ($fXPos, $fYPos) $__f1 = $fRotZ * $fRad $__f2 = Cos($__f1) $__f3 = Sin($__f1) $__fXPos = $__fX1 * $__f2 + $__fY1 * $__f3 $__fYPos = $__fY1 * $__f2 - $__fX1 * $__f3 $__fZPos = $__fZ0 EndFunc ;==>_3Dto2D Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func CalcFPS() ;display FPS $iShowFPS = $iFPS $iFPS = 0 EndFunc ;==>CalcFPS  
      In the attached 7-Zip file you can find the compiled and also a FreeBasic version. -> DL: 3D Sinus Wave.7z
       
      Have fun. 
    • rudi
      By rudi
      Hi.
      You are a solar enthusiast?
      for my personal fun I wrote these two scripts.
      The first one is downloading all the JPG solar pictures, starting at a given date. the 2nd one will display them in an Autoit GUI, with an adjustable image difference for your right and left eye:
      "Stare through" your monitor, so that your left eye will focus the left image, your right eye the right image, then you will recognize the 3D effect.
       
      If you have difficulties to "match" the left / right image to your left / right eye, then ...
      decrease the GUI's size (PAGE-DN), until the "image-middle-distance" is a bit BELOW your eye's distance (depends on your monitor's size and your physiognomy) put your face very close to your monitor, then slowly fade back, until you will recognize to see virtually THREE images Wait a moment to recognize the 3D effect of the "middle image" Concentrate on this "middle image" and it's 3D effect AVOID rotating or moving your head in any direction, except forward/backward! This propably will kill down the focus, if you've had difficulties to get it in the beginning! Try to SLOWLY fade back with your face even more, until you have reached a comfortable distance. Now use PAGE-UP, do increase the GUI's (the images) size: Once you've caught the 3D "match", you can usually increase the size to values, you would have never ever been able to "match" at the first time. (The downloaded images are 1024 x 1024 pixels)  
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=Display NASA JPG solar pics as a 3D movie #AutoIt3Wrapper_Res_Fileversion=1.0.0.7 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=Rudi Thilo #AutoIt3Wrapper_Res_SaveSource=y #AutoIt3Wrapper_Res_Field=phone|+49 171 685 9 685 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs autoit v3.3.12.0 author: Rudi Thilo +49 171 685 9 685 Download the solar JPG pictures of NASA from the subfolders of the URL specified as first variable declaration 1.) download the JPGs using this script 2.) Use "Solar-GUI-2.au3 to display them as a movie inside an Autoit3 GUI as a "poor-man's-3D-cinema" Both scripts have to be in the same folder. have fun! :D #ce #include <Inet.au3> #include <Date.au3> $url = "http://sdo.gsfc.nasa.gov/assets/img/browse/" $Start = "2015/01/01" $NextDate = $Start $RegExJpgName = '(.*?<a href=")([\d_]+?_1024_0193\.jpg)(">.*)' ; $2 returns the JPG file name. Size 1024x1024, Picture colouring type 0193 (whatsoever that exactly means ;-) $SolarFolder = @ScriptDir & "\SolarJPGs\" DirCreate($SolarFolder) ShellExecute($SolarFolder) HttpSetProxy(1) ; direct access While (_DateDiff("D", $NextDate, _NowCalcDate()) > -1) $NextFolder = $url & $NextDate & "/" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NextFolder = ' & $NextFolder & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console GetJPGs($NextFolder) $NextDate = _DateAdd("D", 1, $NextDate) WEnd Func GetJPGs($_URL) $page = _INetGetSource($_URL) $aPage = StringSplit($page, "<tr>", 1) if @error then Exit For $a = 1 To $aPage[0] If StringRegExp($aPage[$a], $RegExJpgName) Then $_JPG = StringStripWS(StringRegExpReplace($aPage[$a], $RegExJpgName, "$2"), 1 + 2) $_NextURL = $_URL & $_JPG $_NextJPG = $SolarFolder & $_JPG If FileExists($_NextJPG) Then ContinueLoop ; that file has been downloaded before ALREADY ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_NextJPG = ' & $_NextJPG & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $result = InetGet($_NextURL, $_NextJPG, 1 + 2, 1) EndIf Next EndFunc ;==>GetJPGs  
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=Display NASA JPG solar pics as a 3D movie #AutoIt3Wrapper_Res_Fileversion=2.0.0.17 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=Rudi Thilo #AutoIt3Wrapper_Res_SaveSource=y #AutoIt3Wrapper_Res_Field=phone|+49 171 685 9 685 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs autoit v3.3.12.0 display the previously downloaded solar images as a movie in one Autoit3 GUI, to get some 3D impression use ARROW-UP to increase the GUI's size use ARROW-DOWN to decrease the GUI's size use LEFT-ARROW to run the movie backward use RIGHT-ARROW to run the movie forward use PAGEUP to increase the delta between the two images (more 3D effect) use PAGEDN to decrease the delta between the two images. Negative values will give you a strange effect use ESC to close the program have fun! :D #ce #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Misc.au3> #include <file.au3> $SolarFolder = @ScriptDir & "\SolarJPGs\" #Region Fill array with all found JPG files $aJPGs = _FileListToArray($SolarFolder, "*.jpg", 1, 1) If @error Then MsgBox(0, "Solar JPGs", "No JGP files found in path" & @CRLF & $SolarFolder) Exit EndIf _ArraySort($aJPGs, 0, 1) #EndRegion Fill array with all found JPG files $Delta = 3 $forward = True $LastDate = StringLeft($aJPGs[1], 4) & "-" & StringMid($aJPGs[1], 5, 2) & "-" & StringMid($aJPGs[1], 7, 2) Local $hDLL = DllOpen("user32.dll") AdlibRegister("ReadKeys") $h = 300 $w = $h * 2 $margin = 2 $GuiTitle = "solar movie, " & $h & " px, " $Gui = GUICreate($GuiTitle & $LastDate, $w + $margin, $h + $margin) $Left = GUICtrlCreatePic($aJPGs[1 + $Delta], $margin, $margin, $w / 2 - $margin * 2, $h - $margin * 2) $Right = GUICtrlCreatePic($aJPGs[1], $w / 2 + $margin, $margin, $w / 2 - $margin * 2, $h - $margin * 2) GUISetState() $pointer = 1 While 1 If ($pointer + $Delta) > (UBound($aJPGs) - 1) Or ($pointer > UBound($aJPGs)) Then MsgBox(0, "", "Last image reached." & @CRLF & @CRLF & "Changing direction to reverse now...", 3) $forward = False $pointer -= 1 ElseIf ($pointer < 1) Or ($pointer + $Delta) < 1 Then MsgBox(0, "", "First image reached." & @CRLF & @CRLF & "Changing direction to forward now...", 3) $forward = True $pointer += 1 EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ConsoleWrite("close erkannt" & @CRLF) #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Default Button=Second, Icon=Question, Timeout=5 ss, Miscellaneous=Top-most attribute If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(262436, "ESC recognized", "Do you want to terminate this program?", 5) Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No Case $iMsgBoxAnswer = -1 ;Timeout EndSelect #EndRegion --- CodeWizard generated code Start --- EndSwitch $NextName = $aJPGs[$pointer + $Delta] $NextName = StringTrimLeft($NextName, StringInStr($NextName, "\", 0, -1)) $NextDate = StringLeft($NextName, 4) & "-" & StringMid($NextName, 5, 2) & "-" & StringMid($NextName, 7, 2) If $NextDate <> $LastDate Then $LastDate = $NextDate AdjustTitle() EndIf $L = $aJPGs[$pointer + $Delta] $R = $aJPGs[$pointer] GUICtrlSetImage($Left, $L) GUICtrlSetImage($Right, $R) If $forward Then $pointer += 1 Else $pointer -= 1 EndIf WEnd Func ReadKeys() $aPos = WinGetPos($Gui) If _IsPressed("26", $hDLL) Then ; UP arrow key $h += 2 $w = $h * 2 WinMove($Gui, "", $aPos[0] - 1, $aPos[1] - 1, $w + $margin * 4, $h + $margin * 2 + 20) ; symmetrically expand one pixel in each direction AdjustTitle() GUICtrlDelete($Left) GUICtrlDelete($Right) $Left = GUICtrlCreatePic($L, $margin, $margin, $w / 2 - $margin * 2, $h - $margin * 2) $Right = GUICtrlCreatePic($R, $w / 2 + $margin, $margin, $w / 2 - $margin * 2, $h - $margin * 2) ElseIf _IsPressed("28", $hDLL) Then ; DOWN arrow key $h -= 2 $w = $h * 2 WinMove($Gui, "", $aPos[0] + 1, $aPos[1] + 1, $w + $margin * 4, $h + $margin * 2 + 20) ; symmetrically shrink one pixel in each direction AdjustTitle() GUICtrlDelete($Left) GUICtrlDelete($Right) $Left = GUICtrlCreatePic($L, $margin, $margin, $w / 2 - $margin * 2, $h - $margin * 2) $Right = GUICtrlCreatePic($R, $w / 2 + $margin, $margin, $w / 2 - $margin * 2, $h - $margin * 2) ElseIf _IsPressed("21", $hDLL) Then ; PAGE-UP key $Delta += 1 If ($pointer + $Delta) > (UBound($aJPGs) - 1) Then MsgBox(0, "", "The End") Exit EndIf AdjustTitle() ElseIf _IsPressed("22", $hDLL) Then ; PAGE-DOWN key $Delta -= 1 AdjustTitle() ElseIf _IsPressed("25", $hDLL) Then ; LEFT cursor key $forward = False ElseIf _IsPressed("27", $hDLL) Then ; RIGHT cursor key $forward = True EndIf EndFunc ;==>ReadKeys Func AdjustTitle() $GuiTitle = "solar movie, " & $h & " px, D: " & $Delta & " " & $LastDate WinSetTitle($Gui, "", $GuiTitle) EndFunc ;==>AdjustTitle Regards, Rudi.
    • rudi
      By rudi
      Hello,
      It's now working quite nice.
      See this post in the UDF forum
       

       
      Regards, Rudi.
       
      ------------ no need to read all the other lines -----------
       
      this is  a first script, to get NASA solar pictures to my local disk. Works quite okay, but it is very slow.
       
      1.) Possibly there is a chance to speed it up?
       
      #include <Inet.au3> #include <Date.au3> $url = "http://sdo.gsfc.nasa.gov/assets/img/browse/" $Start = "2016/01/01" $NextDate = $Start $RegExJpgName = '(.*?<a href=")([\d_]+?_1024_0193\.jpg)(">.*)' ; $2 returns the JPG file name. Size 1024x1024, Picture colouring type 0193 (whatsoever that exactly means ;-) $SolarFolder = @TempDir & "\SolarJPGs\" DirCreate($SolarFolder) ShellExecute($SolarFolder) HttpSetProxy(1) ; direct access While (_DateDiff("D", $NextDate, _NowCalcDate()) > -1) $NextFolder = $url & $NextDate & "/" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NextFolder = ' & $NextFolder & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console GetJPGs($NextFolder) $NextDate = _DateAdd("D", 1, $NextDate) WEnd Func GetJPGs($_URL) $page = _INetGetSource($_URL) $aPage = StringSplit($page, "<tr>", 1) For $a = 1 To $aPage[0] If StringRegExp($aPage[$a], $RegExJpgName) Then $_JPG = StringStripWS(StringRegExpReplace($aPage[$a], $RegExJpgName, "$2"), 1 + 2) $_NextURL = $_URL & $_JPG $_NextJPG = $SolarFolder & $_JPG If FileExists($_NextJPG) Then ContinueLoop ; that file has been downloaded before ALREADY ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_NextJPG = ' & $_NextJPG & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $result = InetGet($_NextURL, $_NextJPG, 1 + 2, 1) EndIf Next EndFunc ;==>GetJPGs 2.) When I open the first picture with Irfan View, I can use the "right" arrow to "movie" through that series of JPG files. What is the easiest way to "merge" those pics to a movie? (format doesn't matter, one that's good for androids would be nice. No experience with all that so far. I found how to split movies to one pic per frame using Irfan, but not how to merge JPGs to a movie)
       
      Any suggestions appreciated, propably there are ready-to-use tools out there I just missed, because I didn't know what to search for exactly.
       
      Or there is an easy solution to "play" the images as a movie within an Autoit GUI?
       
       
      Comment:
      Interesting points of time I've found so far are e.g.:
      2016-01-06@12:41:30 the focus on the sun was almost lost 2016-01-13@13:55:18 it's obviously a satelite cam, starting a 360° rotation at this point of time Regards, Rudi.
    • UEZ
      By UEZ
      Some Graphical Examples using GDI+ Vol. II build 2016-05-07 (33 examples)
       
      This is the continuation of "Some Graphical Examples using GDI+ Vol. I" with currently 33 examples in "snippet style".
       
      For downloads and screenshots just visit the download section.
       
      All examples should properly run on Win7+ operating systems / tested on AutoIt v3.3.14.2!
       
      More examples will follow from time to time.
       
      Thanks to Eukalyptus!
       
      Please report any issues / feel free to post any comment.
       
      Have fun.