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

## Recommended Posts

Hello,

I need help with perspective graphics, I made orthographic 3D renderer, now I want to make it perspective:

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:

Weird... What to do?

Thanks

##### Share on other sites

@algiuxas Give us some code to test

##### Share on other sites
```#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
EndIf
If \$MoveZ <> 0 then
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 \$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))
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

##### Share on other sites
1 hour ago, TheDcoder said:

@algiuxas Give us some code to test

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

##### 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 , but some clever image morphing or something . My brain hurts!

##### 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 , but some clever image morphing or something . My brain hurts!

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

##### Share on other sites
• 6 months later...

Į fixed it a long time ago

##### Share on other sites
46 minutes ago, algiuxas said:

Į fixed it a long time ago

You did? Can I see the final result?

##### Share on other sites
• 3 weeks later...
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!

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

##### Share on other sites

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

##### Share on other sites
1 minute ago, TheDcoder said:

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

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

## Create an account

Register a new account

• ### Similar Content

i tried to create a function that read a folder files to 3d array
e.g
\$array[n][0][0] = ctName
\$array[n][0][1] = ctFilePath
\$array[n][0][2] = crtsections number
\$array[n][m][0] = KeyName
\$array[n][m][1] = KeyVal
\$array[n][m][2] = keySectionName

that the array
when i put one file into the folder all things work fine
but when i put more than one file
the last file worked fine but the others only the first key is showing
please can you help me to correct this problem
here is the example with the folder

array3d.zip
• 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
• 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.
• 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 ...
#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
• 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.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...